Skip to content

Commit

Permalink
Merge pull request #896 from newrelic/develop
Browse files Browse the repository at this point in the history
Release 3.32.0
  • Loading branch information
nr-swilloughby authored Apr 4, 2024
2 parents cb651c4 + 2c742a8 commit 0f93238
Show file tree
Hide file tree
Showing 74 changed files with 647 additions and 152 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
- dirs: v3/integrations/logcontext-v2/nrlogrus
- dirs: v3/integrations/logcontext-v2/nrzerolog
- dirs: v3/integrations/logcontext-v2/nrzap
- dirs: v3/integrations/logcontext-v2/nrslog
- dirs: v3/integrations/logcontext-v2/nrwriter
- dirs: v3/integrations/logcontext-v2/zerologWriter
- dirs: v3/integrations/logcontext-v2/logWriter
Expand Down Expand Up @@ -138,4 +139,4 @@ jobs:
else
echo "Directory /app/$dir does not exist."
fi
done
done
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
## 3.32.0
### Added
* Updates to support for the New Relic security agent to report API endpoints.
* Adds new wrapper function for the `nrecho`, `nrgin`, and `nrgorilla` integrations.
* Handler to take New Relic transaction data from context automatically when using `nrslog` integration (thanks, @adomaskizogian!)

### Fixed
* Adds missing license file to the `nropenai` integration.
* 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.
* Fixes `pgx5` pool example
* Updated unit tests to check `Transaction.Ignore`
* Updated `nrzap` unit tests to add background logger sugared test case.

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

## 3.31.0
### Added
* Integration packages to instrument AI model invocations (see below).
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ package primitives can be found [here](GUIDE.md#datastore-segments).
| [snowflakedb/gosnowflake](https://github.com/snowflakedb/gosnowflake) | [v3/integrations/nrsnowflake](https://godoc.org/github.com/newrelic/go-agent/v3/integrations/nrsnowflake) | Instrument Snowflake driver |
| [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 |

#### AI

| Project | Integration Package | |
| ------------- | ------------- | - |
| [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 |
| [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 |


#### Agent Logging

| Project | Integration Package | |
Expand Down
3 changes: 1 addition & 2 deletions v3/go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module github.com/newrelic/go-agent/v3

go 1.19
go 1.20

require (
github.com/golang/protobuf v1.5.3
golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81
google.golang.org/grpc v1.56.3
)

Expand Down
4 changes: 2 additions & 2 deletions v3/integrations/logcontext-v2/logWriter/go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/newrelic/go-agent/v3/integrations/logcontext-v2/logWriter

go 1.19
go 1.20

require (
github.com/newrelic/go-agent/v3 v3.31.0
github.com/newrelic/go-agent/v3 v3.32.0
github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrwriter v1.0.0
)

Expand Down
4 changes: 2 additions & 2 deletions v3/integrations/logcontext-v2/nrlogrus/go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrlogrus

go 1.19
go 1.20

require (
github.com/newrelic/go-agent/v3 v3.31.0
github.com/newrelic/go-agent/v3 v3.32.0
github.com/sirupsen/logrus v1.8.1
)

Expand Down
4 changes: 2 additions & 2 deletions v3/integrations/logcontext-v2/nrslog/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrslog

go 1.19
go 1.20

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


replace github.com/newrelic/go-agent/v3 => ../../..
40 changes: 40 additions & 0 deletions v3/integrations/logcontext-v2/nrslog/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func JSONHandler(app *newrelic.Application, w io.Writer, opts *slog.HandlerOptio
}

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

// WithTransaction creates a new Slog Logger object to be used for logging within a given transaction it its found
// in a context.
// Calling this function with a logger having underlying TransactionFromContextHandler handler is a no-op.
func WithContext(ctx context.Context, logger *slog.Logger) *slog.Logger {
if ctx == nil {
return logger
Expand Down Expand Up @@ -181,3 +183,41 @@ func (h NRHandler) WithGroup(name string) slog.Handler {
txn: h.txn,
}
}

// NRHandler is an Slog handler that includes logic to implement New Relic Logs in Context.
// New Relic transaction value is taken from context. It cannot be set directly.
// This serves as a quality of life improvement for cases where slog.Default global instance is
// referenced, allowing to use slog methods directly and maintaining New Relic instrumentation.
type TransactionFromContextHandler struct {
NRHandler
}

// WithTransactionFromContext creates a wrapped NRHandler, enabling it to automatically reference New Relic
// transaction from context.
func WithTransactionFromContext(handler NRHandler) TransactionFromContextHandler {
return TransactionFromContextHandler{handler}
}

// Handle handles the Record.
// It will only be called when Enabled returns true.
// The Context argument is as for Enabled and NewRelic transaction.
// Canceling the context should not affect record processing.
// (Among other things, log messages may be necessary to debug a
// cancellation-related problem.)
//
// Handle methods that produce output should observe the following rules:
// - If r.Time is the zero time, ignore the time.
// - If r.PC is zero, ignore it.
// - Attr's values should be resolved.
// - If an Attr's key and value are both the zero value, ignore the Attr.
// This can be tested with attr.Equal(Attr{}).
// - If a group's key is empty, inline the group's Attrs.
// - If a group has no Attrs (even if it has a non-empty key),
// ignore it.
func (h TransactionFromContextHandler) Handle(ctx context.Context, record slog.Record) error {
if txn := newrelic.FromContext(ctx); txn != nil {
return h.NRHandler.WithTransaction(txn).Handle(ctx, record)
}

return h.NRHandler.Handle(ctx, record)
}
37 changes: 37 additions & 0 deletions v3/integrations/logcontext-v2/nrslog/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,40 @@ func TestWithGroup(t *testing.T) {
}

}

func TestTransactionFromContextHandler(t *testing.T) {
app := integrationsupport.NewTestApp(integrationsupport.SampleEverythingReplyFn,
newrelic.ConfigAppLogDecoratingEnabled(true),
newrelic.ConfigAppLogForwardingEnabled(true),
)

out := bytes.NewBuffer([]byte{})
message := "Hello World!"

handler := TextHandler(app.Application, out, &slog.HandlerOptions{})
log := slog.New(WithTransactionFromContext(handler))

txn := app.Application.StartTransaction("my txn")
ctx := newrelic.NewContext(context.Background(), txn)
txninfo := txn.GetLinkingMetadata()

log.InfoContext(ctx, message)

txn.End()

logcontext.ValidateDecoratedOutput(t, out, &logcontext.DecorationExpect{
EntityGUID: integrationsupport.TestEntityGUID,
Hostname: host,
EntityName: integrationsupport.SampleAppName,
})

app.ExpectLogEvents(t, []internal.WantLog{
{
Severity: slog.LevelInfo.String(),
Message: message,
Timestamp: internal.MatchAnyUnixMilli,
SpanID: txninfo.SpanID,
TraceID: txninfo.TraceID,
},
})
}
4 changes: 2 additions & 2 deletions v3/integrations/logcontext-v2/nrwriter/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrwriter

go 1.19
go 1.20

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


replace github.com/newrelic/go-agent/v3 => ../../..
4 changes: 2 additions & 2 deletions v3/integrations/logcontext-v2/nrzap/go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrzap

go 1.19
go 1.20

require (
github.com/newrelic/go-agent/v3 v3.31.0
github.com/newrelic/go-agent/v3 v3.32.0
go.uber.org/zap v1.24.0
)

Expand Down
31 changes: 31 additions & 0 deletions v3/integrations/logcontext-v2/nrzap/nrzap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,37 @@ func TestBackgroundLogger(t *testing.T) {
})
}

func TestBackgroundLoggerSugared(t *testing.T) {
app := integrationsupport.NewTestApp(integrationsupport.SampleEverythingReplyFn,
newrelic.ConfigAppLogDecoratingEnabled(true),
newrelic.ConfigAppLogForwardingEnabled(true),
)

core := zapcore.NewCore(zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()), zapcore.AddSync(os.Stdout), zap.InfoLevel)

backgroundCore, err := WrapBackgroundCore(core, app.Application)
if err != nil && err != ErrNilApp {
t.Fatal(err)
}

logger := zap.New(backgroundCore).Sugar()

err = errors.New("this is a test error")
msg := "this is a test error message"

// for background logging:
logger.Error(msg, zap.Error(err), zap.String("test-key", "test-val"))
logger.Sync()

app.ExpectLogEvents(t, []internal.WantLog{
{
Severity: zap.ErrorLevel.String(),
Message: `this is a test error message{error 26 0 this is a test error} {test-key 15 0 test-val <nil>}`,
Timestamp: internal.MatchAnyUnixMilli,
},
})
}

func TestBackgroundLoggerNilApp(t *testing.T) {
app := integrationsupport.NewTestApp(integrationsupport.SampleEverythingReplyFn,
newrelic.ConfigAppLogDecoratingEnabled(true),
Expand Down
4 changes: 2 additions & 2 deletions v3/integrations/logcontext-v2/nrzerolog/go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrzerolog

go 1.19
go 1.20

require (
github.com/newrelic/go-agent/v3 v3.31.0
github.com/newrelic/go-agent/v3 v3.32.0
github.com/rs/zerolog v1.26.1
)

Expand Down
4 changes: 2 additions & 2 deletions v3/integrations/logcontext-v2/zerologWriter/go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/newrelic/go-agent/v3/integrations/logcontext-v2/zerologWriter

go 1.19
go 1.20

require (
github.com/newrelic/go-agent/v3 v3.31.0
github.com/newrelic/go-agent/v3 v3.32.0
github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrwriter v1.0.0
github.com/rs/zerolog v1.27.0
)
Expand Down
4 changes: 2 additions & 2 deletions v3/integrations/logcontext/nrlogrusplugin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module github.com/newrelic/go-agent/v3/integrations/logcontext/nrlogrusplugin

// As of Dec 2019, the logrus go.mod file uses 1.13:
// https://github.com/sirupsen/logrus/blob/master/go.mod
go 1.19
go 1.20

require (
github.com/newrelic/go-agent/v3 v3.31.0
github.com/newrelic/go-agent/v3 v3.32.0
// v1.4.0 is required for for the log.WithContext.
github.com/sirupsen/logrus v1.4.0
)
Expand Down
4 changes: 2 additions & 2 deletions v3/integrations/nramqp/go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/newrelic/go-agent/v3/integrations/nramqp

go 1.19
go 1.20

require (
github.com/newrelic/go-agent/v3 v3.31.0
github.com/newrelic/go-agent/v3 v3.32.0
github.com/rabbitmq/amqp091-go v1.9.0
)
replace github.com/newrelic/go-agent/v3 => ../..
4 changes: 2 additions & 2 deletions v3/integrations/nrawsbedrock/go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module github.com/newrelic/go-agent/v3/integrations/nrawsbedrock

go 1.19
go 1.20

require (
github.com/aws/aws-sdk-go-v2 v1.26.0
github.com/aws/aws-sdk-go-v2/config v1.27.4
github.com/aws/aws-sdk-go-v2/service/bedrock v1.7.3
github.com/aws/aws-sdk-go-v2/service/bedrockruntime v1.7.1
github.com/google/uuid v1.3.0
github.com/newrelic/go-agent/v3 v3.31.0
github.com/newrelic/go-agent/v3 v3.32.0
)


Expand Down
Loading

0 comments on commit 0f93238

Please sign in to comment.