open-telemetry / opentelemetry-python-contrib

OpenTelemetry instrumentation for Python modules
https://opentelemetry.io
Apache License 2.0
648 stars 535 forks source link

http.server.duration has http.status_code attribute set only when span is recording #1876

Open FelipeLema opened 1 year ago

FelipeLema commented 1 year ago

using opentelemetry.instrumentation.asgi.OpenTelemetryMiddleware with the following packages installed

Steps to reproduce

What is the expected behavior?

Seeing status code as attribute for http.server.duration regardless of whether we're recording spans or not

What is the actual behavior?

Not seeing status code as attribute for http.server.duration when not recording spans

Additional context

sk- commented 8 months ago

Note that we would need to change the interception of the status code in the otel send function to always extract the status code and make it available, so that we can set it in the finally blcok were additional attributes are set.