Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.
Python aiburrchatbot-frameworkdagsgenerative-aigraphshacktoberfestllmopsllmsmlopspersistent-data-structurestate-machinestate-managementvisibility
Passes app_id/partition_key to traces/spans
elijahbenizzy453568df82a1
diff --git a/burr/core/application.py b/burr/core/application.pyindex 98091af0..e6774fff 100644--- a/burr/core/application.py+++ b/burr/core/application.py@@ -459,7 +459,10 @@ class Application:self._parent_pointer = fork_parent_pointerself.dependency_factory = {"__tracer": functools.partial(- visibility.tracing.TracerFactory, lifecycle_adapters=self._adapter_set+ visibility.tracing.TracerFactory,+ lifecycle_adapters=self._adapter_set,+ app_id=self._uid,+ partition_key=self._partition_key,),"__context": self._context_factory,}diff --git a/burr/lifecycle/base.py b/burr/lifecycle/base.pyindex e2f235af..897f41be 100644--- a/burr/lifecycle/base.py+++ b/burr/lifecycle/base.py@@ -167,6 +167,8 @@ class PreStartSpanHook(abc.ABC):action_sequence_id: int,span: "ActionSpan",span_dependencies: list[str],+ app_id: str,+ partition_key: Optional[str],**future_kwargs: Any,):pass@@ -182,6 +184,8 @@ class PreStartSpanHookAsync(abc.ABC):action_sequence_id: int,span: "ActionSpan",span_dependencies: list[str],+ app_id: str,+ partition_key: Optional[str],**future_kwargs: Any,):pass@@ -200,6 +204,8 @@ class PostEndSpanHook(abc.ABC):action_sequence_id: int,span: "ActionSpan",span_dependencies: list[str],+ app_id: str,+ partition_key: Optional[str],**future_kwargs: Any,):pass@@ -215,6 +221,8 @@ class PostEndSpanHookAsync(abc.ABC):action_sequence_id: int,span: "ActionSpan",span_dependencies: list[str],+ app_id: str,+ partition_key: Optional[str],**future_kwargs: Any,):passdiff --git a/burr/tracking/client.py b/burr/tracking/client.pyindex 5a8d4ac4..b175e66e 100644--- a/burr/tracking/client.py+++ b/burr/tracking/client.py@@ -428,7 +428,7 @@ class LocalTrackingClient(span_dependencies: list[str],**future_kwargs: Any,):- being_span_model = BeginSpanModel(+ begin_span_model = BeginSpanModel(start_time=datetime.datetime.now(),action_sequence_id=sequence_id,span_id=span.uid,@@ -436,7 +436,7 @@ class LocalTrackingClient(span_dependencies=span_dependencies,span_name=span.name,)- self._append_write_line(being_span_model)+ self._append_write_line(begin_span_model)def post_end_span(self,diff --git a/burr/visibility/tracing.py b/burr/visibility/tracing.pyindex 1c6d84fd..99c1e175 100644--- a/burr/visibility/tracing.py+++ b/burr/visibility/tracing.py@@ -103,6 +103,8 @@ class ActionSpanTracer(AbstractContextManager, AbstractAsyncContextManager):action_sequence_id: int,span_name: str,lifecycle_adapters: LifecycleAdapterSet,+ app_id: str,+ partition_key: Optional[str],span_dependencies: List[str],top_level_span_count: int = 0,context_var=execution_context_var,@@ -122,6 +124,8 @@ class ActionSpanTracer(AbstractContextManager, AbstractAsyncContextManager):self.span_dependencies = span_dependenciesself.top_level_span_count = top_level_span_countself.context_var = context_var+ self.app_id = app_id+ self.partition_key = partition_keydef _sync_hooks_enter(self, context: ActionSpan):self.lifecycle_adapters.call_all_lifecycle_hooks_sync(@@ -130,6 +134,8 @@ class ActionSpanTracer(AbstractContextManager, AbstractAsyncContextManager):span=context,span_dependencies=self.span_dependencies,sequence_id=self.action_sequence_id,+ app_id=self.app_id,+ partition_key=self.partition_key,)async def _async_hooks_enter(self, context: ActionSpan):@@ -139,6 +145,8 @@ class ActionSpanTracer(AbstractContextManager, AbstractAsyncContextManager):span=context,span_dependencies=self.span_dependencies,sequence_id=self.action_sequence_id,+ app_id=self.app_id,+ partition_key=self.partition_key,)async def _async_hooks_exit(self, context: ActionSpan):@@ -148,6 +156,8 @@ class ActionSpanTracer(AbstractContextManager, AbstractAsyncContextManager):span=context,span_dependencies=self.span_dependencies,sequence_id=self.action_sequence_id,+ app_id=self.app_id,+ partition_key=self.partition_key,)def _enter(self):@@ -178,6 +188,8 @@ class ActionSpanTracer(AbstractContextManager, AbstractAsyncContextManager):span=context,span_dependencies=self.span_dependencies,sequence_id=self.action_sequence_id,+ app_id=self.app_id,+ partition_key=self.partition_key,)def __enter__(self):@@ -241,14 +253,14 @@ class TracerFactory:context_manager: ActionSpanTracer = __tracer("my_span_name")with context_manager:...--"""def __init__(self,action: str,sequence_id: int,+ app_id: str,+ partition_key: str,lifecycle_adapters: LifecycleAdapterSet,_context_var: ContextVar[Optional[ActionSpan]] = execution_context_var,):@@ -263,6 +275,8 @@ class TracerFactory:self.context_var = _context_varself.top_level_span_count = 0self.action_sequence_id = sequence_id+ self.app_id = app_id+ self.partition_key = partition_keydef __call__(self, span_name: str, span_dependencies: Optional[List[str]] = None@@ -279,4 +293,6 @@ class TracerFactory:span_dependencies=span_dependencies,context_var=self.context_var,top_level_span_count=self.top_level_span_count,+ app_id=self.app_id,+ partition_key=self.partition_key,)diff --git a/tests/visibility/test_tracing.py b/tests/visibility/test_tracing.pyindex 572643c7..4550a452 100644--- a/tests/visibility/test_tracing.py+++ b/tests/visibility/test_tracing.py@@ -26,6 +26,8 @@ def test_action_span_tracer_correct_span_count(request):sequence_id=0,lifecycle_adapters=LifecycleAdapterSet(),_context_var=context_var,+ app_id="test_app_id",+ partition_key=None,)assert context_var.get() is None # nothing to startassert tracer_factory.top_level_span_count == 0 # and thus no top-level spans@@ -54,6 +56,8 @@ async def test_action_span_tracer_correct_span_count_async(request):sequence_id=0,lifecycle_adapters=LifecycleAdapterSet(),_context_var=context_var,+ app_id="test_app_id",+ partition_key=None,)assert context_var.get() is None # nothing to startassert tracer_factory.top_level_span_count == 0 # and thus no top-level spans@@ -82,6 +86,8 @@ def test_action_span_tracer_correct_span_count_nested(request):sequence_id=0,lifecycle_adapters=LifecycleAdapterSet(),_context_var=context_var,+ app_id="test_app_id",+ partition_key=None,)with tracer_factory("0") as outside_span_0:@@ -119,6 +125,8 @@ async def test_action_span_tracer_correct_span_count_nested_async(request):sequence_id=0,lifecycle_adapters=LifecycleAdapterSet(),_context_var=context_var,+ app_id="test_app_id",+ partition_key=None,)async with tracer_factory("0") as outside_span_0:@@ -188,6 +196,8 @@ def test_pre_span_lifecycle_hooks_called(request):sequence_id=0,lifecycle_adapters=adapter_set,_context_var=context_var,+ app_id="test_app_id",+ partition_key=None,)# 0:0with tracer_factory_0("0"):@@ -212,6 +222,8 @@ def test_pre_span_lifecycle_hooks_called(request):sequence_id=tracer_factory_0.action_sequence_id + 1,lifecycle_adapters=adapter_set,_context_var=context_var,+ app_id="test_app_id",+ partition_key=None,)# 1:0with tracer_factory_1("2"):@@ -283,6 +295,8 @@ async def test_pre_span_lifecycle_hooks_called_async(request):sequence_id=0,lifecycle_adapters=adapter_set,_context_var=context_var,+ app_id="test_app_id",+ partition_key=None,)# 0:0async with tracer_factory_0("0"):@@ -307,6 +321,8 @@ async def test_pre_span_lifecycle_hooks_called_async(request):sequence_id=tracer_factory_0.action_sequence_id + 1,lifecycle_adapters=adapter_set,_context_var=context_var,+ app_id="test_app_id",+ partition_key=None,)# 1:0async with tracer_factory_1("2"):