Skip to content

AttributeError: 'dict' object has no attribute 'f_back' in profiler thread #1958

Closed

Description

@adamchainz

How do you use Sentry?

Sentry Saas (sentry.io)

Version

1.16.0

Steps to Reproduce

Run sentry SDK with profiling on, Python 3.11

Expected Result

The thread runs fine without crashing.

Actual Result

The profiler thread (<Thread(sentry.profiler.ThreadScheduler, started daemon 140454125577984)>) fails this stack trace:

AttributeError: 'dict' object has no attribute 'f_back'
  File "threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)

Unfortunately there is no more information. It looks like the full stack trace is not captured / lost, perhaps because this is an exception within a thread?

Full screenshot from Sentry UI:

Xnapper-2023-03-15-14 21 38

It's not clear from a quick glance at the source how a dict could be ending up in the profiler thread's queue.

Activity

  1. antonpirker commented on Mar 16, 2023

    @antonpirker
    Contributor

    Hey @adamchainz !

    Thanks for reporting this. We will see if we can reproduce this!

  2. Zylphrex commented on Mar 16, 2023

    @Zylphrex
    Member

    Hey @adamchainz, are you able to share the following?

    • What frameworks do you use to run your application?
    • How do you run it?
    • How does your sentry_sdk.init look like?
    • Do you do any monkey patching in your application? Or is there some monkey patching happening from a package you use?
  3. adamchainz commented on Mar 17, 2023

    @adamchainz
    ContributorAuthor
    * What frameworks do you use to run your application?
    

    Django

    * How do you run it?
    

    Gunicorn

    * How does your `sentry_sdk.init` look like?
    
    sentry_sdk.init(
        dsn=os.environ["RAVEN_DSN"],
        integrations=[
            DjangoIntegration(),
        ],
        send_default_pii=True,
        release=GIT_HASH,
        environment=ENV,
        server_name=env("HOSTNAME"),
        request_bodies="medium",
        before_send=sentry_before_send,
        traces_sampler=traces_sampler,
        _experiments={
            "profiles_sample_rate": 1.0,
        },
    )

    sentry_before_send just drops KeyboardInterrupt

    traces_sampler returns 0.0 for some high traffic paths that don't need profiling, like the heartbeat url.

    * Do you do any monkey patching in your application? Or is there some monkey patching happening from a package you use?
    

    It's hard to audit for monkey patching, but I've grepped. I don't see any monkey patching of things from sentry_sdk or threading. There’s one patch on requests as per my blog post but that doesn't seem relevant here.

  4. LiveNL commented on Mar 20, 2023

    @LiveNL

    Not sure if helpful, but we've had the same issue also using gunicorn but instead of Django we use Flask (with python 3.11).

    Our init looks like:

    sentry_sdk.init(
        integrations=[FlaskIntegration()],
        attach_stacktrace=True,
        traces_sample_rate=1.0,
        _experiments={
            "profiles_sample_rate": 1.0,
        },
        environment=Config.APP_ENV,
    )
    

    We went back to 1.15.0, which resolved the issues for us.

  5. Zylphrex commented on Mar 20, 2023

    @Zylphrex
    Member

    Not sure if helpful, but we've had the same issue also using gunicorn but instead of Django we use Flask (with python 3.11).

    Our init looks like:

    sentry_sdk.init(
        integrations=[FlaskIntegration()],
        attach_stacktrace=True,
        traces_sample_rate=1.0,
        _experiments={
            "profiles_sample_rate": 1.0,
        },
        environment=Config.APP_ENV,
    )
    

    We went back to 1.15.0, which resolved the issues for us.

    Thanks for the additional info! That's helpful to know

  6. Zylphrex commented on Mar 20, 2023

    @Zylphrex
    Member

    @LiveNL @adamchainz One follow-up question for the two of you. Is this error preventing you from collecting profiles completely? Or is it happening occasionally and you are still able to collect some profiles?

  7. LiveNL commented on Mar 20, 2023

    @LiveNL

    The latter for us.

    Btw. the error presented itself in a few different shapes besides 'dict' object ...:
    image

  8. Zylphrex commented on Mar 20, 2023

    @Zylphrex
    Member

    Yeah, I noticed that in another report. It's not clear to me how this can be happening as I cannot reproduce it. The only thing in common from all the reports so far is that they're all from Python 3.11 which may have some edge case where the API is not returning what is expected. I have #1965 to handle these errors as there's not really anything to be done when the data being returned is bad.

  9. adamchainz commented on Mar 20, 2023

    @adamchainz
    ContributorAuthor

    @LiveNL @adamchainz One follow-up question for the two of you. Is this error preventing you from collecting profiles completely? Or is it happening occasionally and you are still able to collect some profiles?

    Same here, only happening occassionally. The profiling dash has thousands of transactions but this error has occurred 33 times.

    Also from the breadcrumbs I can tell it normally occurs a while from the server process startup, sometimes many hours.

    It may be related to Python's shutdown procedure, where threads may still be running whilst objects and classes start getting cleaned up, which could lead to attributes seeming gone or types changed?

  10. Zylphrex commented on Mar 20, 2023

    @Zylphrex
    Member

    Yeah, that's possible. In either case, it should be safe to handle these errors and ignore these samples like in the PR I linked.

  11. ghost added on Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions