diff --git a/opentelemetry-otlp/Cargo.toml b/opentelemetry-otlp/Cargo.toml index c664570c13..a48486ad0b 100644 --- a/opentelemetry-otlp/Cargo.toml +++ b/opentelemetry-otlp/Cargo.toml @@ -83,4 +83,4 @@ reqwest-rustls-webpki-roots = ["reqwest", "opentelemetry-http/reqwest-rustls-web hyper-client = ["opentelemetry-http/hyper"] # test -integration-testing = ["tonic", "prost", "tokio/full", "trace"] +integration-testing = ["tonic", "prost", "tokio/full", "trace", "logs"] diff --git a/opentelemetry-otlp/tests/integration_test/Cargo.toml b/opentelemetry-otlp/tests/integration_test/Cargo.toml index 7828739376..413673286e 100644 --- a/opentelemetry-otlp/tests/integration_test/Cargo.toml +++ b/opentelemetry-otlp/tests/integration_test/Cargo.toml @@ -16,5 +16,15 @@ testcontainers = "0.15.0" [target.'cfg(unix)'.dependencies] opentelemetry-appender-log = { path = "../../../opentelemetry-appender-log", default-features = false} -opentelemetry-otlp = { path = "../../../opentelemetry-otlp", features = ["tonic", "metrics", "logs"] } +opentelemetry-otlp = { path = "../../../opentelemetry-otlp", default-features = false } opentelemetry-semantic-conventions = { path = "../../../opentelemetry-semantic-conventions" } + +[features] +hyper-client = ["opentelemetry-otlp/hyper-client", "opentelemetry-otlp/http-proto", "opentelemetry-otlp/trace", "opentelemetry-otlp/logs", "opentelemetry-otlp/metrics"] +reqwest-client = ["opentelemetry-otlp/reqwest-client", "opentelemetry-otlp/http-proto", "opentelemetry-otlp/trace","opentelemetry-otlp/logs", "opentelemetry-otlp/metrics"] +reqwest-blocking-client = ["opentelemetry-otlp/reqwest-blocking-client", "opentelemetry-otlp/http-proto", "opentelemetry-otlp/trace","opentelemetry-otlp/logs", "opentelemetry-otlp/metrics"] +tonic-client = ["opentelemetry-otlp/grpc-tonic", "opentelemetry-otlp/trace", "opentelemetry-otlp/logs", "opentelemetry-otlp/metrics"] + +# Keep tonic as the default client +default = ["tonic-client"] + diff --git a/opentelemetry-otlp/tests/integration_test/tests/logs.rs b/opentelemetry-otlp/tests/integration_test/tests/logs.rs index 13068d0938..86448e5c51 100644 --- a/opentelemetry-otlp/tests/integration_test/tests/logs.rs +++ b/opentelemetry-otlp/tests/integration_test/tests/logs.rs @@ -12,7 +12,18 @@ use std::fs::File; use std::os::unix::fs::MetadataExt; fn init_logs() -> Result { - let exporter = LogExporter::builder().with_tonic().build()?; + let exporter_builder = LogExporter::builder(); + #[cfg(feature = "tonic-client")] + let exporter_builder = exporter_builder.with_tonic(); + #[cfg(not(feature = "tonic-client"))] + #[cfg(any( + feature = "hyper-client", + feature = "reqwest-client", + feature = "reqwest-blocking-client" + ))] + let exporter_builder = exporter_builder.with_http(); + + let exporter = exporter_builder.build()?; Ok(LoggerProvider::builder() .with_batch_exporter(exporter, runtime::Tokio) diff --git a/opentelemetry-otlp/tests/integration_test/tests/traces.rs b/opentelemetry-otlp/tests/integration_test/tests/traces.rs index a8556e33e1..fe5d185536 100644 --- a/opentelemetry-otlp/tests/integration_test/tests/traces.rs +++ b/opentelemetry-otlp/tests/integration_test/tests/traces.rs @@ -8,6 +8,8 @@ use opentelemetry::{ trace::{TraceContextExt, Tracer}, Key, KeyValue, }; +use opentelemetry_otlp::SpanExporter; + use opentelemetry_proto::tonic::trace::v1::TracesData; use opentelemetry_sdk::{runtime, trace as sdktrace, Resource}; use std::error::Error; @@ -16,9 +18,19 @@ use std::io::Write; use std::os::unix::fs::MetadataExt; fn init_tracer_provider() -> Result { - let exporter = opentelemetry_otlp::SpanExporter::builder() - .with_tonic() - .build()?; + let exporter_builder = SpanExporter::builder(); + #[cfg(feature = "tonic-client")] + let exporter_builder = exporter_builder.with_tonic(); + #[cfg(not(feature = "tonic-client"))] + #[cfg(any( + feature = "hyper-client", + feature = "reqwest-client", + feature = "reqwest-blocking-client" + ))] + let exporter_builder = exporter_builder.with_http(); + + let exporter = exporter_builder.build()?; + Ok(opentelemetry_sdk::trace::TracerProvider::builder() .with_batch_exporter(exporter, runtime::Tokio) .with_resource(Resource::new(vec![KeyValue::new( diff --git a/scripts/integration_tests.sh b/scripts/integration_tests.sh index acdf61bbb9..07b9d472ba 100755 --- a/scripts/integration_tests.sh +++ b/scripts/integration_tests.sh @@ -1 +1,20 @@ -cd ./opentelemetry-otlp/tests/integration_test/tests && cargo test -- --ignored +set -e +TEST_DIR="./opentelemetry-otlp/tests/integration_test/tests" + +if [ -d "$TEST_DIR" ]; then + cd "$TEST_DIR" + # Run tests with the grpc-tonic feature + cargo test --no-default-features --features "tonic-client" -- --ignored + + # Run tests with the reqwest-client feature + cargo test --no-default-features --features "reqwest-client" -- --ignored + + # TODO - Uncomment the following lines once the reqwest-blocking-client feature is working. + # cargo test --no-default-features --features "reqwest-blocking-client" -- --ignored + + # Run tests with the hyper-client feature + cargo test --no-default-features --features "hyper-client" -- --ignored +else + echo "Directory $TEST_DIR does not exist. Skipping tests." + exit 1 +fi