Skip to content

Commit df0400a

Browse files
committed
fix otel tests
1 parent 1f87a25 commit df0400a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

py/src/braintrust/otel/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ def on_start(self, span, parent_context=None):
7474
"""Forward span start events to the inner processor."""
7575
self._processor.on_start(span, parent_context)
7676

77+
def _on_ending(self, span):
78+
"""Called by the OTel SDK before on_end. Forward to inner processor if it supports it."""
79+
if hasattr(self._processor, "_on_ending"):
80+
self._processor._on_ending(span)
81+
7782
def on_end(self, span):
7883
"""Apply filtering logic and conditionally forward span end events."""
7984
if self._should_keep_filtered_span(span):
@@ -318,6 +323,11 @@ def _get_parent_otel_braintrust_parent(self, parent_context):
318323
except Exception:
319324
return None
320325

326+
def _on_ending(self, span):
327+
"""Called by the OTel SDK before on_end. Forward to inner processor if it supports it."""
328+
if hasattr(self._processor, "_on_ending"):
329+
self._processor._on_ending(span)
330+
321331
def on_end(self, span):
322332
"""Forward span end events to the inner processor."""
323333
self._processor.on_end(span)

py/src/braintrust/wrappers/_anthropic_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ def finalize_anthropic_tokens(metrics: dict[str, float]) -> dict[str, float]:
8585
Returns:
8686
Updated metrics with total prompt tokens and total tokens fields
8787
"""
88+
if not metrics:
89+
return metrics
90+
8891
total_prompt_tokens = (
8992
metrics.get("prompt_tokens", 0)
9093
+ metrics.get("prompt_cached_tokens", 0)

0 commit comments

Comments
 (0)