question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Flask Traces Sampler Function seems to have no effect

See original GitHub issue

Environment

How do you use Sentry? Sentry SaaS (sentry.io)

Which SDK and version? sentry-sdk[flask]==1.4.1

Steps to Reproduce

  1. 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
  1. tested locally with Postman to confirm that sentry_traces_sampler goes down correct route for each endpoint
  2. 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):

Screenshot 2021-09-28 at 14-31-59 Performance - urban-jungle - Sentry Screenshot 2021-09-28 at 14-30-51 Performance - urban-jungle - Sentry

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:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
AbhiPrasadcommented, Sep 21, 2022

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!

1reaction
antonpirkercommented, Mar 7, 2022

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found