Skip to content

Commit 6a9ad55

Browse files
committed
Add logging to int tests to help debug
1 parent 23801b9 commit 6a9ad55

File tree

3 files changed

+37
-24
lines changed

3 files changed

+37
-24
lines changed

opentelemetry-otlp/tests/integration_test/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ testcontainers = "0.15.0"
1515
once_cell.workspace = true
1616
anyhow = "1.0.94"
1717
ctor = "0.2.9"
18+
tracing-subscriber = "0.3.19"
19+
tracing = "0.1.41"
1820

1921
[target.'cfg(unix)'.dependencies]
2022
opentelemetry-appender-log = { path = "../../../opentelemetry-appender-log", default-features = false}
@@ -26,7 +28,8 @@ hyper-client = ["opentelemetry-otlp/hyper-client", "opentelemetry-otlp/http-prot
2628
reqwest-client = ["opentelemetry-otlp/reqwest-client", "opentelemetry-otlp/http-proto", "opentelemetry-otlp/trace","opentelemetry-otlp/logs", "opentelemetry-otlp/metrics"]
2729
reqwest-blocking-client = ["opentelemetry-otlp/reqwest-blocking-client", "opentelemetry-otlp/http-proto", "opentelemetry-otlp/trace","opentelemetry-otlp/logs", "opentelemetry-otlp/metrics"]
2830
tonic-client = ["opentelemetry-otlp/grpc-tonic", "opentelemetry-otlp/trace", "opentelemetry-otlp/logs", "opentelemetry-otlp/metrics"]
31+
internal-logs = []
2932

3033
# Keep tonic as the default client
31-
default = ["tonic-client"]
34+
default = ["tonic-client", "internal-logs"]
3235

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

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
use std::collections::HashMap;
2222
use std::fs::File;
2323
use std::os::unix::fs::PermissionsExt;
24-
use std::sync::{Arc, Mutex, OnceLock};
24+
use std::sync::{Arc, Mutex, Once, OnceLock};
2525
use testcontainers::clients::Cli;
2626
use testcontainers::core::{Port, WaitFor};
2727
use testcontainers::{Container, Image, RunnableImage};
28+
use tracing_subscriber::FmtSubscriber;
29+
use opentelemetry::{otel_debug, otel_info};
2830

2931
// Static references for container management
3032
static COLLECTOR_ARC: OnceLock<Mutex<Option<Arc<Container<Collector>>>>> = OnceLock::new();
@@ -38,7 +40,23 @@ pub static METRICS_FILE: &str = "./actual/metrics.json";
3840
pub static LOGS_FILE: &str = "./actual/logs.json";
3941
pub static TRACES_FILE: &str = "./actual/traces.json";
4042

43+
static INIT_TRACING: Once = Once::new();
44+
45+
fn init_tracing() {
46+
INIT_TRACING.call_once(|| {
47+
let subscriber = FmtSubscriber::builder()
48+
.with_max_level(tracing::Level::DEBUG)
49+
.finish();
50+
51+
tracing::subscriber::set_global_default(subscriber)
52+
.expect("Failed to set tracing subscriber");
53+
otel_info!(name: "init_tracing");
54+
});
55+
}
56+
4157
pub async fn start_collector_container() {
58+
init_tracing();
59+
4260
let docker = DOCKER_CLIENT.get_or_init(init_docker_client);
4361
let mut arc_guard = COLLECTOR_ARC
4462
.get_or_init(|| Mutex::new(None))
@@ -54,17 +72,16 @@ pub async fn start_collector_container() {
5472

5573
// Start a new container
5674
let image = Collector::default();
57-
let mut runnable_image = RunnableImage::from(image);
58-
59-
// Map ports
60-
for port in [4317, 4318] {
61-
runnable_image = runnable_image.with_mapped_port(Port {
62-
local: port,
63-
internal: port,
64-
});
65-
}
75+
let runnable_image =
76+
RunnableImage::from(image)
77+
.with_mapped_port(Port::from((4317, 4317)))
78+
.with_mapped_port(Port::from((4318, 4318)));
6679

67-
let container = Arc::new(docker.run(runnable_image));
80+
let container_instance = docker.run(runnable_image);
81+
let container = Arc::new(container_instance);
82+
otel_debug!(
83+
name: "Container started",
84+
ports = format!("{:?}", container.ports()));
6885

6986
// Store the container in COLLECTOR_ARC
7087
*arc_guard = Some(Arc::clone(&container));
@@ -87,13 +104,13 @@ fn upsert_empty_file(path: &str) -> File {
87104
/// suite shutting down!
88105
///
89106
pub fn stop_collector_container() {
90-
println!("Trying to shutdown");
107+
otel_debug!(name: "stop_collector_container");
91108
if let Some(container) = COLLECTOR_ARC
92109
.get()
93110
.and_then(|arc_lock| arc_lock.lock().unwrap().take())
94111
{
95112
container.stop();
96-
println!("Collector container stopped.");
113+
otel_debug!(name: "stop_collector_container::stopped");
97114
}
98115
}
99116

@@ -119,13 +136,6 @@ impl Image for Collector {
119136
fn volumes(&self) -> Box<dyn Iterator<Item = (&String, &String)> + '_> {
120137
Box::new(self.volumes.iter())
121138
}
122-
123-
fn expose_ports(&self) -> Vec<u16> {
124-
vec![
125-
// 4317, // gRPC port, defined in Dockerfile
126-
// 4318, // HTTP port, defined in Dockerfile
127-
]
128-
}
129139
}
130140

131141
impl Default for Collector {

scripts/integration_tests.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ if [ -d "$TEST_DIR" ]; then
66
cd "$TEST_DIR"
77

88
# Run tests with the grpc-tonic feature
9-
cargo test --no-default-features --features "tonic-client"
9+
cargo test --no-default-features --features "tonic-client","internal-logs"
1010

1111
# Run tests with the reqwest-client feature
12-
cargo test --no-default-features --features "reqwest-client"
12+
cargo test --no-default-features --features "reqwest-client","internal-logs"
1313

1414
# TODO - Uncomment the following lines once the reqwest-blocking-client feature is working.
1515
# cargo test --no-default-features --features "reqwest-blocking-client"
1616

1717
# Run tests with the hyper-client feature
18-
cargo test --no-default-features --features "hyper-client"
18+
cargo test --no-default-features --features "hyper-client","internal-logs"
1919
else
2020
echo "Directory $TEST_DIR does not exist. Skipping tests."
2121
exit 1

0 commit comments

Comments
 (0)