Flask Traces Sampler Function seems to have no effect
See original GitHub issueEnvironment
How do you use Sentry? Sentry SaaS (sentry.io)
Which SDK and version? sentry-sdk[flask]==1.4.1
Steps to Reproduce
- Changed from previous code:
sentry_sdk.init(
dsn=sentry_dsn,
traces_sample_rate=0.1,
environment=sentry_environment,
attach_stacktrace=True,
integrations=[
FlaskIntegration(),
sentry_logging,
],
)
to
sentry_sdk.init(
dsn=sentry_dsn,
traces_sampler=sentry_traces_sampler,
environment=sentry_environment,
attach_stacktrace=True,
integrations=[
FlaskIntegration(),
sentry_logging,
],
)
where
def sentry_traces_sampler(sampling_context):
try:
# wsgi_environ is populated by sentry flask integration
# https://docs.sentry.io/platforms/python/guides/flask/configuration/sampling/
request_uri = sampling_context['wsgi_environ']['REQUEST_URI']
except KeyError:
return 0.1
if request_uri == "/ping":
# very low rate as these are extremely frequent and pretty useless
return 0.001
if request_uri in {
"/api/xml/home_aaa_request",
"/api/xml/home_bbb_request",
"/api/xml/home_ccc_request",
"/api/xml/home_ddd_request",
}:
# lower rate as these are very frequent
return 0.01
# default sample rate
return 0.1
- tested locally with Postman to confirm that
sentry_traces_sampler
goes down correct route for each endpoint - released to production
Expected Result
Number of traced requests to API endpoints should drop to < 10% of previous value.
Actual Result
Number of transactions stays roughly same as before. Screenshots showing the release which was roughly 10:00 (28/09/2021):
Assuming that requests haven’t spiked hugely, we should expect to see a dramatic drop in transactions per minute around that time, but it is roughly the same.
One hypothesis is that the try/except catch default value of 0.1 is being hit in production but not locally (I’ll test this now), but it seems possible that the sentry_traces_sampler
return values are not being interpreted correctly?
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Catching a 500 server error in Flask - python - Stack Overflow
I want to catch Python errors when something goes wrong an exception is raised in the code. Is that possible? I should note...
Read more >Sampling for Flask - Sentry Documentation
Sampling Transaction Events We recommend sampling your transactions for two reasons: Capturing a single trace involves minimal overhead, but capturing traces ...
Read more >Handling Application Errors — Flask Documentation (2.2.x)
This can be done by registering error handlers. An error handler is a function that returns a response when a type of error...
Read more >Interactive comment on “Flask sample measurements for CO2 ...
Flask samples can be first analyzed for other trace gases with the ... corrected this effect by employing the water correction function offered...
Read more >Measuring Gas Fluxes in a Flask System with the LI-8250 ...
The LI-8250 Multiplexer system is typically used to measure fluxes of trace gases from soil in situ with actuated chambers. However, with the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @mfumagalli68 - could you open a new issue to track with code snippets, versions of sdk + fastapi you’re using, and your traces sampler config? Thanks!
Hey @AdamUrbanJungle Sorry for taking so long to reply. Can you confirm that this is still an Issue in our newest SDK? If yes, I will try to reproduce this. Thanks!