-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnewrelic.go
40 lines (32 loc) · 930 Bytes
/
newrelic.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
package newrelic_logrus
import (
"errors"
"github.com/newrelic/go-agent"
"github.com/sirupsen/logrus"
)
type NewRelicLogrusHook struct {
Application newrelic.Application
LogLevels []logrus.Level
didFire bool
}
func NewNewRelicLogrusHook(app newrelic.Application, levels []logrus.Level) *NewRelicLogrusHook {
return &NewRelicLogrusHook{
Application: app,
LogLevels: levels,
}
}
func (n *NewRelicLogrusHook) Levels() []logrus.Level {
return n.LogLevels
}
func (n *NewRelicLogrusHook) Fire(entry *logrus.Entry) error {
// Hacky. We don't know what transaction we're in so we
// just start a new one specific to error reporting.
txn := n.Application.StartTransaction("errorTxn", nil, nil)
for k, v := range entry.Data {
txn.AddAttribute(k, v)
}
txn.NoticeError(errors.New(entry.Message))
txn.End()
n.didFire = true // for testing only... there's no way to get data out of NR agent
return nil
}