Skip to content

Commit 6c84bcf

Browse files
authored
Merge pull request #945 from newrelic/develop
Release 3.34.0
2 parents dd2e359 + b838457 commit 6c84bcf

33 files changed

+918
-47
lines changed

.github/auto_assign.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
addReviewers: true
33

44
# Set to true to add assignees to pull requests
5-
addAssignees: false
5+
addAssignees: true
66

77
# A list of reviewers to be added to pull requests (GitHub user name)
88
reviewers:

.github/workflows/autoassign.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ jobs:
77
add-reviews:
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: kentaro-m/auto-assign-action@v1.2.0
10+
- uses: kentaro-m/auto-assign-action@v2.0.0

.github/workflows/ci.yaml

+10-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: Go Agent CI
44
on: pull_request
55
env:
66
# Specifies which go version to run integration tests on
7-
INTEGRATION_TESTS_GO_VERSION: 1.21.5
7+
INTEGRATION_TESTS_GO_VERSION: latest
88

99
jobs:
1010
go-agent-v3:
@@ -15,11 +15,13 @@ jobs:
1515
matrix:
1616
include:
1717
# Core Tests on 3 most recent major Go versions
18-
- go-version: 1.19.0
18+
- go-version: 1.20.14
1919
dirs: v3/newrelic,v3/internal,v3/examples
20-
- go-version: 1.20.0
20+
- go-version: 1.21
2121
dirs: v3/newrelic,v3/internal,v3/examples
22-
- go-version: 1.21.0
22+
- go-version: latest
23+
dirs: v3/newrelic,v3/internal,v3/examples
24+
- go-version: 1.23rc2
2325
dirs: v3/newrelic,v3/internal,v3/examples
2426

2527
# Integration Tests on highest Supported Go Version
@@ -68,6 +70,7 @@ jobs:
6870
- dirs: v3/integrations/nrgraphqlgo,v3/integrations/nrgraphqlgo/example
6971
- dirs: v3/integrations/nrmssql
7072
- dirs: v3/integrations/nropenai
73+
- dirs: v3/integrations/nrslog
7174
steps:
7275
- name: Checkout Code
7376
uses: actions/checkout@v2
@@ -106,11 +109,11 @@ jobs:
106109
matrix:
107110
include:
108111
# Core Tests on 3 most recent major Go versions
109-
- go-version: 1.19.0
112+
- go-version: 1.20.14
110113
dirs: v3/newrelic,v3/internal,v3/examples
111-
- go-version: 1.20.0
114+
- go-version: 1.21
112115
dirs: v3/newrelic,v3/internal,v3/examples
113-
- go-version: 1.21.0
116+
- go-version: latest
114117
dirs: v3/newrelic,v3/internal,v3/examples
115118
steps:
116119
- name: Checkout Code

CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
## 3.34.0
2+
### Added
3+
- logcontext-v2/nrlogrus can now collect user attributes
4+
- logcontext-v2/nrslog can now collect user attributes
5+
- use slog to manage Go agent logs with the new nrslog library
6+
- use zerolog go manage Go agent logs with the new nrzerolog library
7+
- support for `RegisterTLSConfig` in nrmysql
8+
### Fixed
9+
- logcontext-v2/nrlogrus will still print user logs without isses if the Go agent has already been shut down.
10+
- switched protobuff to google.golang.org/protobuff in modfile
11+
### Support statement
12+
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.
13+
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.
14+
15+
116
## 3.33.1
217
### Added
318
- Increased max span events default limit to 2,000 to align with agent specifications

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is used to build the docker image for the Go Agent's GitHub Action tests
22
# Default go version if no arguments passed in
3-
ARG GO_VERSION=1.19
3+
ARG GO_VERSION=1.20
44

55
# Takes in go version
66
FROM golang:${GO_VERSION} as builder

GUIDE.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,13 @@ if nil == err {
137137
}
138138
```
139139

140-
Popular logging libraries `logrus`, `logxi` and `zap` are supported by
140+
Popular logging libraries `logrus`, `logxi`, `zap` and `zerolog` are supported by
141141
integration packages:
142142

143143
* [v3/integrations/nrlogrus](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrlogrus/)
144144
* [v3/integrations/nrlogxi](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrlogxi/)
145145
* [v3/integrations/nrzap](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrzap/)
146+
* [v3/integrations/nrzerolog](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrzerolog/)
146147

147148
## Transactions
148149

README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,13 @@ package primitives can be found [here](GUIDE.md#datastore-segments).
112112

113113
#### Agent Logging
114114

115-
| Project | Integration Package | |
116-
| ------------- | ------------- | - |
117-
| [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 |
118-
| [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 |
119-
| [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 |
115+
| Project | Integration Package | |
116+
|-------------------------------------------------------|-----------------------------------------------------------------------------------------------------|---------------------------------------|
117+
| [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 |
118+
| [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 |
119+
| [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 |
120+
| [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` |
121+
| [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 |
120122

121123
#### Logs in Context
122124

v3/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/newrelic/go-agent/v3
33
go 1.20
44

55
require (
6-
github.com/golang/protobuf v1.5.3
6+
google.golang.org/protobuf v1.5.3
77
google.golang.org/grpc v1.56.3
88
)
99

v3/integrations/logcontext-v2/nrlogrus/formatter.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ func NewFormatter(app *newrelic.Application, formatter logrus.Formatter) Context
3030
// Format renders a single log entry.
3131
func (f ContextFormatter) Format(e *logrus.Entry) ([]byte, error) {
3232
logData := newrelic.LogData{
33-
Severity: e.Level.String(),
34-
Message: e.Message,
33+
Severity: e.Level.String(),
34+
Message: e.Message,
35+
Attributes: e.Data,
3536
}
3637

3738
logBytes, err := f.formatter.Format(e)

v3/integrations/logcontext-v2/nrlogrus/formatter_test.go

+62
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,32 @@ func TestBackgroundLog(t *testing.T) {
114114
})
115115
}
116116

117+
func TestBackgroundLogWithFields(t *testing.T) {
118+
app := integrationsupport.NewTestApp(integrationsupport.SampleEverythingReplyFn,
119+
newrelic.ConfigAppLogDecoratingEnabled(true),
120+
newrelic.ConfigAppLogForwardingEnabled(true),
121+
)
122+
out := bytes.NewBuffer([]byte{})
123+
log := newTextLogger(out, app.Application)
124+
message := "Hello World!"
125+
log.WithField("test field", []string{"a", "b"}).Info(message)
126+
logcontext.ValidateDecoratedOutput(t, out, &logcontext.DecorationExpect{
127+
EntityGUID: integrationsupport.TestEntityGUID,
128+
Hostname: host,
129+
EntityName: integrationsupport.SampleAppName,
130+
})
131+
app.ExpectLogEvents(t, []internal.WantLog{
132+
{
133+
Severity: logrus.InfoLevel.String(),
134+
Message: message,
135+
Timestamp: internal.MatchAnyUnixMilli,
136+
Attributes: map[string]interface{}{
137+
"test field": []string{"a", "b"},
138+
},
139+
},
140+
})
141+
}
142+
117143
func TestJSONBackgroundLog(t *testing.T) {
118144
app := integrationsupport.NewTestApp(integrationsupport.SampleEverythingReplyFn,
119145
newrelic.ConfigAppLogDecoratingEnabled(true),
@@ -192,3 +218,39 @@ func TestLogInContext(t *testing.T) {
192218

193219
txn.End()
194220
}
221+
222+
func TestLogInContextWithFields(t *testing.T) {
223+
app := integrationsupport.NewTestApp(integrationsupport.SampleEverythingReplyFn,
224+
newrelic.ConfigAppLogDecoratingEnabled(true),
225+
newrelic.ConfigAppLogForwardingEnabled(true),
226+
)
227+
out := bytes.NewBuffer([]byte{})
228+
log := newTextLogger(out, app.Application)
229+
txn := app.StartTransaction("test txn")
230+
231+
ctx := newrelic.NewContext(context.Background(), txn)
232+
message := "Hello World!"
233+
log.WithField("hi", 1).WithContext(ctx).Info(message)
234+
235+
logcontext.ValidateDecoratedOutput(t, out, &logcontext.DecorationExpect{
236+
EntityGUID: integrationsupport.TestEntityGUID,
237+
Hostname: host,
238+
EntityName: integrationsupport.SampleAppName,
239+
TraceID: txn.GetLinkingMetadata().TraceID,
240+
SpanID: txn.GetLinkingMetadata().SpanID,
241+
})
242+
txn.ExpectLogEvents(t, []internal.WantLog{
243+
{
244+
Severity: logrus.InfoLevel.String(),
245+
Message: message,
246+
Timestamp: internal.MatchAnyUnixMilli,
247+
SpanID: txn.GetLinkingMetadata().SpanID,
248+
TraceID: txn.GetLinkingMetadata().TraceID,
249+
Attributes: map[string]interface{}{
250+
"hi": 1,
251+
},
252+
},
253+
})
254+
255+
txn.End()
256+
}

v3/integrations/logcontext-v2/nrslog/example/main.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
func main() {
1414
app, err := newrelic.NewApplication(
15+
newrelic.ConfigAppName("slog example app"),
1516
newrelic.ConfigFromEnvironment(),
1617
newrelic.ConfigAppLogEnabled(true),
1718
)
@@ -27,7 +28,11 @@ func main() {
2728
txn := app.StartTransaction("example transaction")
2829
ctx := newrelic.NewContext(context.Background(), txn)
2930

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

3237
// pretend to do some work
3338
time.Sleep(500 * time.Millisecond)

v3/integrations/logcontext-v2/nrslog/handler.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,18 @@ func (h NRHandler) Enabled(ctx context.Context, lvl slog.Level) bool {
129129
// - If a group has no Attrs (even if it has a non-empty key),
130130
// ignore it.
131131
func (h NRHandler) Handle(ctx context.Context, record slog.Record) error {
132+
attrs := map[string]interface{}{}
133+
134+
record.Attrs(func(attr slog.Attr) bool {
135+
attrs[attr.Key] = attr.Value.Any()
136+
return true
137+
})
138+
132139
data := newrelic.LogData{
133-
Severity: record.Level.String(),
134-
Timestamp: record.Time.UnixMilli(),
135-
Message: record.Message,
140+
Severity: record.Level.String(),
141+
Timestamp: record.Time.UnixMilli(),
142+
Message: record.Message,
143+
Attributes: attrs,
136144
}
137145
if h.txn != nil {
138146
h.txn.RecordLog(data)

v3/integrations/logcontext-v2/nrslog/handler_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"log/slog"
7+
"os"
78
"strings"
89
"testing"
910

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

226227
}
227228

229+
func TestWithAttributesFromContext(t *testing.T) {
230+
app := integrationsupport.NewTestApp(integrationsupport.SampleEverythingReplyFn,
231+
newrelic.ConfigAppLogDecoratingEnabled(false),
232+
newrelic.ConfigAppLogForwardingEnabled(true),
233+
)
234+
log := slog.New(TextHandler(app.Application, os.Stdout, &slog.HandlerOptions{}))
235+
236+
log.Info("I am a log message")
237+
238+
txn := app.StartTransaction("example transaction")
239+
ctx := newrelic.NewContext(context.Background(), txn)
240+
241+
log.InfoContext(ctx, "I am a log inside a transaction with custom attributes!",
242+
slog.String("foo", "bar"),
243+
slog.Int("answer", 42),
244+
slog.Any("some_map", map[string]interface{}{"a": 1.0, "b": 2}),
245+
)
246+
247+
txn.End()
248+
249+
app.ExpectLogEvents(t, []internal.WantLog{
250+
{
251+
Severity: slog.LevelInfo.String(),
252+
Message: "I am a log message",
253+
Timestamp: internal.MatchAnyUnixMilli,
254+
},
255+
{
256+
Severity: slog.LevelInfo.String(),
257+
Message: "I am a log inside a transaction with custom attributes!",
258+
Timestamp: internal.MatchAnyUnixMilli,
259+
Attributes: map[string]interface{}{
260+
"foo": "bar",
261+
"answer": 42,
262+
"some_map": map[string]interface{}{"a": 1.0, "b": 2},
263+
},
264+
},
265+
})
266+
267+
}
228268
func TestWithGroup(t *testing.T) {
229269
app := integrationsupport.NewTestApp(integrationsupport.SampleEverythingReplyFn,
230270
newrelic.ConfigAppLogDecoratingEnabled(false),

v3/integrations/nrmssql/nrmssql.go

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright 2020 New Relic Corporation. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
//go:build go1.10
5-
// +build go1.10
6-
74
// Package nrmssql instruments github.com/microsoft/go-mssqldb.
85
//
96
// Use this package to instrument your MSSQL calls without having to manually

v3/integrations/nrmysql/nrmysql.go

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2020 New Relic Corporation. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
//go:build go1.10
45
// +build go1.10
56

67
// Package nrmysql instruments https://github.com/go-sql-driver/mysql.
@@ -48,6 +49,7 @@
4849
package nrmysql
4950

5051
import (
52+
"crypto/tls"
5153
"database/sql"
5254
"net"
5355

@@ -67,6 +69,10 @@ var (
6769
}
6870
)
6971

72+
func RegisterTLSConfig(key string, config *tls.Config) error {
73+
return mysql.RegisterTLSConfig(key, config)
74+
}
75+
7076
func init() {
7177
sql.Register("nrmysql", newrelic.InstrumentSQLDriver(mysql.MySQLDriver{}, baseBuilder))
7278
internal.TrackUsage("integration", "driver", "mysql")

0 commit comments

Comments
 (0)