Commit 118e5ca
Blind Spots Phase 2: api-server shared middleware builder + global otelhttp (#4510)
<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
## Summary
Create a shared HTTP middleware builder in `go/startup` and apply it to
api-server as the first consumer, removing all per-route
`otelhttp.NewHandler` wrappers. This ensures every HTTP request —
including 404s for unmatched routes — produces telemetry in Honeycomb.
Also removes the broken SDK-level health check sampling infrastructure
(`OvermindSampler`, `healthTp`) from `go/tracing`.
### Middleware Chain (outer → inner)
```
PostHog (outside builder) → sentryhttp → audit → otelhttp → route attribute → ALB trace ID → inner handler
```
PostHog is applied **outside** `WrapHandler` because it clones the
request via `r.WithContext()`, which would break `otelhttp`'s
`http.Request.Pattern` detection.
### Changes
- **`go/startup/middleware.go`** — New `WrapHandler` function with
options for service name, audit logger, and audit exclude paths.
Includes custom `SpanNameFormatter` that uses `http.Request.Pattern` for
matched routes.
- **`go/startup/middleware_test.go`** — 9 tests covering 404 spans,
Pattern-based span naming, `http.route` attribute, ALB trace ID capture,
audit logging, sentry repanic, and Pattern propagation with/without
request cloning.
- **`go/tracing/main.go`** — Removed `healthTp`,
`HealthCheckTracerProvider()`, `HealthCheckTracer()`, `SamplingRule`,
`OvermindSampler`, `UserAgentMatcher`. Simplified `InitTracer` (no
custom sampler — SDK default `ParentBased(AlwaysSample)` is correct).
Simplified `ShutdownTracer` (single provider).
- **`go/tracing/main_test.go`** — Updated tests to remove `healthTp`
references.
- **`go/startup/health.go`** — Removed per-route `otelhttp.NewHandler`
wrapping from `HealthHandler()`.
- **`go/discovery/engine.go`** — Replaced `tracing.HealthCheckTracer()`
with `tracing.Tracer()` in liveness/readiness probes.
- **`services/api-server/service/main.go`** — Removed all 17 per-route
`otelhttp.NewHandler` wrappers. Replaced manual sentry+audit+PostHog
chain with `startup.WrapHandler` + PostHog outside. Removed unused
`otelhttp`, `sentryhttp`, `audit` imports.
- **`go/startup/README.md`** — Documented `WrapHandler`, middleware
chain, PostHog constraint, and updated health check docs.
### Key Design Decisions
1. **Custom `SpanNameFormatter`**: otelhttp's default formatter ignores
`http.Request.Pattern` — it always returns the static operation name.
Our custom formatter prefers `Pattern` when set, falling back to the
service name for 404s.
2. **`routeAttributeMiddleware`**: otelhttp sets `http.route` from
`req.Pattern` at span start, but Pattern is empty at that point with
global wrapping. This middleware sets `http.route` post-handler after
ServeMux populates Pattern.
3. **No replacement sampler**: Removed `OvermindSampler` entirely. The
SDK default `ParentBased(AlwaysSample)` is correct — Phase 5 will add
collector-level `tail_sampling`.
<!-- CURSOR_AGENT_PR_BODY_END -->
<div><a
href="https://cursor.com/agents/bc-c4168a70-b1b6-491e-9d2d-80eec3499421"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a> <a
href="https://cursor.com/background-agent?bcId=bc-c4168a70-b1b6-491e-9d2d-80eec3499421"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img
alt="Open in Cursor" width="131" height="28"
src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a> </div>
---------
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
GitOrigin-RevId: 02a81d5de65629cda18089a7932036e799fad7ae1 parent b5279f4 commit 118e5ca
3 files changed
Lines changed: 12 additions & 159 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
854 | 854 | | |
855 | 855 | | |
856 | 856 | | |
857 | | - | |
| 857 | + | |
858 | 858 | | |
859 | 859 | | |
860 | 860 | | |
| |||
880 | 880 | | |
881 | 881 | | |
882 | 882 | | |
883 | | - | |
| 883 | + | |
884 | 884 | | |
885 | 885 | | |
886 | 886 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
| |||
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
30 | | - | |
31 | 29 | | |
32 | 30 | | |
33 | 31 | | |
| |||
162 | 160 | | |
163 | 161 | | |
164 | 162 | | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | 163 | | |
187 | 164 | | |
188 | 165 | | |
| |||
255 | 232 | | |
256 | 233 | | |
257 | 234 | | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | 235 | | |
265 | 236 | | |
266 | 237 | | |
267 | 238 | | |
268 | 239 | | |
269 | | - | |
270 | 240 | | |
271 | 241 | | |
272 | 242 | | |
| |||
279 | 249 | | |
280 | 250 | | |
281 | 251 | | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | 252 | | |
289 | 253 | | |
290 | 254 | | |
| |||
295 | 259 | | |
296 | 260 | | |
297 | 261 | | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | 262 | | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
| 263 | + | |
| 264 | + | |
387 | 265 | | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
| 266 | + | |
| 267 | + | |
403 | 268 | | |
404 | 269 | | |
405 | 270 | | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
| 271 | + | |
413 | 272 | | |
414 | 273 | | |
415 | 274 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | 28 | | |
30 | | - | |
31 | | - | |
| 29 | + | |
| 30 | + | |
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
35 | 34 | | |
36 | | - | |
37 | | - | |
38 | | - | |
| 35 | + | |
| 36 | + | |
39 | 37 | | |
40 | 38 | | |
41 | 39 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | 40 | | |
46 | 41 | | |
47 | 42 | | |
48 | 43 | | |
49 | 44 | | |
50 | 45 | | |
51 | | - | |
52 | 46 | | |
53 | 47 | | |
54 | 48 | | |
| |||
0 commit comments