Skip to content

[2.0] new_scope does not apply scope to unhandled exception #2857

Closed as not planned
@szokeasaurusrex

Description

@szokeasaurusrex

TODO: We should also check whether push_scope in 1.x is affected!

How do you use Sentry?

Sentry Saas (sentry.io)

Version

2.0.0rc2

Steps to Reproduce

Run the following script:

import sentry_sdk

sentry_sdk.init("<dsn>")


with sentry_sdk.new_scope() as scope:
    scope.set_tag("custom tag 1", "value 1")
    1 / 0

Expected Result

The zero division error gets sent to Sentry, and the error event has the tag "custom tag 1" with the value "value 1" set.

Actual Result

Although the zero division error gets reported to Sentry, the error event is missing the tag. This is because the new_scope method restores the original scope within a finally block, which gets called before the scopes are merged and before the event is sent to Sentry. So, the scope that had the tag set is no longer active when the event is prepared for sending.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions