Skip to content

Commit

Permalink
Merge pull request #945 from newrelic/develop
Browse files Browse the repository at this point in the history
Release 3.34.0
  • Loading branch information
iamemilio committed Aug 5, 2024
2 parents dd2e359 + b838457 commit 6c84bcf
Show file tree
Hide file tree
Showing 33 changed files with 918 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/auto_assign.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
addReviewers: true

# Set to true to add assignees to pull requests
addAssignees: false
addAssignees: true

# A list of reviewers to be added to pull requests (GitHub user name)
reviewers:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/autoassign.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ jobs:
add-reviews:
runs-on: ubuntu-latest
steps:
- uses: kentaro-m/auto-assign-action@v1.2.0
- uses: kentaro-m/auto-assign-action@v2.0.0
17 changes: 10 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Go Agent CI
on: pull_request
env:
# Specifies which go version to run integration tests on
INTEGRATION_TESTS_GO_VERSION: 1.21.5
INTEGRATION_TESTS_GO_VERSION: latest

jobs:
go-agent-v3:
Expand All @@ -15,11 +15,13 @@ jobs:
matrix:
include:
# Core Tests on 3 most recent major Go versions
- go-version: 1.19.0
- go-version: 1.20.14
dirs: v3/newrelic,v3/internal,v3/examples
- go-version: 1.20.0
- go-version: 1.21
dirs: v3/newrelic,v3/internal,v3/examples
- go-version: 1.21.0
- go-version: latest
dirs: v3/newrelic,v3/internal,v3/examples
- go-version: 1.23rc2
dirs: v3/newrelic,v3/internal,v3/examples

# Integration Tests on highest Supported Go Version
Expand Down Expand Up @@ -68,6 +70,7 @@ jobs:
- dirs: v3/integrations/nrgraphqlgo,v3/integrations/nrgraphqlgo/example
- dirs: v3/integrations/nrmssql
- dirs: v3/integrations/nropenai
- dirs: v3/integrations/nrslog
steps:
- name: Checkout Code
uses: actions/checkout@v2
Expand Down Expand Up @@ -106,11 +109,11 @@ jobs:
matrix:
include:
# Core Tests on 3 most recent major Go versions
- go-version: 1.19.0
- go-version: 1.20.14
dirs: v3/newrelic,v3/internal,v3/examples
- go-version: 1.20.0
- go-version: 1.21
dirs: v3/newrelic,v3/internal,v3/examples
- go-version: 1.21.0
- go-version: latest
dirs: v3/newrelic,v3/internal,v3/examples
steps:
- name: Checkout Code
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## 3.34.0
### Added
- logcontext-v2/nrlogrus can now collect user attributes
- logcontext-v2/nrslog can now collect user attributes
- use slog to manage Go agent logs with the new nrslog library
- use zerolog go manage Go agent logs with the new nrzerolog library
- support for `RegisterTLSConfig` in nrmysql
### Fixed
- logcontext-v2/nrlogrus will still print user logs without isses if the Go agent has already been shut down.
- switched protobuff to google.golang.org/protobuff in modfile
### Support statement
We use the latest version of the Go language. At minimum, you should be using no version of Go older than what is supported by the Go team themselves.
See the [Go agent EOL Policy](/docs/apm/agents/go-agent/get-started/go-agent-eol-policy) for details about supported versions of the Go agent and third-party components.


## 3.33.1
### Added
- Increased max span events default limit to 2,000 to align with agent specifications
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is used to build the docker image for the Go Agent's GitHub Action tests
# Default go version if no arguments passed in
ARG GO_VERSION=1.19
ARG GO_VERSION=1.20

# Takes in go version
FROM golang:${GO_VERSION} as builder
Expand Down
3 changes: 2 additions & 1 deletion GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,13 @@ if nil == err {
}
```

Popular logging libraries `logrus`, `logxi` and `zap` are supported by
Popular logging libraries `logrus`, `logxi`, `zap` and `zerolog` are supported by
integration packages:

* [v3/integrations/nrlogrus](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrlogrus/)
* [v3/integrations/nrlogxi](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrlogxi/)
* [v3/integrations/nrzap](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrzap/)
* [v3/integrations/nrzerolog](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrzerolog/)

## Transactions

Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ package primitives can be found [here](GUIDE.md#datastore-segments).

#### Agent Logging

| Project | Integration Package | |
| ------------- | ------------- | - |
| [sirupsen/logrus](https://github.com/sirupsen/logrus) | [v3/integrations/nrlogrus](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrlogrus) | Send agent log messages to Logrus |
| [mgutz/logxi](https://github.com/mgutz/logxi) | [v3/integrations/nrlogxi](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrlogxi) | Send agent log messages to Logxi |
| [uber-go/zap](https://github.com/uber-go/zap) | [v3/integrations/nrzap](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrzap) | Send agent log messages to Zap |
| Project | Integration Package | |
|-------------------------------------------------------|-----------------------------------------------------------------------------------------------------|---------------------------------------|
| [sirupsen/logrus](https://github.com/sirupsen/logrus) | [v3/integrations/nrlogrus](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrlogrus) | Send agent log messages to Logrus |
| [mgutz/logxi](https://github.com/mgutz/logxi) | [v3/integrations/nrlogxi](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrlogxi) | Send agent log messages to Logxi |
| [uber-go/zap](https://github.com/uber-go/zap) | [v3/integrations/nrzap](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrzap) | Send agent log messages to Zap |
| [log/slog](https://pkg.go.dev/log/slog) | [v3/integrations/nrslog](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrslog) | Send agent log messages to `log/slog` |
| [rs/zerolog](https://github.com/rs/zerolog) | [v3/integrations/nrzerolog](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrzerolog) | Send agent log messages to Zerolog |

#### Logs in Context

Expand Down
2 changes: 1 addition & 1 deletion v3/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/newrelic/go-agent/v3
go 1.20

require (
github.com/golang/protobuf v1.5.3
google.golang.org/protobuf v1.5.3
google.golang.org/grpc v1.56.3
)

Expand Down
5 changes: 3 additions & 2 deletions v3/integrations/logcontext-v2/nrlogrus/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ func NewFormatter(app *newrelic.Application, formatter logrus.Formatter) Context
// 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,
Severity: e.Level.String(),
Message: e.Message,
Attributes: e.Data,
}

logBytes, err := f.formatter.Format(e)
Expand Down
62 changes: 62 additions & 0 deletions v3/integrations/logcontext-v2/nrlogrus/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,32 @@ func TestBackgroundLog(t *testing.T) {
})
}

func TestBackgroundLogWithFields(t *testing.T) {
app := integrationsupport.NewTestApp(integrationsupport.SampleEverythingReplyFn,
newrelic.ConfigAppLogDecoratingEnabled(true),
newrelic.ConfigAppLogForwardingEnabled(true),
)
out := bytes.NewBuffer([]byte{})
log := newTextLogger(out, app.Application)
message := "Hello World!"
log.WithField("test field", []string{"a", "b"}).Info(message)
logcontext.ValidateDecoratedOutput(t, out, &logcontext.DecorationExpect{
EntityGUID: integrationsupport.TestEntityGUID,
Hostname: host,
EntityName: integrationsupport.SampleAppName,
})
app.ExpectLogEvents(t, []internal.WantLog{
{
Severity: logrus.InfoLevel.String(),
Message: message,
Timestamp: internal.MatchAnyUnixMilli,
Attributes: map[string]interface{}{
"test field": []string{"a", "b"},
},
},
})
}

func TestJSONBackgroundLog(t *testing.T) {
app := integrationsupport.NewTestApp(integrationsupport.SampleEverythingReplyFn,
newrelic.ConfigAppLogDecoratingEnabled(true),
Expand Down Expand Up @@ -192,3 +218,39 @@ func TestLogInContext(t *testing.T) {

txn.End()
}

func TestLogInContextWithFields(t *testing.T) {
app := integrationsupport.NewTestApp(integrationsupport.SampleEverythingReplyFn,
newrelic.ConfigAppLogDecoratingEnabled(true),
newrelic.ConfigAppLogForwardingEnabled(true),
)
out := bytes.NewBuffer([]byte{})
log := newTextLogger(out, app.Application)
txn := app.StartTransaction("test txn")

ctx := newrelic.NewContext(context.Background(), txn)
message := "Hello World!"
log.WithField("hi", 1).WithContext(ctx).Info(message)

logcontext.ValidateDecoratedOutput(t, out, &logcontext.DecorationExpect{
EntityGUID: integrationsupport.TestEntityGUID,
Hostname: host,
EntityName: integrationsupport.SampleAppName,
TraceID: txn.GetLinkingMetadata().TraceID,
SpanID: txn.GetLinkingMetadata().SpanID,
})
txn.ExpectLogEvents(t, []internal.WantLog{
{
Severity: logrus.InfoLevel.String(),
Message: message,
Timestamp: internal.MatchAnyUnixMilli,
SpanID: txn.GetLinkingMetadata().SpanID,
TraceID: txn.GetLinkingMetadata().TraceID,
Attributes: map[string]interface{}{
"hi": 1,
},
},
})

txn.End()
}
7 changes: 6 additions & 1 deletion v3/integrations/logcontext-v2/nrslog/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

func main() {
app, err := newrelic.NewApplication(
newrelic.ConfigAppName("slog example app"),
newrelic.ConfigFromEnvironment(),
newrelic.ConfigAppLogEnabled(true),
)
Expand All @@ -27,7 +28,11 @@ func main() {
txn := app.StartTransaction("example transaction")
ctx := newrelic.NewContext(context.Background(), txn)

log.InfoContext(ctx, "I am a log inside a transaction")
log.InfoContext(ctx, "I am a log inside a transaction with custom attributes!",
slog.String("foo", "bar"),
slog.Int("answer", 42),
slog.Any("some_map", map[string]interface{}{"a": 1.0, "b": 2}),
)

// pretend to do some work
time.Sleep(500 * time.Millisecond)
Expand Down
14 changes: 11 additions & 3 deletions v3/integrations/logcontext-v2/nrslog/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,18 @@ func (h NRHandler) Enabled(ctx context.Context, lvl slog.Level) bool {
// - If a group has no Attrs (even if it has a non-empty key),
// ignore it.
func (h NRHandler) Handle(ctx context.Context, record slog.Record) error {
attrs := map[string]interface{}{}

record.Attrs(func(attr slog.Attr) bool {
attrs[attr.Key] = attr.Value.Any()
return true
})

data := newrelic.LogData{
Severity: record.Level.String(),
Timestamp: record.Time.UnixMilli(),
Message: record.Message,
Severity: record.Level.String(),
Timestamp: record.Time.UnixMilli(),
Message: record.Message,
Attributes: attrs,
}
if h.txn != nil {
h.txn.RecordLog(data)
Expand Down
40 changes: 40 additions & 0 deletions v3/integrations/logcontext-v2/nrslog/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"log/slog"
"os"
"strings"
"testing"

Expand Down Expand Up @@ -225,6 +226,45 @@ func TestWithAttributes(t *testing.T) {

}

func TestWithAttributesFromContext(t *testing.T) {
app := integrationsupport.NewTestApp(integrationsupport.SampleEverythingReplyFn,
newrelic.ConfigAppLogDecoratingEnabled(false),
newrelic.ConfigAppLogForwardingEnabled(true),
)
log := slog.New(TextHandler(app.Application, os.Stdout, &slog.HandlerOptions{}))

log.Info("I am a log message")

txn := app.StartTransaction("example transaction")
ctx := newrelic.NewContext(context.Background(), txn)

log.InfoContext(ctx, "I am a log inside a transaction with custom attributes!",
slog.String("foo", "bar"),
slog.Int("answer", 42),
slog.Any("some_map", map[string]interface{}{"a": 1.0, "b": 2}),
)

txn.End()

app.ExpectLogEvents(t, []internal.WantLog{
{
Severity: slog.LevelInfo.String(),
Message: "I am a log message",
Timestamp: internal.MatchAnyUnixMilli,
},
{
Severity: slog.LevelInfo.String(),
Message: "I am a log inside a transaction with custom attributes!",
Timestamp: internal.MatchAnyUnixMilli,
Attributes: map[string]interface{}{
"foo": "bar",
"answer": 42,
"some_map": map[string]interface{}{"a": 1.0, "b": 2},
},
},
})

}
func TestWithGroup(t *testing.T) {
app := integrationsupport.NewTestApp(integrationsupport.SampleEverythingReplyFn,
newrelic.ConfigAppLogDecoratingEnabled(false),
Expand Down
3 changes: 0 additions & 3 deletions v3/integrations/nrmssql/nrmssql.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

//go:build go1.10
// +build go1.10

// Package nrmssql instruments github.com/microsoft/go-mssqldb.
//
// Use this package to instrument your MSSQL calls without having to manually
Expand Down
6 changes: 6 additions & 0 deletions v3/integrations/nrmysql/nrmysql.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

//go:build go1.10
// +build go1.10

// Package nrmysql instruments https://github.com/go-sql-driver/mysql.
Expand Down Expand Up @@ -48,6 +49,7 @@
package nrmysql

import (
"crypto/tls"
"database/sql"
"net"

Expand All @@ -67,6 +69,10 @@ var (
}
)

func RegisterTLSConfig(key string, config *tls.Config) error {
return mysql.RegisterTLSConfig(key, config)
}

func init() {
sql.Register("nrmysql", newrelic.InstrumentSQLDriver(mysql.MySQLDriver{}, baseBuilder))
internal.TrackUsage("integration", "driver", "mysql")
Expand Down
Loading

0 comments on commit 6c84bcf

Please sign in to comment.