Skip to content

fix(service): put trace ids on Service JSON log lines #4510

Closed

Description

@dan-petty

Problem Description

The roadmap Service writes its logs as JSON lines to stdout. No line carries a trace id, so you cannot go from a Service log line to its trace in Tempo.

Three causes:

  1. JsonLogFormatter writes only the keys in CONTEXT_LOG_KEYS (src/devops_cli/server/json_logs.py). trace_id and span_id are not in it.
  2. No record that the json handler gets goes through TraceCorrelationFilter. attach_otel_logging_handler() puts the filter on the root logger, and a logger filter runs only for records logged on that logger. The Service log config sets devops_cli and uvicorn to propagate: False. Also, dictConfig replaces the root handlers with ["json"], so the Service has no OTLP log handler.
  3. The Grafana Loki derived field regex is (?:trace_id|traceId|traceID)[=:]\s*"?([a-f0-9]+)"? (k8s/monitoring/grafana-values.yaml). In a JSON line a " comes after the key and before :, so the regex does not match "trace_id":"...".

Reproduction Steps

  1. Run a Loki query over 6 hours: sum(count_over_time({service_name="roadmap-service"} |~ "trace_?[iI]d" [6h])).
  2. Compare it with sum(count_over_time({service_name="roadmap-service"} [6h])).

Expected vs Actual Behavior

Expected: each Service JSON line that is written while a span is open carries trace_id and span_id, and Grafana shows a Tempo link on that line. Target: 90 % of job lines carry a trace_id.

Actual: 0 of 7,251 roadmap-service lines in 6 hours carry a trace id (2026-11-11).

Environment Diagnostics

roadmap-service on the homelab cluster, image from main on 2026-11-11. Loki 3.7.9, Grafana Loki data source from k8s/monitoring/grafana-values.yaml.

Logs, Traces, or Terminal Output

Evidence from the observability study of 2026-11-11 (practice P12, skeptic correction of P12). OTLP log records from runner Jobs do carry trace_id as structured metadata, but none come from roadmap-service.

Proposed fix

  • Put TraceCorrelationFilter on the json handler (a handler filter runs for each record the handler gets).
  • Write trace_id and span_id in JsonLogFormatter only when they are not empty.
  • Change the derived field regex so it also matches a JSON key, and add a second derived field that reads the trace_id structured metadata of OTLP log records. Do not make trace_id a Loki stream label.

Pre-Submission Checklist

Activity

  1. added
    source/agent
    type/bug
    status/new
    value/medium
    effort/medium
    on Nov 11, 2026
  2. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: none. The title has the scope server, and .github/labels.yml declares no scope/server label. Add the label to the file to give the scope to this item.
    • Priority: P2-Medium. Zero of 7251 service log lines carry a trace id, blocking trace correlation, but the service still functions.
    • Value: Medium. Enables debugging by linking service log lines to Tempo traces, a core observability need.
    • Effort: Medium. Three small changes: move the filter to the handler, add two keys to the formatter, and fix one regex.
    • Related: feat(telemetry): send devops-cli logs with trace ids to Loki #813, which asks for a different change. Both add trace ids to logs in Loki, but #813 delivers the OTLP collector path while this item fixes the Service stdout JSON line path and the Grafana derived field regex.
  3. added
    priority/p2-medium
    owner/agent
    on Nov 11, 2026
  4. changed the title [-]fix(server): put trace ids on Service JSON log lines[/-] [+]fix(service): put trace ids on Service JSON log lines[/+] on Nov 11, 2026
  5. added
    scope/service
    status/in-progress
    status/in-review
    and removed
    status/new
    status/in-progress
    on Nov 11, 2026
  6. removed
    status/in-review
    owner/agent
    on Nov 11, 2026
  7. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor
  8. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-11 14:13 UTC

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

    effort/mediumpriority/p2-mediumscope/servicesource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions