|
@@ -6,13 +6,13 @@ import (
|
|
|
"net/http"
|
|
|
"time"
|
|
|
|
|
|
- newrelic "github.com/newrelic/go-agent"
|
|
|
+ "github.com/newrelic/go-agent/v3/newrelic"
|
|
|
)
|
|
|
|
|
|
var (
|
|
|
newRelicEnabled = false
|
|
|
|
|
|
- newRelicApp newrelic.Application
|
|
|
+ newRelicApp *newrelic.Application
|
|
|
|
|
|
newRelicTransactionCtxKey = ctxKey("newRelicTransaction")
|
|
|
)
|
|
@@ -29,8 +29,10 @@ func initNewrelic() error {
|
|
|
|
|
|
var err error
|
|
|
|
|
|
- config := newrelic.NewConfig(name, conf.NewRelicKey)
|
|
|
- newRelicApp, err = newrelic.NewApplication(config)
|
|
|
+ newRelicApp, err = newrelic.NewApplication(
|
|
|
+ newrelic.ConfigAppName(name),
|
|
|
+ newrelic.ConfigLicense(conf.NewRelicKey),
|
|
|
+ )
|
|
|
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("Can't init New Relic agent: %s", err)
|
|
@@ -41,25 +43,27 @@ func initNewrelic() error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func startNewRelicTransaction(ctx context.Context, rw http.ResponseWriter, r *http.Request) (context.Context, context.CancelFunc) {
|
|
|
- txn := newRelicApp.StartTransaction("request", rw, r)
|
|
|
+func startNewRelicTransaction(ctx context.Context, rw http.ResponseWriter, r *http.Request) (context.Context, context.CancelFunc, http.ResponseWriter) {
|
|
|
+ txn := newRelicApp.StartTransaction("request")
|
|
|
+ txn.SetWebRequestHTTP(r)
|
|
|
+ newRw := txn.SetWebResponse(rw)
|
|
|
cancel := func() { txn.End() }
|
|
|
- return context.WithValue(ctx, newRelicTransactionCtxKey, txn), cancel
|
|
|
+ return context.WithValue(ctx, newRelicTransactionCtxKey, txn), cancel, newRw
|
|
|
}
|
|
|
|
|
|
func startNewRelicSegment(ctx context.Context, name string) context.CancelFunc {
|
|
|
- txn := ctx.Value(newRelicTransactionCtxKey).(newrelic.Transaction)
|
|
|
- segment := newrelic.StartSegment(txn, name)
|
|
|
+ txn := ctx.Value(newRelicTransactionCtxKey).(*newrelic.Transaction)
|
|
|
+ segment := txn.StartSegment(name)
|
|
|
return func() { segment.End() }
|
|
|
}
|
|
|
|
|
|
func sendErrorToNewRelic(ctx context.Context, err error) {
|
|
|
- txn := ctx.Value(newRelicTransactionCtxKey).(newrelic.Transaction)
|
|
|
+ txn := ctx.Value(newRelicTransactionCtxKey).(*newrelic.Transaction)
|
|
|
txn.NoticeError(err)
|
|
|
}
|
|
|
|
|
|
func sendTimeoutToNewRelic(ctx context.Context, d time.Duration) {
|
|
|
- txn := ctx.Value(newRelicTransactionCtxKey).(newrelic.Transaction)
|
|
|
+ txn := ctx.Value(newRelicTransactionCtxKey).(*newrelic.Transaction)
|
|
|
txn.NoticeError(newrelic.Error{
|
|
|
Message: "Timeout",
|
|
|
Class: "Timeout",
|