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
# These tests make sure that the examples from the documentation [1]
# are working when OTel (OpenTelemetry) instrumentation is turned on,
# and therefore, the Sentry 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")
with sentry_sdk.start_transaction(
op="task", name="test_transaction_name"
) as transaction:
assert isinstance(transaction, NoOpSpan)
assert sentry_sdk.get_current_scope().span is transaction
transaction.name = "new name"
def test_noop_start_span(sentry_init):
sentry_init(instrumenter="otel")
with sentry_sdk.start_span(op="http", name="GET /") as span:
assert isinstance(span, NoOpSpan)
assert sentry_sdk.get_current_scope().span is span
span.set_tag("http.response.status_code", 418)
span.set_data("http.entity_type", "teapot")
def test_noop_transaction_start_child(sentry_init):
sentry_init(instrumenter="otel")
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.get_current_scope().span is child
def test_noop_span_start_child(sentry_init):
sentry_init(instrumenter="otel")
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.get_current_scope().span is child
|