fix: the Loki trace link reads the trace_id metadata

Merged
HA
8d ago
+5-7

Summary

Fixes #294

The Loki to Jaeger link never appeared. The derived field looked for "trace_id":"..." in the log line, but structlog writes a space after the colon, so it matched 0% of lines. The issue's other half, every process logging as integr8scode-backend, is already fixed on main by #376: the worker logs as integr8scode-worker.

Changes

The derived field now uses matcherType: label on trace_id. Loki's OTLP ingest already stores each record's trace id as structured metadata, so the link no longer depends on how the line is formatted. Third-party records logged inside a span, like aiokafka's plain-text warnings, get the link too. The Loki and Grafana docs drop the "broken" notes.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • CI/CD or tooling changes

Test Plan

  • Backend unit tests pass (cd backend && uv run pytest tests/unit)
  • Frontend unit tests pass (cd frontend && npm run test)
  • Backend E2E tests pass (docker compose exec -T backend sh -c 'uv sync --group test --no-dev --frozen --no-install-project --no-build && pytest tests/e2e')
  • Frontend E2E tests pass (cd frontend && npm run test:e2e)
  • API spec and client regenerated if routes or schemas changed (./deploy.sh openapi, then ./deploy.sh types), never edited by hand
  • Manual testing performed

Validation: Loki 3.7.8 and Grafana 13.2.3 in throwaway containers with the repo's Loki config and datasources, plus two OTLP records with a trace id (a structlog JSON line and a plain one). In Explore the TraceID field covered 0% of lines on main and 100% on this branch, and an expanded line links to datasource: jaeger, query: <trace id>. mkdocs build --strict passes.

Checklist

  • My code follows the project's style guidelines
  • I have run pre-commit run --all-files and all checks pass
  • I have added tests that prove my fix/feature works
  • I have updated documentation if needed
  • My changes don't introduce new warnings

Summary by cubic

Fixes the Loki to Jaeger trace link so it appears on every log line logged inside a span. The derived field matched "trace_id":"(\w+)" in the log line, but structlog writes a space after the colon, so the link never showed up.

The derived field now uses matcherType: label on trace_id, reading the structured metadata Loki's OTLP ingest already stores. The link no longer depends on how the line is formatted, so third-party records logged inside a span get it too. The Loki and Grafana docs drop the "broken" notes.