Skip to content

Commit 0f93238

Browse files
Merge pull request #896 from newrelic/develop
Release 3.32.0
2 parents cb651c4 + 2c742a8 commit 0f93238

File tree

74 files changed

+647
-152
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+647
-152
lines changed

.github/workflows/ci.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
- dirs: v3/integrations/logcontext-v2/nrlogrus
3131
- dirs: v3/integrations/logcontext-v2/nrzerolog
3232
- dirs: v3/integrations/logcontext-v2/nrzap
33+
- dirs: v3/integrations/logcontext-v2/nrslog
3334
- dirs: v3/integrations/logcontext-v2/nrwriter
3435
- dirs: v3/integrations/logcontext-v2/zerologWriter
3536
- dirs: v3/integrations/logcontext-v2/logWriter
@@ -138,4 +139,4 @@ jobs:
138139
else
139140
echo "Directory /app/$dir does not exist."
140141
fi
141-
done
142+
done

CHANGELOG.md

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
## 3.32.0
2+
### Added
3+
* Updates to support for the New Relic security agent to report API endpoints.
4+
* Adds new wrapper function for the `nrecho`, `nrgin`, and `nrgorilla` integrations.
5+
* Handler to take New Relic transaction data from context automatically when using `nrslog` integration (thanks, @adomaskizogian!)
6+
7+
### Fixed
8+
* Adds missing license file to the `nropenai` integration.
9+
* Changes `*bedrockruntime.Client` parameters in `nrawsbedrock` integration to use a more general interface type, allowing the use of custom types which extend the bedrock client type.
10+
* Fixes `pgx5` pool example
11+
* Updated unit tests to check `Transaction.Ignore`
12+
* Updated `nrzap` unit tests to add background logger sugared test case.
13+
14+
### Support statement
15+
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.
16+
See the [Go agent EOL Policy](https://docs.newrelic.com/docs/apm/agents/go-agent/get-started/go-agent-eol-policy/) for details about supported versions of the Go agent and third-party components.
17+
118
## 3.31.0
219
### Added
320
* Integration packages to instrument AI model invocations (see below).

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ package primitives can be found [here](GUIDE.md#datastore-segments).
102102
| [snowflakedb/gosnowflake](https://github.com/snowflakedb/gosnowflake) | [v3/integrations/nrsnowflake](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrsnowflake) | Instrument Snowflake driver |
103103
| [mongodb/mongo-go-driver](https://github.com/mongodb/mongo-go-driver) | [v3/integrations/nrmongo](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrmongo) | Instrument MongoDB calls |
104104

105+
#### AI
106+
107+
| Project | Integration Package | |
108+
| ------------- | ------------- | - |
109+
| [sashabaranov/go-openai](https://github.com/sashabaranov/go-openai) | [v3/integrations/nropenai](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nropenai) | Send AI Monitoring Events with OpenAI |
110+
| [aws/aws-sdk-go-v2/tree/main/service/bedrockruntime](https://github.com/aws/aws-sdk-go-v2/tree/main/service/bedrockruntime) | [v3/integrations/nrawsbedrock](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrawsbedrock) | Send AI Monitoring Events with AWS Bedrock |
111+
112+
105113
#### Agent Logging
106114

107115
| Project | Integration Package | |

v3/go.mod

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
module github.com/newrelic/go-agent/v3
22

3-
go 1.19
3+
go 1.20
44

55
require (
66
github.com/golang/protobuf v1.5.3
7-
golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81
87
google.golang.org/grpc v1.56.3
98
)
109

v3/integrations/logcontext-v2/logWriter/go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module github.com/newrelic/go-agent/v3/integrations/logcontext-v2/logWriter
22

3-
go 1.19
3+
go 1.20
44

55
require (
6-
github.com/newrelic/go-agent/v3 v3.31.0
6+
github.com/newrelic/go-agent/v3 v3.32.0
77
github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrwriter v1.0.0
88
)
99

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrlogrus
22

3-
go 1.19
3+
go 1.20
44

55
require (
6-
github.com/newrelic/go-agent/v3 v3.31.0
6+
github.com/newrelic/go-agent/v3 v3.32.0
77
github.com/sirupsen/logrus v1.8.1
88
)
99

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrslog
22

3-
go 1.19
3+
go 1.20
44

5-
require github.com/newrelic/go-agent/v3 v3.31.0
5+
require github.com/newrelic/go-agent/v3 v3.32.0
66

77

88
replace github.com/newrelic/go-agent/v3 => ../../..

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

+40
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func JSONHandler(app *newrelic.Application, w io.Writer, opts *slog.HandlerOptio
3939
}
4040

4141
// WithTransaction creates a new Slog Logger object to be used for logging within a given transaction.
42+
// Calling this function with a logger having underlying TransactionFromContextHandler handler is a no-op.
4243
func WithTransaction(txn *newrelic.Transaction, logger *slog.Logger) *slog.Logger {
4344
if txn == nil || logger == nil {
4445
return logger
@@ -56,6 +57,7 @@ func WithTransaction(txn *newrelic.Transaction, logger *slog.Logger) *slog.Logge
5657

5758
// WithTransaction creates a new Slog Logger object to be used for logging within a given transaction it its found
5859
// in a context.
60+
// Calling this function with a logger having underlying TransactionFromContextHandler handler is a no-op.
5961
func WithContext(ctx context.Context, logger *slog.Logger) *slog.Logger {
6062
if ctx == nil {
6163
return logger
@@ -181,3 +183,41 @@ func (h NRHandler) WithGroup(name string) slog.Handler {
181183
txn: h.txn,
182184
}
183185
}
186+
187+
// NRHandler is an Slog handler that includes logic to implement New Relic Logs in Context.
188+
// New Relic transaction value is taken from context. It cannot be set directly.
189+
// This serves as a quality of life improvement for cases where slog.Default global instance is
190+
// referenced, allowing to use slog methods directly and maintaining New Relic instrumentation.
191+
type TransactionFromContextHandler struct {
192+
NRHandler
193+
}
194+
195+
// WithTransactionFromContext creates a wrapped NRHandler, enabling it to automatically reference New Relic
196+
// transaction from context.
197+
func WithTransactionFromContext(handler NRHandler) TransactionFromContextHandler {
198+
return TransactionFromContextHandler{handler}
199+
}
200+
201+
// Handle handles the Record.
202+
// It will only be called when Enabled returns true.
203+
// The Context argument is as for Enabled and NewRelic transaction.
204+
// Canceling the context should not affect record processing.
205+
// (Among other things, log messages may be necessary to debug a
206+
// cancellation-related problem.)
207+
//
208+
// Handle methods that produce output should observe the following rules:
209+
// - If r.Time is the zero time, ignore the time.
210+
// - If r.PC is zero, ignore it.
211+
// - Attr's values should be resolved.
212+
// - If an Attr's key and value are both the zero value, ignore the Attr.
213+
// This can be tested with attr.Equal(Attr{}).
214+
// - If a group's key is empty, inline the group's Attrs.
215+
// - If a group has no Attrs (even if it has a non-empty key),
216+
// ignore it.
217+
func (h TransactionFromContextHandler) Handle(ctx context.Context, record slog.Record) error {
218+
if txn := newrelic.FromContext(ctx); txn != nil {
219+
return h.NRHandler.WithTransaction(txn).Handle(ctx, record)
220+
}
221+
222+
return h.NRHandler.Handle(ctx, record)
223+
}

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

+37
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,40 @@ func TestWithGroup(t *testing.T) {
258258
}
259259

260260
}
261+
262+
func TestTransactionFromContextHandler(t *testing.T) {
263+
app := integrationsupport.NewTestApp(integrationsupport.SampleEverythingReplyFn,
264+
newrelic.ConfigAppLogDecoratingEnabled(true),
265+
newrelic.ConfigAppLogForwardingEnabled(true),
266+
)
267+
268+
out := bytes.NewBuffer([]byte{})
269+
message := "Hello World!"
270+
271+
handler := TextHandler(app.Application, out, &slog.HandlerOptions{})
272+
log := slog.New(WithTransactionFromContext(handler))
273+
274+
txn := app.Application.StartTransaction("my txn")
275+
ctx := newrelic.NewContext(context.Background(), txn)
276+
txninfo := txn.GetLinkingMetadata()
277+
278+
log.InfoContext(ctx, message)
279+
280+
txn.End()
281+
282+
logcontext.ValidateDecoratedOutput(t, out, &logcontext.DecorationExpect{
283+
EntityGUID: integrationsupport.TestEntityGUID,
284+
Hostname: host,
285+
EntityName: integrationsupport.SampleAppName,
286+
})
287+
288+
app.ExpectLogEvents(t, []internal.WantLog{
289+
{
290+
Severity: slog.LevelInfo.String(),
291+
Message: message,
292+
Timestamp: internal.MatchAnyUnixMilli,
293+
SpanID: txninfo.SpanID,
294+
TraceID: txninfo.TraceID,
295+
},
296+
})
297+
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrwriter
22

3-
go 1.19
3+
go 1.20
44

5-
require github.com/newrelic/go-agent/v3 v3.31.0
5+
require github.com/newrelic/go-agent/v3 v3.32.0
66

77

88
replace github.com/newrelic/go-agent/v3 => ../../..

v3/integrations/logcontext-v2/nrzap/go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrzap
22

3-
go 1.19
3+
go 1.20
44

55
require (
6-
github.com/newrelic/go-agent/v3 v3.31.0
6+
github.com/newrelic/go-agent/v3 v3.32.0
77
go.uber.org/zap v1.24.0
88
)
99

v3/integrations/logcontext-v2/nrzap/nrzap_test.go

+31
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,37 @@ func TestBackgroundLogger(t *testing.T) {
4343
})
4444
}
4545

46+
func TestBackgroundLoggerSugared(t *testing.T) {
47+
app := integrationsupport.NewTestApp(integrationsupport.SampleEverythingReplyFn,
48+
newrelic.ConfigAppLogDecoratingEnabled(true),
49+
newrelic.ConfigAppLogForwardingEnabled(true),
50+
)
51+
52+
core := zapcore.NewCore(zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()), zapcore.AddSync(os.Stdout), zap.InfoLevel)
53+
54+
backgroundCore, err := WrapBackgroundCore(core, app.Application)
55+
if err != nil && err != ErrNilApp {
56+
t.Fatal(err)
57+
}
58+
59+
logger := zap.New(backgroundCore).Sugar()
60+
61+
err = errors.New("this is a test error")
62+
msg := "this is a test error message"
63+
64+
// for background logging:
65+
logger.Error(msg, zap.Error(err), zap.String("test-key", "test-val"))
66+
logger.Sync()
67+
68+
app.ExpectLogEvents(t, []internal.WantLog{
69+
{
70+
Severity: zap.ErrorLevel.String(),
71+
Message: `this is a test error message{error 26 0 this is a test error} {test-key 15 0 test-val <nil>}`,
72+
Timestamp: internal.MatchAnyUnixMilli,
73+
},
74+
})
75+
}
76+
4677
func TestBackgroundLoggerNilApp(t *testing.T) {
4778
app := integrationsupport.NewTestApp(integrationsupport.SampleEverythingReplyFn,
4879
newrelic.ConfigAppLogDecoratingEnabled(true),

v3/integrations/logcontext-v2/nrzerolog/go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrzerolog
22

3-
go 1.19
3+
go 1.20
44

55
require (
6-
github.com/newrelic/go-agent/v3 v3.31.0
6+
github.com/newrelic/go-agent/v3 v3.32.0
77
github.com/rs/zerolog v1.26.1
88
)
99

v3/integrations/logcontext-v2/zerologWriter/go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module github.com/newrelic/go-agent/v3/integrations/logcontext-v2/zerologWriter
22

3-
go 1.19
3+
go 1.20
44

55
require (
6-
github.com/newrelic/go-agent/v3 v3.31.0
6+
github.com/newrelic/go-agent/v3 v3.32.0
77
github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrwriter v1.0.0
88
github.com/rs/zerolog v1.27.0
99
)

v3/integrations/logcontext/nrlogrusplugin/go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ module github.com/newrelic/go-agent/v3/integrations/logcontext/nrlogrusplugin
22

33
// As of Dec 2019, the logrus go.mod file uses 1.13:
44
// https://github.com/sirupsen/logrus/blob/master/go.mod
5-
go 1.19
5+
go 1.20
66

77
require (
8-
github.com/newrelic/go-agent/v3 v3.31.0
8+
github.com/newrelic/go-agent/v3 v3.32.0
99
// v1.4.0 is required for for the log.WithContext.
1010
github.com/sirupsen/logrus v1.4.0
1111
)

v3/integrations/nramqp/go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module github.com/newrelic/go-agent/v3/integrations/nramqp
22

3-
go 1.19
3+
go 1.20
44

55
require (
6-
github.com/newrelic/go-agent/v3 v3.31.0
6+
github.com/newrelic/go-agent/v3 v3.32.0
77
github.com/rabbitmq/amqp091-go v1.9.0
88
)
99
replace github.com/newrelic/go-agent/v3 => ../..

v3/integrations/nrawsbedrock/go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module github.com/newrelic/go-agent/v3/integrations/nrawsbedrock
22

3-
go 1.19
3+
go 1.20
44

55
require (
66
github.com/aws/aws-sdk-go-v2 v1.26.0
77
github.com/aws/aws-sdk-go-v2/config v1.27.4
88
github.com/aws/aws-sdk-go-v2/service/bedrock v1.7.3
99
github.com/aws/aws-sdk-go-v2/service/bedrockruntime v1.7.1
1010
github.com/google/uuid v1.3.0
11-
github.com/newrelic/go-agent/v3 v3.31.0
11+
github.com/newrelic/go-agent/v3 v3.32.0
1212
)
1313

1414

0 commit comments

Comments
 (0)