diff --git a/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py b/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py index 4453b95952..e6db46e48d 100644 --- a/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py +++ b/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py @@ -1,6 +1,8 @@ import atexit import logging import os +import contextvars +import uuid from colorama import Fore @@ -59,6 +61,7 @@ class TracerWrapper(object): enable_content_tracing: bool = True endpoint: str = None headers: Dict[str, str] = {} + association_properties_var: ContextVar = None __tracer_provider: TracerProvider = None __image_uploader: ImageUploader = None @@ -462,6 +465,12 @@ def get_tracer(self): def set_association_properties(properties: dict) -> None: attach(set_value("association_properties", properties)) + # Generate a unique UUID for the task + wrapper_uuid = str(uuid.uuid4()) + + # Set a wrapper-specific value using the generated UUID + token = TracerWrapper.association_properties_var.set({'wrapper_uuid': wrapper_uuid}) + # Attach association properties to the current span, if it's a workflow or a task span = trace.get_current_span() if get_value("workflow_name") is not None or get_value("entity_name") is not None: