Skip to content

profiles_sample_rate as string causes Django to not bootstrap. #4294

Closed as not planned

Description

@jreeter

How do you use Sentry?

Sentry Saas (sentry.io)

Version

2.22.0

Steps to Reproduce

Set traces and profile rates to strings:

traces_sample_rate="1",
profiles_sample_rate="1",

Expected Result

For Django to bootstrap and run and/or for traces and profiles sample rates to either both accept strings or both fail, either way they should be consistent it seems.

Actual Result

To adjust profile and sample rates on the fly we add them to a centralized store as strings. However,
this surfaced an inconsistency, setting profiles_sample_rate as a string causes Django to not bootstrap.

Output

 File "/Users/jree/.pyenv/versions/3.11.4/envs/shepherd-3.11/lib/python3.11/site-packages/sentry_sdk/profiler/transaction_profiler.py", line 127, in has_profiling_enabled
    if profiles_sample_rate is not None and profiles_sample_rate > 0:
                                            ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '>' not supported between instances of 'str' and 'int'

This only affects profiles_sample_rate, traces_sample_rate is not affected by this.

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Apr 14, 2025
  2. szokeasaurusrex commented on Apr 15, 2025

    @szokeasaurusrex
    Member

    @jreeter profiles_sample_rate and traces_sample_rate are both typed as Optional[float]. Passing any other type, including str, is not supported. The SDK's behavior when passing an invalid type is undefined, meaning that it might work fine or it might not; it might error, or could fail silently; it could get stuck in an infinite loop, or your app could crash. In particular, we don't guarantee that passing invalid types will result in the same behavior for both traces_sample_rate and profiles_sample_rate.

    tldr: the SDK is behaving as expected, from our end there is nothing to do here; please pass float values instead of str for both of these. If you are storing the values as strings, you need to convert them to float values before passing them to the SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions