Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions openinference-streaming.patch
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ diff --git a/python/instrumentation/openinference-instrumentation-beeai/src/open
index d3f3adc6..5497ff77 100644
--- a/python/instrumentation/openinference-instrumentation-beeai/src/openinference/instrumentation/beeai/__init__.py
+++ b/python/instrumentation/openinference-instrumentation-beeai/src/openinference/instrumentation/beeai/__init__.py
@@ -1,18 +1,15 @@
@@ -1,18 +1,16 @@
-import contextlib
import logging
+from enum import Enum
from importlib.metadata import PackageNotFoundError, version
-from typing import TYPE_CHECKING, Any, Callable, Collection, Generator
+from typing import TYPE_CHECKING, Any, Callable, Collection
Expand All @@ -25,7 +26,7 @@ index d3f3adc6..5497ff77 100644
from openinference.instrumentation import (
OITracer,
TraceConfig,
@@ -32,13 +29,14 @@ except PackageNotFoundError:
@@ -32,13 +30,14 @@ except PackageNotFoundError:


class BeeAIInstrumentor(BaseInstrumentor): # type: ignore
Expand All @@ -42,7 +43,7 @@ index d3f3adc6..5497ff77 100644

def instrumentation_dependencies(self) -> Collection[str]:
return _instruments
@@ -70,39 +68,81 @@ class BeeAIInstrumentor(BaseInstrumentor): # type: ignore
@@ -70,39 +69,85 @@ class BeeAIInstrumentor(BaseInstrumentor): # type: ignore
def _uninstrument(self, **kwargs: Any) -> None:
self._cleanup()
self._processes.clear()
Expand Down Expand Up @@ -81,6 +82,13 @@ index d3f3adc6..5497ff77 100644
+ node = processor.span
+ _OTEL_TYPES = (bool, str, bytes, int, float)
+ for key, value in node.attributes.items():
+ # Extract enum value if it's an enum
+ if isinstance(value, Enum):
+ value = value.value
+ # Extract enum values from arrays/tuples
+ elif isinstance(value, (list, tuple)):
+ value = type(value)(v.value if isinstance(v, Enum) else v for v in value)
+ # Convert to string if not an OTEL type
Comment thread
qodo-for-packit[bot] marked this conversation as resolved.
+ if not isinstance(value, _OTEL_TYPES) and not (
+ isinstance(value, (list, tuple)) and all(isinstance(v, _OTEL_TYPES) for v in value)
+ ):
Expand Down Expand Up @@ -147,7 +155,7 @@ index d3f3adc6..5497ff77 100644

@exception_handler
async def _handler(self, data: Any, event: "EventMeta") -> None:
@@ -118,10 +158,8 @@ class BeeAIInstrumentor(BaseInstrumentor): # type: ignore
@@ -118,10 +163,8 @@ class BeeAIInstrumentor(BaseInstrumentor): # type: ignore
if event.trace.parent_run_id and not parent:
raise ValueError(f"Parent run with ID {event.trace.parent_run_id} was not found!")

Expand All @@ -159,7 +167,7 @@ index d3f3adc6..5497ff77 100644
else:
node = self._processes[event.trace.run_id]

@@ -129,8 +167,8 @@ class BeeAIInstrumentor(BaseInstrumentor): # type: ignore
@@ -129,8 +172,8 @@ class BeeAIInstrumentor(BaseInstrumentor): # type: ignore

if isinstance(data, RunContextFinishEvent):
await node.end(data, event)
Expand Down
22 changes: 18 additions & 4 deletions trace_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,19 @@ def _b64_to_hex(value: str) -> str:
return value


_TRACE_ID_RE = re.compile(r"^[0-9a-fA-F]{32}$")
_SPAN_ID_RE = re.compile(r"^[0-9a-fA-F]{16}$")


def _normalize_hex_id(value: str, pattern: re.Pattern) -> str:
"""Lowercase a hex trace/span ID so lookups are case-insensitive.

Only touches values that actually look like the expected hex ID, so
non-hex or malformed IDs are passed through untouched.
"""
return value.lower() if pattern.match(value) else value


def _normalize_protobuf_ids(otlp_data: dict) -> None:
"""Convert base64 trace/span IDs produced by MessageToDict to hex in-place."""
for rs in otlp_data.get("resourceSpans") or []:
Expand Down Expand Up @@ -366,9 +379,9 @@ def _extract_spans(otlp_data: dict) -> list[SpanRow]:
status_code = _STATUS_CODE_NAMES.get(status_code, 0)
spans.append(
SpanRow(
trace_id=span.get("traceId") or "",
span_id=span.get("spanId") or "",
parent_span_id=span.get("parentSpanId") or "",
trace_id=_normalize_hex_id(span.get("traceId") or "", _TRACE_ID_RE),
span_id=_normalize_hex_id(span.get("spanId") or "", _SPAN_ID_RE),
parent_span_id=_normalize_hex_id(span.get("parentSpanId") or "", _SPAN_ID_RE),
name=name,
start_time=int(span.get("startTimeUnixNano") or 0),
end_time=int(span.get("endTimeUnixNano") or 0) or None,
Expand Down Expand Up @@ -488,6 +501,7 @@ def query_spans(issue: str, params: dict) -> list[dict]:
trace_id = params.get("trace_id")
if not trace_id:
return []
trace_id = _normalize_hex_id(trace_id, _TRACE_ID_RE)
query_bindings: list = [trace_id]
subquery = "SELECT ? AS trace_id"

Expand Down Expand Up @@ -536,7 +550,7 @@ def query_spans(issue: str, params: dict) -> list[dict]:

if trace_id := params.get("trace_id"):
issue_conditions.append("si.trace_id = ?")
issue_bindings.append(trace_id)
issue_bindings.append(_normalize_hex_id(trace_id, _TRACE_ID_RE))

if names := params.get("name"):
name_list = [n.strip() for n in names.split(",")]
Expand Down
Loading
Loading