Skip to content

Fix OTel tracing of HTTP headers#709

Merged
colega merged 5 commits into
mainfrom
fix-otel-http-headers-tracing
Jun 5, 2025
Merged

Fix OTel tracing of HTTP headers#709
colega merged 5 commits into
mainfrom
fix-otel-http-headers-tracing

Conversation

@colega

@colega colega commented Jun 5, 2025

Copy link
Copy Markdown
Contributor

OTel tracing of HTTP headers was broken, as we were using the LabelerFromContext which actually labels metrics, not adds tracing attributes.

I fixed headers tracing, introducing an exclusion list similar to the one we use in logging.

I also added tests for OTel tracing: I had to move these under server/internal/ because since both Jaeger and OTel tracing set up a global state, they need to run in different test packages.

I took a slightly different approach for excluded headers: instead of just silently skipping them, I've added a trace attribute saying they were present in the request: that will likely make debugging easier.

Ref: #707

What this PR does:

Which issue(s) this PR fixes:

Fixes #

Checklist

  • Tests updated
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

colega added 2 commits June 5, 2025 17:21
OTel tracing of HTTP headers was broken, as we were using the
LabelerFromContext which actually labels metrics, not adds tracing
attributes.

I fixed headers tracing, introducing an exclusion list similar to the
one we use in logging.

I also added tests for OTel tracing: I had to move these under
server/internal/ because since both Jaeger and OTel tracing set up a
global state, they need to run in different test packages.

I took a slightly different approach for excluded headers: instead of
just silently skipping them, I've added a trace attribute saying they
were present in the request: that will likely make debugging easier.

Ref: #707

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
@colega colega marked this pull request as ready for review June 5, 2025 15:26
@colega colega requested a review from Copilot June 5, 2025 15:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the OpenTelemetry tracing of HTTP headers by correctly using tracing attributes and excluding specific headers, and adds dedicated tests to validate the changes.

  • Updated server configuration to support tracing header options.
  • Refactored middleware to use a new tracer implementation and updated header-exclusion handling.
  • Added/updated test files under server/internal for both OpenTelemetry and OpenTracing.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
server/server.go Added config flags and updated tracer usage for header tracing.
server/internal/oteltest/server_otel_test.go Added tests for OTel tracing including header exclusion behavior.
server/internal/opentracingtest/server_opentracing_test.go Refactored package name and fixed references to server instance.
middleware/logging.go Renamed the default excluded headers variable and updated dump function.
middleware/http_tracing.go Introduced NewTracer and revised tracing middleware to add header attributes.
CHANGELOG.md Added a bugfix entry for HTTP headers in OTel tracing.


if t.traceHeaders {
headers := maps.Keys(r.Header)
const maxHeadersToAddAsSpanAttributes = 100

Copilot AI Jun 5, 2025

Copy link

Choose a reason for hiding this comment

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

Consider moving the constant 'maxHeadersToAddAsSpanAttributes' to a package-level declaration to avoid using a magic number and facilitate future adjustments.

Suggested change
const maxHeadersToAddAsSpanAttributes = 100

Copilot uses AI. Check for mistakes.

@tcard tcard left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM (FWIW), just a few nitpicks and micro-optimization suggestions.

Comment thread middleware/http_tracing.go Outdated
Comment thread middleware/http_tracing.go Outdated
Comment thread middleware/http_tracing.go Outdated
Comment thread middleware/http_tracing.go
Comment thread middleware/http_tracing.go
Comment thread middleware/http_tracing.go Outdated
colega added 3 commits June 5, 2025 18:32
Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
@colega colega merged commit 8a9c353 into main Jun 5, 2025
9 checks passed
@colega colega deleted the fix-otel-http-headers-tracing branch June 5, 2025 17:55
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