Skip to content

Commit

Permalink
fix(core): correctly set Listener.handleNewSignedBlockfrom's spanStat…
Browse files Browse the repository at this point in the history
…us 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 celestiaorg#3814
  • Loading branch information
odeke-em committed Oct 7, 2024
1 parent 4309c83 commit 40598bc
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion core/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 40598bc

Please sign in to comment.