Skip to content

Conversation

seun-ja
Copy link
Contributor

@seun-ja seun-ja commented Jul 17, 2025

Fixes #2811

Signed-off-by: Aminu 'Seun Joshua <seun.aminujoshua@gmail.com>
@lann
Copy link
Collaborator

lann commented Jul 17, 2025

Did anyone try this without any code changes? I think the opentelemetry crate already checks some of the standard env vars...

@lann
Copy link
Collaborator

lann commented Jul 17, 2025

@seun-ja
Copy link
Contributor Author

seun-ja commented Jul 17, 2025

Yeah, looks like they all are checked. Judging by the code base.

@seun-ja
Copy link
Contributor Author

seun-ja commented Jul 17, 2025

@lann would you suggest #2811 be closed?

Comment on lines +7 to +14
use crate::env::OtelExporterOtlpHeaders;

/// Injects the current W3C TraceContext into the provided request.
pub fn inject_trace_context<'a>(req: impl Into<HeaderInjector<'a>>) {
let mut injector = req.into();
for (key, value) in OtelExporterOtlpHeaders::headers() {
injector.set(&key, value);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We wouldn't want to inject the headers here. This is for propagating context to outgoing requests. OTEL_EXPORTER_OTLP_TRACES_HEADERS is for setting headers on requests made to the OTel collector to export traces.

@calebschoepp
Copy link
Collaborator

@seun-ja the next step here would be to run Spin off main and see if it respects these env vars already. You could point Spin at a collector that is actually just a proxy to see if the headers are being set or not.

@seun-ja
Copy link
Contributor Author

seun-ja commented Aug 12, 2025

It respects it, I ran it on main and was able to see the key-pair data parsed into the header.

sample env data provided:

export OTEL_EXPORTER_OTLP_TRACES_HEADERS="authorization=Bearer trace-token,x-trace-id=abc123"

result:
Screenshot 2025-08-12 at 3 45 38 PM

Apologies for the late response

cc: @calebschoepp

@lann lann closed this Aug 12, 2025
@seun-ja seun-ja deleted the add-support-for-otel-exporter-otlp-trace-logs-metrics-header branch August 12, 2025 19:52
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.

Support for OTEL_EXPORTER_OTLP_HEADERS/OTEL_EXPORTER_OTLP_{TRACE,LOG,METRICS}_HEADERS
3 participants