|
1 | 1 | import sentry_sdk |
| 2 | +from sentry_sdk.tracing import Transaction |
2 | 3 |
|
3 | 4 |
|
4 | 5 | def test_transaction_name_span_description_compat( |
@@ -52,3 +53,47 @@ def test_transaction_name_span_description_compat( |
52 | 53 | assert span["op"] == "span-op" |
53 | 54 | assert span["data"]["sentry.op"] == "span-op" |
54 | 55 | 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