Skip to content

Export traces and metrics over OpenTelemetry #1539

Backlog

Description

@gedaiu

Hi! Right now the server only logs to stdout, and several recent problems were hard to see from there: a source stuck as queued (#1451), sync checkpoints skipping tickets (#1359), alignment re-queueing on an empty balance (#1381), a lane running days behind.

I'd like to add optional OpenTelemetry export. It stays off unless OTEL_EXPORTER_OTLP_ENDPOINT is set, so nothing changes for anyone who doesn't set it. The existing tracing spans get a tracing-opentelemetry layer, and a few metrics are added, labelled by knowledge base where it makes sense:

  • jobs: queue size and oldest wait per base and lane, outcomes, retries, duration
  • storage per base: chunks, facts, vectors, blob bytes (one grouped query every few minutes)
  • throughput and processing time per item and stage
  • model calls: latency, tokens, cost, errors by the existing classes (rate limited, out of credit, rejected, ...)
  • syncs: items listed, fetched and written, upstream status codes, last success
  • search latency per base

I'd send it as small PRs, each under 500 lines, starting with the setup plus the job queue metrics. Does this shape work for you? Happy to change anything.

Activity

  1. gedaiu commented on Nov 28, 2026

    @gedaiu
    ContributorAuthor

    Hi! Gentle nudge, no rush at all. The first slices are up as drafts so the shape is easy to see: #1540 (setup and queue size per base), #1541 (oldest wait) and #1543 (model call duration, tokens and outcome). Export stays off unless OTEL_EXPORTER_OTLP_ENDPOINT is set.

    If the plan above works for you, I'll mark #1540 ready. If you'd rather change the metric names, the labels or the order, I'm happy to rework them first. Thanks!

  2. WaylandYang commented on Nov 29, 2026

    @WaylandYang
    Contributor

    Thanks for the plan and for the patience; sorry it took a while to answer. Yes, optional OTLP export that stays off unless OTEL_EXPORTER_OTLP_ENDPOINT is set works for us, and the drafts made the shape easy to see.

    Having read the whole stack (#1540 to #1548), I'd like it smaller before it goes in. Most of the 1,800 lines go into carrying a base to every model call: CallObserver and CallRecord around all five call paths, with_observer, AppState::observed, about 20 call sites edited, and an extra base_of query after every job. Here's what I'd suggest:

    1. No kb label on model-call metrics. Credit and rate limits belong to the model and the workspace's settings, not to a base, and per-base load already shows in the queue gauges. Without the base, utopia-llm can report through one process-wide hook set once in main (a OnceLock, so the crate still doesn't depend on OpenTelemetry), and the per-client observer, the AppState fields and the call-site edits all go away. Labels: model, task, outcome, plus kind on tokens.

    2. A bounded task label. call_label is the first sentence of the system prompt, which is fine in a log line, but a metric label has to stay a small fixed set. If every system prompt starts with a constant sentence, keep it, and a test asserting that would help. Otherwise use fixed names (chat, tools, embed, …).

    3. Job metrics labelled by kind and outcome only. That drops the base_of query per finished job. The queue gauges keep kb, and that's where a stuck base shows up. The JobOutcome::of / outcome_label refactor is good, please keep it.

    4. Three PRs instead of seven, each against dev rather than stacked:

      I'll review and merge them in that order.

    Smaller things for the first PR:

    • The OTel layer sits under the same EnvFilter as stdout, so utopia=debug spans get exported too. A separate filter on the OTel layer (default info) would keep the trace volume down.
    • Lighter tests: one in-memory exporter test per metric is plenty.

    Storage, sync and search metrics from the original list can come later as their own small PRs. Thanks again, this will make the next #1381 much easier to see.

  3. gedaiu commented on Nov 29, 2026

    @gedaiu
    ContributorAuthor

    Thank you for reading the whole stack so carefully, and no worries at all about the wait. Your suggestions make sense, and they make the whole thing a lot smaller. I'll go with all of them:

    1. No kb on model-call metrics. utopia-llm reports through one process-wide hook set once in main (a OnceLock, so no OpenTelemetry in the crate). The per-client observer, the AppState fields and the call-site edits go away. Labels: model, task, outcome, plus kind on tokens.
    2. A bounded task label. I'll check whether every system prompt starts with a constant sentence. If they do, I'll add a test asserting it; if not, I'll use fixed names.
    3. Job metrics labelled by kind and outcome only, without the base_of query, keeping JobOutcome::of / outcome_label.
    4. Three PRs against dev. I'll start with The server can export its job queue size and oldest wait per base over OpenTelemetry #1540, folding The server exports how long the oldest due job has waited #1541 into it and giving the OTel layer its own filter (default info), and trim the tests to one in-memory exporter test per metric. Then model calls and job outcomes, in that order. I'll close The server exports how long the oldest due job has waited #1541 and Model calls report their duration, tokens and outcome per base #1543 to Finished jobs report their outcome and duration per kind and base #1548 as the replacements open.

    Storage, sync and search will come later as their own small PRs. Thanks again!

  4. gedaiu commented on Nov 29, 2026

    @gedaiu
    ContributorAuthor

    @WaylandYang thanks again for the suggestions. The three PRs are up in the shape you described, all green, in the order you asked for:

    1. The server can export its job queue size and oldest wait per base over OpenTelemetry #1540: setup plus both queue gauges, with The server exports how long the oldest due job has waited #1541 folded in. The OTel layer has its own filter (info by default, UTOPIA_OTEL_FILTER to change it), and there's one in-memory exporter test per gauge.
    2. The server exports the time and tokens of every model call over OpenTelemetry #1556: model calls through one process-wide hook set in main (a OnceLock), with no kb label, no AppState fields and no call-site edits. Labels are model, task (fixed: chat, tools, embed) and outcome, plus kind on tokens.
    3. The server exports how many jobs finish and how long they take over OpenTelemetry #1557: job outcomes labelled by kind and outcome only, with no base_of query, keeping JobOutcome::of / outcome_label.

    #1556 and #1557 each build on #1540, so their diffs will shrink to a single commit once it merges. I'll update them onto dev then. #1541 and #1543 to #1548 are closed.

    And on #1544, the EXPLAIN (ANALYZE, BUFFERS) numbers you asked for are posted, along with a small speedup for the "nothing new" case.

    No rush at all, whenever you have time. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions