-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added top level API to get current span (#1954)
* Added top level API to get current span
- Loading branch information
1 parent
3e67535
commit e952020
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import mock | ||
|
||
from sentry_sdk import ( | ||
configure_scope, | ||
get_current_span, | ||
start_transaction, | ||
) | ||
|
||
|
||
def test_get_current_span(): | ||
fake_hub = mock.MagicMock() | ||
fake_hub.scope = mock.MagicMock() | ||
|
||
fake_hub.scope.span = mock.MagicMock() | ||
assert get_current_span(fake_hub) == fake_hub.scope.span | ||
|
||
fake_hub.scope.span = None | ||
assert get_current_span(fake_hub) is None | ||
|
||
|
||
def test_get_current_span_default_hub(sentry_init): | ||
sentry_init() | ||
|
||
assert get_current_span() is None | ||
|
||
with configure_scope() as scope: | ||
fake_span = mock.MagicMock() | ||
scope.span = fake_span | ||
|
||
assert get_current_span() == fake_span | ||
|
||
|
||
def test_get_current_span_default_hub_with_transaction(sentry_init): | ||
sentry_init() | ||
|
||
assert get_current_span() is None | ||
|
||
with start_transaction() as new_transaction: | ||
assert get_current_span() == new_transaction |