fix(tracing): semconv v1.27.0→v1.34.0, fix mcp.tool_call attribute misuse, add server.address#6683
Conversation
…ibute, add server.address, defer fwdSpan.End()
There was a problem hiding this comment.
Pull request overview
This PR updates the gateway’s OpenTelemetry instrumentation to align with newer semantic conventions (semconv v1.34.0) and fixes attribute usage on non-HTTP/internal spans, while improving proxy forwarding span metadata for upstream visibility.
Changes:
- Upgraded semconv imports from
v1.27.0tov1.34.0across tracing/proxy code. - Replaced hand-rolled
gen_ai.*attribute keys with official semconv constants and introducedmcp.response.statusfor internal MCP spans. - Improved proxy forwarding span lifecycle handling and added
server.addressattribution for upstream tracing.
Show a summary per file
| File | Description |
|---|---|
| internal/tracing/provider.go | Bumps semconv import to v1.34.0 for provider/resource attributes. |
| internal/tracing/provider_test.go | Updates tests to match semconv v1.34.0 import. |
| internal/tracing/http.go | Updates HTTP span wrapper to semconv v1.34.0 import. |
| internal/tracing/genai_attrs.go | Re-exports official gen_ai keys and adds mcp.response.status. |
| internal/server/unified.go | Stops using HTTP status semconv on an internal span; uses mcp.response.status instead. |
| internal/proxy/proxy.go | Adds Server.upstreamHost() helper for server.address attribution. |
| internal/proxy/handler.go | Adds server.address to forward span and defers span end for safety. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 7/7 changed files
- Comments generated: 2
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Fixed in the latest commit. The |
Addresses several OTel correctness and best-practice issues identified in the go-fan module review: a semantic attribute mismatch on an internal span, manual gen_ai key definitions that duplicated official semconv, and minor span hygiene gaps.
Semconv upgrade (
v1.27.0→v1.34.0)Updated the import alias in all four files that reference semconv. v1.34.0 is bundled with the already-pinned
go.opentelemetry.io/otel@v1.43.0— no module version bump required.genai_attrs.go: replace manual constants with official semconv aliasesThe five
gen_ai.*keys were hand-rolled strings. They're now aliases to the officialsemconv/v1.34.0constants, eliminating drift risk. Call sites are unchanged — the alias type is identical (attribute.Key).Added
MCPResponseStatus = attribute.Key("mcp.response.status")for the conceptual HTTP status on internal MCP spans.unified.go: fix semantic mismatch onmcp.tool_callspanmcp.tool_callisSpanKindInternal— settinghttp.response.status_codeon it violates the OTel spec (that attribute is reserved for HTTP client/server spans). Replaced with the newmcp.response.statuskey.proxy/handler.go: span hygienesemconv.ServerAddressKey(upstream hostname) to theproxy.backend.forwardspan for upstream visibility in trace backends. Extracted via a newServer.upstreamHost()helper.fwdSpan.End()todefer fwdSpan.End()to prevent span leaks if early-return paths are introduced by future refactors.