From 67e7db8f9151e00031c10723fa40d56daba6d186 Mon Sep 17 00:00:00 2001 From: Ankur Shrivastava Date: Fri, 3 Apr 2026 02:03:49 +0800 Subject: [PATCH 1/3] feat: link ColdBrew trace ID to OTEL span as attribute Set coldbrew.trace_id attribute on the OTEL span after resolving the trace ID, connecting the ColdBrew correlation ID to the distributed trace for easier cross-system debugging. --- go.mod | 2 +- notifier/notifier.go | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index cad074d..e7408dc 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/go-coldbrew/options v0.2.6 github.com/google/uuid v1.6.0 github.com/rollbar/rollbar-go v1.4.8 + go.opentelemetry.io/otel v1.42.0 go.opentelemetry.io/otel/trace v1.42.0 google.golang.org/grpc v1.79.3 ) @@ -236,7 +237,6 @@ require ( go-simpler.org/sloglint v0.11.1 // indirect go.augendre.info/arangolint v0.4.0 // indirect go.augendre.info/fatcontext v0.9.0 // indirect - go.opentelemetry.io/otel v1.42.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.27.1 // indirect go.yaml.in/yaml/v3 v3.0.4 // indirect diff --git a/notifier/notifier.go b/notifier/notifier.go index 3db5480..bc33563 100644 --- a/notifier/notifier.go +++ b/notifier/notifier.go @@ -19,6 +19,7 @@ import ( "github.com/go-coldbrew/options" "github.com/google/uuid" rollbar "github.com/rollbar/rollbar-go" + otelattr "go.opentelemetry.io/otel/attribute" oteltrace "go.opentelemetry.io/otel/trace" "google.golang.org/grpc/metadata" ) @@ -537,6 +538,7 @@ func SetTraceId(ctx context.Context) context.Context { return ctx } var traceID string + // Check gRPC metadata first — client-supplied trace ID takes priority. if md, ok := metadata.FromIncomingContext(ctx); ok { if id, ok := md["grpcmetadata-"+traceHeader]; ok { traceID = strings.Join(id, ",") @@ -544,10 +546,13 @@ func SetTraceId(ctx context.Context) context.Context { traceID = strings.Join(id, ",") } } - if span := oteltrace.SpanFromContext(ctx); span.SpanContext().IsValid() && strings.TrimSpace(traceID) == "" { - traceID = span.SpanContext().TraceID().String() + // Fall back to OTEL span trace ID. + if strings.TrimSpace(traceID) == "" { + if span := oteltrace.SpanFromContext(ctx); span.SpanContext().IsValid() { + traceID = span.SpanContext().TraceID().String() + } } - // if no trace id then create one + // Last resort: generate UUID. if strings.TrimSpace(traceID) == "" { u, err := uuid.NewRandom() if err != nil { @@ -555,6 +560,11 @@ func SetTraceId(ctx context.Context) context.Context { } traceID = u.String() } + // Link the resolved trace ID to the OTEL span as an attribute + // so ColdBrew correlation ID and distributed trace are connected. + if span := oteltrace.SpanFromContext(ctx); span.SpanContext().IsValid() { + span.SetAttributes(otelattr.String("coldbrew.trace_id", traceID)) + } ctx = loggers.AddToLogContext(ctx, "trace", traceID) return options.AddToOptions(ctx, tracerID, traceID) } From 3eb643d47d28e06de19839f91714e29d93df20b0 Mon Sep 17 00:00:00 2001 From: Ankur Shrivastava Date: Fri, 3 Apr 2026 09:46:50 +0800 Subject: [PATCH 2/3] chore: bump go-coldbrew/log v0.2.7 -> v0.2.8 (slog default) --- go.mod | 4 +--- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index e7408dc..719457d 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.25.8 require ( github.com/airbrake/gobrake/v5 v5.6.2 github.com/getsentry/sentry-go v0.43.0 - github.com/go-coldbrew/log v0.2.7 + github.com/go-coldbrew/log v0.2.8 github.com/go-coldbrew/options v0.2.6 github.com/google/uuid v1.6.0 github.com/rollbar/rollbar-go v1.4.8 @@ -88,8 +88,6 @@ require ( github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-git/go-billy/v5 v5.8.0 // indirect github.com/go-git/go-git/v5 v5.17.1 // indirect - github.com/go-kit/log v0.2.1 // indirect - github.com/go-logfmt/logfmt v0.6.1 // indirect github.com/go-toolsmith/astcast v1.1.0 // indirect github.com/go-toolsmith/astcopy v1.1.0 // indirect github.com/go-toolsmith/astequal v1.2.0 // indirect diff --git a/go.sum b/go.sum index ad6eb7a..3376cf6 100644 --- a/go.sum +++ b/go.sum @@ -221,8 +221,8 @@ github.com/ghostiam/protogetter v0.3.20 h1:oW7OPFit2FxZOpmMRPP9FffU4uUpfeE/rEdE1 github.com/ghostiam/protogetter v0.3.20/go.mod h1:FjIu5Yfs6FT391m+Fjp3fbAYJ6rkL/J6ySpZBfnODuI= github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c= github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU= -github.com/go-coldbrew/log v0.2.7 h1:kRQeTYLPLcjjAWuCcGZpNn8twSY/NbsGpjIKbpXEnRA= -github.com/go-coldbrew/log v0.2.7/go.mod h1:BB+2VecklLXTaDQdNNe2h3r5rSZL2DGvJBXAgrXq1dk= +github.com/go-coldbrew/log v0.2.8 h1:aF+vw23zMyh5S9vhhofERiaPpSDyeJH1Tv1CYREn/a0= +github.com/go-coldbrew/log v0.2.8/go.mod h1:RKvGzMZMt7FpQ9u36adkDigRxkOvRj1diwgAgRJZH4E= github.com/go-coldbrew/options v0.2.6 h1:Nr93v7PbO+EYLHhzA8biGumaTTSHLHqTYLg70n/foXE= github.com/go-coldbrew/options v0.2.6/go.mod h1:Os4pZwIgMHES079iOKXTlzcipWXbxw0OhsAN5D9m2mM= github.com/go-critic/go-critic v0.14.3 h1:5R1qH2iFeo4I/RJU8vTezdqs08Egi4u5p6vOESA0pog= From fe5d5cbfd376a9909485c2566b887a21ba5b5e8b Mon Sep 17 00:00:00 2001 From: Ankur Shrivastava Date: Fri, 3 Apr 2026 13:50:47 +0800 Subject: [PATCH 3/3] fix: set coldbrew.trace_id on OTEL span even on early return --- notifier/notifier.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/notifier/notifier.go b/notifier/notifier.go index bc33563..3ccf16a 100644 --- a/notifier/notifier.go +++ b/notifier/notifier.go @@ -534,7 +534,11 @@ func SetRelease(rel string) { // if no trace id is found then it will create one and update the context // You should use the context returned by this function instead of the one passed func SetTraceId(ctx context.Context) context.Context { - if GetTraceId(ctx) != "" { + if traceID := GetTraceId(ctx); traceID != "" { + // Trace ID already set — ensure it's linked to the OTEL span. + if span := oteltrace.SpanFromContext(ctx); span.SpanContext().IsValid() { + span.SetAttributes(otelattr.String("coldbrew.trace_id", traceID)) + } return ctx } var traceID string