Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Few fixes to OTLP Exporter Examples #2518

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@
"reqwest",
"runtimes",
"rustc",
"serde",
"shoppingcart",
"struct",
"Tescher",
"testresults",
"thiserror",
"tracerprovider",
"updown",
"Zhongyang",
Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-otlp/examples/basic-otlp-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
6 changes: 0 additions & 6 deletions opentelemetry-otlp/examples/basic-otlp-http/Dockerfile

This file was deleted.

37 changes: 6 additions & 31 deletions opentelemetry-otlp/examples/basic-otlp-http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
15 changes: 0 additions & 15 deletions opentelemetry-otlp/examples/basic-otlp-http/docker-compose.yaml

This file was deleted.

5 changes: 2 additions & 3 deletions opentelemetry-otlp/examples/basic-otlp-http/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ fn init_metrics() -> Result<opentelemetry_sdk::metrics::SdkMeterProvider, Metric
.build())
}

// #[tokio::main]
// TODO: Re-enable tokio::main, if needed, after
fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
let logger_provider = init_logs()?;

// Create a new OpenTelemetryTracingBridge using the above LoggerProvider.
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-otlp/examples/basic-otlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
6 changes: 0 additions & 6 deletions opentelemetry-otlp/examples/basic-otlp/Dockerfile

This file was deleted.

29 changes: 4 additions & 25 deletions opentelemetry-otlp/examples/basic-otlp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,42 +49,21 @@ fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {

## 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
Expand Down
15 changes: 0 additions & 15 deletions opentelemetry-otlp/examples/basic-otlp/docker-compose.yaml

This file was deleted.

8 changes: 8 additions & 0 deletions opentelemetry-sdk/src/logs/log_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 14 additions & 23 deletions opentelemetry-sdk/src/metrics/periodic_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<E> {
interval: Duration,
Expand Down Expand Up @@ -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.
/// 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.
///
/// 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.
/// `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
///
Expand Down
Loading