Skip to content

armgit / burr

Public Imported from GitHub
0

Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.

Adds updates to OpenTel tracker + base tracker for streaming, parent linking

elijahbenizzy22fd1de56977
diff --git a/burr/integrations/opentelemetry.py b/burr/integrations/opentelemetry.py
index 18d0a61b..fd803484 100644
--- a/burr/integrations/opentelemetry.py
+++ b/burr/integrations/opentelemetry.py
@@ -1,4 +1,5 @@
import dataclasses
+import datetime
import json
import logging
import random
@@ -232,8 +233,68 @@ class OpenTelemetryTracker(
Note that this globally sets a tracer provider -- it is possible that this will interfere with
other 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):
@property
diff --git a/burr/tracking/base.py b/burr/tracking/base.py
index 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 this
TODO -- create an async tracking client"""
+ @abc.abstractmethod
def copy(self):
pass
diff --git a/burr/tracking/client.py b/burr/tracking/client.py
index 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.py
index 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 well
value: Union[dict, str, int, float, bool, list, None]
tags: Dict[str, str]
+ time_logged: Optional[datetime.datetime] = None
type: str = "attribute"
@property
diff --git a/burr/tracking/s3client.py b/burr/tracking/s3client.py
index 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, Union
import pydantic
+from burr import system
from burr.common import types as burr_types
from burr.core import Action, ApplicationGraph, State, serde
from 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)