diff --git a/sentry_sdk/_span_batcher.py b/sentry_sdk/_span_batcher.py index 967011c083..426d5d9629 100644 --- a/sentry_sdk/_span_batcher.py +++ b/sentry_sdk/_span_batcher.py @@ -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, @@ -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()