Skip to content

Commit

Permalink
Add OTLP integration test for hyper and request client for logs and t…
Browse files Browse the repository at this point in the history
…races (#2312)

Co-authored-by: Zhongyang Wu <[email protected]>
Co-authored-by: Cijo Thomas <[email protected]>
  • Loading branch information
3 people authored Dec 2, 2024
1 parent 5b6e9b9 commit c225c82
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 7 deletions.
2 changes: 1 addition & 1 deletion opentelemetry-otlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
12 changes: 11 additions & 1 deletion opentelemetry-otlp/tests/integration_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

13 changes: 12 additions & 1 deletion opentelemetry-otlp/tests/integration_test/tests/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@ use std::fs::File;
use std::os::unix::fs::MetadataExt;

fn init_logs() -> Result<sdklogs::LoggerProvider, LogError> {
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)
Expand Down
18 changes: 15 additions & 3 deletions opentelemetry-otlp/tests/integration_test/tests/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,9 +18,19 @@ use std::io::Write;
use std::os::unix::fs::MetadataExt;

fn init_tracer_provider() -> Result<sdktrace::TracerProvider, TraceError> {
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(
Expand Down
21 changes: 20 additions & 1 deletion scripts/integration_tests.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c225c82

Please sign in to comment.