Skip to content

Commit bb44b3d

Browse files
feat: Telemetry in A2A Python SDK
1 parent 263cfcd commit bb44b3d

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/a2a/utils/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# type: ignore
2-
from opentelemetry.trace import SpanKind as OTelSpanKind
3-
41
from a2a.utils.artifact import new_text_artifact
52
from a2a.utils.helpers import (
63
append_artifact_to_task,
@@ -15,9 +12,7 @@
1512
from a2a.utils.task import new_task
1613

1714

18-
SpanKind = OTelSpanKind
1915
__all__ = [
20-
'SpanKind',
2116
'append_artifact_to_task',
2217
'build_text_artifact',
2318
'create_task_obj',

src/a2a/utils/telemetry.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# type: ignore
21
"""OpenTelemetry Tracing Utilities for A2A Python SDK.
32
43
This module provides decorators to simplify the integration of OpenTelemetry
@@ -57,11 +56,15 @@ def internal_method(self):
5756
import functools
5857
import inspect
5958
import logging
59+
import traceback
6060

6161
from opentelemetry import trace
62-
from opentelemetry.trace import SpanKind, StatusCode
62+
from opentelemetry.trace import SpanKind as _SpanKind
63+
from opentelemetry.trace import StatusCode
6364

6465

66+
SpanKind = _SpanKind
67+
__all__ = ['SpanKind']
6568
INSTRUMENTING_MODULE_NAME = 'a2a-python-sdk'
6669
INSTRUMENTING_MODULE_VERSION = '1.0.0'
6770

@@ -160,6 +163,10 @@ async def async_wrapper(*args, **kwargs) -> any:
160163
except Exception as e:
161164
exception = e
162165
span.record_exception(e)
166+
formatted_traceback = ''.join(
167+
traceback.format_exception(type(e), e, e.__traceback__)
168+
)
169+
print(formatted_traceback)
163170
span.set_status(StatusCode.ERROR, description=str(e))
164171
raise
165172
finally:
@@ -211,8 +218,8 @@ def sync_wrapper(*args, **kwargs):
211218

212219

213220
def trace_class(
214-
include_list: list[str] = None,
215-
exclude_list: list[str] = None,
221+
include_list: list[str] | None = None,
222+
exclude_list: list[str] | None = None,
216223
kind=SpanKind.INTERNAL,
217224
):
218225
"""A class decorator to automatically trace specified methods of a class.

0 commit comments

Comments
 (0)