Skip to content

Commit ff337c7

Browse files
authored
Include errors in logging (transparency-dev#854)
This fixes transparency-dev#850 by ensuring that error types are converted into JSON-serializable strings. I can't think of other types than error where we'd log something that isn't a string/int primitive, but if needed, more can be added here.
1 parent 31c5a19 commit ff337c7

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

internal/logger/gcp.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,13 @@ func (h *Exporter) Handle(ctx context.Context, r slog.Record) error {
184184
// in the entry.
185185
case slog.LevelKey, slog.TimeKey:
186186
default:
187-
target[a.Key] = a.Value.Any()
187+
v := a.Value.Any()
188+
// Map types to something JSON serialisable.
189+
if err, ok := v.(error); ok {
190+
target[a.Key] = err.Error()
191+
} else {
192+
target[a.Key] = v
193+
}
188194
}
189195
return true
190196
})

0 commit comments

Comments
 (0)