Skip to content

Add ability to control metric output level through spin_telemetry cargo feature#3619

Closed
rylev wants to merge 1 commit into
mainfrom
control-telemetry
Closed

Add ability to control metric output level through spin_telemetry cargo feature#3619
rylev wants to merge 1 commit into
mainfrom
control-telemetry

Conversation

@rylev

@rylev rylev commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

This gives embedders a way to control at which level telemetry should be emitted at. I think this is the best way to allow metrics which are emitted deep from within Spin's codebase to still be controlled by embedders which may choose to statically strip out traces and would thus never see these metrics.

…go feature

Signed-off-by: Ryan Levick <rlevick@akamai.com>
@rylev
rylev requested review from calebschoepp and lann July 16, 2026 12:28
@lann

lann commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

It would be a larger change but I'd be inclined to switch metrics to use opentelemetry directly rather than through the wonky tracing interface.

Ok(MetricsLayer::new(meter_provider))
}

// The two mutually exclusive features cannot both select a default level.

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.

FWIW we do already have cfg-if in the dep tree...

Looking forward to bumping the MSRV too.

Comment on lines +92 to +98
#[cfg(all(
feature = "metrics-default-level-debug",
feature = "metrics-default-level-info"
))]
compile_error!(
"features `metrics-default-level-debug` and `metrics-default-level-info` are mutually exclusive"
);

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.

Given that these are sort of "logically additive" it would be nice to treat this the same as just enabling metrics-default-level-info so that --all-features doesn't break.

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.

...though annoyingly that already appears to be broken by llm-metal / llm-cublas.

@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.

It would be a larger change but I'd be inclined to switch metrics to use opentelemetry directly rather than through the wonky tracing interface.

I share the same desire, but not blocking of course.

@rylev

rylev commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator Author

It would be a larger change but I'd be inclined to switch metrics to use opentelemetry directly rather than through the wonky tracing interface.

@lann @calebschoepp I'd be fine with this, but that would be a breaking change. Not sure how we want to handle that.

@calebschoepp

Copy link
Copy Markdown
Collaborator

@lann @calebschoepp I'd be fine with this, but that would be a breaking change. Not sure how we want to handle that.

Breaking change for embedders, or for something else I'm misunderstanding?

@lann

lann commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Not if they're using the macros! 😅

@rylev

rylev commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator Author

For all users of spin. It's not a breaking code change, but if we use opentelemetry directly, users of spin will suddenly start seeing metrics even if they had previously filtered them out with RUST_LOG=info before.

@lann

lann commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

I think you already have to opt-in with env vars don't you?

/// Returns a boolean indicating if the OTEL metrics layer should be enabled.
///
/// It is considered enabled if any of the following environment variables are set and not empty:
/// - `OTEL_EXPORTER_OTLP_ENDPOINT`
/// - `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`
///
/// Note that this is overridden if OTEL_SDK_DISABLED is set and not empty.
pub fn otel_metrics_enabled() -> bool {
any_vars_set(&[
OTEL_EXPORTER_OTLP_ENDPOINT,
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT,
]) && !otel_sdk_disabled()
}

@calebschoepp

Copy link
Copy Markdown
Collaborator

For all users of spin. It's not a breaking code change, but if we use opentelemetry directly, users of spin will suddenly start seeing metrics even if they had previously filtered them out with RUST_LOG=info before.

I personally don't see this as a problem. I'd be really surprised if people were explicitly using RUST_LOG to filter out metrics while still opting into forwarding stuff to the OTel collector. The fact that metrics can be filtered out by RUST_LOG is just a weird side effect of our implementation that I think we should move away from.

@itowlson

Copy link
Copy Markdown
Collaborator

I see two approvals but a lot of ongoing discussion. Should I merge this or are folks thinking there is more work/thought needed?

@rylev

rylev commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator Author

@itowlson I've provided an alternative implementation in #3623 - let's see what @lann and @calebschoepp think

@rylev

rylev commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator Author

Closing in favor of #3623

@rylev rylev closed this Jul 17, 2026
@rylev
rylev deleted the control-telemetry branch July 17, 2026 15:50
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.

4 participants