Commit ebbdfef
fix(telemetry): TLS + NR api-key header for OTLP exporter (P0-2)
Distributed tracing was 100% dead in prod across api, worker, and
provisioner — every pod logged a trace-export failure every 15-30s and
`trace_id` was empty on every log line, making cross-service request
correlation impossible. Root cause from BUGHUNT-2026-05-20-T21 P0-2:
tracer.go called `otlptracegrpc.WithInsecure()` (plaintext gRPC) but
the OTel endpoint pointed at the TLS host
`https://otlp.nr-data.net:4317`. The exporter sent cleartext HTTP/2
into a TLS listener; the TLS ServerHello bytes were misread as an
oversized HTTP/2 frame and every export silently dropped. Compounding
the issue, no `api-key` header was sent — NR OTLP ingest requires it,
so even a fixed handshake would have returned UNAUTHENTICATED.
Fix (mirrors the api repo change):
- Auto-detect TLS from endpoint scheme: `https://` prefix, NR's
`otlp.*nr-data.net` host, or a `:443` suffix → TLS;
everything else → plaintext (for local dev / in-cluster
collectors).
- When NEW_RELIC_LICENSE_KEY is set, attach it as the `api-key`
gRPC header on every export (NR ingest contract).
- Fail-open: empty endpoint = noop shutdown; empty/CHANGE_ME license
key = WARN + exporter is still constructed (it dials lazily so
boot never blocks).
- Stamp INFO `telemetry.tracer_initialized` with endpoint + tls
+ nr_auth flags at boot so an operator can verify the config
from a single log line.
Regression tests (tracer_test.go) — same set as api / provisioner:
- TestInitTracer_EmptyEndpointNoop
- TestInitTracer_Boots
- TestShouldUseTLS
- TestStripScheme
`go test ./internal/telemetry/...` green (the rest of the worker
tree currently has an unrelated in-flight edit in internal/jobs/
expire.go from a parallel agent — out of scope for this commit).
Refs: BUGHUNT-2026-05-20-T21.md (P0-2), CLAUDE-AGENT-RELIABILITY-RULES.md
rule 22 (contract changes touch all surfaces — mirror commits in api,
provisioner, infra).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 5721fce commit ebbdfef
2 files changed
Lines changed: 183 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
21 | 48 | | |
22 | | - | |
23 | | - | |
| 49 | + | |
| 50 | + | |
24 | 51 | | |
25 | 52 | | |
| 53 | + | |
26 | 54 | | |
27 | 55 | | |
28 | 56 | | |
29 | 57 | | |
30 | | - | |
31 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
32 | 89 | | |
33 | 90 | | |
34 | 91 | | |
35 | 92 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 93 | + | |
40 | 94 | | |
41 | | - | |
| 95 | + | |
42 | 96 | | |
43 | 97 | | |
44 | 98 | | |
| |||
61 | 115 | | |
62 | 116 | | |
63 | 117 | | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
64 | 124 | | |
65 | 125 | | |
66 | 126 | | |
| |||
70 | 130 | | |
71 | 131 | | |
72 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
0 commit comments