Skip to content

Commit 1adcf62

Browse files
committed
Integration test for non tokio main
1 parent b53c19e commit 1adcf62

File tree

3 files changed

+45
-16
lines changed

3 files changed

+45
-16
lines changed

opentelemetry-otlp/tests/integration_test/src/test_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn init_tracing() {
5252
// Initialize the tracing subscriber with the OpenTelemetry layer and the
5353
// Fmt layer.
5454
tracing_subscriber::registry().with(fmt_layer).init();
55-
otel_info!(name: "tracing initializing completed!");
55+
otel_info!(name: "tracing::fmt initializing completed! SDK internal logs will be printed to stdout.");
5656
});
5757
}
5858

opentelemetry-otlp/tests/integration_test/tests/logs.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ mod logtests {
7070
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
7171
#[cfg(not(feature = "hyper-client"))]
7272
#[cfg(not(feature = "reqwest-client"))]
73-
pub async fn test_logs() -> Result<()> {
74-
// Make sure the container is running
75-
73+
pub async fn logs_batch() -> Result<()> {
7674
use integration_test_runner::test_utils;
7775
use opentelemetry_appender_tracing::layer;
7876
use tracing::info;
@@ -88,8 +86,7 @@ mod logtests {
8886
let _guard = tracing::subscriber::set_default(subscriber);
8987
info!(target: "my-target", "hello from {}. My price is {}.", "banana", 2.99);
9088
}
91-
// TODO: remove below wait before calling logger_provider.shutdown()
92-
// tokio::time::sleep(Duration::from_secs(10)).await;
89+
9390
let _ = logger_provider.shutdown();
9491

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

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

128125
Ok(())

opentelemetry-sdk/CHANGELOG.md

+40-8
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,10 @@
5858
**`experimental_metrics_periodicreader_with_async_runtime`**.
5959

6060
Migration Guide:
61-
62-
1. *Default Implementation, requires no async runtime* (**Recommended**) The
61+
1. *Default Implementation, requires no async runtime* (**Recommended**) The
6362
new default implementation does not require a runtime argument. Replace the
6463
builder method accordingly:
65-
- *Before:*
64+
- *Before:*
6665
```rust
6766
let reader = opentelemetry_sdk::metrics::PeriodicReader::builder(exporter, runtime::Tokio).build();
6867
```
@@ -71,21 +70,31 @@
7170
let reader = opentelemetry_sdk::metrics::PeriodicReader::builder(exporter).build();
7271
```
7372

73+
The new PeriodicReader can be used with OTLP Exporter, and supports
74+
following exporter features:
75+
- `grpc-tonic`: This requires `MeterProvider` to be created within a tokio
76+
runtime.
77+
- `reqwest-blocking-client`: Works with a regular `main` or `tokio::main`.
78+
79+
In other words, other clients like `reqwest` and `hyper` are not supported.
80+
7481
2. *Async Runtime Support*
7582
If your application cannot spin up new threads or you prefer using async
7683
runtimes, enable the
7784
"experimental_metrics_periodicreader_with_async_runtime" feature flag and
7885
adjust code as below.
7986

8087
- *Before:*
88+
8189
```rust
8290
let reader = opentelemetry_sdk::metrics::PeriodicReader::builder(exporter, runtime::Tokio).build();
8391
```
8492

8593
- *After:*
94+
8695
```rust
8796
let reader = opentelemetry_sdk::metrics::periodic_reader_with_async_runtime::PeriodicReader::builder(exporter, runtime::Tokio).build();
88-
```
97+
```
8998

9099
*Requirements:*
91100
- Enable the feature flag:
@@ -104,11 +113,10 @@
104113
- Getter methods have been introduced to access field values.
105114
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`).
106115

107-
- 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
116+
- 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
108117
metadata, a feature introduced in version 0.1.40. [#2418](https://github.com/open-telemetry/opentelemetry-rust/pull/2418)
109118

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

@@ -120,33 +128,45 @@ metadata, a feature introduced in version 0.1.40. [#2418](https://github.com/ope
120128
new default implementation does not require a runtime argument. Replace the
121129
builder method accordingly:
122130
- *Before:*
131+
123132
```rust
124133
let logger_provider = LoggerProvider::builder()
125134
.with_log_processor(BatchLogProcessor::builder(exporter, runtime::Tokio).build())
126135
.build();
127136
```
128137

129138
- *After:*
139+
130140
```rust
131141
let logger_provider = LoggerProvider::builder()
132142
.with_log_processor(BatchLogProcessor::builder(exporter).build())
133143
.build();
134144
```
135145

146+
The new BatchLogProcessor can be used with OTLP Exporter, and supports
147+
following exporter features:
148+
- `grpc-tonic`: This requires `MeterProvider` to be created within a tokio
149+
runtime.
150+
- `reqwest-blocking-client`: Works with a regular `main` or `tokio::main`.
151+
152+
In other words, other clients like `reqwest` and `hyper` are not supported.
153+
136154
2. *Async Runtime Support*
137155
If your application cannot spin up new threads or you prefer using async
138156
runtimes, enable the
139157
"experimental_logs_batch_log_processor_with_async_runtime" feature flag and
140158
adjust code as below.
141159

142160
- *Before:*
161+
143162
```rust
144163
let logger_provider = LoggerProvider::builder()
145164
.with_log_processor(BatchLogProcessor::builder(exporter, runtime::Tokio).build())
146165
.build();
147166
```
148167

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

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

164184
`BatchSpanProcessor` no longer requires an async runtime by default. Instead, a dedicated
165185
background thread is created to do the batch processing and exporting.
@@ -172,33 +192,45 @@ metadata, a feature introduced in version 0.1.40. [#2418](https://github.com/ope
172192
new default implementation does not require a runtime argument. Replace the
173193
builder method accordingly:
174194
- *Before:*
195+
175196
```rust
176197
let tracer_provider = TracerProvider::builder()
177198
.with_span_processor(BatchSpanProcessor::builder(exporter, runtime::Tokio).build())
178199
.build();
179200
```
180201

181202
- *After:*
203+
182204
```rust
183205
let tracer_provider = TracerProvider::builder()
184206
.with_span_processor(BatchSpanProcessor::builder(exporter).build())
185207
.build();
186208
```
187209

210+
The new BatchLogProcessor can be used with OTLP Exporter, and supports
211+
following exporter features:
212+
- `grpc-tonic`: This requires `MeterProvider` to be created within a tokio
213+
runtime.
214+
- `reqwest-blocking-client`: Works with a regular `main` or `tokio::main`.
215+
216+
In other words, other clients like `reqwest` and `hyper` are not supported.
217+
188218
2. *Async Runtime Support*
189219
If your application cannot spin up new threads or you prefer using async
190220
runtimes, enable the
191221
"experimental_trace_batch_span_processor_with_async_runtime" feature flag and
192222
adjust code as below.
193223

194224
- *Before:*
225+
195226
```rust
196227
let tracer_provider = TracerProvider::builder()
197228
.with_span_processor(BatchSpanProcessor::builder(exporter, runtime::Tokio).build())
198229
.build();
199230
```
200231

201232
- *After:*
233+
202234
```rust
203235
let tracer_provider = TracerProvider::builder()
204236
.with_span_processor(span_processor_with_async_runtime::BatchSpanProcessor::builder(exporter, runtime::Tokio).build())

0 commit comments

Comments
 (0)