-
Notifications
You must be signed in to change notification settings - Fork 2
/
client_newrelic.go
57 lines (44 loc) · 1.47 KB
/
client_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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package newrelic
import (
"context"
newrelic "github.com/americanas-go/ignite/newrelic/go-agent.v3"
"github.com/americanas-go/log"
"github.com/go-redis/redis/v8"
"github.com/newrelic/go-agent/v3/integrations/nrredis-v8"
)
// ClientNewrelic represents a newrelic client for redis.
type ClientNewrelic struct {
options *Options
}
// NewClientNewrelicWithConfigPath returns a newrelic client with options from config path.
func NewClientNewrelicWithConfigPath(path string) (*ClientNewrelic, error) {
o, err := NewOptionsWithPath(path)
if err != nil {
return nil, err
}
return NewClientNewrelicWithOptions(o), nil
}
// NewClientNewrelicWithOptions returns a newrelic client with options.
func NewClientNewrelicWithOptions(options *Options) *ClientNewrelic {
return &ClientNewrelic{options: options}
}
// Register registers this newrelic client on redis client.
func (d *ClientNewrelic) Register(ctx context.Context, client *redis.Client) error {
if !d.options.Enabled || !newrelic.IsEnabled() {
return nil
}
logger := log.FromContext(ctx)
logger.Trace("integrating redis in newrelic")
client.AddHook(nrredis.NewHook(client.Options()))
logger.Debug("redis successfully integrated in newrelic")
return nil
}
// ClientRegister registers a new newrelic client on redis client.
func ClientRegister(ctx context.Context, client *redis.Client) error {
o, err := NewOptions()
if err != nil {
return err
}
n := NewClientNewrelicWithOptions(o)
return n.Register(ctx, client)
}