open-telemetry / open-telemetry/opentelemetry-python-contrib

Incompatible with CORSMiddleware app

Open
#4,031 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
1.1k
Forks
1.1k
Avg merge
4d 15h
Merged PRs (30d)
16

Description

Describe your environment

OS: any
Python version: any
Package version: 0.60b0

What happened?

https://github.com/open-telemetry/opentelemetry-python-contrib/blob/46a0d1dd2f458744ed72357c83fd908848717746/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py#L336

https://github.com/fastapi/fastapi/discussions/8027

Steps to Reproduce
from typing import Optional
from starlette.middleware.cors import CORSMiddleware
from fastapi import FastAPI


fastapi_app = FastAPI()
app = CORSMiddleware(app=fastapi_app, allow_origins=['*'])
FastAPIInstrumentor.instrument_app(app)
Expected Result

Compatible with CORSMiddleware app.

Actual Result

Skipping FastAPI instrumentation due ... got CORSMiddleware.

Additional context

No response

Would you like to implement a fix?

None

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/init.py around line 336 and reproduce the provided CORSMiddleware example. Trace FastAPIInstrumentor.instrument_app(app) and confirm that instrumentation no longer skips a CORSMiddleware-wrapped app.

Written by the indexing model from the issue text.

Assessment

Tech stack
fastapi, python
Domain
backend, observability
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.