Skip to content

Commit

Permalink
Merge pull request #546 from newrelic/develop
Browse files Browse the repository at this point in the history
Release 3.18.0
  • Loading branch information
iamemilio authored Aug 1, 2022
2 parents d71efc4 + dfb5698 commit b580d7f
Show file tree
Hide file tree
Showing 60 changed files with 1,666 additions and 214 deletions.
22 changes: 7 additions & 15 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -133,7 +123,7 @@ jobs:
- go-version: 1.15.x
dirs: v3/integrations/nrelasticsearch-v7
extratesting: go get -u github.com/elastic/go-elasticsearch/v7@7.x
- 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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
## 3.18.0
### Added
* Code-Level Metrics are now available for instrumented transactions. This is off by default but once enabled via `ConfigCodeLevelMetricsEnabled(true)` transactions will include information about the location in the source code where `StartTransaction` was invoked.
* Adds information about where in your source code transaction traces originated.
* See the Go Agent documentation for details on [configuring](https://docs.newrelic.com/docs/apm/agents/go-agent/configuration/go-agent-code-level-metrics-config) Code-Level Metrics and how to [instrument](https://docs.newrelic.com/docs/apm/agents/go-agent/instrumentation/go-agent-code-level-metrics-instrument) your code using them.
* New V2 logs in context plugin is available for Logrus, packed with all the features you didn't know you wanted:
* Automatic Log Forwarding
* Log Metrics
* Capture logs anywhere in your code; both inside or outside of a transaction.
* Use the Logrus formatting package of your choice
* Local Log Decorating is now available for the new logcontext-v2/nrlogrus plugin only. This is off by default but can be enabled with `ConfigAppLogForwardingEnabled(true)`.

### Fixed
* Fixed issue with custom event limits and number of DT Spans to more accurately follow configured limits.

### Support Statement
New Relic recommends that you upgrade the agent regularly to ensure that you’re getting the latest features and performance benefits. Additionally, older releases will no longer be supported when they reach end-of-life.
* Note that the oldest supported version of the Go Agent is 3.6.0.

## 3.17.0
### Added
* Logs in context now supported for zerolog.
Expand Down
1 change: 0 additions & 1 deletion v3/examples/server-http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func makeApplication() (*newrelic.Application, error) {
newrelic.ConfigAppName("HTTP Server App"),
newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
newrelic.ConfigDebugLogger(os.Stdout),
newrelic.ConfigDistributedTracerEnabled(true),
)
if nil != err {
return nil, err
Expand Down
5 changes: 4 additions & 1 deletion v3/examples/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ func main() {
newrelic.ConfigFromEnvironment(),
newrelic.ConfigDebugLogger(os.Stdout),
newrelic.ConfigAppLogForwardingEnabled(true),
newrelic.ConfigCodeLevelMetricsEnabled(true),
newrelic.ConfigCodeLevelMetricsPathPrefix("go-agent/v3"),
)
if err != nil {
fmt.Println(err)
Expand All @@ -287,10 +289,11 @@ func main() {
http.HandleFunc(newrelic.WrapHandleFunc(app, "/message", message))
http.HandleFunc(newrelic.WrapHandleFunc(app, "/log", logTxnMessage))

//loc := newrelic.ThisCodeLocation()
http.HandleFunc("/background", func(w http.ResponseWriter, req *http.Request) {
// Transactions started without an http.Request are classified as
// background transactions.
txn := app.StartTransaction("background")
txn := app.StartTransaction("background", newrelic.WithThisCodeLocation())
defer txn.End()

io.WriteString(w, "background transaction")
Expand Down
63 changes: 63 additions & 0 deletions v3/integrations/logcontext-v2/nrlogrus/example/main.go
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()
}
64 changes: 64 additions & 0 deletions v3/integrations/logcontext-v2/nrlogrus/formatter.go
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
}
Loading

0 comments on commit b580d7f

Please sign in to comment.