Skip to content

Commit

Permalink
Integration test for non tokio main
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas committed Jan 15, 2025
1 parent b53c19e commit 1adcf62
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn init_tracing() {
// Initialize the tracing subscriber with the OpenTelemetry layer and the
// Fmt layer.
tracing_subscriber::registry().with(fmt_layer).init();
otel_info!(name: "tracing initializing completed!");
otel_info!(name: "tracing::fmt initializing completed! SDK internal logs will be printed to stdout.");
});
}

Expand Down
11 changes: 4 additions & 7 deletions opentelemetry-otlp/tests/integration_test/tests/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ mod logtests {
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
#[cfg(not(feature = "hyper-client"))]
#[cfg(not(feature = "reqwest-client"))]
pub async fn test_logs() -> Result<()> {
// Make sure the container is running

pub async fn logs_batch() -> Result<()> {
use integration_test_runner::test_utils;
use opentelemetry_appender_tracing::layer;
use tracing::info;
Expand All @@ -88,8 +86,7 @@ mod logtests {
let _guard = tracing::subscriber::set_default(subscriber);
info!(target: "my-target", "hello from {}. My price is {}.", "banana", 2.99);
}
// TODO: remove below wait before calling logger_provider.shutdown()
// tokio::time::sleep(Duration::from_secs(10)).await;

let _ = logger_provider.shutdown();

tokio::time::sleep(Duration::from_secs(10)).await;
Expand All @@ -99,7 +96,7 @@ mod logtests {
Ok(())
}

#[ignore = "TODO: [Fix Me] Failing on CI. Needs to be investigated and resolved."]
//#[ignore = "TODO: [Fix Me] Failing on CI. Needs to be investigated and resolved."]
#[test]
#[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))]
pub fn logs_batch_non_tokio_main() -> Result<()> {
Expand All @@ -122,7 +119,7 @@ mod logtests {
info!(target: "my-target", "hello from {}. My price is {}.", "banana", 2.99);
}
let _ = logger_provider.shutdown();
// tokio::time::sleep(Duration::from_secs(10)).await;
std::thread::sleep(Duration::from_secs(10));
assert_logs_results(test_utils::LOGS_FILE, "expected/logs.json")?;

Ok(())
Expand Down
48 changes: 40 additions & 8 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@
**`experimental_metrics_periodicreader_with_async_runtime`**.

Migration Guide:

1. *Default Implementation, requires no async runtime* (**Recommended**) The
1. *Default Implementation, requires no async runtime* (**Recommended**) The
new default implementation does not require a runtime argument. Replace the
builder method accordingly:
- *Before:*
- *Before:*
```rust
let reader = opentelemetry_sdk::metrics::PeriodicReader::builder(exporter, runtime::Tokio).build();
```
Expand All @@ -71,21 +70,31 @@
let reader = opentelemetry_sdk::metrics::PeriodicReader::builder(exporter).build();
```

The new PeriodicReader can be used with OTLP Exporter, and supports
following exporter features:
- `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.

2. *Async Runtime Support*
If your application cannot spin up new threads or you prefer using async
runtimes, enable the
"experimental_metrics_periodicreader_with_async_runtime" feature flag and
adjust code as below.

- *Before:*

```rust
let reader = opentelemetry_sdk::metrics::PeriodicReader::builder(exporter, runtime::Tokio).build();
```

- *After:*

```rust
let reader = opentelemetry_sdk::metrics::periodic_reader_with_async_runtime::PeriodicReader::builder(exporter, runtime::Tokio).build();
```
```

*Requirements:*
- Enable the feature flag:
Expand All @@ -104,11 +113,10 @@
- Getter methods have been introduced to access field values.
This change impacts custom exporter and processor developers by requiring updates to code that directly accessed LogRecord fields. They must now use the provided getter methods (e.g., `log_record.event_name()` instead of `log_record.event_name`).

- Upgrade the tracing crate used for internal logging to version 0.1.40 or later. This is necessary because the internal logging macros utilize the name field as
- Upgrade the tracing crate used for internal logging to version 0.1.40 or later. This is necessary because the internal logging macros utilize the name field as
metadata, a feature introduced in version 0.1.40. [#2418](https://github.com/open-telemetry/opentelemetry-rust/pull/2418)

- **Breaking** [#2436](https://github.com/open-telemetry/opentelemetry-rust/pull/2436)

- *Breaking* - `BatchLogProcessor` Updates [#2436](https://github.com/open-telemetry/opentelemetry-rust/pull/2436)
`BatchLogProcessor` no longer requires an async runtime by default. Instead, a dedicated
background thread is created to do the batch processing and exporting.

Expand All @@ -120,33 +128,45 @@ metadata, a feature introduced in version 0.1.40. [#2418](https://github.com/ope
new default implementation does not require a runtime argument. Replace the
builder method accordingly:
- *Before:*

```rust
let logger_provider = LoggerProvider::builder()
.with_log_processor(BatchLogProcessor::builder(exporter, runtime::Tokio).build())
.build();
```

- *After:*

```rust
let logger_provider = LoggerProvider::builder()
.with_log_processor(BatchLogProcessor::builder(exporter).build())
.build();
```

The new BatchLogProcessor can be used with OTLP Exporter, and supports
following exporter features:
- `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.

2. *Async Runtime Support*
If your application cannot spin up new threads or you prefer using async
runtimes, enable the
"experimental_logs_batch_log_processor_with_async_runtime" feature flag and
adjust code as below.

- *Before:*

```rust
let logger_provider = LoggerProvider::builder()
.with_log_processor(BatchLogProcessor::builder(exporter, runtime::Tokio).build())
.build();
```

- *After:*

```rust
let logger_provider = LoggerProvider::builder()
.with_log_processor(log_processor_with_async_runtime::BatchLogProcessor::builder(exporter, runtime::Tokio).build())
Expand All @@ -159,7 +179,7 @@ metadata, a feature introduced in version 0.1.40. [#2418](https://github.com/ope
- Continue enabling one of the async runtime feature flags: `rt-tokio`,
`rt-tokio-current-thread`, or `rt-async-std`.

- **Breaking** [#2456](https://github.com/open-telemetry/opentelemetry-rust/pull/2456)
- *Breaking* - `BatchSpanProcessor` Updates [#2435](https://github.com/open-telemetry/opentelemetry-rust/pull/2456)

`BatchSpanProcessor` no longer requires an async runtime by default. Instead, a dedicated
background thread is created to do the batch processing and exporting.
Expand All @@ -172,33 +192,45 @@ metadata, a feature introduced in version 0.1.40. [#2418](https://github.com/ope
new default implementation does not require a runtime argument. Replace the
builder method accordingly:
- *Before:*

```rust
let tracer_provider = TracerProvider::builder()
.with_span_processor(BatchSpanProcessor::builder(exporter, runtime::Tokio).build())
.build();
```

- *After:*

```rust
let tracer_provider = TracerProvider::builder()
.with_span_processor(BatchSpanProcessor::builder(exporter).build())
.build();
```

The new BatchLogProcessor can be used with OTLP Exporter, and supports
following exporter features:
- `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.

2. *Async Runtime Support*
If your application cannot spin up new threads or you prefer using async
runtimes, enable the
"experimental_trace_batch_span_processor_with_async_runtime" feature flag and
adjust code as below.

- *Before:*

```rust
let tracer_provider = TracerProvider::builder()
.with_span_processor(BatchSpanProcessor::builder(exporter, runtime::Tokio).build())
.build();
```

- *After:*

```rust
let tracer_provider = TracerProvider::builder()
.with_span_processor(span_processor_with_async_runtime::BatchSpanProcessor::builder(exporter, runtime::Tokio).build())
Expand Down

0 comments on commit 1adcf62

Please sign in to comment.