Skip to content

Emit otel metrics directly instead of through tracing - #3623

Open
rylev wants to merge 2 commits into
mainfrom
direct-otel-metrics
Open

Emit otel metrics directly instead of through tracing#3623
rylev wants to merge 2 commits into
mainfrom
direct-otel-metrics

Conversation

@rylev

@rylev rylev commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Alternative to #3619

Instead of doing some compile time magic, we instead get rid of our dependency on tracing for emitting metrics and instead emit the otel metrics directly.

This does require duplicating macros to specify types as as far as I can tell we can't infer the type param we need to pass to the opentelemetry::metrics types.

I also deleted some tests in crates/connection-semaphore/src/lib.rs where were testing that we were emitting specific metrics. This is harder to test with the new implementation, and I'm not convinced we actually got that much out of those tests.

Signed-off-by: Ryan Levick <rlevick@akamai.com>
Comment thread crates/telemetry/src/metrics.rs Outdated
@lann

lann commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

This does require duplicating macros to specify types as as far as I can tell we can't infer the type param we need to pass to the opentelemetry::metrics types.

This seems more robust than what tracing-opentelemetry does anyway: https://docs.rs/tracing-opentelemetry/latest/tracing_opentelemetry/struct.MetricsLayer.html#floating-point-numbers

Comment thread crates/telemetry/src/lib.rs
Comment thread crates/telemetry/src/metrics.rs Outdated

@lann lann left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor quibbles. I think this is better than tracing.

pub use propagation::extract_trace_context;
pub use propagation::inject_trace_context;

/// Initializes telemetry for Spin using the [tracing] library.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this should be updated to mention that it sets the global metrics provider. An LLM might read it...

@calebschoepp calebschoepp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach a lot more

Comment thread crates/telemetry/src/metrics.rs Outdated
Comment thread crates/telemetry/src/lib.rs Outdated
Comment thread crates/telemetry/src/metrics.rs Outdated
Comment thread crates/telemetry/src/lib.rs
@rylev
rylev force-pushed the direct-otel-metrics branch from 869e2a3 to b22447f Compare July 28, 2026 15:55
Signed-off-by: Ryan Levick <rlevick@akamai.com>
@rylev
rylev force-pushed the direct-otel-metrics branch from b22447f to 625b120 Compare July 28, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants