Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
Signed-off-by: Teo <teocns@gmail.com>
  • Loading branch information
teocns committed Nov 27, 2024
1 parent 27a4cf6 commit 36a725e
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 129 deletions.
20 changes: 13 additions & 7 deletions agentops/session/exporter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import json
import sys
import threading
from abc import ABC
from datetime import datetime, timezone
Expand Down Expand Up @@ -207,7 +208,6 @@ def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
for span in spans:
# Convert span attributes to event using adapter
event = GenericAdapter.from_span_attributes(span.attributes or {})

# Add session ID
event["session_id"] = str(self.session.session_id)
events.append(event)
Expand Down Expand Up @@ -281,20 +281,26 @@ def _setup_otel(self):
self._exporter = SessionExporter(self) # type: ignore

# Create and configure tracer provider
self._tracer_provider = TracerProvider(resource=Resource.create({SERVICE_NAME: "agentops"}))
self._tracer_provider = TracerProvider()
self._otel_tracer = self._tracer_provider.get_tracer(
f"agentops.session.{str(self.session_id)}",
)
# Create and register span processor with test-friendly settings
self._span_processor = BatchSpanProcessor(
self._exporter,
max_queue_size=self.config.max_queue_size,
schedule_delay_millis=self.config.max_wait_time,
max_export_batch_size=min(max(self.config.max_queue_size // 20, 1), min(self.config.max_queue_size, 32)),
export_timeout_millis=20000,
)

# Create and register span processor
self._span_processor = BatchSpanProcessor(self._exporter)
self._tracer_provider.add_span_processor(self._span_processor)

# Get tracer
self._tracer = self._tracer_provider.get_tracer(__name__)

def _record_otel_event(self, event: Union[Event, ErrorEvent], flush_now: bool = False) -> None:
"""Record an event using OpenTelemetry spans"""
if not hasattr(self, "_tracer"):
self._setup_otel()

# Create span context
context = set_value("session_id", str(self.session_id))
token = attach(context)
Expand Down
Loading

0 comments on commit 36a725e

Please sign in to comment.