/
test_noop_span.py
52 lines (36 loc) · 1.74 KB
/
test_noop_span.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import sentry_sdk
from sentry_sdk.tracing import NoOpSpan
# This tests make sure, that the examples from the documentation [1]
# are working when OTel (OpenTelementry) instrumentation is turned on
# and therefore the Senntry tracing should not do anything.
#
# 1: https://docs.sentry.io/platforms/python/performance/instrumentation/custom-instrumentation/
def test_noop_start_transaction(sentry_init):
sentry_init(instrumenter="otel", debug=True)
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"
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")
def test_noop_transaction_start_child(sentry_init):
sentry_init(instrumenter="otel", debug=True)
transaction = sentry_sdk.start_transaction(name="task")
assert isinstance(transaction, NoOpSpan)
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):
sentry_init(instrumenter="otel", debug=True)
span = sentry_sdk.start_span(name="task")
assert isinstance(span, NoOpSpan)
with span.start_child(op="child_task") as child:
assert isinstance(child, NoOpSpan)
assert sentry_sdk.Hub.current.scope.span is child