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
Metrics not sent on program exit #2983
Comments
Possibly related: #687 |
This is because in Python 3.12 you can't start a new thread at interpreter shutdown. If you just let the program finish, the atexit hook will try to get the transport to send the pending events, but since the transport worker doesn't have a thread running yet, it first has to try to start one -- which fails here. If you We can look into improving this but I'm not sure how likely this is to happen in real world usage. Usually the worker thread has already been set up so there's no need to start it at shutdown. We could probably start it right away instead of on demand, but that could lead to issues on setups that fork the process the SDK is running in. |
@sentrivana Thank you for the detailed explanation. It indeed appears that this issue is specific to Python 3.12, since metrics are sent at program exit in the other Python versions I tested (3.11 and 3.8). This behavior is quite confusing from a user perspective, however, so I think we should invest in creating a solution that allows us to ensure the transport is flushed at program exit in Python 3.12. Would running the worker in a separate process perhaps allow us to work around the situation where the user code forks the process the SDK is running in? |
How do you use Sentry?
Sentry Saas (sentry.io)
Version
1.45.0 and 2.0.0rcX
Steps to Reproduce
Follow these steps.
Expected Result
The
drank-drinks
metric is sent to Sentry, regardless of whether we callsentry_sdk.flush()
before the program's end.Actual Result
The
drank-drinks
method is only sent if we callsentry_sdk.flush()
before the program ends, or if we interrupt the program by pressing⌃C
. If we run the code withsentry_sdk.flush()
commented out, i.e. without modifying the sample in "Steps to Reproduce," the metric does not get sent.The text was updated successfully, but these errors were encountered: