From f5160dd8313e39ca7cbde41fc241ab6e0e2457a2 Mon Sep 17 00:00:00 2001 From: Yeongju Kang <46637297+yeongjukang@users.noreply.github.com> Date: Wed, 1 Jan 2025 17:35:47 +0900 Subject: [PATCH] Bump the otel group with 4 updates and change builder functions (#124) Signed-off-by: Yeongju Kang Signed-off-by: Yeongju Kang <979156@gmail.com> added some new lines following linter Co-authored-by: Yeongju Kang --- Cargo.lock | 25 +++++++++++++------------ Cargo.toml | 8 ++++---- README.md | 2 +- docker-compose.yaml | 22 ++++++++++++++++++++++ justfile | 5 +++-- src/telemetry.rs | 18 ++++++++++-------- 6 files changed, 53 insertions(+), 27 deletions(-) create mode 100644 docker-compose.yaml diff --git a/Cargo.lock b/Cargo.lock index 1ebab70..b8aa666 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1740,23 +1740,23 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "opentelemetry" -version = "0.26.0" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "570074cc999d1a58184080966e5bd3bf3a9a4af650c3b05047c2621e7405cd17" +checksum = "ab70038c28ed37b97d8ed414b6429d343a8bbf44c9f79ec854f3a643029ba6d7" dependencies = [ "futures-core", "futures-sink", "js-sys", - "once_cell", "pin-project-lite", "thiserror 1.0.69", + "tracing", ] [[package]] name = "opentelemetry-otlp" -version = "0.26.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29e1f9c8b032d4f635c730c0efcf731d5e2530ea13fa8bef7939ddc8420696bd" +checksum = "91cf61a1868dacc576bf2b2a1c3e9ab150af7272909e80085c3173384fe11f76" dependencies = [ "async-trait", "futures-core", @@ -1768,13 +1768,14 @@ dependencies = [ "thiserror 1.0.69", "tokio", "tonic", + "tracing", ] [[package]] name = "opentelemetry-proto" -version = "0.26.1" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9d3968ce3aefdcca5c27e3c4ea4391b37547726a70893aab52d3de95d5f8b34" +checksum = "a6e05acbfada5ec79023c85368af14abd0b307c015e9064d249b2a950ef459a6" dependencies = [ "opentelemetry", "opentelemetry_sdk", @@ -1784,16 +1785,15 @@ dependencies = [ [[package]] name = "opentelemetry_sdk" -version = "0.26.0" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2c627d9f4c9cdc1f21a29ee4bfbd6028fcb8bcf2a857b43f3abdf72c9c862f3" +checksum = "231e9d6ceef9b0b2546ddf52335785ce41252bc7474ee8ba05bfad277be13ab8" dependencies = [ "async-trait", "futures-channel", "futures-executor", "futures-util", "glob", - "once_cell", "opentelemetry", "percent-encoding", "rand", @@ -1801,6 +1801,7 @@ dependencies = [ "thiserror 1.0.69", "tokio", "tokio-stream", + "tracing", ] [[package]] @@ -2851,9 +2852,9 @@ dependencies = [ [[package]] name = "tracing-opentelemetry" -version = "0.27.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc58af5d3f6c5811462cabb3289aec0093f7338e367e5a33d28c0433b3c7360b" +checksum = "97a971f6058498b5c0f1affa23e7ea202057a7301dbff68e968b2d578bcbd053" dependencies = [ "js-sys", "once_cell", diff --git a/Cargo.toml b/Cargo.toml index eead904..943f255 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,10 +37,10 @@ serde_yaml = "0.9.25" chrono = { version = "0.4.39", features = ["serde"] } tracing = "0.1.41" tracing-subscriber = { version = "0.3.19", features = ["json", "env-filter"] } -tracing-opentelemetry = "0.27.0" -opentelemetry = { version = "0.26.0", features = ["trace"] } -opentelemetry-otlp = { version = "0.26.0", optional = true } -opentelemetry_sdk = { version = "0.26.0", features = ["rt-tokio"] } +tracing-opentelemetry = "0.28.0" +opentelemetry = { version = "0.27.1", features = ["trace"] } +opentelemetry-otlp = { version = "0.27.0", optional = true } +opentelemetry_sdk = { version = "0.27.1", features = ["rt-tokio"] } thiserror = "2.0.9" anyhow = "1.0.95" prometheus-client = "0.22.2" diff --git a/README.md b/README.md index b1d77dc..d2058ee 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ cargo run or, with optional telemetry: ```sh -OPENTELEMETRY_ENDPOINT_URL=https://0.0.0.0:55680 RUST_LOG=info,kube=trace,controller=debug cargo run --features=telemetry +OPENTELEMETRY_ENDPOINT_URL=https://0.0.0.0:4317 RUST_LOG=info,kube=trace,controller=debug cargo run --features=telemetry ``` ### In-cluster diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..460694e --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,22 @@ +version: "3" +services: + zipkin: + image: openzipkin/zipkin:latest + environment: + - JAVA_OPTS=-Xms512m -Xmx512m -XX:+ExitOnOutOfMemoryError + restart: always + ports: + - "9411:9411" + + otel-collector: + image: otel/opentelemetry-collector:latest + restart: always + command: > + --set=receivers.otlp.protocols.grpc.endpoint=0.0.0.0:4317 + --set=exporters.zipkin.endpoint=http://zipkin:9411/api/v2/spans + --set=service.pipelines.traces.receivers=[otlp] + --set=service.pipelines.traces.exporters=[zipkin] + ports: + - "4317:4317" + depends_on: + - zipkin diff --git a/justfile b/justfile index 411115a..2731078 100644 --- a/justfile +++ b/justfile @@ -12,7 +12,8 @@ generate: # run with opentelemetry run-telemetry: - OPENTELEMETRY_ENDPOINT_URL=http://127.0.0.1:55680 RUST_LOG=info,kube=debug,controller=debug cargo run --features=telemetry + docker-compose up -d + OPENTELEMETRY_ENDPOINT_URL=http://127.0.0.1:4317 RUST_LOG=info,kube=debug,controller=debug cargo run --features=telemetry # run without opentelemetry run: @@ -30,7 +31,7 @@ test-integration: install-crd cargo test -- --ignored # run telemetry tests test-telemetry: - OPENTELEMETRY_ENDPOINT_URL=http://127.0.0.1:55680 cargo test --lib --all-features -- get_trace_id_returns_valid_traces --ignored + OPENTELEMETRY_ENDPOINT_URL=http://127.0.0.1:4317 cargo test --lib --all-features -- get_trace_id_returns_valid_traces --ignored # compile for musl (for docker image) compile features="": diff --git a/src/telemetry.rs b/src/telemetry.rs index 5202712..20fdce4 100644 --- a/src/telemetry.rs +++ b/src/telemetry.rs @@ -25,16 +25,18 @@ fn resource() -> Resource { #[cfg(feature = "telemetry")] fn init_tracer() -> sdktrace::Tracer { - use opentelemetry_otlp::WithExportConfig; + use opentelemetry_otlp::{SpanExporter, WithExportConfig}; let endpoint = std::env::var("OPENTELEMETRY_ENDPOINT_URL").expect("Needs an otel collector"); - let exporter = opentelemetry_otlp::new_exporter().tonic().with_endpoint(endpoint); + let exporter = SpanExporter::builder() + .with_tonic() + .with_endpoint(endpoint) + .build() + .unwrap(); - let provider = opentelemetry_otlp::new_pipeline() - .tracing() - .with_exporter(exporter) - .with_trace_config(Config::default().with_resource(resource())) - .install_batch(runtime::Tokio) - .expect("valid tracer"); + let provider = sdktrace::TracerProvider::builder() + .with_batch_exporter(exporter, runtime::Tokio) + .with_resource(resource()) + .build(); opentelemetry::global::set_tracer_provider(provider.clone()); provider.tracer("tracing-otel-subscriber")