Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions sentry_sdk/_span_batcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,21 @@ def add(self, span: "StreamedSpan") -> None:
@staticmethod
def _estimate_size(item: "StreamedSpan") -> int:
# Rough estimate of serialized span size that's quick to compute.
# 210 is the rough size of the payload without attributes, and we
# estimate additional 70 bytes on top of that per attribute.
return 210 + 70 * len(item._attributes)
# 210 is the rough size of the payload without attributes, and then we
# estimate the attributes separately.
estimate = 210
for value in item._attributes.values():
estimate += 50

if isinstance(value, str):
estimate += len(value)
else:
estimate += len(str(value))

return estimate

@staticmethod
def _to_transport_format(item: "StreamedSpan") -> "Any":
# TODO[span-first]
res: "dict[str, Any]" = {
"trace_id": item.trace_id,
"span_id": item.span_id,
Expand Down Expand Up @@ -126,7 +134,7 @@ def _flush(self) -> None:
return

envelopes = []
for trace_id, spans in self._span_buffer.items():
for spans in self._span_buffer.values():
if spans:
dsc = spans[0]._dynamic_sampling_context()

Expand Down
Loading