Skip to content

FastAPI instrumentor stops recording exception event starting v0.55b0 #3637

@RogerHYang

Description

@RogerHYang

Describe your environment

OS: MacOS
Python version: (e.g., Python 3.13)
Package version: (e.g., 0.56b0)

What happened?

Starting 0.55b0, exception event is no longer captured. Screenshot below shows that the span has ended before it gets to record the exception.

Image

Steps to Reproduce

Below is a script to reproduce the issue. By changing the version from 0.55b0 down to 0.54b1, we can see the exception event in the span. But for 0.55b0 onward, the span has no event.

# /// script
# dependencies = [
#   "fastapi",
#   "uvicorn",
#   "opentelemetry-sdk",
#   "opentelemetry-instrumentation-fastapi==0.55b0",
# ]
# ///
from fastapi import FastAPI
import uvicorn
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor

tracer_provider = TracerProvider()
tracer_provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))
trace.set_tracer_provider(tracer_provider)
tracer = trace.get_tracer(__name__)

app = FastAPI()
FastAPIInstrumentor.instrument_app(app)

@app.get("/")
def root():
    raise RuntimeError()

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8000)

Expected Result

exception event should be recorded

Actual Result

empty event list

Additional context

No response

Would you like to implement a fix?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions