add back span

This commit is contained in:
Dinesh Yeduguru 2024-12-11 08:37:56 -08:00
parent a4a29ea3a3
commit 62bb230ab0
3 changed files with 13 additions and 15 deletions

View file

@ -81,9 +81,7 @@ def trace_protocol(cls: Type[T]) -> Type[T]:
self, *args, **kwargs
)
with tracing.SpanContextManager(
f"{class_name}.{method_name}", span_attributes
) as span:
with tracing.span(f"{class_name}.{method_name}", span_attributes) as span:
try:
count = 0
async for item in method(self, *args, **kwargs):
@ -98,9 +96,7 @@ def trace_protocol(cls: Type[T]) -> Type[T]:
self, *args, **kwargs
)
with tracing.SpanContextManager(
f"{class_name}.{method_name}", span_attributes
) as span:
with tracing.span(f"{class_name}.{method_name}", span_attributes) as span:
try:
result = await method(self, *args, **kwargs)
span.set_attribute("output", serialize_value(result))
@ -115,9 +111,7 @@ def trace_protocol(cls: Type[T]) -> Type[T]:
self, *args, **kwargs
)
with tracing.SpanContextManager(
f"{class_name}.{method_name}", span_attributes
) as span:
with tracing.span(f"{class_name}.{method_name}", span_attributes) as span:
try:
result = method(self, *args, **kwargs)
span.set_attribute("output", serialize_value(result))

View file

@ -259,6 +259,10 @@ class SpanContextManager:
return wrapper
def span(name: str, attributes: Dict[str, Any] = None):
return SpanContextManager(name, attributes)
def get_current_span() -> Optional[Span]:
global CURRENT_TRACE_CONTEXT
context = CURRENT_TRACE_CONTEXT