Skip to content

Commit

Permalink
Clean up golangci-lint warnings, shadowing logger, deprecated Instrum…
Browse files Browse the repository at this point in the history
…entRoutes
  • Loading branch information
Tit Petric committed Dec 23, 2024
1 parent c7c7ef7 commit f8b7d99
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 6 additions & 6 deletions gateway/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,31 +256,31 @@ func NewGateway(config config.Config, ctx context.Context) *Gateway {
return gw
}

// SetupNewRelic creates new newrelic.Application instance
// SetupNewRelic creates new newrelic.Application instance.
func (gw *Gateway) SetupNewRelic() (app *newrelic.Application) {
var (
err error
gwConfig = gw.GetConfig()
)

logger := log.WithFields(logrus.Fields{"prefix": "newrelic"})
logger.Info("Initializing NewRelic...")
log := log.WithFields(logrus.Fields{"prefix": "newrelic"})
log.Info("Initializing NewRelic...")

cfg := []newrelic.ConfigOption{
newrelic.ConfigAppName(gwConfig.NewRelic.AppName),
newrelic.ConfigLicense(gwConfig.NewRelic.LicenseKey),
newrelic.ConfigEnabled(gwConfig.NewRelic.AppName != ""),
newrelic.ConfigDistributedTracerEnabled(gwConfig.NewRelic.EnableDistributedTracing),
newrelic.ConfigLogger(newrelic.NewLogger(logger)),
newrelic.ConfigLogger(newrelic.NewLogger(log)),
}

if app, err = newrelic.NewApplication(cfg...); err != nil {
logger.Warn("Error initializing NewRelic, skipping... ", err)
log.Warn("Error initializing NewRelic, skipping... ", err)
return
}

instrument.AddSink(newrelic.NewSink(app))
logger.Info("NewRelic initialized")
log.Info("NewRelic initialized")

return
}
Expand Down
5 changes: 3 additions & 2 deletions internal/service/newrelic/newrelic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"fmt"
"strconv"

"github.com/TykTechnologies/tyk/internal/httpctx"
"github.com/newrelic/go-agent/v3/integrations/nrgorilla"
"github.com/newrelic/go-agent/v3/newrelic"

"github.com/gocraft/health"
"github.com/gorilla/mux"
"github.com/sirupsen/logrus"

"github.com/TykTechnologies/tyk/internal/httpctx"
)

type (
Expand All @@ -33,7 +34,7 @@ var (

// AddNewRelicInstrumentation adds NewRelic instrumentation to the router
func AddNewRelicInstrumentation(app *newrelic.Application, r *mux.Router) {
nrgorilla.InstrumentRoutes(r, app)
r.Use(nrgorilla.Middleware(app))
}

type Logger struct{ *logrus.Entry }
Expand Down

0 comments on commit f8b7d99

Please sign in to comment.