-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #546 from newrelic/develop
Release 3.18.0
- Loading branch information
Showing
60 changed files
with
1,666 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,22 +75,16 @@ jobs: | |
# As of June 2020, confirmed errors still result | ||
# - go-version: 1.13.x | ||
# dirs: _integrations/nrmicro | ||
- go-version: 1.13.x | ||
dirs: _integrations/nrnats | ||
- go-version: 1.13.x | ||
dirs: _integrations/nrstan | ||
# As of Jul 2022, we have depreciated the legacy nrnats,nrmssql, nrzap, and nrstan integrations tests. | ||
# These tests still exist under the v3 versions of the integrations. | ||
- go-version: 1.13.x | ||
dirs: _integrations/logcontext | ||
- go-version: 1.13.x | ||
dirs: _integrations/nrzap | ||
- go-version: 1.13.x | ||
dirs: _integrations/nrhttprouter | ||
- go-version: 1.13.x | ||
dirs: _integrations/nrb3 | ||
- go-version: 1.13.x | ||
dirs: _integrations/nrmongo | ||
- go-version: 1.13.x | ||
dirs: _integrations/nrmssql | ||
|
||
# v3 agent | ||
- go-version: 1.7.x | ||
|
@@ -105,10 +99,6 @@ jobs: | |
dirs: v3/newrelic,v3/internal,v3/examples | ||
- go-version: 1.12.x | ||
dirs: v3/newrelic,v3/internal,v3/examples | ||
- go-version: 1.13.x | ||
dirs: v3/newrelic,v3/internal,v3/examples | ||
- go-version: 1.14.x | ||
dirs: v3/newrelic,v3/internal,v3/examples | ||
- go-version: 1.15.x | ||
dirs: v3/newrelic,v3/internal,v3/examples,v3/integrations/logcontext | ||
|
||
|
@@ -133,7 +123,7 @@ jobs: | |
- go-version: 1.15.x | ||
dirs: v3/integrations/nrelasticsearch-v7 | ||
extratesting: go get -u github.com/elastic/go-elasticsearch/[email protected] | ||
- go-version: 1.15.x | ||
- go-version: 1.18.x | ||
dirs: v3/integrations/nrgin | ||
extratesting: go get -u github.com/gin-gonic/gin@master | ||
- go-version: 1.15.x | ||
|
@@ -174,14 +164,15 @@ jobs: | |
- go-version: 1.15.x | ||
dirs: v3/integrations/nrgrpc | ||
extratesting: go get -u google.golang.org/grpc@master | ||
- go-version: 1.15.x | ||
- go-version: 1.17.x | ||
dirs: v3/integrations/nrmicro | ||
# As of Dec 2019, there is a race condition in when using go-micro@master | ||
# in their logging system. Instead, we'll test against the latest | ||
# released version. | ||
# As of Jan 2019, it is impossible to go get the latest micro version. | ||
# As of June 2020, confirmed errors still result | ||
# extratesting: go get -u github.com/micro/go-micro@latest | ||
# If we are using the latest released version to test, we need to use a newer version of go | ||
- go-version: 1.15.x | ||
dirs: v3/integrations/nrnats | ||
extratesting: go get -u github.com/nats-io/nats.go/@master | ||
|
@@ -200,7 +191,8 @@ jobs: | |
- go-version: 1.15.x | ||
dirs: v3/integrations/logcontext | ||
extratesting: go get -u github.com/sirupsen/logrus@master | ||
- go-version: 1.15.x | ||
# nrzap only supports the two most recent minor go releases | ||
- go-version: 1.17.x | ||
dirs: v3/integrations/nrzap | ||
extratesting: go get -u go.uber.org/zap@master | ||
- go-version: 1.15.x | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
"github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrlogrus" | ||
newrelic "github.com/newrelic/go-agent/v3/newrelic" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func doFunction2(txn *newrelic.Transaction, e *logrus.Entry) { | ||
defer txn.StartSegment("doFunction2").End() | ||
e.Error("In doFunction2") | ||
} | ||
|
||
func doFunction1(txn *newrelic.Transaction, e *logrus.Entry) { | ||
defer txn.StartSegment("doFunction1").End() | ||
e.Trace("In doFunction1") | ||
doFunction2(txn, e) | ||
} | ||
|
||
func main() { | ||
app, err := newrelic.NewApplication( | ||
newrelic.ConfigAppName("Logrus Logs In Context Example"), | ||
newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")), | ||
newrelic.ConfigInfoLogger(os.Stdout), | ||
newrelic.ConfigAppLogForwardingEnabled(true), | ||
|
||
// If you wanted to forward your logs using a log forwarder instead | ||
// newrelic.ConfigAppLogDecoratingEnabled(true), | ||
// newrelic.ConfigAppLogForwardingEnabled(false), | ||
) | ||
if nil != err { | ||
log.Panic("Failed to create application", err) | ||
} | ||
|
||
log := logrus.New() | ||
log.SetLevel(logrus.TraceLevel) | ||
// Enable New Relic log decoration | ||
log.SetFormatter(nrlogrus.NewFormatter(app, &logrus.TextFormatter{})) | ||
log.Trace("waiting for connection to New Relic...") | ||
|
||
err = app.WaitForConnection(10 * time.Second) | ||
if nil != err { | ||
log.Panic("Failed to connect application", err) | ||
} | ||
defer app.Shutdown(10 * time.Second) | ||
log.Info("application connected to New Relic") | ||
log.Debug("Starting transaction now") | ||
txn := app.StartTransaction("main") | ||
|
||
// Add the transaction context to the logger. Only once this happens will | ||
// the logs be properly decorated with all required fields. | ||
e := log.WithContext(newrelic.NewContext(context.Background(), txn)) | ||
|
||
doFunction1(txn, e) | ||
|
||
e.Info("Ending transaction") | ||
txn.End() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2020 New Relic Corporation. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package nrlogrus | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/newrelic/go-agent/v3/internal" | ||
newrelic "github.com/newrelic/go-agent/v3/newrelic" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func init() { internal.TrackUsage("integration", "logcontext-v2", "logrus") } | ||
|
||
// ContextFormatter is a `logrus.Formatter` that will format logs for sending | ||
// to New Relic. | ||
type ContextFormatter struct { | ||
app *newrelic.Application | ||
formatter logrus.Formatter | ||
} | ||
|
||
func NewFormatter(app *newrelic.Application, formatter logrus.Formatter) ContextFormatter { | ||
return ContextFormatter{ | ||
app: app, | ||
formatter: formatter, | ||
} | ||
} | ||
|
||
// Format renders a single log entry. | ||
func (f ContextFormatter) Format(e *logrus.Entry) ([]byte, error) { | ||
logData := newrelic.LogData{ | ||
Severity: e.Level.String(), | ||
Message: e.Message, | ||
} | ||
|
||
logBytes, err := f.formatter.Format(e) | ||
if err != nil { | ||
return nil, err | ||
} | ||
logBytes = bytes.TrimRight(logBytes, "\n") | ||
b := bytes.NewBuffer(logBytes) | ||
|
||
ctx := e.Context | ||
var txn *newrelic.Transaction | ||
if ctx != nil { | ||
txn = newrelic.FromContext(ctx) | ||
} | ||
if txn != nil { | ||
txn.RecordLog(logData) | ||
err := newrelic.EnrichLog(b, newrelic.FromTxn(txn)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} else { | ||
f.app.RecordLog(logData) | ||
err := newrelic.EnrichLog(b, newrelic.FromApp(f.app)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
b.WriteString("\n") | ||
return b.Bytes(), nil | ||
} |
Oops, something went wrong.