Skip to content

Commit

Permalink
Fix traces and metrics not working. Fix slow tests. Rename variable
Browse files Browse the repository at this point in the history
Signed-off-by: Caleb Schoepp <[email protected]>
  • Loading branch information
calebschoepp committed Sep 24, 2024
1 parent 5fea155 commit 50262c0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions crates/factor-observe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions crates/telemetry/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::time::Duration;

use anyhow::{bail, Result};
use opentelemetry::global;
use opentelemetry_otlp::MetricsExporterBuilder;
use opentelemetry_sdk::{
metrics::{
Expand Down Expand Up @@ -57,6 +58,8 @@ pub(crate) fn otel_metrics_layer<S: Subscriber + for<'span> LookupSpan<'span>>(
.with_resource(resource)
.build();

global::set_meter_provider(meter_provider.clone());

Ok(MetricsLayer::new(meter_provider))
}

Expand Down
4 changes: 3 additions & 1 deletion crates/telemetry/src/traces.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -50,6 +50,8 @@ pub(crate) fn otel_tracing_layer<S: Subscriber + for<'span> 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
Expand Down
18 changes: 9 additions & 9 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -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(())
Expand Down

0 comments on commit 50262c0

Please sign in to comment.