Skip to content

Commit f2757ae

Browse files
fix(tracing): record span drop metrics in a single counter increment
1 parent 1fa0323 commit f2757ae

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

src/agentex/lib/core/observability/tracing_metrics_recording.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ def record_span_enqueued(event_type: str) -> None:
5757
pass
5858

5959

60-
def record_span_dropped(reason: str) -> None:
61-
if not is_metrics_enabled():
60+
def record_span_dropped(reason: str, count: int = 1) -> None:
61+
if count <= 0 or not is_metrics_enabled():
6262
return
6363
try:
64-
_tracing_module().get_tracing_metrics().span_events_dropped.add(1, {"reason": reason})
64+
_tracing_module().get_tracing_metrics().span_events_dropped.add(
65+
count, {"reason": reason}
66+
)
6567
except Exception:
6668
pass
6769

src/agentex/lib/core/tracing/span_queue.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,9 @@ def _record_drop(self, count: int, reason: str) -> None:
164164
return
165165
self._dropped_spans += count
166166
if "shutting down" in reason:
167-
for _ in range(count):
168-
_metrics.record_span_dropped("shutdown")
167+
_metrics.record_span_dropped("shutdown", count)
169168
elif "queue full" in reason:
170-
for _ in range(count):
171-
_metrics.record_span_dropped("queue_full")
169+
_metrics.record_span_dropped("queue_full", count)
172170
# Warn on the first drop and then sparsely, so a drop storm is visible
173171
# without flooding the log.
174172
if self._dropped_spans == count or self._dropped_spans % 100 < count:

0 commit comments

Comments
 (0)