ExAgent.Telemetry (ExAgent v3.0.0)

View Source

Telemetry event helpers.

Stability — Stable.

The framework emits the standard Elixir :telemetry events so any host app can observe agent runs through the usual OTel / Telemetry.Metrics / LiveDashboard pipeline.

Events

:system_time is the VM's Unix time in native units. :duration is monotonic elapsed time in native units. Metadata never carries prompts, messages, tool arguments or results: content reaches traces only through the opt-in redactor of ExAgent.Observability.OpenTelemetry.

The run and model-request events carry :telemetry_span_context in their metadata. Match this opaque string by equality to pair a start with its stop or exception. Resuming a paused run creates a fresh context. Run and logical model request events also carry :namespace from the host runtime or continuation Store. Absent or overlong namespaces appear as nil. Namespace strings are limited to 512 UTF-8 bytes in metadata and are excluded from the built-in metric tags.

Every [:exagent, :run, *] event carries the lineage :run_id, :root_run_id (equal to :run_id for a root run), :parent_run_id (nil for a root run) and the :attempt_id of this execution attempt.

  • [:exagent, :mcp, :catalogue, :drift] (candidate) — a pinned client completed a comparison with differences. Measurements count :added, :removed and :changed declaration names. Metadata carries :revision and :on_drift.
  • [:exagent, :run, :start] — measurements: %{system_time}, metadata: %{agent} plus lineage
  • [:exagent, :run, :stop] — measurements: %{duration}, metadata: %{agent, status, usage, steps} plus lineage. A confirmed approval pause reports :paused and success reports :succeeded. Duration covers this attempt. Usage and steps include earlier attempts of the run. Usage retains qualified accounting. usage.details holds known numeric counters under string keys such as "cached_tokens". A missing key is unknown.
  • [:exagent, :run, :exception] — measurements: %{duration}, metadata: %{agent, reason} plus lineage. reason is the bounded diagnostic (%{type: ...}, plus provider and status for a request error), never the run error's own strings. Both run terminal events include usage and cost coverage from their result.
  • [:exagent, :model, :request, :start | :stop | :exception] — one start and one stop or exception per admitted model request, output retries included. Metadata: %{agent, run_id, root_run_id, model_request_id, step, model, provider, stream, fixture}; stop and exception add usage_status, usage_quality, cost_status (cost_cents for a full estimate or cost_subtotal_cents for a known portion). Stop adds finish_reason and exception adds a bounded reason diagnostic. A provider's incomplete terminal ({:incomplete_response, finish}, such as :length) is a stop with that finish_reason and its reported tokens, whichever the model. Stop measurements are %{duration} plus :input_tokens, :output_tokens, :cache_read_tokens, :cache_write_tokens and :reasoning_tokens only for the dimensions the provider reported: an unreported dimension is absent, never zero. ExAgent.Models.ReqLLM counts a dimension only with evidence (see its "Usage" section).

  • [:exagent, :model, :reasoning_prefix, :reset] (candidate) — input reasoning retired when projecting a request, selecting a portable ReqLLM leaf or processing a reported Responses prefix mismatch. Measurements: %{dropped_blocks}. Metadata: %{model, provider, reasons} and, in a run, run_id and model_request_id. The reasons are bounded atoms. The event carries no history, fingerprints, signature bytes, or provider item IDs.
  • [:exagent, :model, :attempt, :start | :stop] emits one pair per model adapter dispatch in a run, including Fallback leaves and their retries. Start measures system_time. Both events carry agent, run_id, root_run_id, model_request_id, step, model, provider, operation, conversation_compacted, stream, source, fixture, telemetry_span_context. The opaque span context matches the span's exagent.attempt.id. Group by the logical request ID. The candidate GenAI fields are operation ("chat") and conversation_compacted. conversation_compacted is true when the effective projection is known to be compacted and nil otherwise. Model and GenAI provider labels come from the selected adapter. Invalid labels map to "other". Source is :test for ExAgent.Models.Test and :adapter for other callbacks. fixture is :record during cassette recording and nil otherwise. Replay bypasses dispatch and appears on the logical request with fixture: :replay. Stop measures duration and any known token dimensions listed above. It adds outcome (:succeeded, :failed, :incomplete or :cancelled), finish_reason, http_status and the same coverage and price fields as logical requests. The price is the adapter's estimate when supplied. The finish, HTTP status and usage quality are nil when unavailable.

  • [:exagent, :embeddings, :request, :start | :stop] (candidate) — one pair per admitted embeddings or rerank dispatch. Metadata includes operation ("embeddings" or "rerank"), provider, model, input_items, run_id, call_ref and telemetry_span_context. The latter matches the span's exagent.request_id. Start measures system_time. Stop carries outcome, reason, http_status and qualified usage and cost metadata. Stop measures duration, available token counts and any observed rerank_search_units. Unavailable measurements are omitted.

  • [:exagent, :media, :request, :start | :stop] (candidate) — admitted transcription, speech, image generation and OCR requests. Metadata includes operation, provider, model, run_id, call_ref and telemetry_span_context. On return, stop adds the outcome, HTTP status when available, qualified usage_units and cost metadata. Measurements include duration and available token counts or media units. Media input, output and provider error bodies are excluded.

  • [:exagent, :tool, :stop] — :duration is in native time units. Metadata includes :agent, :run_id, the declared :tool_name (or "unknown_tool"), the invocation's opaque :call_ref, the tool return's :status, :success (status == :succeeded) and :duration_measured. When the worker returns its elapsed time, :duration_measured is true. If it exits without reporting a duration, the value covers the whole tool batch, including other calls, and :duration_measured is false. For a nested candidate Tool.CodeMode step, metadata also includes :program_call_ref, the one-based :program_step and :effect.
  • [:exagent, :guardrail, :tripped] counts a policy decision with %{count: 1} and metadata name, stage, run_id, root_run_id, attempt_id.
  • [:exagent, :output, :partial] counts structured stream previews with %{count: 1} and metadata %{mode: :tool | :native | :prompted}.
  • [:exagent, :model, :retry] — emitted by ExAgent.Models.Fallback before a retry or fallback; measurements: %{attempt, delay_ms}, metadata: %{model, status, fallback}
  • [:exagent, :rate_limiter, :wait | :reject | :cooldown] — queued attempt, refused attempt or received provider cooldown. Measurements include count: 1 and wait_ms when known. Metadata contains the configured quota :key.

  • [:exagent, :rate_limiter, :settlement_retry] — background retry of a shared permit's terminal report. Measurements are %{count: 1, delay_ms: delay} and metadata contains the configured quota :key. A single late report uses a delay of zero.
  • [:exagent, :usage_limits, :budget, :settlement] (candidate) describes a terminal spend observation or an acknowledged host reconciliation. Measurements include count: 1, the runtime's reservation_cents when available, and either charged_cents for a confirmed full charge or subtotal_cents for partial evidence. Unknown amounts are absent. Metadata contains reservation_id, bounded labels and source (:runtime or :reconciliation). Values of coverage are :available, :partial or :unavailable, with outcome :priced, :unused or :held. A repeated reconciliation can report the same reservation ID. Runtime charges are based on qualified estimates.
  • [:exagent, :usage_limits, :budget, :threshold] (candidate) reports a reached spend threshold. Measurements include count: 1, charged_cents and limit_cents. Metadata contains window_start (Unix milliseconds), threshold (whole percent) and account (the local ETS account name or the lowercase hexadecimal PostgreSQL scope digest). Delivery is best effort. An account claims a threshold at most once per window.
  • [:exagent, :usage_limits, :budget, :settlement, :unconfirmed] (candidate) counts a settlement whose retry could not be confirmed. Measurements are %{count: 1} and metadata is empty.
  • [:exagent, :conversations, :activation] counts cold activation activity with %{count: 1}. Metadata contains only :status, one of :waiting, :queue_full, :capacity, :wait_timeout, :factory_timeout, :start_unconfirmed or :reconciled. Reconciliation releases a reservation when its start settles or its supervising partition exits.
  • [:exagent, :job, :start] and [:exagent, :job, :stop] — ExAgent.Jobs; measurements: %{system_time} / %{duration}, metadata: %{job_id, name} (and status on stop)
  • [:exagent, :store, :postgres, :maintenance_failed] (candidate) counts a failed cleanup for one table with %{count: 1} and metadata %{repo, table, error}. The error is a diagnostic map with a string :type and excludes SQL, row data and exception messages.
  • [:exagent, :chat, :checkpoint_wait_expired] (candidate) counts a generated chat resume job cancelled after waiting for a pending checkpoint. Measurements are %{count: 1} and metadata is %{job_id}.
  • [:exagent, :judge, :verdict] — ExAgent.Judge; measurements: %{count: 1}, metadata: %{kind, verdict}
  • [:exagent, :eval, :online, :result] — measurements: %{count: 1, duration, system_time}. duration covers grading, including the wait for a durable grade. Both times use native units. Metadata includes projection_version: 1, event_name, id, scope, run_id, run_status, source, evaluator, evaluator_version, response_id, trace, tools, tools_complete, score, label, error and grading. The optional trace contains IDs and sampling flags. Grading usage is qualified and tools use safe identities.
  • [:exagent, :eval, :online, :delivery] — measurements: %{count: 1}. Metadata shares the result's projection_version, id, scope, run_id, source, evaluator and evaluator_version. status is :dispatched when the OTLP callback returned :ok and any durable marker was confirmed, or :delivery_unconfirmed otherwise. Queues without an OTLP callback emit only the result.
  • [:exagent, :eval, :online, :discard] — measurements: %{count: 1}. Metadata includes projection_version: 1, scope, run_id, source, evaluator, evaluator_version and reason. It reports an admitted sample that yielded no published grade, for example when a C7 receipt could not be verified or a durable export claim was unconfirmed.
  • [:exagent, :memory, :command] — ExAgent.Memory.tool/2 and the preload of ExAgent.Memory.capability/2 (command: :preload); measurements: %{count: 1}, metadata: %{command, status} (no scope or content)
  • [:exagent, :compaction, :stop] — ExAgent.Compaction.capability/2, once per model request; measurements: %{duration, input_messages, output_messages}, metadata: %{agent, run_id, step, compactor, status, error}. status is :compacted, :no_change or :error; on :error the request keeps its incoming projection and error is a bounded diagnostic (no content).

Summary

Functions

Metric definitions for LiveDashboard and Telemetry.Metrics reporters.

Functions

metrics()

@spec metrics() :: [Telemetry.Metrics.t()]

Metric definitions for LiveDashboard and Telemetry.Metrics reporters.

Available when compiled with the optional :telemetry_metrics dependency. Durations are milliseconds. Request and attempt token sums retain their usage quality and coverage tags. Attempts can include known subtotals. Correlation IDs, provider and model are available to event handlers. The built-in series use fixed tags. Error counters tag known diagnostic types. Custom types share "other".