forked from remind101/empire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nr.go
47 lines (36 loc) · 1.02 KB
/
nr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package nr
import (
"fmt"
"strings"
"github.com/remind101/newrelic"
"github.com/remind101/pkg/reporter"
"github.com/remind101/pkg/reporter/util"
"golang.org/x/net/context"
)
// Ensure that Reporter implements the reporter.Reporter interface.
var _ reporter.Reporter = &Reporter{}
type Reporter struct{}
func NewReporter() *Reporter {
return &Reporter{}
}
func (r *Reporter) Report(ctx context.Context, err error) error {
if tx, ok := newrelic.FromContext(ctx); ok {
var (
exceptionType string
errorMessage string
stackTrace []string
stackFrameDelim string
)
errorMessage = err.Error()
stackFrameDelim = "\n"
stackTrace = make([]string, 0)
if e, ok := err.(*reporter.Error); ok {
exceptionType = util.ClassName(e.Err)
for _, l := range e.Backtrace {
stackTrace = append(stackTrace, fmt.Sprintf("%s:%d %s", l.File, l.Line, util.FunctionName(l.PC)))
}
}
return tx.ReportError(exceptionType, errorMessage, strings.Join(stackTrace, stackFrameDelim), stackFrameDelim)
}
return nil
}