feat: add gqlgen Recover that logs panics as one structured record
gqlgen's DefaultRecover prints the panic and debug.PrintStack() to stderr, so the log collector stores every stack line as a separate, level-less entry. Recover logs the panic as a single ERROR record via slog.Default() with panic, stack and path attributes, records it on the active span with status Error, and returns the generic "internal system error" without leaking the panic text. Install with srv.SetRecoverFunc(otelsetup.Recover). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H6eVuR4Yt3m7TbDTDwyZJi
This commit is contained in:
1 parent
9fe1a21c02
commit
ff0585ad68
4 files changed
+167
-1
No files matched your search
@@ -28,6 +28,12 @@ defer shutdown(ctx)
|
||||
|
||||
// Wrap HTTP handlers with tracing
|
||||
http.Handle("/", otelsetup.Handler(myHandler))
|
||||
|
||||
// gqlgen server hooks
|
||||
srv.AroundOperations(otelsetup.AroundOperations)
|
||||
srv.AroundRootFields(otelsetup.AroundRootFields)
|
||||
srv.AroundFields(otelsetup.AroundFields)
|
||||
srv.SetRecoverFunc(otelsetup.Recover)
|
||||
```
|
||||
|
||||
### Features
|
||||
@@ -37,6 +43,8 @@ http.Handle("/", otelsetup.Handler(myHandler))
|
||||
- **Logging** - Stdout log exporter
|
||||
- **Propagation** - TraceContext and Baggage propagation
|
||||
- **HTTP Handler** - Middleware for automatic span creation
|
||||
- **gqlgen hooks** - Spans per operation, root field and resolver field
|
||||
- **gqlgen recover** - `Recover` logs a resolver panic as one ERROR record via `slog.Default()` (attributes `panic`, `stack`, `path`), records it on the active span with status Error, and returns the generic "internal system error" to the client (gqlgen's default prints the stack to stderr line by line)
|
||||
|
||||
### Environment Variables
|
||||
|
||||
|
||||
Reference in new issue
Block a user