From d49bd89061d7f0b38ef46f572ef096462098b3ac Mon Sep 17 00:00:00 2001 From: Pratyush Shukla Date: Wed, 12 Mar 2025 10:14:01 +0530 Subject: [PATCH 1/3] count both spans and traces --- src/agents/tracing/processors.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/agents/tracing/processors.py b/src/agents/tracing/processors.py index 282bc23c..f325e869 100644 --- a/src/agents/tracing/processors.py +++ b/src/agents/tracing/processors.py @@ -81,7 +81,17 @@ def export(self, items: list[Trace | Span[Any]]) -> None: traces: list[dict[str, Any]] = [] spans: list[dict[str, Any]] = [] - data = [item.export() for item in items if item.export()] + # Categorize items into traces and spans + for item in items: + if hasattr(item, 'export') and callable(item.export): + export_data = item.export() + if export_data: + if isinstance(item, Trace): + traces.append(export_data) + else: + spans.append(export_data) + + data = traces + spans payload = {"data": data} headers = { From 69624109764a1deff4822bdbee782a6df0b02346 Mon Sep 17 00:00:00 2001 From: Pratyush Shukla Date: Wed, 12 Mar 2025 10:19:14 +0530 Subject: [PATCH 2/3] Revert "count both spans and traces" This reverts commit d49bd89061d7f0b38ef46f572ef096462098b3ac. --- src/agents/tracing/processors.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/agents/tracing/processors.py b/src/agents/tracing/processors.py index f325e869..282bc23c 100644 --- a/src/agents/tracing/processors.py +++ b/src/agents/tracing/processors.py @@ -81,17 +81,7 @@ def export(self, items: list[Trace | Span[Any]]) -> None: traces: list[dict[str, Any]] = [] spans: list[dict[str, Any]] = [] - # Categorize items into traces and spans - for item in items: - if hasattr(item, 'export') and callable(item.export): - export_data = item.export() - if export_data: - if isinstance(item, Trace): - traces.append(export_data) - else: - spans.append(export_data) - - data = traces + spans + data = [item.export() for item in items if item.export()] payload = {"data": data} headers = { From e5917724dccf09de93e173fcf5b9136a18f2e9d3 Mon Sep 17 00:00:00 2001 From: Pratyush Shukla Date: Wed, 12 Mar 2025 10:20:15 +0530 Subject: [PATCH 3/3] resort to show total number of spans and traces --- src/agents/tracing/processors.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/agents/tracing/processors.py b/src/agents/tracing/processors.py index 282bc23c..308adf2a 100644 --- a/src/agents/tracing/processors.py +++ b/src/agents/tracing/processors.py @@ -78,9 +78,6 @@ def export(self, items: list[Trace | Span[Any]]) -> None: logger.warning("OPENAI_API_KEY is not set, skipping trace export") return - traces: list[dict[str, Any]] = [] - spans: list[dict[str, Any]] = [] - data = [item.export() for item in items if item.export()] payload = {"data": data} @@ -100,7 +97,7 @@ def export(self, items: list[Trace | Span[Any]]) -> None: # If the response is successful, break out of the loop if response.status_code < 300: - logger.debug(f"Exported {len(traces)} traces, {len(spans)} spans") + logger.debug(f"Exported {len(items)} items") return # If the response is a client error (4xx), we wont retry