Skip to content

[FEATURE] Add traces and logs to the telemetry package (single CLI telemetry engine) #893

Closed

Description

@edenreich

Summary

The internal/telemetry package currently records the metrics signal only
(gen_ai.* + infer.* instruments via the OTel SDK, exported to a local
OTLP/semconv file and, opt-in, pushed over OTLP/HTTP). The package was
deliberately named "telemetry" rather than "metrics" to leave room for the
other OTel signals. This issue tracks adding traces and logs so the CLI
becomes the single telemetry engine for all three signals.

Direction: the CLI is the one place telemetry is produced and it is fully
configurable via the standard OTel environment variables. Downstream consumers
(infer-action, CI, operators) only set env vars and run infer - they never
re-implement export. The metrics path already honors
OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, OTEL_SERVICE_NAME,
and OTEL_RESOURCE_ATTRIBUTES; traces and logs must follow the same pattern and
share the same resource.

Traces

A trace makes an agent run legible end to end: one root span per session, child
spans for each LLM stream and each tool call, so latency and failures attribute
to a specific step instead of being read off an aggregate counter.

Proposed span shape (GenAI semconv):

  • Root: session span - infer.execution.mode, agent mode, infer.run.outcome, duration.
  • Child: chat <model> per LLM turn - gen_ai.request.model, gen_ai.provider.name, token usage.
  • Child: execute_tool <name> per tool call - gen_ai.tool.name, gen_ai.tool.type=function, infer.tool.outcome, error.type.

W3C trace-context propagates to the gateway so CLI spans link to gateway spans.

Logs

Emit the CLI's structured logs through the OTel logs signal (OTLP), correlated
to the active trace/span, so a run's metrics, spans, and logs share one resource
and one correlation id. Local-first: a file exporter when no endpoint is set.

Shared with metrics

  • Same resource (service.name, service.version, infer.execution.mode + env attrs).
  • Same endpoint/headers config (telemetry.otlp.* / OTEL_EXPORTER_OTLP_*).
  • Local-first, remote opt-in, delta temporality, no prompt/response content recorded.
  • Zero overhead when telemetry.enabled=false.

Acceptance Criteria

  • Tracer provider wired in internal/telemetry sharing the resource and OTLP endpoint/headers config with the meter provider.
  • Session root span with per-LLM-turn and per-tool-call child spans, GenAI semconv names/attributes, no prompt/response content.
  • W3C trace-context propagated to the gateway so CLI spans link to gateway spans.
  • Logger provider wired: CLI structured logs exported via OTLP logs, correlated to the active span; local file export when no endpoint is set.
  • All three signals honor OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, OTEL_SERVICE_NAME, OTEL_RESOURCE_ATTRIBUTES; zero overhead when disabled.
  • [DOCS] follow-up filed against inference-gateway/docs for tracing/logs config + example collector setup.

Activity

  1. added
    enhancement
    on Jul 12, 2026
  2. moved this to Todo in 2026on Jul 12, 2026
  3. edenreich commented on Jul 13, 2026

    @edenreich
    ContributorAuthor

    @infer Can you work on this? use /go /go-concurrency /ponytail:ponytail

  4. inference-gateway-maintainer commented on Jul 13, 2026

    @inference-gateway-maintainer
    Contributor

    Model: ollama_cloud/deepseek-v4-flash · View Job

    Todos

    • Read current telemetry package to understand metrics implementation
    • Read telemetry config and related config files
    • Set up working branch and add OTel trace/log dependencies
    • Add tracer provider sharing resource and OTLP config with meter provider
    • Add logger provider for OTLP logs with local file fallback
    • Wire session root span, LLM turn child spans, tool call child spans with GenAI semconv
    • Propagate W3C trace-context to the gateway
    • Ensure all three signals honor OTel env vars and zero overhead when disabled
    • Commit, push, create draft PR, and file [DOCS] follow-up
    • Run precommit and push

    Pull Request

    #901

    ✅ Infer Result: Success

    The implementation is complete and all acceptance criteria are met. The draft PR #901 is open on the fix/issue-893 branch with all changes committed and pushed.

    Model: ollama_cloud/deepseek-v4-flash · Exit Code: 0 · Duration: 22m 3s

    Tokens: 11,302,153 in · 32,347 out · 11,334,500 total (65 requests)

    Tool calls: 76 total · 96% success rate

    ⚠️ 3 failed tool call(s)
    • Bash:
      exit status 1: internal/telemetry/logger.go:9:2: no required module provides package go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp; to add it:
      	go get go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp
      … (truncated)
      
    • Bash:
      exit status 1: # github.com/inference-gateway/cli/internal/telemetry
      internal/telemetry/recorder.go:35:2: "go.opentelemetry.io/otel/log" imported and not used
      … (truncated)
      
    • Bash:
      exit status -1: [INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
      [INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
      … (truncated)
      

    Triggered by edenreich · Infer Action

  5. moved this from Todo to Done in 2026on Jul 17, 2026
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

    enhancement

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions