From dc52ef670c506ea6962dded2ec03326af5bbf44a Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Wed, 15 Jan 2025 12:02:07 -0800 Subject: [PATCH 1/5] OTLP Example fixes --- .../examples/basic-otlp-http/Cargo.toml | 6 +-- .../examples/basic-otlp-http/Dockerfile | 6 --- .../examples/basic-otlp-http/README.md | 37 +++-------------- .../basic-otlp-http/docker-compose.yaml | 15 ------- .../examples/basic-otlp-http/src/main.rs | 9 ++-- .../examples/basic-otlp/Cargo.toml | 2 +- .../examples/basic-otlp/Dockerfile | 6 --- .../examples/basic-otlp/README.md | 29 ++----------- .../examples/basic-otlp/docker-compose.yaml | 15 ------- .../src/metrics/periodic_reader.rs | 41 ++++++++----------- 10 files changed, 34 insertions(+), 132 deletions(-) delete mode 100644 opentelemetry-otlp/examples/basic-otlp-http/Dockerfile delete mode 100644 opentelemetry-otlp/examples/basic-otlp-http/docker-compose.yaml delete mode 100644 opentelemetry-otlp/examples/basic-otlp/Dockerfile delete mode 100644 opentelemetry-otlp/examples/basic-otlp/docker-compose.yaml diff --git a/opentelemetry-otlp/examples/basic-otlp-http/Cargo.toml b/opentelemetry-otlp/examples/basic-otlp-http/Cargo.toml index 242ea0c1f8..ef1595b0ae 100644 --- a/opentelemetry-otlp/examples/basic-otlp-http/Cargo.toml +++ b/opentelemetry-otlp/examples/basic-otlp-http/Cargo.toml @@ -6,14 +6,14 @@ license = "Apache-2.0" publish = false [features] +default = ["reqwest-blocking"] reqwest-blocking = ["opentelemetry-otlp/reqwest-blocking-client"] -hyper = ["opentelemetry-otlp/hyper-client"] [dependencies] once_cell = { workspace = true } opentelemetry = { path = "../../../opentelemetry" } -opentelemetry_sdk = { path = "../../../opentelemetry-sdk", features = ["rt-tokio", "experimental_metrics_periodicreader_with_async_runtime"]} -opentelemetry-otlp = { path = "../..", features = ["http-proto", "http-json", "logs", "internal-logs"]} +opentelemetry_sdk = { path = "../../../opentelemetry-sdk" } +opentelemetry-otlp = { path = "../..", features = ["http-proto", "http-json", "logs", "internal-logs"], default-features = false} opentelemetry-appender-tracing = { path = "../../../opentelemetry-appender-tracing", default-features = false} tokio = { workspace = true, features = ["full"] } diff --git a/opentelemetry-otlp/examples/basic-otlp-http/Dockerfile b/opentelemetry-otlp/examples/basic-otlp-http/Dockerfile deleted file mode 100644 index f88c276a55..0000000000 --- a/opentelemetry-otlp/examples/basic-otlp-http/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM rust:1.51 -COPY . /usr/src/basic-otlp-http/ -WORKDIR /usr/src/basic-otlp-http/ -RUN cargo build --release -RUN cargo install --path . -CMD ["/usr/local/cargo/bin/basic-otlp-http"] diff --git a/opentelemetry-otlp/examples/basic-otlp-http/README.md b/opentelemetry-otlp/examples/basic-otlp-http/README.md index 2d06e6a8fe..78ff779a66 100644 --- a/opentelemetry-otlp/examples/basic-otlp-http/README.md +++ b/opentelemetry-otlp/examples/basic-otlp-http/README.md @@ -16,46 +16,25 @@ recommended approach when using OTLP exporters. While it can be modified to use a `SimpleExporter`, this requires making the main function a regular main and *not* tokio main. -// TODO: Document `hyper` feature flag when using SimpleProcessor. +// TODO: Document how to use hyper client. ## Usage -### `docker-compose` - -By default runs against the `otel/opentelemetry-collector:latest` image, and uses `reqwest-client` -as the http client, using http as the transport. - -```shell -docker-compose up -``` - -In another terminal run the application `cargo run` - -The docker-compose terminal will display logs, traces, metrics. - -Press Ctrl+C to stop the collector, and then tear it down: - -```shell -docker-compose down -``` - -### Manual - -If you don't want to use `docker-compose`, you can manually run the `otel/opentelemetry-collector` container -and inspect the logs to see traces being transferred. +Run the `otel/opentelemetry-collector` container using docker +and inspect the logs to see the exported telemetry. On Unix based systems use: ```shell # From the current directory, run `opentelemetry-collector` -docker run --rm -it -p 4318:4318 -v $(pwd):/cfg otel/opentelemetry-collector:latest --config=/cfg/otel-collector-config.yaml +docker run --rm -it -p 4317:4317 -p 4318:4318 -v $(pwd):/cfg otel/opentelemetry-collector:latest --config=/cfg/otel-collector-config.yaml ``` On Windows use: ```shell # From the current directory, run `opentelemetry-collector` -docker run --rm -it -p 4318:4318 -v "%cd%":/cfg otel/opentelemetry-collector:latest --config=/cfg/otel-collector-config.yaml +docker run --rm -it -p 4317:4317 -p 4318:4318 -v "%cd%":/cfg otel/opentelemetry-collector:latest --config=/cfg/otel-collector-config.yaml ``` Run the app which exports logs, metrics and traces via OTLP to the collector @@ -64,11 +43,7 @@ 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 -``` +The app will use a `reqwest-blocking` client to send. ## View results diff --git a/opentelemetry-otlp/examples/basic-otlp-http/docker-compose.yaml b/opentelemetry-otlp/examples/basic-otlp-http/docker-compose.yaml deleted file mode 100644 index dc9d1e7a5d..0000000000 --- a/opentelemetry-otlp/examples/basic-otlp-http/docker-compose.yaml +++ /dev/null @@ -1,15 +0,0 @@ -version: "2" -services: - - # Collector - otel-collector: - image: otel/opentelemetry-collector:latest - command: ["--config=/etc/otel-collector-config.yaml", "${OTELCOL_ARGS}"] - volumes: - - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml - ports: - - "4318:4318" # OTLP HTTP receiver - - - - diff --git a/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs b/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs index bf33828091..ee34493f51 100644 --- a/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs +++ b/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs @@ -36,7 +36,7 @@ fn init_logs() -> Result Result { .build()?; Ok(TracerProvider::builder() - .with_batch_exporter(exporter) + .with_simple_exporter(exporter) .with_resource(RESOURCE.clone()) .build()) } @@ -69,9 +69,8 @@ fn init_metrics() -> Result Result<(), Box> { +#[tokio::main] +async fn main() -> Result<(), Box> { let logger_provider = init_logs()?; // Create a new OpenTelemetryTracingBridge using the above LoggerProvider. diff --git a/opentelemetry-otlp/examples/basic-otlp/Cargo.toml b/opentelemetry-otlp/examples/basic-otlp/Cargo.toml index 735a9470d7..f841ae5374 100644 --- a/opentelemetry-otlp/examples/basic-otlp/Cargo.toml +++ b/opentelemetry-otlp/examples/basic-otlp/Cargo.toml @@ -8,7 +8,7 @@ publish = false [dependencies] once_cell = { workspace = true } opentelemetry = { path = "../../../opentelemetry" } -opentelemetry_sdk = { path = "../../../opentelemetry-sdk", features = ["rt-tokio"] } +opentelemetry_sdk = { path = "../../../opentelemetry-sdk" } opentelemetry-otlp = { path = "../../../opentelemetry-otlp", features = ["grpc-tonic"] } tokio = { version = "1.0", features = ["full"] } opentelemetry-appender-tracing = { path = "../../../opentelemetry-appender-tracing", default-features = false} diff --git a/opentelemetry-otlp/examples/basic-otlp/Dockerfile b/opentelemetry-otlp/examples/basic-otlp/Dockerfile deleted file mode 100644 index b63241e283..0000000000 --- a/opentelemetry-otlp/examples/basic-otlp/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM rust:1.51 -COPY . /usr/src/basic-otlp/ -WORKDIR /usr/src/basic-otlp/ -RUN cargo build --release -RUN cargo install --path . -CMD ["/usr/local/cargo/bin/basic-otlp"] diff --git a/opentelemetry-otlp/examples/basic-otlp/README.md b/opentelemetry-otlp/examples/basic-otlp/README.md index ca02018ad5..f4ebe150fb 100644 --- a/opentelemetry-otlp/examples/basic-otlp/README.md +++ b/opentelemetry-otlp/examples/basic-otlp/README.md @@ -49,42 +49,21 @@ fn main() -> Result<(), Box> { ## Usage -### `docker-compose` - -By default runs against the `otel/opentelemetry-collector:latest` image, and uses the `tonic`'s -`grpc` example as the transport. - -```shell -docker-compose up -``` - -In another terminal run the application `cargo run` - -The docker-compose terminal will display logs, traces, metrics. - -Press Ctrl+C to stop the collector, and then tear it down: - -```shell -docker-compose down -``` - -### Manual - -If you don't want to use `docker-compose`, you can manually run the `otel/opentelemetry-collector` container -and inspect the logs to see traces being transferred. +Run the `otel/opentelemetry-collector` container using docker +and inspect the logs to see the exported telemetry. On Unix based systems use: ```shell # From the current directory, run `opentelemetry-collector` -docker run --rm -it -p 4317:4317 -v $(pwd):/cfg otel/opentelemetry-collector:latest --config=/cfg/otel-collector-config.yaml +docker run --rm -it -p 4317:4317 -p 4318:4318 -v $(pwd):/cfg otel/opentelemetry-collector:latest --config=/cfg/otel-collector-config.yaml ``` On Windows use: ```shell # From the current directory, run `opentelemetry-collector` -docker run --rm -it -p 4317:4317 -v "%cd%":/cfg otel/opentelemetry-collector:latest --config=/cfg/otel-collector-config.yaml +docker run --rm -it -p 4317:4317 -p 4318:4318 -v "%cd%":/cfg otel/opentelemetry-collector:latest --config=/cfg/otel-collector-config.yaml ``` Run the app which exports logs, metrics and traces via OTLP to the collector diff --git a/opentelemetry-otlp/examples/basic-otlp/docker-compose.yaml b/opentelemetry-otlp/examples/basic-otlp/docker-compose.yaml deleted file mode 100644 index fc9b3f1948..0000000000 --- a/opentelemetry-otlp/examples/basic-otlp/docker-compose.yaml +++ /dev/null @@ -1,15 +0,0 @@ -version: "2" -services: - - # Collector - otel-collector: - image: otel/opentelemetry-collector:latest - command: ["--config=/etc/otel-collector-config.yaml", "${OTELCOL_ARGS}"] - volumes: - - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml - ports: - - "4317:4317" # OTLP gRPC receiver - - - - diff --git a/opentelemetry-sdk/src/metrics/periodic_reader.rs b/opentelemetry-sdk/src/metrics/periodic_reader.rs index ad9d4ccb54..db73c142f2 100644 --- a/opentelemetry-sdk/src/metrics/periodic_reader.rs +++ b/opentelemetry-sdk/src/metrics/periodic_reader.rs @@ -26,20 +26,6 @@ const METRIC_EXPORT_INTERVAL_NAME: &str = "OTEL_METRIC_EXPORT_INTERVAL"; const METRIC_EXPORT_TIMEOUT_NAME: &str = "OTEL_METRIC_EXPORT_TIMEOUT"; /// Configuration options for [PeriodicReader]. -/// -/// A periodic reader is a [MetricReader] that collects and exports metric data -/// to the exporter at a defined interval. -/// -/// By default, the returned [MetricReader] will collect and export data every -/// 60 seconds. The export time is not counted towards the interval between -/// attempts. PeriodicReader itself does not enforce timeout. Instead timeout -/// is passed on to the exporter for each export attempt. -/// -/// The [collect] method of the returned [MetricReader] continues to gather and -/// return metric data to the user. It will not automatically send that data to -/// the exporter outside of the predefined interval. -/// -/// [collect]: MetricReader::collect #[derive(Debug)] pub struct PeriodicReaderBuilder { interval: Duration, @@ -104,20 +90,25 @@ where } } -/// A [MetricReader] that continuously collects and exports metric data at a set +/// A [MetricReader] that continuously collects and exports metrics at a set /// interval. /// -/// By default, PeriodicReader will collect and export data every -/// 60 seconds. The export time is not counted towards the interval between -/// attempts. PeriodicReader itself does not enforce timeout. -/// Instead timeout is passed on to the exporter for each export attempt. -/// -/// The [collect] method of the returned continues to gather and -/// return metric data to the user. It will not automatically send that data to -/// the exporter outside of the predefined interval. -/// +/// By default, `PeriodicReader` will collect and export metrics every 60 +/// seconds. The export time is not counted towards the interval between +/// attempts. `PeriodicReader` itself does not enforce a timeout. Instead, the +/// timeout is passed on to the configured exporter for each export attempt. +/// +/// `PeriodicReader` spawns a background thread to handle the periodic +/// collection and export of metrics. The background thread will continue to run +/// until `shutdown()` is called. +/// +/// When using this reader with the OTLP Exporter, the following exporter +/// features are supported: +/// - `grpc-tonic`: This requires `MeterProvider` to be created within a tokio +/// runtime. +/// - `reqwest-blocking-client`: Works with a regular `main` or `tokio::main`. /// -/// [collect]: MetricReader::collect +/// In other words, other clients like `reqwest` and `hyper` are not supported. /// /// # Example /// From d92da246c8753143cb0a37a27e71d5c88b86c311 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Wed, 15 Jan 2025 12:02:26 -0800 Subject: [PATCH 2/5] fmt --- opentelemetry-sdk/src/metrics/periodic_reader.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opentelemetry-sdk/src/metrics/periodic_reader.rs b/opentelemetry-sdk/src/metrics/periodic_reader.rs index db73c142f2..09d380b658 100644 --- a/opentelemetry-sdk/src/metrics/periodic_reader.rs +++ b/opentelemetry-sdk/src/metrics/periodic_reader.rs @@ -97,11 +97,11 @@ where /// seconds. The export time is not counted towards the interval between /// attempts. `PeriodicReader` itself does not enforce a timeout. Instead, the /// timeout is passed on to the configured exporter for each export attempt. -/// +/// /// `PeriodicReader` spawns a background thread to handle the periodic /// collection and export of metrics. The background thread will continue to run /// until `shutdown()` is called. -/// +/// /// When using this reader with the OTLP Exporter, the following exporter /// features are supported: /// - `grpc-tonic`: This requires `MeterProvider` to be created within a tokio From c028fc78b1d9957908406c7c7c7caea034e18814 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Wed, 15 Jan 2025 12:06:21 -0800 Subject: [PATCH 3/5] keep batch --- opentelemetry-otlp/examples/basic-otlp-http/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs b/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs index ee34493f51..763add8b50 100644 --- a/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs +++ b/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs @@ -36,7 +36,7 @@ fn init_logs() -> Result Result { .build()?; Ok(TracerProvider::builder() - .with_simple_exporter(exporter) + .with_batch_exporter(exporter) .with_resource(RESOURCE.clone()) .build()) } From a05dbda3da9945911e06b8597e27818b696dabd6 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Wed, 15 Jan 2025 12:07:43 -0800 Subject: [PATCH 4/5] spellings --- .cspell.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.cspell.json b/.cspell.json index fd5a476fb7..1cb18e2438 100644 --- a/.cspell.json +++ b/.cspell.json @@ -60,10 +60,12 @@ "reqwest", "runtimes", "rustc", + "serde", "shoppingcart", "struct", "Tescher", "testresults", + "thiserror", "tracerprovider", "updown", "Zhongyang", From 1098354c68d60ed218b0c58b829b91202c31911d Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Wed, 15 Jan 2025 12:10:58 -0800 Subject: [PATCH 5/5] add batchlog doc --- opentelemetry-sdk/src/logs/log_processor.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/opentelemetry-sdk/src/logs/log_processor.rs b/opentelemetry-sdk/src/logs/log_processor.rs index c70654ef56..9135141574 100644 --- a/opentelemetry-sdk/src/logs/log_processor.rs +++ b/opentelemetry-sdk/src/logs/log_processor.rs @@ -223,6 +223,14 @@ type LogsData = Box<(LogRecord, InstrumentationScope)>; /// - **Export timeout**: Maximum duration allowed for an export operation. /// - **Scheduled delay**: Frequency at which the batch is exported. /// +/// When using this processor with the OTLP Exporter, the following exporter +/// features are supported: +/// - `grpc-tonic`: This requires `MeterProvider` to be created within a tokio +/// runtime. +/// - `reqwest-blocking-client`: Works with a regular `main` or `tokio::main`. +/// +/// In other words, other clients like `reqwest` and `hyper` are not supported. +/// /// ### Using a BatchLogProcessor: /// /// ```rust