|
1 | 1 | import random |
2 | 2 | from unittest import mock |
3 | 3 |
|
| 4 | +import sentry_sdk |
4 | 5 | from sentry_sdk import _experimental_logger as sentry_logger |
5 | 6 |
|
6 | 7 |
|
@@ -189,3 +190,32 @@ def test_logs_message_python_logging(sentry_init, capture_envelopes): |
189 | 190 | assert str(ex) == "capture_log() takes 3 positional arguments but 4 were given" |
190 | 191 |
|
191 | 192 | assert len(envelopes) == 0 |
| 193 | + |
| 194 | + |
| 195 | +def test_logs_tied_to_transactions(sentry_init, capture_envelopes): |
| 196 | + """ |
| 197 | + Log messages are also tied to transactions. |
| 198 | + """ |
| 199 | + sentry_init(enable_sentry_logs=True) |
| 200 | + envelopes = capture_envelopes() |
| 201 | + |
| 202 | + with sentry_sdk.start_transaction(name="test-transaction") as trx: |
| 203 | + sentry_logger.warn("This is a log tied to a transaction") |
| 204 | + |
| 205 | + log_entry = envelopes[0].items[0].payload.json |
| 206 | + assert log_entry["attributes"][-1] =={'key': 'sentry.trace.parent_span_id', 'value': {'stringValue': trx.span_id}} |
| 207 | + |
| 208 | + |
| 209 | +def test_logs_tied_to_spans(sentry_init, capture_envelopes): |
| 210 | + """ |
| 211 | + Log messages are also tied to spans. |
| 212 | + """ |
| 213 | + sentry_init(enable_sentry_logs=True) |
| 214 | + envelopes = capture_envelopes() |
| 215 | + |
| 216 | + with sentry_sdk.start_transaction(name="test-transaction") as trx: |
| 217 | + with sentry_sdk.start_span(description="test-span") as span: |
| 218 | + sentry_logger.warn("This is a log tied to a span") |
| 219 | + |
| 220 | + log_entry = envelopes[0].items[0].payload.json |
| 221 | + assert log_entry["attributes"][-1] =={'key': 'sentry.trace.parent_span_id', 'value': {'stringValue': span.span_id}} |
0 commit comments