open-telemetry / opentelemetry-python-contrib

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

Exceptions are not recorded in traces from instrumented Pyramid apps #2619

Closed rbagd closed 1 week ago

rbagd commented 1 week ago

What problem do you want to solve?

Traces resulting from Pyramid instrumentation do not record server exceptions that have resulted in errored requests. Here is the relevant output part by calling an instrumented Pyramid app.

    "status": {
        "status_code": "ERROR"
    },
    "attributes": {
        "http.method": "GET",
        ...
        "http.status_code": 500
    },
    "events": []

In case of another WSGI, e.g. Flask, errors are bubbled up in status with the traceback as a span event looking like this

    "status": {
        "status_code": "ERROR",
        "description": "ValueError: bad value"
    },
    "attributes": {
        "http.method": "GET",
        ...
        "http.status_code": 500
    },
    "events": [
        {
            "name": "exception",
            "timestamp": "2024-06-19T10:44:00.468880Z",
            "attributes": {
                "exception.type": "ValueError",
                "exception.message": "bad value",
                "exception.stacktrace": "Traceback ...",
                "exception.escaped": "False"
            }
        }
    ]

Such traces are much more valuable in troubleshooting.

Describe the solution you'd like

Implement recording of exceptions as status attributes and span events in Pyramid instrumentation, similar to how it is done for other WSGI apps.

Describe alternatives you've considered

No response

Additional Context

No response

Would you like to implement a fix?

Yes