Skip to content

Commit 60a7b84

Browse files
committed
add transaction compat tests
1 parent 98f48cf commit 60a7b84

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/opentelemetry/test_compat.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sentry_sdk
2+
from sentry_sdk.tracing import Transaction
23

34

45
def test_transaction_name_span_description_compat(
@@ -52,3 +53,47 @@ def test_transaction_name_span_description_compat(
5253
assert span["op"] == "span-op"
5354
assert span["data"]["sentry.op"] == "span-op"
5455
assert span["data"]["sentry.description"] == "span-desc"
56+
57+
58+
def test_start_transaction_compat(
59+
sentry_init,
60+
capture_events,
61+
):
62+
sentry_init(traces_sample_rate=1.0)
63+
64+
events = capture_events()
65+
66+
with sentry_sdk.start_transaction(
67+
name="trx-name",
68+
op="trx-op",
69+
):
70+
...
71+
72+
transaction = events[0]
73+
assert transaction["transaction"] == "trx-name"
74+
assert transaction["contexts"]["trace"]["op"] == "trx-op"
75+
assert transaction["contexts"]["trace"]["data"]["sentry.op"] == "trx-op"
76+
assert transaction["contexts"]["trace"]["data"]["sentry.name"] == "trx-name"
77+
assert "sentry.description" not in transaction["contexts"]["trace"]["data"]
78+
79+
80+
def test_start_transaction_with_explicit_transaction_compat(
81+
sentry_init,
82+
capture_events,
83+
):
84+
"""It should still be possible to provide a ready-made Transaction to start_transaction."""
85+
sentry_init(traces_sample_rate=1.0)
86+
87+
events = capture_events()
88+
89+
transaction = Transaction(name="trx-name", op="trx-op")
90+
91+
with sentry_sdk.start_transaction(transaction=transaction):
92+
pass
93+
94+
transaction = events[0]
95+
assert transaction["transaction"] == "trx-name"
96+
assert transaction["contexts"]["trace"]["op"] == "trx-op"
97+
assert transaction["contexts"]["trace"]["data"]["sentry.op"] == "trx-op"
98+
assert transaction["contexts"]["trace"]["data"]["sentry.name"] == "trx-name"
99+
assert "sentry.description" not in transaction["contexts"]["trace"]["data"]

0 commit comments

Comments
 (0)