Skip to content

Commit

Permalink
Merge branch 'main' into background_thread_batch_log
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomsonTan authored Dec 18, 2024
2 parents aef732d + 0605341 commit 1f31465
Show file tree
Hide file tree
Showing 54 changed files with 1,623 additions and 608 deletions.
3 changes: 3 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
"nocapture",
"Ochtman",
"opentelemetry",
"OTELCOL",
"OTLP",
"periodicreader",
"protoc",
"quantile",
"Redelmeier",
Expand All @@ -59,6 +61,7 @@
"shoppingcart",
"struct",
"Tescher",
"testresults",
"tracerprovider",
"updown",
"Zhongyang",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ jobs:
if: hashFiles('Cargo.lock') == ''
run: cargo generate-lockfile
- name: cargo llvm-cov
run: cargo llvm-cov --locked --all-features --workspace --lcov --output-path lcov.info
run: cargo llvm-cov --locked --all-features --workspace --lcov --lib --output-path lcov.info
- name: Upload to codecov.io
uses: codecov/codecov-action@v4
env:
Expand Down
2 changes: 0 additions & 2 deletions examples/logs-basic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ license = "Apache-2.0"
publish = false

[dependencies]
opentelemetry = { path = "../../opentelemetry", features = ["logs"] }
opentelemetry_sdk = { path = "../../opentelemetry-sdk", features = ["logs"] }
opentelemetry-stdout = { path = "../../opentelemetry-stdout", features = ["logs"]}
opentelemetry-appender-tracing = { path = "../../opentelemetry-appender-tracing", default-features = false}
opentelemetry-semantic-conventions = { path = "../../opentelemetry-semantic-conventions" }
tracing = { workspace = true, features = ["std"]}
tracing-subscriber = { workspace = true, features = ["registry", "std"] }
1 change: 0 additions & 1 deletion examples/metrics-advanced/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ opentelemetry = { path = "../../opentelemetry", features = ["metrics"] }
opentelemetry_sdk = { path = "../../opentelemetry-sdk", features = ["spec_unstable_metrics_views", "rt-tokio"] }
opentelemetry-stdout = { path = "../../opentelemetry-stdout", features = ["metrics"] }
tokio = { workspace = true, features = ["full"] }
serde_json = { workspace = true }
1 change: 0 additions & 1 deletion examples/metrics-basic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ opentelemetry = { path = "../../opentelemetry", features = ["metrics"] }
opentelemetry_sdk = { path = "../../opentelemetry-sdk", features = ["metrics", "rt-tokio"] }
opentelemetry-stdout = { path = "../../opentelemetry-stdout", features = ["metrics"]}
tokio = { workspace = true, features = ["full"] }
serde_json = { workspace = true }

1 change: 0 additions & 1 deletion examples/tracing-grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ opentelemetry-stdout = { path = "../../opentelemetry-stdout", features = ["trace
prost = { workspace = true }
tokio = { workspace = true, features = ["full"] }
tonic = { workspace = true }
serde_json = { workspace = true }

[build-dependencies]
tonic-build = { workspace = true }
1 change: 0 additions & 1 deletion examples/tracing-jaeger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ publish = false
opentelemetry = { path = "../../opentelemetry" }
opentelemetry_sdk = { path = "../../opentelemetry-sdk", features = ["rt-tokio"] }
opentelemetry-otlp = { path = "../../opentelemetry-otlp", features = ["tonic"] }
opentelemetry-semantic-conventions = { path = "../../opentelemetry-semantic-conventions" }
tokio = { workspace = true, features = ["full"] }
7 changes: 0 additions & 7 deletions opentelemetry-otlp/examples/basic-otlp-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,9 @@ experimental_metrics_periodicreader_with_async_runtime = ["opentelemetry_sdk/exp
once_cell = { workspace = true }
opentelemetry = { path = "../../../opentelemetry" }
opentelemetry_sdk = { path = "../../../opentelemetry-sdk", features = ["rt-tokio", "experimental_metrics_periodicreader_with_async_runtime"]}
opentelemetry-http = { path = "../../../opentelemetry-http", optional = true, default-features = false}
opentelemetry-otlp = { path = "../..", features = ["http-proto", "http-json", "logs"] , default-features = false}
opentelemetry-appender-tracing = { path = "../../../opentelemetry-appender-tracing", default-features = false}
opentelemetry-semantic-conventions = { path = "../../../opentelemetry-semantic-conventions" }

async-trait = { workspace = true, optional = true }
bytes = { workspace = true, optional = true }
http = { workspace = true, optional = true }
http-body-util = { workspace = true, optional = true }
tokio = { workspace = true, features = ["full"] }
tracing = { workspace = true, features = ["std"]}
tracing-core = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter","registry", "std", "fmt"] }
6 changes: 2 additions & 4 deletions opentelemetry-otlp/examples/basic-otlp-http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ recommended approach when using OTLP exporters. While it can be modified to use
a `SimpleExporter`, this requires enabling feature flag `reqwest-blocking-client` and
making the `main()` a normal main and *not* `tokio::main`

// TODO: Metrics does not work with non tokio main when using `reqwest-blocking-client` today, fix that when switching
// TODO: Metrics does not work with non tokio main when using `reqwest-blocking-client` today, fix that when switching
// default to use own thread.
// TODO: Document `hyper` feature flag when using SimpleProcessor.

Expand Down Expand Up @@ -66,14 +66,12 @@ Run the app which exports logs, metrics and traces via OTLP to the collector
cargo run
```


By default the app will use a `reqwest` client to send. A hyper 0.14 client can be used with the `hyper` feature enabled

```shell
cargo run --no-default-features --features=hyper
```


## View results

You should be able to see something similar below with different time and ID in the same console that docker runs.
Expand Down Expand Up @@ -135,7 +133,7 @@ SpanEvent #0
-> Timestamp: 2024-05-14 02:15:56.824201397 +0000 UTC
-> DroppedAttributesCount: 0
-> Attributes::
-> bogons: Int(100)
-> some.key: Int(100)
{"kind": "exporter", "data_type": "traces", "name": "logging"}
...
```
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-otlp/examples/basic-otlp-http/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {

// Create a new tracing::Fmt layer to print the logs to stdout. It has a
// default filter of `info` level and above, and `debug` and above for logs
// from OpenTelemtry crates. The filter levels can be customized as needed.
// from OpenTelemetry crates. The filter levels can be customized as needed.
let filter_fmt = EnvFilter::new("info").add_directive("opentelemetry=debug".parse().unwrap());
let fmt_layer = tracing_subscriber::fmt::layer()
.with_thread_names(true)
Expand Down Expand Up @@ -148,7 +148,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
let span = cx.span();
span.add_event(
"Nice operation!".to_string(),
vec![KeyValue::new("bogons", 100)],
vec![KeyValue::new("some.key", 100)],
);
span.set_attribute(KeyValue::new("another.key", "yes"));

Expand Down
2 changes: 0 additions & 2 deletions opentelemetry-otlp/examples/basic-otlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ once_cell = { workspace = true }
opentelemetry = { path = "../../../opentelemetry" }
opentelemetry_sdk = { path = "../../../opentelemetry-sdk", features = ["rt-tokio"] }
opentelemetry-otlp = { path = "../../../opentelemetry-otlp" }
opentelemetry-semantic-conventions = { path = "../../../opentelemetry-semantic-conventions" }
tokio = { version = "1.0", features = ["full"] }
opentelemetry-appender-tracing = { path = "../../../opentelemetry-appender-tracing", default-features = false}
tracing = { workspace = true, features = ["std"]}
tracing-core = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter","registry", "std", "fmt"] }
4 changes: 2 additions & 2 deletions opentelemetry-otlp/examples/basic-otlp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ recommended approach when using OTLP exporters. While it can be modified to use
a `SimpleExporter`, this requires the main method to be a `tokio::main` function
since the `tonic` client requires a Tokio runtime. If you prefer not to use
`tokio::main`, then the `init_logs` and `init_traces` functions must be executed
within a Tokio runtime.
within a Tokio runtime.

This examples uses the default `PeriodicReader` for metrics, which uses own
thread for background processing/exporting. Since the `tonic` client requires a
Expand Down Expand Up @@ -154,7 +154,7 @@ SpanEvent #0
-> Timestamp: 2024-05-22 20:25:42.8770471 +0000 UTC
-> DroppedAttributesCount: 0
-> Attributes::
-> bogons: Int(100)
-> some.key: Int(100)
{"kind": "exporter", "data_type": "traces", "name": "logging"}
```

Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-otlp/examples/basic-otlp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {

// Create a new tracing::Fmt layer to print the logs to stdout. It has a
// default filter of `info` level and above, and `debug` and above for logs
// from OpenTelemtry crates. The filter levels can be customized as needed.
// from OpenTelemetry crates. The filter levels can be customized as needed.
let filter_fmt = EnvFilter::new("info").add_directive("opentelemetry=debug".parse().unwrap());
let fmt_layer = tracing_subscriber::fmt::layer()
.with_thread_names(true)
Expand Down
7 changes: 5 additions & 2 deletions opentelemetry-otlp/src/exporter/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ pub struct HttpConfig {
impl Default for HttpConfig {
fn default() -> Self {
#[cfg(feature = "reqwest-blocking-client")]
let default_client =
Some(Arc::new(reqwest::blocking::Client::new()) as Arc<dyn HttpClient>);
let default_client = std::thread::spawn(|| {
Some(Arc::new(reqwest::blocking::Client::new()) as Arc<dyn HttpClient>)
})
.join()
.expect("creating reqwest::blocking::Client on a new thread not to fail");
#[cfg(all(not(feature = "reqwest-blocking-client"), feature = "reqwest-client"))]
let default_client = Some(Arc::new(reqwest::Client::new()) as Arc<dyn HttpClient>);
#[cfg(all(
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-otlp/tests/integration_test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lcov.info
actual/*.json
25 changes: 15 additions & 10 deletions opentelemetry-otlp/tests/integration_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,32 @@ version = "0.1.0"
edition = "2021"
publish = false


[dependencies]
opentelemetry = { path = "../../../opentelemetry", features = ["metrics", "logs"] }
opentelemetry_sdk = { path = "../../../opentelemetry-sdk", features = ["rt-tokio", "logs", "testing"] }
opentelemetry-proto = { path = "../../../opentelemetry-proto", features = ["gen-tonic-messages", "trace", "logs", "with-serde"] }
opentelemetry = { path = "../../../opentelemetry", features = [] }
opentelemetry_sdk = { path = "../../../opentelemetry-sdk", features = ["rt-tokio", "testing"] }
opentelemetry-proto = { path = "../../../opentelemetry-proto", features = ["gen-tonic-messages", "trace", "logs", "metrics", "with-serde"] }
log = { workspace = true }
tokio = { version = "1.0", features = ["full"] }
serde_json = "1"
testcontainers = "0.15.0"
testcontainers = { version = "0.23.1", features = ["http_wait"]}
once_cell.workspace = true
anyhow = "1.0.94"
ctor = "0.2.9"
tracing-subscriber = { workspace = true, features = ["env-filter","registry", "std", "fmt"] }
tracing = "0.1.41"

[target.'cfg(unix)'.dependencies]
opentelemetry-appender-log = { path = "../../../opentelemetry-appender-log", default-features = false}
opentelemetry-otlp = { path = "../../../opentelemetry-otlp", default-features = false }
opentelemetry-semantic-conventions = { path = "../../../opentelemetry-semantic-conventions" }

[features]
hyper-client = ["opentelemetry-otlp/hyper-client", "opentelemetry-otlp/http-proto", "opentelemetry-otlp/trace", "opentelemetry-otlp/logs", "opentelemetry-otlp/metrics"]
reqwest-client = ["opentelemetry-otlp/reqwest-client", "opentelemetry-otlp/http-proto", "opentelemetry-otlp/trace","opentelemetry-otlp/logs", "opentelemetry-otlp/metrics"]
reqwest-blocking-client = ["opentelemetry-otlp/reqwest-blocking-client", "opentelemetry-otlp/http-proto", "opentelemetry-otlp/trace","opentelemetry-otlp/logs", "opentelemetry-otlp/metrics"]
tonic-client = ["opentelemetry-otlp/grpc-tonic", "opentelemetry-otlp/trace", "opentelemetry-otlp/logs", "opentelemetry-otlp/metrics"]
hyper-client = ["opentelemetry-otlp/hyper-client", "opentelemetry-otlp/http-proto", "opentelemetry-otlp/trace", "opentelemetry-otlp/logs", "opentelemetry-otlp/metrics", "internal-logs"]
reqwest-client = ["opentelemetry-otlp/reqwest-client", "opentelemetry-otlp/http-proto", "opentelemetry-otlp/trace","opentelemetry-otlp/logs", "opentelemetry-otlp/metrics", "internal-logs"]
reqwest-blocking-client = ["opentelemetry-otlp/reqwest-blocking-client", "opentelemetry-otlp/http-proto", "opentelemetry-otlp/trace","opentelemetry-otlp/logs", "opentelemetry-otlp/metrics", "internal-logs"]
tonic-client = ["opentelemetry-otlp/grpc-tonic", "opentelemetry-otlp/trace", "opentelemetry-otlp/logs", "opentelemetry-otlp/metrics", "internal-logs"]
internal-logs = ["opentelemetry-otlp/internal-logs"]

# Keep tonic as the default client
default = ["tonic-client"]
default = ["tonic-client", "internal-logs"]

17 changes: 17 additions & 0 deletions opentelemetry-otlp/tests/integration_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# OTLP - Integration Tests

This directory contains integration tests for `opentelemetry-otlp`. It uses
[testcontainers](https://testcontainers.com/) to start an instance of the OTEL
collector using [otel-collector-config.yaml](otel-collector-config.yaml), which
then uses a file exporter per signal to write the output it receives back to the
host machine.

The tests connect directly to the collector on `localhost:4317` and
`localhost:4318`, push data through, and then check that what they expect has
popped back out into the files output by the collector.

## Pre-requisites

* Docker, for the test container
* TCP/4317 and TCP/4318 free on your local machine. If you are running another
collector, you'll need to stop it for the tests to run.
1 change: 1 addition & 0 deletions opentelemetry-otlp/tests/integration_test/actual/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Output from the otel-collector goes here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"resourceMetrics": [
{
"resource": {
"attributes": [
{
"key": "service.name",
"value": {
"stringValue": "metrics-integration-test"
}
}
]
},
"scopeMetrics": [
{
"scope": {
"name": "meter"
},
"metrics": [
{
"name": "counter_u64",
"sum": {
"dataPoints": [
{
"attributes": [
{
"key": "mykey1",
"value": {
"stringValue": "mydifferentval"
}
},
{
"key": "mykey2",
"value": {
"stringValue": "myvalue2"
}
}
],
"startTimeUnixNano": "1734094309366798000",
"timeUnixNano": "1734094317871514000",
"asInt": "15"
}
],
"aggregationTemporality": 2,
"isMonotonic": true
}
},
{
"name": "example_histogram",
"histogram": {
"dataPoints": [
{
"attributes": [
{
"key": "mykey3",
"value": {
"stringValue": "myvalue4"
}
}
],
"startTimeUnixNano": "1734094309366875000",
"timeUnixNano": "1734094317871537000",
"count": "1",
"sum": 42,
"bucketCounts": [
"0",
"0",
"0",
"0",
"1",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0"
],
"explicitBounds": [
0,
5,
10,
25,
50,
75,
100,
250,
500,
750,
1000,
2500,
5000,
7500,
10000
],
"min": 42,
"max": 42
}
],
"aggregationTemporality": 2
}
},
{
"name": "example_up_down_counter",
"sum": {
"dataPoints": [
{
"attributes": [
{
"key": "mykey5",
"value": {
"stringValue": "myvalue5"
}
}
],
"startTimeUnixNano": "1734094309366941000",
"timeUnixNano": "1734094317871548000",
"asInt": "-1"
}
],
"aggregationTemporality": 2
}
}
]
}
]
}
]
}
Loading

0 comments on commit 1f31465

Please sign in to comment.