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
Adds updates to OpenTel tracker + base tracker for streaming, parent linking
elijahbenizzy22fd1de56977
diff --git a/burr/integrations/opentelemetry.py b/burr/integrations/opentelemetry.pyindex 18d0a61b..fd803484 100644--- a/burr/integrations/opentelemetry.py+++ b/burr/integrations/opentelemetry.py@@ -1,4 +1,5 @@import dataclasses+import datetimeimport jsonimport loggingimport random@@ -232,8 +233,68 @@ class OpenTelemetryTracker(Note that this globally sets a tracer provider -- it is possible that this will interfere withother tracers, and we are actively investigating it.+ TODO -- add stream start/end to opentel + TTFS, etc..."""+ def pre_start_stream(+ self,+ *,+ action: str,+ sequence_id: int,+ app_id: str,+ partition_key: Optional[str],+ **future_kwargs: Any,+ ):+ return self.burr_tracker.pre_start_stream(+ action=action,+ sequence_id=sequence_id,+ app_id=app_id,+ partition_key=partition_key,+ **future_kwargs,+ )++ def post_stream_item(+ self,+ *,+ item: Any,+ item_index: int,+ stream_initialize_time: datetime.datetime,+ first_stream_item_start_time: datetime.datetime,+ action: str,+ sequence_id: int,+ app_id: str,+ partition_key: Optional[str],+ **future_kwargs: Any,+ ):+ return self.burr_tracker.post_stream_item(+ item=item,+ item_index=item_index,+ stream_initialize_time=stream_initialize_time,+ first_stream_item_start_time=first_stream_item_start_time,+ action=action,+ sequence_id=sequence_id,+ app_id=app_id,+ partition_key=partition_key,+ **future_kwargs,+ )++ def post_end_stream(+ self,+ *,+ action: str,+ sequence_id: int,+ app_id: str,+ partition_key: Optional[str],+ **future_kwargs: Any,+ ):+ return self.burr_tracker.post_end_stream(+ action=action,+ sequence_id=sequence_id,+ app_id=app_id,+ partition_key=partition_key,+ **future_kwargs,+ )+def __init__(self, burr_tracker: SyncTrackingClient):initialize_tracer()self.tracer = trace.get_tracer("burr.integrations.opentelemetry")@@ -367,6 +428,9 @@ class OpenTelemetryTracker(_exit_span(exception)tracker_context.set(None)+ def copy(self):+ return OpenTelemetryTracker(burr_tracker=self.burr_tracker.copy())+class BurrTrackingSpanProcessor(SpanProcessor):@propertydiff --git a/burr/tracking/base.py b/burr/tracking/base.pyindex 635ddc07..f5813e2f 100644--- a/burr/tracking/base.py+++ b/burr/tracking/base.py@@ -7,7 +7,12 @@ from burr.lifecycle import (PreRunStepHook,PreStartSpanHook,)-from burr.lifecycle.base import DoLogAttributeHook+from burr.lifecycle.base import (+ DoLogAttributeHook,+ PostEndStreamHook,+ PostStreamItemHook,+ PreStartStreamHook,+)class SyncTrackingClient(@@ -17,11 +22,15 @@ class SyncTrackingClient(PreStartSpanHook,PostEndSpanHook,DoLogAttributeHook,+ PreStartStreamHook,+ PostStreamItemHook,+ PostEndStreamHook,abc.ABC,):"""Base class for synchronous tracking clients. All tracking clients must implement from thisTODO -- create an async tracking client"""+ @abc.abstractmethoddef copy(self):passdiff --git a/burr/tracking/client.py b/burr/tracking/client.pyindex 0a093a14..1c85ff16 100644--- a/burr/tracking/client.py+++ b/burr/tracking/client.py@@ -497,6 +497,7 @@ class LocalTrackingClient(span_id=span.uid if span is not None else None,value=serde.serialize(attribute, **self.serde_kwargs),tags=tags,+ time_logged=system.now(),)self._append_write_line(attribute_model)diff --git a/burr/tracking/common/models.py b/burr/tracking/common/models.pyindex e73ab00d..3ba52f45 100644--- a/burr/tracking/common/models.py+++ b/burr/tracking/common/models.py@@ -204,6 +204,7 @@ class AttributeModel(IdentifyingModel):] # It doesn't have to relate to a span, it can be at the level of an action as wellvalue: Union[dict, str, int, float, bool, list, None]tags: Dict[str, str]+ time_logged: Optional[datetime.datetime] = Nonetype: str = "attribute"@propertydiff --git a/burr/tracking/s3client.py b/burr/tracking/s3client.pyindex 79906745..bb5de6ae 100644--- a/burr/tracking/s3client.py+++ b/burr/tracking/s3client.py@@ -12,6 +12,7 @@ from typing import Any, Dict, List, Optional, Tuple, Unionimport pydantic+from burr import systemfrom burr.common import types as burr_typesfrom burr.core import Action, ApplicationGraph, State, serdefrom burr.integrations.base import require_plugin@@ -137,6 +138,7 @@ class S3TrackingClient(SyncTrackingClient):span_id=span.uid if span is not None else None,value=serde.serialize(attribute, **self.serde_kwargs),tags=tags,+ time_logged=system.now(),)self.submit_log_event(attribute_model, app_id=app_id, partition_key=partition_key)