Skip to content

Commit

Permalink
Convert merry stacktrace
Browse files Browse the repository at this point in the history
  • Loading branch information
beornf committed Apr 27, 2020
1 parent ab0fa2e commit 256b994
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sync"
"time"

"github.com/ansel1/merry"
raven "github.com/getsentry/raven-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -305,36 +306,43 @@ func (hook *SentryHook) Flush() {

func (hook *SentryHook) findStacktrace(err error) *raven.Stacktrace {
var stacktrace *raven.Stacktrace
var stackErr errors.StackTrace
var stack []uintptr
for err != nil {
// Find the earliest *raven.Stacktrace, or error.StackTrace
// Find the earliest *raven.Stacktrace, error.StackTrace or merry.Stack
if tracer, ok := err.(Stacktracer); ok {
stacktrace = tracer.GetStacktrace()
stackErr = nil
stack = nil
} else if tracer, ok := err.(pkgErrorStackTracer); ok {
stacktrace = nil
stackErr = tracer.StackTrace()
stackErr := tracer.StackTrace()
stackFrames := []errors.Frame(stackErr)
stack = make([]uintptr, len(stackFrames))
for i := 0; i < len(stack); i++ {
stack[i] = uintptr(stackFrames[i])
}
} else {
stacktrace = nil
stack = merry.Stack(err)
}
if cause, ok := err.(causer); ok {
err = cause.Cause()
} else {
break
}
}
if stackErr != nil {
stacktrace = hook.convertStackTrace(stackErr)
if stack != nil {
stacktrace = hook.convertStack(stack)
}
return stacktrace
}

// convertStackTrace converts an errors.StackTrace into a natively consumable
// convertStack converts an []uintptr into a natively consumable
// *raven.Stacktrace
func (hook *SentryHook) convertStackTrace(st errors.StackTrace) *raven.Stacktrace {
func (hook *SentryHook) convertStack(stack []uintptr) *raven.Stacktrace {
stConfig := &hook.StacktraceConfiguration
stFrames := []errors.Frame(st)
frames := make([]*raven.StacktraceFrame, 0, len(stFrames))
for i := range stFrames {
pc := uintptr(stFrames[i])
frames := make([]*raven.StacktraceFrame, 0, len(stack))
for i := range stack {
pc := stack[i]
fn := runtime.FuncForPC(pc)
file, line := fn.FileLine(pc)
frame := raven.NewStacktraceFrame(pc, fn.Name(), file, line, stConfig.Context, stConfig.InAppPrefixes)
Expand Down

0 comments on commit 256b994

Please sign in to comment.