Skip to content

Commit

Permalink
Bump the otel group with 4 updates and change builder functions (#124)
Browse files Browse the repository at this point in the history
Signed-off-by: Yeongju Kang <[email protected]>
Signed-off-by: Yeongju Kang <[email protected]>

added some new lines following linter

Co-authored-by: Yeongju Kang <[email protected]>
  • Loading branch information
yeongjukang and Yeongju Kang authored Jan 1, 2025
1 parent d98ebe8 commit f5160dd
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 27 deletions.
25 changes: 13 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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="":
Expand Down
18 changes: 10 additions & 8 deletions src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit f5160dd

Please sign in to comment.