Skip to content

Commit fbcba3b

Browse files
authored
Enable metric integration test for req-blocking (open-telemetry#2445)
1 parent 9011f63 commit fbcba3b

File tree

5 files changed

+35
-21
lines changed

5 files changed

+35
-21
lines changed

.cspell.json

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"shoppingcart",
6262
"struct",
6363
"Tescher",
64+
"testresults",
6465
"tracerprovider",
6566
"updown",
6667
"Zhongyang",

opentelemetry-otlp/tests/integration_test/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ testcontainers = { version = "0.23.1", features = ["http_wait"]}
1515
once_cell.workspace = true
1616
anyhow = "1.0.94"
1717
ctor = "0.2.9"
18-
tracing-subscriber = "0.3.19"
18+
tracing-subscriber = { workspace = true, features = ["env-filter","registry", "std", "fmt"] }
1919
tracing = "0.1.41"
2020

2121
[target.'cfg(unix)'.dependencies]
@@ -28,7 +28,7 @@ hyper-client = ["opentelemetry-otlp/hyper-client", "opentelemetry-otlp/http-prot
2828
reqwest-client = ["opentelemetry-otlp/reqwest-client", "opentelemetry-otlp/http-proto", "opentelemetry-otlp/trace","opentelemetry-otlp/logs", "opentelemetry-otlp/metrics", "internal-logs"]
2929
reqwest-blocking-client = ["opentelemetry-otlp/reqwest-blocking-client", "opentelemetry-otlp/http-proto", "opentelemetry-otlp/trace","opentelemetry-otlp/logs", "opentelemetry-otlp/metrics", "internal-logs"]
3030
tonic-client = ["opentelemetry-otlp/grpc-tonic", "opentelemetry-otlp/trace", "opentelemetry-otlp/logs", "opentelemetry-otlp/metrics", "internal-logs"]
31-
internal-logs = []
31+
internal-logs = ["opentelemetry-otlp/internal-logs"]
3232

3333
# Keep tonic as the default client
3434
default = ["tonic-client", "internal-logs"]
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# OTLP - Integration Tests
2-
This directory contains integration tests for `opentelemetry-otlp`. It uses
3-
[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.
42

5-
The tests connect directly to the collector on `localhost:4317` and `localhost:4318`, push data through, and then check that what they expect
6-
has popped back out into the files output by the collector.
3+
This directory contains integration tests for `opentelemetry-otlp`. It uses
4+
[testcontainers](https://testcontainers.com/) to start an instance of the OTEL
5+
collector using [otel-collector-config.yaml](otel-collector-config.yaml), which
6+
then uses a file exporter per signal to write the output it receives back to the
7+
host machine.
8+
9+
The tests connect directly to the collector on `localhost:4317` and
10+
`localhost:4318`, push data through, and then check that what they expect has
11+
popped back out into the files output by the collector.
12+
13+
## Pre-requisites
714

8-
For this to work, you need a couple of things:
915
* Docker, for the test container
10-
* 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
16+
* TCP/4317 and TCP/4318 free on your local machine. If you are running another
17+
collector, you'll need to stop it for the tests to run.

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

+14-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ use std::sync::{Arc, Mutex, Once, OnceLock};
2727
use testcontainers::core::wait::HttpWaitStrategy;
2828
use testcontainers::core::{ContainerPort, Mount};
2929
use testcontainers::{core::WaitFor, runners::AsyncRunner, ContainerAsync, GenericImage, ImageExt};
30-
use tracing_subscriber::FmtSubscriber;
30+
use tracing_subscriber::layer::SubscriberExt;
31+
use tracing_subscriber::util::SubscriberInitExt;
32+
use tracing_subscriber::{EnvFilter, Layer};
3133

3234
// Static references for container management
3335
static COLLECTOR_ARC: OnceLock<Mutex<Option<Arc<ContainerAsync<GenericImage>>>>> = OnceLock::new();
@@ -40,13 +42,17 @@ static INIT_TRACING: Once = Once::new();
4042

4143
fn init_tracing() {
4244
INIT_TRACING.call_once(|| {
43-
let subscriber = FmtSubscriber::builder()
44-
.with_max_level(tracing::Level::DEBUG)
45-
.finish();
46-
47-
tracing::subscriber::set_global_default(subscriber)
48-
.expect("Failed to set tracing subscriber");
49-
otel_info!(name: "init_tracing");
45+
// Info and above for all, debug for opentelemetry
46+
let filter_fmt =
47+
EnvFilter::new("info").add_directive("opentelemetry=debug".parse().unwrap());
48+
let fmt_layer = tracing_subscriber::fmt::layer()
49+
.with_thread_names(true)
50+
.with_filter(filter_fmt);
51+
52+
// Initialize the tracing subscriber with the OpenTelemetry layer and the
53+
// Fmt layer.
54+
tracing_subscriber::registry().with(fmt_layer).init();
55+
otel_info!(name: "tracing initializing completed!");
5056
});
5157
}
5258

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async fn init_metrics() -> SdkMeterProvider {
3030
let exporter = create_exporter();
3131

3232
let reader = PeriodicReader::builder(exporter)
33-
.with_interval(Duration::from_millis(100))
33+
.with_interval(Duration::from_millis(500))
3434
.with_timeout(Duration::from_secs(1))
3535
.build();
3636

@@ -146,7 +146,7 @@ async fn setup_metrics_test() -> Result<()> {
146146
println!("Running setup before any tests...");
147147
*done = true; // Mark setup as done
148148

149-
// Initialise the metrics subsystem
149+
// Initialize the metrics subsystem
150150
_ = init_metrics().await;
151151
}
152152

@@ -184,13 +184,13 @@ pub fn validate_metrics_against_results(scope_name: &str) -> Result<()> {
184184
}
185185

186186
///
187-
/// TODO - the HTTP metrics exporters do not seem to flush at the moment.
187+
/// TODO - the HTTP metrics exporters except reqwest-blocking-client do not seem
188+
/// to work at the moment.
188189
/// TODO - fix this asynchronously.
189190
///
190191
#[cfg(test)]
191192
#[cfg(not(feature = "hyper-client"))]
192193
#[cfg(not(feature = "reqwest-client"))]
193-
#[cfg(not(feature = "reqwest-blocking-client"))]
194194
mod tests {
195195

196196
use super::*;
@@ -293,7 +293,7 @@ mod tests {
293293
// Set up the exporter
294294
let exporter = create_exporter();
295295
let reader = PeriodicReader::builder(exporter)
296-
.with_interval(Duration::from_millis(100))
296+
.with_interval(Duration::from_secs(30))
297297
.with_timeout(Duration::from_secs(1))
298298
.build();
299299
let resource = Resource::builder_empty()

0 commit comments

Comments
 (0)