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(otel): NoOpSpan updates scope #1834

Merged
merged 2 commits into from Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions sentry_sdk/tracing.py
Expand Up @@ -859,14 +859,6 @@ def __repr__(self):
# type: () -> str
return self.__class__.__name__

def __enter__(self):
# type: () -> NoOpSpan
return self

def __exit__(self, ty, value, tb):
# type: (Optional[Any], Optional[Any], Optional[Any]) -> None
pass

def start_child(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs):
# type: (str, **Any) -> NoOpSpan
return NoOpSpan()
Expand Down
12 changes: 9 additions & 3 deletions tests/tracing/test_noop_span.py
Expand Up @@ -11,17 +11,21 @@
def test_noop_start_transaction(sentry_init):
sentry_init(instrumenter="otel", debug=True)

transaction = sentry_sdk.start_transaction(op="task", name="test_transaction_name")
assert isinstance(transaction, NoOpSpan)
with sentry_sdk.start_transaction(
op="task", name="test_transaction_name"
) as transaction:
assert isinstance(transaction, NoOpSpan)
assert sentry_sdk.Hub.current.scope.span is transaction

transaction.name = "new name"
transaction.name = "new name"


def test_noop_start_span(sentry_init):
sentry_init(instrumenter="otel", debug=True)

with sentry_sdk.start_span(op="http", description="GET /") as span:
assert isinstance(span, NoOpSpan)
assert sentry_sdk.Hub.current.scope.span is span

span.set_tag("http.status_code", "418")
span.set_data("http.entity_type", "teapot")
Expand All @@ -35,6 +39,7 @@ def test_noop_transaction_start_child(sentry_init):

with transaction.start_child(op="child_task") as child:
assert isinstance(child, NoOpSpan)
assert sentry_sdk.Hub.current.scope.span is child


def test_noop_span_start_child(sentry_init):
Expand All @@ -44,3 +49,4 @@ def test_noop_span_start_child(sentry_init):

with span.start_child(op="child_task") as child:
assert isinstance(child, NoOpSpan)
assert sentry_sdk.Hub.current.scope.span is child