Skip to content

fix: align OTel server span status with HTTP semantic conventions#1672

Merged
ernado merged 4 commits into
ogen-go:mainfrom
totomojp:fix/otel-server-span-status
May 19, 2026
Merged

fix: align OTel server span status with HTTP semantic conventions#1672
ernado merged 4 commits into
ogen-go:mainfrom
totomojp:fix/otel-server-span-status

Conversation

@totomojp
Copy link
Copy Markdown
Contributor

@totomojp totomojp commented May 9, 2026

Fixes #1671

Summary

Fixes OTel server span status handling in generated response encoders to follow the HTTP semantic conventions.

Generated server code now:

  • leaves 1xx/2xx/3xx responses as Unset
  • leaves 4xx responses as Unset
  • sets codes.Error only for 5xx responses

This is a follow-up to #1477. That PR fixed part of the server span error condition, but the generated response encoder still marked 4xx responses as Error and successful responses as Ok.

Motivation

For server spans, 4xx responses are client-side errors and should not be reported as server span errors. Also, OTel instrumentation should not set span status to Ok for successful HTTP responses unless explicitly configured to do so.

Reference:

https://opentelemetry.io/docs/specs/semconv/http/http-spans/#status

Changes

  • Update gen/_template/response_encode.tmpl to set span status only for 5xx responses.
  • Add span status integration coverage for:
    • fixed 2xx/4xx/5xx responses
    • dynamic status-code responses
    • generated error responses
    • handler error paths
    • webhooks
  • Regenerate affected generated files.

Out of scope

Response encoding or response write failures after a non-5xx status has already been written are a related but separate issue and are not addressed by this PR.

@totomojp totomojp force-pushed the fix/otel-server-span-status branch from 8682ef1 to 3086e2a Compare May 9, 2026 14:57
@ernado ernado merged commit 40e5c31 into ogen-go:main May 19, 2026
15 checks passed
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.

server: OTel server spans set incorrect status for 4xx and successful responses

2 participants