Class OtelAgenorTelemetry

java.lang.Object
dev.agenor.adapters.telemetry.OtelAgenorTelemetry
All Implemented Interfaces:
AgenorTelemetry, AutoCloseable

public final class OtelAgenorTelemetry extends Object implements AgenorTelemetry, AutoCloseable
AgenorTelemetry implementation backed by the OpenTelemetry SDK.

Each call to spanBuilder(String) captures the current OTel Context, so spans started from it are automatically children of the ambient parent span. Parent-child relationships are preserved across virtual-thread boundaries as long as the caller holds the context correctly (e.g., within a try-with-resources scope returned by Context.makeCurrent()).

Use OtelTelemetryFactory to construct instances:


 AgenorTelemetry telemetry = OtelTelemetryFactory.builder()
     .serviceName("my-agent")
     .exporter("otlp-http")
     .endpoint("http://localhost:4318")
     .build();
 
Since:
0.19.0
  • Constructor Details

    • OtelAgenorTelemetry

      public OtelAgenorTelemetry(io.opentelemetry.api.OpenTelemetry openTelemetry)
      Creates an OtelAgenorTelemetry backed by the given OpenTelemetry instance.

      The instance is retained so that close() can flush and shut down the underlying OpenTelemetrySdk (including its BatchSpanProcessor) when the runtime stops. Without holding a reference the SDK would be eligible for GC immediately after construction, silently discarding all buffered spans.

      Parameters:
      openTelemetry - the configured OTel instance; never null
  • Method Details

    • close

      public void close()
      Flushes and shuts down the underlying OTel SDK.

      Forces the BatchSpanProcessor to export any buffered spans before the process exits. Called automatically by AgenorRuntime.stop() when telemetry is AutoCloseable.

      Specified by:
      close in interface AutoCloseable
    • spanBuilder

      public SpanBuilder spanBuilder(String operationName)
      Description copied from interface: AgenorTelemetry
      Returns a SpanBuilder for the given operation name.

      The returned builder captures the current tracing context so that spans started from it are automatically children of the ambient parent span.

      Specified by:
      spanBuilder in interface AgenorTelemetry
      Parameters:
      operationName - the name of the span (e.g. "llm.chat"); never null
      Returns:
      a new span builder; never null