fix(metrics): return errors instead of panic/log.Fatalf in library code#557
Open
k4leung4 wants to merge 1 commit into
Open
fix(metrics): return errors instead of panic/log.Fatalf in library code#557k4leung4 wants to merge 1 commit into
k4leung4 wants to merge 1 commit into
Conversation
SetupTracer now returns (func(), error) instead of panicking on failure, letting callers decide how to handle the error. RegisterAndServe and RegisterListenAndServe now use clog instead of stdlib log, and ignore http.ErrServerClosed on shutdown. Fix log.Fatalf in tls_test.go to use t.Fatalf. BREAKING CHANGE: SetupTracer signature changed from func() to (func(), error). ~149 callers in mono using `defer metrics.SetupTracer(ctx)()` will need updating to handle the error. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Kenny Leung <kleung@chainguard.dev>
cpanato
approved these changes
Mar 23, 2026
eslerm
approved these changes
Mar 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
(func(), error)instead of panicking on failurecloginstead of stdliblog, and ignorehttp.ErrServerClosedon shutdownlog.Fatalf→t.Fatalfintls_test.gologimport frommetrics/server.goMotivation
Library code should not call
panicorlog.Fatalf— these terminate the entire process and prevent callers from implementing graceful error handling. ~149 callers in mono usedefer metrics.SetupTracer(ctx)()which would crash if the trace exporter fails to initialize.Breaking change
SetupTracersignature:func(context.Context) func()→func(context.Context) (func(), error)Callers need to change from:
to:
Test plan
go test ./... -count=1 -racepasses🤖 Generated with Claude Code