-
Notifications
You must be signed in to change notification settings - Fork 642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FastAPI auto-instrumentation sends extra trace for a single API execution #840
Comments
Are you sure it is two traces not two spans under same trace? |
@lonewolf3739 Yes I am sure that there are two traces. |
@makeavish I was unable to reproduce the issue here using your sample code. It doesn't generate two traces but only one trace with three spans. This is duplicate of #831. Please follow discussion there. Feel free to re-open if you can reproduce the issue of two traces for one request. |
@lonewolf3739 I see that you used |
@makeavish Setting sdk |
Thanks @lonewolf3739, I understood my mistake. |
I am not sure I understood your question. If you do not use the |
Describe Problem
I have a sample python project with FastAPI auto-instrumentation which export the traces to OTLP server, and I have a simple "GET" API which returns a "Hello": "World". But I notice it generates 2 traces instead of 1 for same API request. I was able to fix this issue after using
TracerProvider
from python otel sdk.Describe your environment
fastapi==0.68.1
python-dotenv==0.19.0
uvicorn==0.15.0
requests
opentelemetry-distro==0.26b1
opentelemetry-exporter-otlp==1.7.1
opentelemetry-instrumentation-fastapi==0.26b1
Steps to reproduce
Here's the sample code that I am running:
Run command:
opentelemetry-instrument --traces_exporter console uvicorn main:app
When I make the below REST request:
curl --location --request GET 'http://localhost:8000/'
then I get 2 traces which are exactly same (except for span and trace Id).
What is the expected behavior?
Exactly one trace for one API execution
What is the actual behavior?
2 traces for one API execution
Additional context
I tried initializing tracer from python otel sdk and apparently it fixed the issue and now I am seeing exactly one trace for single API execution.
Here's that code which works:
To check difference between both the code you can check this PR: SigNoz/sample-fastAPI-app#2
The text was updated successfully, but these errors were encountered: