Skip to content

Commit

Permalink
Merge pull request #531 from newrelic/develop
Browse files Browse the repository at this point in the history
Release 3.17.0
  • Loading branch information
nr-swilloughby committed Jun 29, 2022
2 parents a0f3666 + 56d78e8 commit d71efc4
Show file tree
Hide file tree
Showing 55 changed files with 2,524 additions and 156 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/ci.yaml
Expand Up @@ -89,6 +89,8 @@ jobs:
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 Down Expand Up @@ -124,9 +126,10 @@ jobs:
dirs: v3/integrations/nrecho-v3
# Test against the latest v3 Echo:
extratesting: go get -u github.com/labstack/echo@v3
- go-version: 1.15.x
# go/new/http no longer stable under go 1.17.x
- go-version: 1.17.x
dirs: v3/integrations/nrecho-v4
extratesting: go get -u github.com/labstack/echo@master
extratesting: go get -u github.com/labstack/echo/v4@master
- go-version: 1.15.x
dirs: v3/integrations/nrelasticsearch-v7
extratesting: go get -u github.com/elastic/go-elasticsearch/v7@7.x
Expand Down Expand Up @@ -211,6 +214,9 @@ jobs:
- go-version: 1.15.x
dirs: v3/integrations/nrgraphqlgo,v3/integrations/nrgraphqlgo/example
extratesting: go get -u github.com/graphql-go/graphql@master
- go-version: 1.15.x
dirs: v3/integrations/nrmssql
extratesting: go get -u github.com/denisenkom/go-mssqldb@master

steps:
- name: Install Go
Expand Down
25 changes: 25 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,28 @@
## 3.17.0
### Added
* Logs in context now supported for zerolog.
* This is a quick way to view logs no matter where you are in the platform.
* Adds support for logging metrics which shows the rate of log messages by severity in the Logs chart in the APM Summary view. This is enabled by default in this release.
* Adds support for forwarding application logs to New Relic. This automatically sends application logs that have been enriched to power APM logs in context. This is disabled by default in this release. This will be on by default in a future release.
* To learn more about APM logs in context see the documentation [here](https://docs.newrelic.com/docs/logs/logs-context/logs-in-context).
* Includes the `RecordLog` function for recording log data from a single log entry
* An integrated plugin for zerolog to automatically ingest log data with the Go Agent.
* Resolves [issue 178](https://github.com/newrelic/go-agent/issues/178), [issue 488](https://github.com/newrelic/go-agent/issues/488), [issue 489](https://github.com/newrelic/go-agent/issues/489), [issue 490](https://github.com/newrelic/go-agent/issues/490), and [issue 491](https://github.com/newrelic/go-agent/issues/491) .
* Added integration for MS SQL Server ([PR 425](https://github.com/newrelic/go-agent/pull/425); thanks @ishahid91!)
* This introduces the `nrmssql` integration v1.0.0.
* Added config function `ConfigCustomInsightsEventsMaxSamplesStored` for limiting the number of samples stored in a custom insights event. Fixes [issue 476](https://github.com/newrelic/go-agent/issues/476)

### Fixed
* Improved speed of building distributed trace header JSON payload. Fixes [issue 505](https://github.com/newrelic/go-agent/issues/505).
* Renamed the gRPC attribute names from `GrpcStatusLevel`, `GrpcStatusMessage`, and `GrpcStatusCode` to `grpcStatusLevel`, `grpcStatusMessage`, and `grpcStatusCode` respectively, to conform to existing naming conventions for New Relic agents. Fixes [issue 492](https://github.com/newrelic/go-agent/issues/492).
* Updated `go.mod` for the `nrgin` integration to mitigate security issue in 3rd party dependency.
* Updated `go.mod` for the `nrawssdk-v1` integration to properly reflect its dependency on version 3.16.0 of the Go Agent.
* Updated `go.mod` for the `nrlambda` integration to require `aws-lambda-go` version 1.20.0. ([PR 356](https://github.com/newrelic/go-agent/pull/356); thanks MattWhelan!)

### 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.

# ChangeLog
## 3.16.1
### Fixed
Expand Down
5 changes: 4 additions & 1 deletion GUIDE.md
Expand Up @@ -67,7 +67,7 @@ Now, add instrumentation to your Go application to get additional performance da
* Import any of our [integration packages](https://github.com/newrelic/go-agent#integrations) for out-of-the box support for many popular Go web
frameworks and libraries.
* [Instrument Transactions](#transactions)
* [Use Distributed Tracing](#distributed-tracing)
* [Use Distributed Tracing](#distributed-tracing) (Note that this is on by default.)
* [(Optional) Instrument Segments](#segments) for an extra level of timing detail
* External segments are needed for Distributed Tracing
* Read through the rest of this GUIDE for more instrumentation
Expand Down Expand Up @@ -102,6 +102,9 @@ app, err := newrelic.NewApplication(

## Logging

For information about logs in context, please see [the documentation here](https://docs.newrelic.com/docs/logs/logs-context/logs-in-context).
As of Go Agent version 3.17.0, we support logs in context with the zerolog integration.

The agent's logging system is designed to be easily extensible. By default, no
logging will occur. To enable logging, use the following config functions
with an [io.Writer](https://godoc.org/github.com/pkg/io/#Writer):
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -15,7 +15,6 @@ Go is a compiled language, and doesn’t use a virtual machine. This means that
### Compatibility and Requirements

For the latest version of the agent, Go 1.7+ is required, due to the use of `context.Context`.
(For versions 2.X and earlier of the Go agent, Go 1.3+ is required.)

Linux, OS X, and Windows (Vista, Server 2008 and later) are supported.

Expand Down Expand Up @@ -91,6 +90,7 @@ package primitives can be found [here](GUIDE.md#datastore-segments).
| ------------- | ------------- | - |
| [lib/pq](https://github.com/lib/pq) | [v3/integrations/nrpq](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrpq) | Instrument PostgreSQL driver (`pq` driver for `database/sql`) |
| [jackc/pgx](https://github.com/jackc/pgx) | [v3/integrations/nrpgx](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrpgx) | Instrument PostgreSQL driver (`pgx` driver for `database/sql`)|
| [go-mssqldb](github.com/denisenkom/go-mssqldb) | [v3/integrations/nrmssql](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrmssql) | Instrument MS SQL driver |
| [go-sql-driver/mysql](https://github.com/go-sql-driver/mysql) | [v3/integrations/nrmysql](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrmysql) | Instrument MySQL driver |
| [elastic/go-elasticsearch](https://github.com/elastic/go-elasticsearch) | [v3/integrations/nrelasticsearch-v7](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrelasticsearch-v7) | Instrument Elasticsearch datastore calls |
| [database/sql](https://godoc.org/database/sql) | Use a supported database driver or [builtin instrumentation](https://godoc.org/github.com/newrelic/go-agent/v3/newrelic#InstrumentSQLConnector) | Instrument database calls with SQL |
Expand Down
7 changes: 7 additions & 0 deletions build-script.sh
Expand Up @@ -35,6 +35,10 @@ pin_go_dependency() {
fi
}

go_mod_tidy() {
go mod tidy
}

IFS=","
for dir in $DIRS; do
cd "$pwd/$dir"
Expand All @@ -43,6 +47,9 @@ for dir in $DIRS; do
go mod edit -replace github.com/newrelic/go-agent/v3="$pwd"/v3
fi

# Do tidy if we can
go_mod_tidy || true

pin_go_dependency "$PIN"

# avoid testing v3 code when testing v2 newrelic package
Expand Down
24 changes: 24 additions & 0 deletions v3/examples/server/main.go
Expand Up @@ -246,11 +246,22 @@ func browser(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "browser header page")
}

func logTxnMessage(w http.ResponseWriter, r *http.Request) {
txn := newrelic.FromContext(r.Context())
txn.RecordLog(newrelic.LogData{
Message: "Log Message",
Severity: "info",
})

io.WriteString(w, "A log message was recorded")
}

func main() {
app, err := newrelic.NewApplication(
newrelic.ConfigAppName("Example App"),
newrelic.ConfigFromEnvironment(),
newrelic.ConfigDebugLogger(os.Stdout),
newrelic.ConfigAppLogForwardingEnabled(true),
)
if err != nil {
fmt.Println(err)
Expand All @@ -274,6 +285,7 @@ func main() {
http.HandleFunc(newrelic.WrapHandleFunc(app, "/browser", browser))
http.HandleFunc(newrelic.WrapHandleFunc(app, "/async", async))
http.HandleFunc(newrelic.WrapHandleFunc(app, "/message", message))
http.HandleFunc(newrelic.WrapHandleFunc(app, "/log", logTxnMessage))

http.HandleFunc("/background", func(w http.ResponseWriter, req *http.Request) {
// Transactions started without an http.Request are classified as
Expand All @@ -285,5 +297,17 @@ func main() {
time.Sleep(150 * time.Millisecond)
})

http.HandleFunc("/background_log", func(w http.ResponseWriter, req *http.Request) {
// Logs that occur outside of a transaction are classified as
// background logs.

app.RecordLog(newrelic.LogData{
Message: "Background Log Message",
Severity: "info",
})

io.WriteString(w, "A background log message was recorded")
})

http.ListenAndServe(":8000", nil)
}
95 changes: 95 additions & 0 deletions v3/integrations/logcontext-v2/nrzerolog/Readme.md
@@ -0,0 +1,95 @@
# Zerolog In Context

This plugin for zerolog implements the logs in context tooling for the go agent. This hook
function can be added to any zerolog logger, and will automatically collect the log data
from zerolog, and send it to New Relic through the go agent. The following Logging features
are supported by this plugin in the current release:

| Logging Feature | Supported |
| ------- | --------- |
| Forwarding | :heavy_check_mark: |
| Metrics | :heavy_check_mark: |
| Enrichment | :x: |

## Installation

The nrzerolog plugin, and the go-agent need to be integrated into your code
in order to use this tool. Make sure to set `newrelic.ConfigAppLogForwardingEnabled(true)`
in your config settings for the application. This will enable log forwarding
in the go agent. If you want to disable metrics, set `newrelic.ConfigAppLogMetricsEnabled(false),`.
Note that the agent sets the default number of logs per harverst cycle to 10000, but that
number may be reduced by the server. You can manually set this number by setting
`newrelic.ConfigAppLogForwardingMaxSamplesStored(123),`.

The following example will shows how to install and set up your code to send logs to new relic from zerolog.

```go

import (
"github.com/rs/zerolog"
"github.com/newrelic/go-agent/v3/newrelic"
"github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrzerolog"
)

func main() {
// Initialize a zerolog logger
baseLogger := zerolog.New(os.Stdout)

app, err := newrelic.NewApplication(
newrelic.ConfigFromEnvironment(),
newrelic.ConfigAppName("NRZerolog Example"),
newrelic.ConfigInfoLogger(os.Stdout),
newrelic.ConfigAppLogForwarding(true),
)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

// Send logs to New Relic outside of a transaction
nrHook := nrzerolog.NewRelicHook{
App: app,
}

// Wrap logger with New Relic Hook
nrLogger := baseLogger.Hook(nrHook)
nrLogger.Info().Msg("Hello World")

// Send logs to New Relic inside of a transaction
txn := app.StartTransaction("My Transaction")
ctx := newrelic.NewContext(context.Background(), txn)

nrTxnHook := nrzerolog.NewRelicHook{
App: app,
Context: ctx,
}

txnLogger := baseLogger.Hook(nrTxnHook)
txnLogger.Debug().Msg("This is a transaction log")

txn.End()
}
```

## Usage

Please enable the agent to ingest your logs by calling newrelic.ConfigAppLogForwardingEnabled(true),
when setting up your application. This is not enabled by default.

This integration for the zerolog logging frameworks uses a built in feature
of the zerolog framework called hook functions. Zerolog loggers can be modified
to have hook functions run on them before each time a write is executed. When a
logger is hooked, meaning a hook function was added to that logger with the Hook()
funciton, a copy of that logger is created with those changes. Note that zerolog
will *never* attempt to verify that any hook functions have not been not duplicated, or
that fields are not repeated in any way. As a result, we recommend that you create
a base logger that is configured in the way you prefer to use zerolog. Then you
create hooked loggers to send log data to New Relic from that base logger.

The plugin captures the log level, and the message from zerolog. It will also collect
distributed tracing data from your transaction context. At the moment the hook function is
called in zerolog, a timestamp will be generated for your log. In most cases, this
timestamp will be the same as the time posted in the zerolog log message, however it is possible that
there could be a slight offset depending on the the performance of your system.


53 changes: 53 additions & 0 deletions v3/integrations/logcontext-v2/nrzerolog/example/main.go
@@ -0,0 +1,53 @@
package main

import (
"context"
"fmt"
"os"
"time"

"github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrzerolog"
"github.com/newrelic/go-agent/v3/newrelic"
"github.com/rs/zerolog"
)

func main() {
baseLogger := zerolog.New(os.Stdout)

app, err := newrelic.NewApplication(
newrelic.ConfigFromEnvironment(),
newrelic.ConfigAppName("NRZerolog Example"),
newrelic.ConfigInfoLogger(os.Stdout),
newrelic.ConfigAppLogForwardingEnabled(true),
)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

app.WaitForConnection(5 * time.Second)

nrHook := nrzerolog.NewRelicHook{
App: app,
}

nrLogger := baseLogger.Hook(nrHook)
nrLogger.Info().Msg("Hello World")

// With transaction context
txn := app.StartTransaction("My Transaction")
ctx := newrelic.NewContext(context.Background(), txn)

nrTxnHook := nrzerolog.NewRelicHook{
App: app,
Context: ctx,
}

txnLogger := baseLogger.Hook(nrTxnHook)
txnLogger.Debug().Msg("This is a transaction log")

txn.End()

nrLogger.Info().Msg("Goodbye")
app.Shutdown(10 * time.Second)
}
8 changes: 8 additions & 0 deletions v3/integrations/logcontext-v2/nrzerolog/go.mod
@@ -0,0 +1,8 @@
module github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrzerolog

go 1.15

require (
github.com/newrelic/go-agent/v3 v3.16.0
github.com/rs/zerolog v1.26.1
)
41 changes: 41 additions & 0 deletions v3/integrations/logcontext-v2/nrzerolog/hook.go
@@ -0,0 +1,41 @@
package nrzerolog

import (
"context"

"github.com/newrelic/go-agent/v3/internal"
"github.com/newrelic/go-agent/v3/newrelic"
"github.com/rs/zerolog"
)

func init() { internal.TrackUsage("integration", "logcontext", "zerolog") }

type NewRelicHook struct {
App *newrelic.Application
Context context.Context
}

func (h NewRelicHook) Run(e *zerolog.Event, level zerolog.Level, msg string) {
var txn *newrelic.Transaction
if h.Context != nil {
txn = newrelic.FromContext(h.Context)
}

logLevel := ""
if level == zerolog.NoLevel {
logLevel = newrelic.LogSeverityUnknown
} else {
logLevel = level.String()
}

data := newrelic.LogData{
Severity: logLevel,
Message: msg,
}

if txn != nil {
txn.RecordLog(data)
} else {
h.App.RecordLog(data)
}
}
2 changes: 1 addition & 1 deletion v3/integrations/nrawssdk-v1/go.mod
Expand Up @@ -8,5 +8,5 @@ go 1.7
require (
// v1.15.0 is the first aws-sdk-go version with module support.
github.com/aws/aws-sdk-go v1.15.0
github.com/newrelic/go-agent/v3 v3.0.0
github.com/newrelic/go-agent/v3 v3.16.0
)

0 comments on commit d71efc4

Please sign in to comment.