From 50262c0f2d802cffa599e6509a61ff5e96e09daf Mon Sep 17 00:00:00 2001 From: Caleb Schoepp Date: Wed, 18 Sep 2024 11:01:47 -0600 Subject: [PATCH] Fix traces and metrics not working. Fix slow tests. Rename variable Signed-off-by: Caleb Schoepp --- crates/factor-observe/src/lib.rs | 4 ++-- crates/telemetry/src/metrics.rs | 3 +++ crates/telemetry/src/traces.rs | 4 +++- tests/integration.rs | 18 +++++++++--------- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/crates/factor-observe/src/lib.rs b/crates/factor-observe/src/lib.rs index 770338e694..71d8979d80 100644 --- a/crates/factor-observe/src/lib.rs +++ b/crates/factor-observe/src/lib.rs @@ -146,7 +146,7 @@ impl ObserveContext { }; // If there are no active guest spans then there is nothing to do - let Some(current_span_id) = state.active_spans.last() else { + let Some(active_span) = state.active_spans.last() else { return; }; @@ -166,7 +166,7 @@ impl ObserveContext { // Now reparent the current span to the last active guest span let span_context = state .guest_spans - .get(*current_span_id) + .get(*active_span) .unwrap() .inner .span_context() diff --git a/crates/telemetry/src/metrics.rs b/crates/telemetry/src/metrics.rs index 200a786a27..58e62826f5 100644 --- a/crates/telemetry/src/metrics.rs +++ b/crates/telemetry/src/metrics.rs @@ -1,6 +1,7 @@ use std::time::Duration; use anyhow::{bail, Result}; +use opentelemetry::global; use opentelemetry_otlp::MetricsExporterBuilder; use opentelemetry_sdk::{ metrics::{ @@ -57,6 +58,8 @@ pub(crate) fn otel_metrics_layer LookupSpan<'span>>( .with_resource(resource) .build(); + global::set_meter_provider(meter_provider.clone()); + Ok(MetricsLayer::new(meter_provider)) } diff --git a/crates/telemetry/src/traces.rs b/crates/telemetry/src/traces.rs index 06eb60beb8..9ec38f2b40 100644 --- a/crates/telemetry/src/traces.rs +++ b/crates/telemetry/src/traces.rs @@ -1,7 +1,7 @@ use std::time::Duration; use anyhow::bail; -use opentelemetry::trace::TracerProvider; +use opentelemetry::{global, trace::TracerProvider}; use opentelemetry_otlp::SpanExporterBuilder; use opentelemetry_sdk::{ resource::{EnvResourceDetector, TelemetryResourceDetector}, @@ -50,6 +50,8 @@ pub(crate) fn otel_tracing_layer LookupSpan<'span>>( .with_trace_config(opentelemetry_sdk::trace::Config::default().with_resource(resource)) .install_batch(opentelemetry_sdk::runtime::Tokio)?; + global::set_tracer_provider(tracer_provider.clone()); + let env_filter = match EnvFilter::try_from_env("SPIN_OTEL_TRACING_LEVEL") { Ok(filter) => filter, // If it isn't set or it fails to parse default to info diff --git a/tests/integration.rs b/tests/integration.rs index 16fd24afc1..0a293b738f 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -1425,7 +1425,7 @@ mod otel_integration_tests { }, ServicesConfig::none(), |env| { - env.set_env_var("OTEL_EXPORTER_OTLP_ENDPOINT", collector_endpoint); + env.set_env_var("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", collector_endpoint); env.set_env_var("OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", "grpc"); env.set_env_var("OTEL_BSP_SCHEDULE_DELAY", "5"); Ok(()) @@ -1468,7 +1468,7 @@ mod otel_integration_tests { }, ServicesConfig::none(), |env| { - env.set_env_var("OTEL_EXPORTER_OTLP_ENDPOINT", collector_endpoint); + env.set_env_var("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", collector_endpoint); env.set_env_var("OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", "grpc"); env.set_env_var("OTEL_BSP_SCHEDULE_DELAY", "5"); Ok(()) @@ -1538,7 +1538,7 @@ mod otel_integration_tests { }, ServicesConfig::none(), |env| { - env.set_env_var("OTEL_EXPORTER_OTLP_ENDPOINT", collector_endpoint); + env.set_env_var("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", collector_endpoint); env.set_env_var("OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", "grpc"); env.set_env_var("OTEL_BSP_SCHEDULE_DELAY", "5"); Ok(()) @@ -1603,7 +1603,7 @@ mod otel_integration_tests { }, ServicesConfig::none(), |env| { - env.set_env_var("OTEL_EXPORTER_OTLP_ENDPOINT", collector_endpoint); + env.set_env_var("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", collector_endpoint); env.set_env_var("OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", "grpc"); env.set_env_var("OTEL_BSP_SCHEDULE_DELAY", "5"); Ok(()) @@ -1664,7 +1664,7 @@ mod otel_integration_tests { }, ServicesConfig::none(), |env| { - env.set_env_var("OTEL_EXPORTER_OTLP_ENDPOINT", collector_endpoint); + env.set_env_var("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", collector_endpoint); env.set_env_var("OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", "grpc"); env.set_env_var("OTEL_BSP_SCHEDULE_DELAY", "5"); Ok(()) @@ -1726,7 +1726,7 @@ mod otel_integration_tests { }, ServicesConfig::none(), |env| { - env.set_env_var("OTEL_EXPORTER_OTLP_ENDPOINT", collector_endpoint); + env.set_env_var("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", collector_endpoint); env.set_env_var("OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", "grpc"); env.set_env_var("OTEL_BSP_SCHEDULE_DELAY", "5"); Ok(()) @@ -1792,7 +1792,7 @@ mod otel_integration_tests { }, ServicesConfig::none(), |env| { - env.set_env_var("OTEL_EXPORTER_OTLP_ENDPOINT", collector_endpoint); + env.set_env_var("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", collector_endpoint); env.set_env_var("OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", "grpc"); env.set_env_var("OTEL_BSP_SCHEDULE_DELAY", "5"); Ok(()) @@ -1850,7 +1850,7 @@ mod otel_integration_tests { }, ServicesConfig::none(), |env| { - env.set_env_var("OTEL_EXPORTER_OTLP_ENDPOINT", collector_endpoint); + env.set_env_var("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", collector_endpoint); env.set_env_var("OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", "grpc"); env.set_env_var("OTEL_BSP_SCHEDULE_DELAY", "5"); Ok(()) @@ -1907,7 +1907,7 @@ mod otel_integration_tests { }, ServicesConfig::none(), |env| { - env.set_env_var("OTEL_EXPORTER_OTLP_ENDPOINT", collector_endpoint); + env.set_env_var("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", collector_endpoint); env.set_env_var("OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", "grpc"); env.set_env_var("OTEL_BSP_SCHEDULE_DELAY", "5"); Ok(())