Upgrade newrelic to v3

pull/990/head
Mariano Cano 2 years ago
parent 135c481893
commit 821743f71e

@ -35,7 +35,7 @@ require (
github.com/mattn/go-isatty v0.0.13 // indirect github.com/mattn/go-isatty v0.0.13 // indirect
github.com/micromdm/scep/v2 v2.1.0 github.com/micromdm/scep/v2 v2.1.0
github.com/miekg/pkcs11 v1.1.1 // indirect github.com/miekg/pkcs11 v1.1.1 // indirect
github.com/newrelic/go-agent v3.18.0+incompatible github.com/newrelic/go-agent/v3 v3.18.0
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/rs/xid v1.2.1 github.com/rs/xid v1.2.1
github.com/sirupsen/logrus v1.8.1 github.com/sirupsen/logrus v1.8.1

@ -633,8 +633,8 @@ github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/nbrownus/go-metrics-prometheus v0.0.0-20210712211119-974a6260965f/go.mod h1:nwPd6pDNId/Xi16qtKrFHrauSwMNuvk+zcjk89wrnlA= github.com/nbrownus/go-metrics-prometheus v0.0.0-20210712211119-974a6260965f/go.mod h1:nwPd6pDNId/Xi16qtKrFHrauSwMNuvk+zcjk89wrnlA=
github.com/newrelic/go-agent v3.18.0+incompatible h1:0MUUHr33A9yIhTZh98JaqWV26iFezRABqicL8MQAYTM= github.com/newrelic/go-agent/v3 v3.18.0 h1:AOR3hhF2ZVE0yfvNPuOaEhEvNMYyIfEBY8EizQpnt7g=
github.com/newrelic/go-agent v3.18.0+incompatible/go.mod h1:a8Fv1b/fYhFSReoTU6HDkTYIMZeSVNffmoS726Y0LzQ= github.com/newrelic/go-agent/v3 v3.18.0/go.mod h1:BFJOlbZWRlPTXKYIC1TTTtQKTnYntEJaU0VU507hDc0=
github.com/nishanths/predeclared v0.0.0-20200524104333-86fad755b4d3/go.mod h1:nt3d53pc1VYcphSCIaYAJtnPYnr3Zyn8fMq2wvPGPso= github.com/nishanths/predeclared v0.0.0-20200524104333-86fad755b4d3/go.mod h1:nt3d53pc1VYcphSCIaYAJtnPYnr3Zyn8fMq2wvPGPso=
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=

@ -7,7 +7,7 @@ import (
"strconv" "strconv"
"strings" "strings"
newrelic "github.com/newrelic/go-agent" "github.com/newrelic/go-agent/v3/newrelic"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/smallstep/certificates/logging" "github.com/smallstep/certificates/logging"
) )
@ -41,7 +41,10 @@ func New(raw json.RawMessage) (*Monitoring, error) {
m := new(Monitoring) m := new(Monitoring)
switch strings.ToLower(config.Type) { switch strings.ToLower(config.Type) {
case "", "newrelic": case "", "newrelic":
app, err := newrelic.NewApplication(newrelic.NewConfig(config.Name, config.Key)) app, err := newrelic.NewApplication(
newrelic.ConfigAppName(config.Name),
newrelic.ConfigLicense(config.Key),
)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "error loading New Relic application") return nil, errors.Wrap(err, "error loading New Relic application")
} }
@ -58,13 +61,16 @@ func (m *Monitoring) Middleware(next http.Handler) http.Handler {
return m.middleware(next) return m.middleware(next)
} }
func newRelicMiddleware(app newrelic.Application) Middleware { func newRelicMiddleware(app *newrelic.Application) Middleware {
return func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Start transaction // Start transaction
txn := app.StartTransaction(transactionName(r), w, r) txn := app.StartTransaction(transactionName(r))
defer txn.End() defer txn.End()
w = txn.SetWebResponse(w)
txn.SetWebRequestHTTP(r)
// Wrap request writer if necessary // Wrap request writer if necessary
rw := logging.NewResponseLogger(w) rw := logging.NewResponseLogger(w)

Loading…
Cancel
Save