Skip to content

Commit 5c38edb

Browse files
Item instead of dictionary argument
1 parent a61f8d6 commit 5c38edb

File tree

3 files changed

+80
-50
lines changed

3 files changed

+80
-50
lines changed

sentry_sdk/_log_batcher.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,21 @@ def add(
8383

8484
with self._lock:
8585
if len(self._log_buffer) >= self.MAX_LOGS_BEFORE_DROP:
86+
# Construct log envelope item without sending it to report lost bytes
87+
log_item = Item(
88+
type="log",
89+
content_type="application/vnd.sentry.items.log+json",
90+
headers={
91+
"item_count": 1,
92+
},
93+
payload=PayloadRef(
94+
json={"items": [LogBatcher._log_to_transport_format(log)]}
95+
),
96+
)
8697
self._record_lost_func(
8798
reason="queue_overflow",
8899
data_category="log_item",
89-
item=LogBatcher._log_to_transport_format(log),
100+
item=log_item,
90101
quantity=1,
91102
)
92103
return None

sentry_sdk/client.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,15 @@
6262
from typing import Union
6363
from typing import TypeVar
6464

65-
from sentry_sdk._types import Event, Hint, SDKInfo, Log, Metric, EventDataCategory
65+
from sentry_sdk._types import (
66+
Event,
67+
Hint,
68+
SDKInfo,
69+
Log,
70+
Metric,
71+
EventDataCategory,
72+
Item,
73+
)
6674
from sentry_sdk.integrations import Integration
6775
from sentry_sdk.scope import Scope
6876
from sentry_sdk.session import Session
@@ -360,13 +368,15 @@ def _capture_envelope(envelope):
360368
def _record_lost_event(
361369
reason, # type: str
362370
data_category, # type: EventDataCategory
371+
item, # type: Item
363372
quantity=1, # type: int
364373
):
365374
# type: (...) -> None
366375
if self.transport is not None:
367376
self.transport.record_lost_event(
368377
reason=reason,
369378
data_category=data_category,
379+
item=item,
370380
quantity=quantity,
371381
)
372382

tests/test_logs.py

Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import sentry_sdk
1010
import sentry_sdk.logger
1111
from sentry_sdk import get_client
12-
from sentry_sdk.envelope import Envelope
12+
from sentry_sdk.envelope import Envelope, Item, PayloadRef
1313
from sentry_sdk.types import Log
1414
from sentry_sdk.consts import SPANDATA, VERSION
1515

@@ -471,51 +471,60 @@ def record_lost_event(reason, data_category=None, item=None, *, quantity=1):
471471

472472
assert len(lost_event_calls) == 5
473473

474-
expected_dropped_item = {
475-
"body": "This is a 'info' log...",
476-
"level": "info",
477-
"timestamp": mock.ANY,
478-
"trace_id": mock.ANY,
479-
"attributes": {
480-
"sentry.environment": {
481-
"type": "string",
482-
"value": "production",
483-
},
484-
"sentry.release": {
485-
"type": "string",
486-
"value": "1.0.0",
487-
},
488-
"sentry.sdk.name": {
489-
"type": "string",
490-
"value": mock.ANY,
491-
},
492-
"sentry.sdk.version": {
493-
"type": "string",
494-
"value": VERSION,
495-
},
496-
"sentry.severity_number": {
497-
"type": "integer",
498-
"value": 9,
499-
},
500-
"sentry.severity_text": {
501-
"type": "string",
502-
"value": "info",
503-
},
504-
"sentry.trace.parent_span_id": {
505-
"type": "string",
506-
"value": mock.ANY,
507-
},
508-
"server.address": {
509-
"type": "string",
510-
"value": "test-server",
511-
},
512-
},
513-
}
514-
515474
for lost_event_call in lost_event_calls:
516-
assert lost_event_call == (
517-
"queue_overflow",
518-
"log_item",
519-
expected_dropped_item,
520-
1,
521-
)
475+
reason, data_category, item, quantity = lost_event_call
476+
477+
assert reason == "queue_overflow"
478+
assert data_category == "log_item"
479+
assert quantity == 1
480+
481+
assert item.type == "log"
482+
assert item.headers == {
483+
"type": "log",
484+
"item_count": 1,
485+
"content_type": "application/vnd.sentry.items.log+json",
486+
}
487+
assert item.payload.json == {
488+
"items": [
489+
{
490+
"body": "This is a 'info' log...",
491+
"level": "info",
492+
"timestamp": mock.ANY,
493+
"trace_id": mock.ANY,
494+
"attributes": {
495+
"sentry.environment": {
496+
"type": "string",
497+
"value": "production",
498+
},
499+
"sentry.release": {
500+
"type": "string",
501+
"value": "1.0.0",
502+
},
503+
"sentry.sdk.name": {
504+
"type": "string",
505+
"value": mock.ANY,
506+
},
507+
"sentry.sdk.version": {
508+
"type": "string",
509+
"value": VERSION,
510+
},
511+
"sentry.severity_number": {
512+
"type": "integer",
513+
"value": 9,
514+
},
515+
"sentry.severity_text": {
516+
"type": "string",
517+
"value": "info",
518+
},
519+
"sentry.trace.parent_span_id": {
520+
"type": "string",
521+
"value": mock.ANY,
522+
},
523+
"server.address": {
524+
"type": "string",
525+
"value": "test-server",
526+
},
527+
},
528+
}
529+
]
530+
}

0 commit comments

Comments
 (0)