open-telemetry / opentelemetry-cpp-contrib

https://opentelemetry.io/
Apache License 2.0
121 stars 130 forks source link

Nginx OpenTelemetry module not setting span status to error when HTTP status_code is in the 5xx range #269

Open ghitabot-vg opened 1 year ago

ghitabot-vg commented 1 year ago

Describe your environment Describe any aspect of your environment relevant to the problem, including your platform, build system, version numbers of installed dependencies, etc. If you're reporting a problem with a specific version of a library in this repo, please check whether the problem has been fixed on main branch. Nginx 1.21.6 opentelemetry module autoinstrumented from this image: registry.k8s.io/ingress-nginx/opentelemetry@sha256:40f766ac4a9832f36f217bb0e98d44c8d38faeccbfe861fbc1a76af7e9ab257f (but the current master branch has the same issue)

When Nginx Open Telemetry instrumentation is enabled using the otel_ngx_module.so module, the spans created from Nginx don't have a status, even if the HTTP status code is 500.

Here is an example location set to return 500:

location = /errorTest/ {
     opentelemetry on;
     opentelemetry_propagate;
     opentelemetry_trust_incoming_spans on;
     return 500 'Error !!';
}
And you can see the OpenTelemetry span data: Attribute Value
http.flavor "1.1"
http.host http host
http.method "GET"
http.scheme "http"
http.server_name
http.status_code 500
http.target "/errorTest/"
http.user_agent "Chrome/111.0.0.0 Safari/537.36"
net.host.port 80
net.peer.ip peer ip
net.peer.port 54456
otel.library.name "nginx"
span.kind "server"
status.code 0
Resource Value
service.name "test_service"
telemetry.sdk.language "cpp"
telemetry.sdk.name "opentelemetry"
telemetry.sdk.version "1.8.1"

I would expect, per the documentation from here and here to have the span status set as error (status.code = 2) instead of Unset (0).

Steps to reproduce Start Nginx with OpenTelemetry module enabled, create a location in the default server with the following specs:

location = /errorTest/ {
     opentelemetry on;
     opentelemetry_propagate;
     opentelemetry_trust_incoming_spans on;
     return 500 'Error !!';
}

Make a call to the /errorTest location, then look for OpenTelemetry data to see that the span status is not set to Error.

What is the expected behavior? When the http status is in the 5xx range, the span status to be set to Error.

What is the actual behavior? Span status is not set in any scenario (regardles of the http status code)

Additional context We are trying to export the OpenTelemetry data to Instana and due to missing Span status, the erroneous calls are not properly identified.

sbquinlan commented 3 months ago

Any update or workaround for this? This feels like very basic missing functionality.

aryanishan1001 commented 2 months ago

You can try using the otel-webserver-module instrumentation. I dont think they have this issue.