Skip to content

Commit

Permalink
test(tracing): Add test for transaction not started warning
Browse files Browse the repository at this point in the history
  • Loading branch information
szokeasaurusrex committed Apr 25, 2024
1 parent e107d46 commit 881304d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/tracing/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,23 @@ def test_transaction_dropeed_sampled_false(sentry_init):
mock_logger.debug.assert_any_call(
"Discarding transaction because it was not started with sentry_sdk.start_transaction"
)


def test_transaction_not_started_warning(sentry_init):
sentry_init(enable_tracing=True)

tx = Transaction()

with mock.patch("sentry_sdk.tracing.logger") as mock_logger:
with tx:
pass

mock_logger.warning.assert_any_call(
"""Transaction was entered without being started with sentry_sdk.start_transaction.
The transaction will not be sent to Sentry. To fix, start the transaction by
passing it to sentry_sdk.start_transaction, like so:
with sentry_sdk.start_transaction(transaction):
# code here
"""
)

0 comments on commit 881304d

Please sign in to comment.