Skip to content
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

Disable ASGI send/receive spans by default #371

Merged
merged 11 commits into from
Aug 22, 2024
Merged

Conversation

alexmojaki
Copy link
Contributor

A user reported that generating many http receive spans significantly slowed down requests: https://pydanticlogfire.slack.com/archives/C06EDRBSAH3/p1722626116726899

In addition to these spans adding overhead in user code, they will eventually have a significant cost, since we will be charging based on the number of spans. This is out of proportion with the value they provide, especially since they're hidden by default in the UI.

So by default we're now preventing them from being created. The user can still opt in with record_send_receive=True in instrument_fastapi/starlette, in which case they will still have the debug log level.

We might want to eventually move the logic in processor_wrapper.py that sets the log level and span name to the new TweakAsgiSpansTracer. This will improve performance in general by avoiding checking whether we need to tweak every span on both start and end. But this will mean that the tweaking only works when going through instrument_* methods. At the very least this requires creating instrument_asgi.

Copy link

cloudflare-workers-and-pages bot commented Aug 8, 2024

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3198dff
Status: ✅  Deploy successful!
Preview URL: https://3ca12064.logfire-docs.pages.dev
Branch Preview URL: https://alex-record-send-receive.logfire-docs.pages.dev

View logs

# Instrument an app with request hooks to make sure that they work.
# We make a new app here instead of using the fixtures because the same app can't be instrumented twice.
# Then make a request to it to generate spans.
# The tests then check that the spans are in the right place both with and without send/receive spans.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what the spans look like:

Screenshot 2024-08-08 at 13 45 09

@alexmojaki alexmojaki requested a review from Kludex August 8, 2024 11:55
Copy link

codecov bot commented Aug 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (ffe0c25) to head (3198dff).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #371   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          126       127    +1     
  Lines         9256      9303   +47     
  Branches      1206      1211    +5     
=========================================
+ Hits          9256      9303   +47     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alexmojaki alexmojaki enabled auto-merge (squash) August 22, 2024 11:36
@alexmojaki alexmojaki merged commit b7afdd5 into main Aug 22, 2024
11 checks passed
@alexmojaki alexmojaki deleted the alex/record_send_receive branch August 22, 2024 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant