Skip to content
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

Fix threading by carrying forward span reference in use_scope #3851

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

sl0thentr0py
Copy link
Member

@sl0thentr0py sl0thentr0py commented Dec 4, 2024

Since the otel context span reference is the source of truth for the current active span, we need to explicitly pass the span reference on the scope through when we use use_scope since we are changing context variables in the other thread.

Also,

  • remove deprecated propagate_hub completely
  • fixes some typing in the original scope
  • adds more types to the contextvars_context manager

`use_scope`

Since the otel context span reference is the source of truth for the
current active span, we need to explicitly pass the span reference on
the scope through when we use `use_scope` since we are changing context
variables in the other thread.

Also,

* fixes some typing in the original scope
* adds more types to the `contextvars_context` manager
@sl0thentr0py sl0thentr0py changed the title Fix ThreadingIntegration by carrying forward span reference in Fix threading by carrying forward span reference in use_scope Dec 4, 2024
Copy link

codecov bot commented Dec 4, 2024

❌ 308 Tests Failed:

Tests completed Failed Passed Skipped
19313 308 19005 4438
View the full list of 3 ❄️ flaky tests
tests.test_scope test_get_current_scope_tags

Flake rate in main: 21.43% (Passed 33 times, Failed 9 times)

Stack Traces | 0.001s run time
tests/test_scope.py:341: in test_get_current_scope_tags
    assert scope1.client.__class__ == NonRecordingClient
E   AttributeError: client
tests.test_scope test_get_current_scope_tags

Flake rate in main: 37.50% (Passed 15 times, Failed 9 times)

Stack Traces | 0.001s run time
tests/test_scope.py:341: in test_get_current_scope_tags
    assert scope1.client.__class__ == NonRecordingClient
E   AttributeError: 'PotelScope' object has no attribute 'client'
tests.test_scope test_get_current_scope_tags

Flake rate in main: 29.03% (Passed 22 times, Failed 9 times)

Stack Traces | 0.001s run time
tests/test_scope.py:341: in test_get_current_scope_tags
    assert scope1.client.__class__ == NonRecordingClient
E   AttributeError: 'PotelScope' object has no attribute 'client'

To view more test analytics, go to the Test Analytics Dashboard
📢 Thoughts on this report? Let us know!

@@ -99,7 +86,8 @@ def _run_old_run_func():
with sentry_sdk.use_scope(current_scope_to_use):
return _run_old_run_func()
else:
return _run_old_run_func()
with sentry_sdk.isolation_scope():
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the old logic here was actually wrong but kinda worked because of some fallback code in the scope implementation.

Semantically, if we don't explicitly propagate the scopes, we should ALWAYS have created a new isolation scope for the new thread.

Copy link
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense to me

@sl0thentr0py sl0thentr0py merged commit 92f5f0a into neel/potel/move-scope-init Dec 5, 2024
67 of 125 checks passed
@sl0thentr0py sl0thentr0py deleted the neel/potel/fix-threading branch December 5, 2024 13:20
sl0thentr0py added a commit that referenced this pull request Dec 5, 2024
* Move scope context init outside integration

* Fix ThreadingIntegration by carrying forward span reference in (#3851)

`use_scope`

Since the otel context span reference is the source of truth for the
current active span, we need to explicitly pass the span reference on
the scope through when we use `use_scope` since we are changing context
variables in the other thread.

Also,

* fixes some typing in the original scope
* adds more types to the `contextvars_context` manager
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants