From 40598bcbb6643106981aa92cae505db742f385e3 Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Sat, 5 Oct 2024 17:54:03 -0700 Subject: [PATCH] fix(core): correctly set Listener.handleNewSignedBlockfrom's spanStatus from returned error or panics This change ensures that if a panic occurs, that span.RecordError correctly records it and then if an error is returned that span.Status correctly captures and records it. Fixes #3814 --- core/listener.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/core/listener.go b/core/listener.go index 67e532d970..948210902d 100644 --- a/core/listener.go +++ b/core/listener.go @@ -10,6 +10,7 @@ import ( "github.com/tendermint/tendermint/types" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/codes" libhead "github.com/celestiaorg/go-header" @@ -220,13 +221,38 @@ func (cl *Listener) listen(ctx context.Context, sub <-chan types.EventDataSigned } } -func (cl *Listener) handleNewSignedBlock(ctx context.Context, b types.EventDataSignedBlock) error { +func (cl *Listener) handleNewSignedBlock(ctx context.Context, b types.EventDataSignedBlock) (err error) { ctx, span := tracer.Start(ctx, "handle-new-signed-block") defer span.End() span.SetAttributes( attribute.Int64("height", b.Header.Height), ) + defer func() { + rerr := err + r := recover() + if r != nil { + var ok bool + rerr, ok = r.(error) + if !ok { + rerr = fmt.Errorf("%v", r) + } + // Record the "exception"/panic. + span.RecordError(rerr) + } + + if rerr == nil { + return + } + + // Otherwise now record the span error. + span.SetStatus(codes.Error, err.Error()) + + if r != nil { // Re-panic + panic(r) + } + }() + eds, err := extendBlock(b.Data, b.Header.Version.App) if err != nil { return fmt.Errorf("extending block data: %w", err)