openinference-instrumentation-beeai 0.1.9__tar.gz → 0.1.10__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. {openinference_instrumentation_beeai-0.1.9 → openinference_instrumentation_beeai-0.1.10}/PKG-INFO +1 -1
  2. {openinference_instrumentation_beeai-0.1.9 → openinference_instrumentation_beeai-0.1.10}/src/openinference/instrumentation/beeai/__init__.py +25 -8
  3. {openinference_instrumentation_beeai-0.1.9 → openinference_instrumentation_beeai-0.1.10}/src/openinference/instrumentation/beeai/processors/base.py +3 -0
  4. {openinference_instrumentation_beeai-0.1.9 → openinference_instrumentation_beeai-0.1.10}/src/openinference/instrumentation/beeai/processors/tool.py +5 -1
  5. openinference_instrumentation_beeai-0.1.10/src/openinference/instrumentation/beeai/version.py +1 -0
  6. openinference_instrumentation_beeai-0.1.9/src/openinference/instrumentation/beeai/version.py +0 -1
  7. {openinference_instrumentation_beeai-0.1.9 → openinference_instrumentation_beeai-0.1.10}/.gitignore +0 -0
  8. {openinference_instrumentation_beeai-0.1.9 → openinference_instrumentation_beeai-0.1.10}/README.md +0 -0
  9. {openinference_instrumentation_beeai-0.1.9 → openinference_instrumentation_beeai-0.1.10}/pyproject.toml +0 -0
  10. {openinference_instrumentation_beeai-0.1.9 → openinference_instrumentation_beeai-0.1.10}/src/openinference/instrumentation/beeai/_span.py +0 -0
  11. {openinference_instrumentation_beeai-0.1.9 → openinference_instrumentation_beeai-0.1.10}/src/openinference/instrumentation/beeai/_utils.py +0 -0
  12. {openinference_instrumentation_beeai-0.1.9 → openinference_instrumentation_beeai-0.1.10}/src/openinference/instrumentation/beeai/processors/__init__.py +0 -0
  13. {openinference_instrumentation_beeai-0.1.9 → openinference_instrumentation_beeai-0.1.10}/src/openinference/instrumentation/beeai/processors/agents/__init__.py +0 -0
  14. {openinference_instrumentation_beeai-0.1.9 → openinference_instrumentation_beeai-0.1.10}/src/openinference/instrumentation/beeai/processors/agents/base.py +0 -0
  15. {openinference_instrumentation_beeai-0.1.9 → openinference_instrumentation_beeai-0.1.10}/src/openinference/instrumentation/beeai/processors/agents/react.py +0 -0
  16. {openinference_instrumentation_beeai-0.1.9 → openinference_instrumentation_beeai-0.1.10}/src/openinference/instrumentation/beeai/processors/agents/requirement_agent.py +0 -0
  17. {openinference_instrumentation_beeai-0.1.9 → openinference_instrumentation_beeai-0.1.10}/src/openinference/instrumentation/beeai/processors/agents/tool_calling.py +0 -0
  18. {openinference_instrumentation_beeai-0.1.9 → openinference_instrumentation_beeai-0.1.10}/src/openinference/instrumentation/beeai/processors/chat.py +0 -0
  19. {openinference_instrumentation_beeai-0.1.9 → openinference_instrumentation_beeai-0.1.10}/src/openinference/instrumentation/beeai/processors/embedding.py +0 -0
  20. {openinference_instrumentation_beeai-0.1.9 → openinference_instrumentation_beeai-0.1.10}/src/openinference/instrumentation/beeai/processors/locator.py +0 -0
  21. {openinference_instrumentation_beeai-0.1.9 → openinference_instrumentation_beeai-0.1.10}/src/openinference/instrumentation/beeai/processors/requirement.py +0 -0
  22. {openinference_instrumentation_beeai-0.1.9 → openinference_instrumentation_beeai-0.1.10}/src/openinference/instrumentation/beeai/processors/workflow.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openinference-instrumentation-beeai
3
- Version: 0.1.9
3
+ Version: 0.1.10
4
4
  Summary: OpenInference BeeAI Instrumentation
5
5
  Project-URL: Homepage, https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-beeai
6
6
  Author: IBM Corp.
@@ -1,9 +1,12 @@
1
+ import contextlib
1
2
  import logging
2
3
  from importlib.metadata import PackageNotFoundError, version
3
- from typing import TYPE_CHECKING, Any, Callable, Collection
4
+ from typing import TYPE_CHECKING, Any, Callable, Collection, Generator
4
5
 
5
6
  from opentelemetry.trace import StatusCode
6
7
 
8
+ from openinference.instrumentation._spans import OpenInferenceSpan
9
+
7
10
  if TYPE_CHECKING:
8
11
  from beeai_framework.emitter import EventMeta
9
12
 
@@ -29,12 +32,13 @@ except PackageNotFoundError:
29
32
 
30
33
 
31
34
  class BeeAIInstrumentor(BaseInstrumentor): # type: ignore
32
- __slots__ = ("_tracer", "_cleanup", "_processes")
35
+ __slots__ = ("_tracer", "_cleanup", "_processes", "_processes_deps")
33
36
 
34
37
  def __init__(self, *args: Any, **kwargs: Any) -> None:
35
38
  super().__init__(*args, **kwargs)
36
39
  self._cleanup: Callable[[], None] = lambda: None
37
40
  self._processes: dict[str, Processor] = {}
41
+ self._processes_deps: dict[str, list[Processor]] = {}
38
42
 
39
43
  def instrumentation_dependencies(self) -> Collection[str]:
40
44
  return _instruments
@@ -66,8 +70,16 @@ class BeeAIInstrumentor(BaseInstrumentor): # type: ignore
66
70
  def _uninstrument(self, **kwargs: Any) -> None:
67
71
  self._cleanup()
68
72
  self._processes.clear()
73
+ self._processes_deps.clear()
74
+
75
+ def _build_tree(self, processor: Processor) -> None:
76
+ with self._build_tree_for_span(processor.span):
77
+ for child in self._processes_deps.pop(processor.run_id):
78
+ self._build_tree(child)
79
+ self._processes.pop(processor.run_id)
69
80
 
70
- def _build_tree(self, node: SpanWrapper) -> None:
81
+ @contextlib.contextmanager
82
+ def _build_tree_for_span(self, node: SpanWrapper) -> Generator[OpenInferenceSpan, None, None]:
71
83
  with self._tracer.start_as_current_span(
72
84
  name=node.name,
73
85
  openinference_span_kind=node.kind,
@@ -75,13 +87,16 @@ class BeeAIInstrumentor(BaseInstrumentor): # type: ignore
75
87
  start_time=_datetime_to_span_time(node.started_at) if node.started_at else None,
76
88
  end_on_exit=False, # we do it manually
77
89
  ) as current_span:
90
+ yield current_span
91
+
78
92
  for event in node.events:
79
93
  current_span.add_event(
80
94
  name=event.name, attributes=event.attributes, timestamp=event.timestamp
81
95
  )
82
96
 
83
97
  for children in node.children:
84
- self._build_tree(children)
98
+ with self._build_tree_for_span(children):
99
+ pass
85
100
 
86
101
  current_span.set_status(node.status)
87
102
  if node.error is not None and node.status == StatusCode.ERROR:
@@ -91,7 +106,8 @@ class BeeAIInstrumentor(BaseInstrumentor): # type: ignore
91
106
 
92
107
  @exception_handler
93
108
  async def _handler(self, data: Any, event: "EventMeta") -> None:
94
- assert event.trace is not None, "Event must have a trace"
109
+ if event.trace is None:
110
+ return
95
111
 
96
112
  if event.trace.run_id not in self._processes:
97
113
  parent = (
@@ -102,9 +118,10 @@ class BeeAIInstrumentor(BaseInstrumentor): # type: ignore
102
118
  if event.trace.parent_run_id and not parent:
103
119
  raise ValueError(f"Parent run with ID {event.trace.parent_run_id} was not found!")
104
120
 
121
+ self._processes_deps[event.trace.run_id] = []
105
122
  node = self._processes[event.trace.run_id] = ProcessorLocator.locate(data, event)
106
123
  if parent is not None:
107
- parent.span.children.append(node.span)
124
+ self._processes_deps[parent.run_id].append(node)
108
125
  else:
109
126
  node = self._processes[event.trace.run_id]
110
127
 
@@ -112,8 +129,8 @@ class BeeAIInstrumentor(BaseInstrumentor): # type: ignore
112
129
 
113
130
  if isinstance(data, RunContextFinishEvent):
114
131
  await node.end(data, event)
115
- self._build_tree(node.span)
116
- self._processes.pop(event.trace.run_id)
132
+ if event.trace.parent_run_id is None:
133
+ self._build_tree(node)
117
134
  else:
118
135
  if event.context.get("internal"):
119
136
  return
@@ -24,6 +24,9 @@ class Processor:
24
24
  assert isinstance(meta.creator, RunContext)
25
25
  target_cls = type(meta.creator.instance)
26
26
 
27
+ assert meta.trace is not None
28
+ self.run_id = meta.trace.run_id
29
+
27
30
  self.span = SpanWrapper(name=target_cls.__name__, kind=type(self).kind)
28
31
  self.span.started_at = meta.created_at
29
32
  self.span.attributes.update(
@@ -2,7 +2,7 @@ from typing import Any, ClassVar
2
2
 
3
3
  from beeai_framework.context import RunContext, RunContextStartEvent
4
4
  from beeai_framework.emitter import EventMeta
5
- from beeai_framework.tools import ToolErrorEvent, ToolRetryEvent, ToolSuccessEvent
5
+ from beeai_framework.tools import ToolErrorEvent, ToolRetryEvent, ToolStartEvent, ToolSuccessEvent
6
6
  from beeai_framework.tools.tool import Tool
7
7
  from typing_extensions import override
8
8
 
@@ -48,6 +48,10 @@ class ToolProcessor(Processor):
48
48
  self.span.add_event(f"{meta.name} ({meta.path})", timestamp=meta.created_at)
49
49
 
50
50
  match event:
51
+ case ToolStartEvent():
52
+ pass
53
+ case None: # finish event
54
+ pass
51
55
  case ToolSuccessEvent():
52
56
  output_cls = type(event.output)
53
57