Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): correctly set Listener.handleNewSignedBlockfrom's spanStatus from returned error or panics #3817

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Comment on lines +240 to +241
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets move it out of recover block and put it instead of SetStatus, while SetStatus goes to every individual error check.

As per otel API these are used together and not only on recovering. RecordError does what it says, while SetStatus has a description on it to put next to the operation.

So extendBlock would become

eds, err := extendBlock(b.Data, b.Header.Version.App)
	if err != nil {
               span.SetStatus(codes.Error, "extendBlock")
		return fmt.Errorf("extending block data: %w", err)
	}
and so on

}

if rerr == nil {
return
}

// Otherwise now record the span error.
span.SetStatus(codes.Error, rerr.Error())

if r != nil { // Re-panic
panic(r)
}
Comment on lines +251 to +253
Copy link
Member

@Wondertan Wondertan Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanted to avoid re-panicing, but actually we should so that the panic during sync doesn't go unnoticed
[not actionable]

}()

eds, err := extendBlock(b.Data, b.Header.Version.App)
if err != nil {
return fmt.Errorf("extending block data: %w", err)
Expand Down
Loading