feat(telemetry): traces to SigNoz for requests, outbound calls and SQL #102

Merged
sharang merged 3 commits from feat/otel-tracing into main 2026-10-28 22:10:25 +00:00
Owner

Package A of the instrumentation plan (research/observability/2026-10-28-instrumentation-portal-registry-db.md, backlog t36). Werkmeister copies this shape afterwards.

What

internal/telemetry:

  • Setup — OTLP/HTTP tracer provider from the standard env. OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS and OTEL_SERVICE_NAME are already set on tenant-registry-stage/-prod (orca-platform), so merging is enough to start traces on stage. Unset endpoint = off (only the W3C propagator). Resource: service.name, service.version (/version), vcs.ref.head.revision, deployment.environment from APP_ENV; OTEL_RESOURCE_ATTRIBUTES overrides. Flush with a 5 s timeout on SIGTERM.
  • Server spans — one per request, named after the matched ServeMux pattern (GET /v1/tenants/{id}, GET unmatched), incoming traceparent continued, status code recorded, 5xx = error. /healthz and /readyz are skipped.
  • Client spans — http.DefaultTransport is wrapped, so Keycloak, ERP, LiteLLM, OIDC/JWKS and the product client are covered; traceparent is injected.
  • SQL spans — a pgx QueryTracer on the pool: db <OPERATION>, statement text with $n placeholders (max 2000 chars), errors (not ErrNoRows).
  • Client and SQL spans only inside a request: the outbox/reconcile/mail loops poll every few seconds and would otherwise flood SigNoz with single-span traces.
  • slog — LogHandler adds trace_id/span_id to lines logged with a request context; the access log now logs with it.

Privacy

No raw paths (slugs are names), no query strings, no bodies, no SQL parameters, no client addresses in spans; outbound spans carry the host only (paths hold ERP document names and Keycloak user ids). Hence own small wrappers instead of otelhttp/otelpgx, which record url.full, the raw path and the client address. Tests check that the raw path, query and SQL parameters never reach an attribute.

Access log change: "path": r.URL.Path → "route": <pattern> (same reason). The remote field stays as it is.

Dependencies

otel / sdk / otlptracehttp v1.41.0 — the version already in go.mod as indirect (a plain @latest dragged in unrelated majors, e.g. jsonpointer 1.0 under kin-openapi). Transitive bumps: grpc 1.79.1, protobuf 1.36.11, otlp proto 1.9.0.

Checks

  • go vet, gofmt, go test ./... green; internal/telemetry 98.9 % (race), added to the CI test list.
  • CI test command locally: 69.7 % vs 69.4 % on main (both without Docker, so the Postgres store tests are skipped here; CI runs them).
  • Local smoke test against a fake OTLP receiver: POST /v1/traces (protobuf) with the auth header; access-log lines carry route and trace_id; /healthz untraced.

After merge (stage)

SigNoz → Services: tenant-registry-stage appears with operations named after routes; a trace from a portal action shows the server span with db SELECT … and Keycloak/ERP children. The portal does not propagate yet (package C), so its calls start new traces here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4

Package A of the instrumentation plan (`research/observability/2026-10-28-instrumentation-portal-registry-db.md`, backlog t36). Werkmeister copies this shape afterwards. ## What `internal/telemetry`: - **Setup** — OTLP/HTTP tracer provider from the standard env. `OTEL_EXPORTER_OTLP_ENDPOINT`, `OTEL_EXPORTER_OTLP_HEADERS` and `OTEL_SERVICE_NAME` are **already set** on tenant-registry-stage/-prod (orca-platform), so merging is enough to start traces on stage. Unset endpoint = off (only the W3C propagator). Resource: service.name, service.version (`/version`), `vcs.ref.head.revision`, `deployment.environment` from `APP_ENV`; `OTEL_RESOURCE_ATTRIBUTES` overrides. Flush with a 5 s timeout on SIGTERM. - **Server spans** — one per request, named after the matched ServeMux pattern (`GET /v1/tenants/{id}`, `GET unmatched`), incoming `traceparent` continued, status code recorded, 5xx = error. `/healthz` and `/readyz` are skipped. - **Client spans** — `http.DefaultTransport` is wrapped, so Keycloak, ERP, LiteLLM, OIDC/JWKS and the product client are covered; `traceparent` is injected. - **SQL spans** — a pgx `QueryTracer` on the pool: `db <OPERATION>`, statement text with `$n` placeholders (max 2000 chars), errors (not `ErrNoRows`). - Client and SQL spans **only inside a request**: the outbox/reconcile/mail loops poll every few seconds and would otherwise flood SigNoz with single-span traces. - **slog** — `LogHandler` adds `trace_id`/`span_id` to lines logged with a request context; the access log now logs with it. ## Privacy No raw paths (slugs are names), no query strings, no bodies, no SQL parameters, no client addresses in spans; outbound spans carry the host only (paths hold ERP document names and Keycloak user ids). Hence own small wrappers instead of `otelhttp`/`otelpgx`, which record `url.full`, the raw path and the client address. Tests check that the raw path, query and SQL parameters never reach an attribute. **Access log change:** `"path": r.URL.Path` → `"route": <pattern>` (same reason). The `remote` field stays as it is. ## Dependencies otel / sdk / otlptracehttp **v1.41.0** — the version already in go.mod as indirect (a plain `@latest` dragged in unrelated majors, e.g. jsonpointer 1.0 under kin-openapi). Transitive bumps: grpc 1.79.1, protobuf 1.36.11, otlp proto 1.9.0. ## Checks - `go vet`, `gofmt`, `go test ./...` green; `internal/telemetry` 98.9 % (race), added to the CI test list. - CI test command locally: 69.7 % vs 69.4 % on main (both without Docker, so the Postgres store tests are skipped here; CI runs them). - Local smoke test against a fake OTLP receiver: `POST /v1/traces` (protobuf) with the auth header; access-log lines carry `route` and `trace_id`; `/healthz` untraced. ## After merge (stage) SigNoz → Services: `tenant-registry-stage` appears with operations named after routes; a trace from a portal action shows the server span with `db SELECT …` and Keycloak/ERP children. The portal does not propagate yet (package C), so its calls start new traces here. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
sharang added 1 commit 2026-10-28 21:24:36 +00:00
feat(telemetry): traces to SigNoz for requests, outbound calls and SQL
ci / shared (pull_request) Failing after 12s
ci / test (pull_request) Failing after 15m24s
ci / image (pull_request) Skipped
65ad1b52f6
internal/telemetry: OTLP/HTTP tracer provider from the OTEL_* env
(already set on stage and prod; unset = off), W3C propagation, one server
span per request named after the ServeMux pattern, client spans on the
default transport (Keycloak, ERP, LiteLLM, OIDC) and a pgx QueryTracer.
Client and DB spans only inside a request, so the background loops add
no traces. No raw paths, query strings, bodies, SQL parameters or client
addresses in spans; outbound spans carry the host only.

slog lines logged with a request context get trace_id/span_id; the
access log names the route instead of the raw path (slugs are names).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
sharang added 1 commit 2026-10-28 21:25:52 +00:00
fix(deps): otel 1.47.0 and grpc 1.83.2 for trivy
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Failing after 15m21s
ci / image (pull_request) Skipped
2f3749d1c0
trivy on the PR: otel/sdk v1.41.0 CVE-2026-39883 (fixed 1.43.0); grpc
v1.79.1 CVE-2026-33186 (critical), CVE-2026-84304, CVE-2026-84445 and
GHSA-hrxh-6v49-42gf (fixed by 1.83.2). jsonpointer 1.0.0 comes with the
otel bump; kin-openapi (contract test only) passes with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
sharang added 1 commit 2026-10-28 21:43:04 +00:00
test(telemetry): errcheck and Value.String for golangci-lint
ci / shared (pull_request) Successful in 14s
ci / test (pull_request) Successful in 27m1s
ci / image (pull_request) Skipped
2aa9d8022d
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
sharang merged commit 7d3e4a656d into main 2026-10-28 22:10:25 +00:00
Sign in to join this conversation.