AgentObs.Handlers.Phoenix (agent_obs v0.1.4)

View Source

Arize Phoenix handler for AgentObs.

This handler translates AgentObs telemetry events into OpenTelemetry spans with OpenInference semantic conventions, suitable for export to Arize Phoenix or any OpenInference-compatible observability platform.

Configuration

config :agent_obs,
  handlers: [AgentObs.Handlers.Phoenix]

config :agent_obs, AgentObs.Handlers.Phoenix,
  endpoint: "http://localhost:6006/v1/traces",
  api_key: nil  # Optional, for authenticated Phoenix instances

OpenTelemetry SDK Configuration

This handler requires the OpenTelemetry SDK to be configured in your application. Add to config/runtime.exs:

config :opentelemetry,
  span_processor: :batch,
  resource: [service: [name: "my_llm_agent"]]

config :opentelemetry_exporter,
  otlp_protocol: :http_protobuf,
  otlp_endpoint: System.fetch_env!("ARIZE_PHOENIX_OTLP_ENDPOINT"),
  otlp_headers: [
    {"authorization", "Bearer #{System.get_env("ARIZE_PHOENIX_API_KEY")}"}
  ]

How It Works

  1. Attaches to all AgentObs telemetry events (:agent, :tool, :llm, :prompt)
  2. On :start events, creates an OpenTelemetry span and stores context in process dictionary
  3. On :stop events, adds attributes and ends the span
  4. On :exception events, records the exception and marks span as errored
  5. Uses Phoenix.Translator to convert metadata to OpenInference attributes

Span Context Management

Spans are stored in the process dictionary with a unique key per event type. This allows nested instrumentation (e.g., agent -> llm -> tool) to create proper parent-child span relationships automatically.

Summary

Functions

Returns a specification to start this module under a supervisor.

Starts the Phoenix handler GenServer.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts)

@spec start_link(map()) :: GenServer.on_start()

Starts the Phoenix handler GenServer.

Called by AgentObs.Supervisor with handler-specific configuration.