Skip to content

Commit 697843c

Browse files
committed
Bump version to 0.2 and add new distribution files; enhance s2_agent decorator with optional trace callback for improved tracing
1 parent d1556d3 commit 697843c

File tree

4 files changed

+8
-22
lines changed

4 files changed

+8
-22
lines changed
10.8 KB
Binary file not shown.

dist/singlestore_pulse-0.2.tar.gz

9.14 KB
Binary file not shown.

pulse_otel/main.py

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -277,46 +277,32 @@ def wrapper(*args, **kwargs):
277277
return decorator
278278

279279
def s2_agent(name):
280-
"""
281-
s2_agent is a dedicated decorator for for event_generator function of s2ai framework that
282-
wraps an asynchronous event_generator function to add tracing
283-
capabilities using OpenTelemetry. It captures the current context, creates
284-
a new span, and ensures that the decorated function is executed within the
285-
captured context.
286-
287-
This is being done to make sure parent context is rightfully captured and propagated in a sync function so that
288-
the traceID of the current otel span is used is passed on the asynchronous generator function.
289-
Args:
290-
name (str): The name of the span to be created for tracing.
291-
Returns:
292-
Callable: A decorator that wraps the target asynchronous generator
293-
function, adding tracing and context management.
294-
"""
295280
def decorator(func):
296281
@functools.wraps(func)
297282
def wrapper(*args, **kwargs):
298-
# Capture the current context
299283
ctx = copy_context()
300-
284+
trace_callback = kwargs.pop("trace_callback", None) # Accept optional callback
285+
301286
async def async_wrapper():
302287
add_session_id_to_span_attributes(**kwargs)
303288
tracer = trace.get_tracer(__name__)
304289

305-
# Create new span within the async context
306290
with tracer.start_as_current_span(name) as span:
307291
trace_id_hex = format(span.get_span_context().trace_id, "032x")
308292
logger.debug(f"[s2_agent wrapper] Started span. TraceID: {trace_id_hex}")
309293

310-
# Execute decorated function and yield results
294+
if trace_callback:
295+
trace_callback(trace_id_hex) # Notify the caller
296+
311297
decorated_func = agent(name)(func)
312298
async for item in decorated_func(*args, **kwargs):
313299
yield item
314-
315-
# Run the entire async generator in captured context
300+
316301
return ctx.run(async_wrapper)
317302
return wrapper
318303
return decorator
319304

305+
320306
class CustomFileSpanExporter(SpanExporter):
321307
def __init__(self, file_name):
322308
self.file_name = file_name

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='singlestore_pulse',
8-
version='0.1',
8+
version='0.2',
99
packages=find_packages(),
1010
description='Singlestore Python SDK for OpenTelemetry Integration',
1111
long_description=open('README.md').read(),

0 commit comments

Comments
 (0)