mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
9935ca3733
* add tracing * monitoring pkg * move prom * Add client stats Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
32 lines
752 B
Go
32 lines
752 B
Go
package tracing
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"runtime"
|
|
"runtime/debug"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
"go.opencensus.io/trace"
|
|
)
|
|
|
|
// RecoveryHandlerFunc is a function that recovers from the panic `p` by returning an `error`.
|
|
// The context can be used to extract request scoped metadata and context values.
|
|
func RecoveryHandlerFunc(ctx context.Context, p interface{}) error {
|
|
span := trace.FromContext(ctx)
|
|
if span != nil {
|
|
span.AddAttributes(trace.StringAttribute("stack", string(debug.Stack())))
|
|
}
|
|
var err error
|
|
switch v := p.(type) {
|
|
case runtime.Error:
|
|
err = errors.New(v.Error())
|
|
default:
|
|
err = fmt.Errorf("%v", p)
|
|
}
|
|
|
|
logrus.WithError(err).WithField("stack", string(debug.Stack())).Error("gRPC panicked!")
|
|
return err
|
|
}
|