Skip to content

Add network/client span attributes and fix span status per OTEL semconv - #3750

Merged
ChrisJBurns merged 2 commits into
mainfrom
otel/pr2b-new-attributes-v2
Feb 10, 2026
Merged

ChrisJBurns merged 2 commits into
mainfrom
otel/pr2b-new-attributes-v2

Conversation

@ChrisJBurns

@ChrisJBurns ChrisJBurns commented Feb 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds new additive span attributes for better observability:
    • network.protocol.version from incoming HTTP request protocol
    • mcp.backend.protocol.version from backend transport (SSE→"1.1", streamable-http→"2")
    • client.address and client.port from RemoteAddr
    • mcp.session.id from Mcp-Session-Id header
    • error.type on 5xx errors
  • Fixes span status to follow OTEL HTTP server span semantic conventions:
    • 4xx responses → Unset (client errors, not server errors per OTEL spec)
    • 5xx responses → Error with error.type attribute
    • 2xx/3xx → Ok (unchanged)
  • Separates frontend and backend protocol versions into distinct attributes to avoid silent overwrite when they differ (e.g., HTTP/2 client with SSE/HTTP1.1 backend)
  • Extracts addNetworkAttributes helper to keep cyclomatic complexity within limits

Protocol version attributes:

Attribute Source Example
network.protocol.version Incoming HTTP request "2" (HTTP/2 client)
mcp.backend.protocol.version Backend MCP transport "1.1" (SSE backend)

Stacked on #3748 (attribute renames) and #3747 (feature flag).

Test plan

  • New unit tests for httpProtocolVersion helper
  • New unit tests for parseRemoteAddr helper
  • New tests for client.address, client.port, mcp.session.id attributes
  • Negative test for mcp.session.id when header absent
  • Test verifying HTTP/2 client + SSE backend produces distinct protocol versions
  • Updated span status tests: 4xx → Unset, 5xx → Error with error.type
  • task lint passes
  • task test passes

🤖 Generated with Claude Code

Add new additive span attributes:
- network.protocol.version from incoming HTTP request
- client.address and client.port from RemoteAddr
- mcp.session.id from Mcp-Session-Id header
- error.type on 5xx errors

Fix span status to follow OTEL semantic conventions:
- 4xx responses now leave span status Unset (client errors)
- 5xx responses set Error with error.type attribute
- 2xx/3xx remain Ok

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions Bot added the size/S Small PR: 100-299 lines changed label Feb 10, 2026
JAORMX
JAORMX previously approved these changes Feb 10, 2026
@codecov

codecov Bot commented Feb 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.41%. Comparing base (e15caa0) to head (4aa65ab).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/telemetry/middleware.go 95.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3750      +/-   ##
==========================================
+ Coverage   66.39%   66.41%   +0.01%     
==========================================
  Files         427      427              
  Lines       41864    41894      +30     
==========================================
+ Hits        27797    27825      +28     
  Misses      11956    11956              
- Partials     2111     2113       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Use network.protocol.version for the incoming HTTP request protocol
and mcp.backend.protocol.version for the backend transport protocol,
avoiding a silent overwrite when the two differ (e.g., HTTP/2 client
with SSE/HTTP1.1 backend).

Also add negative test for mcp.session.id when header is absent.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions Bot added size/S Small PR: 100-299 lines changed and removed size/S Small PR: 100-299 lines changed labels Feb 10, 2026
@ChrisJBurns
ChrisJBurns merged commit 9405bac into main Feb 10, 2026
36 checks passed
@ChrisJBurns
ChrisJBurns deleted the otel/pr2b-new-attributes-v2 branch February 10, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Small PR: 100-299 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants