Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uber/zap WithField(...) not showing up in NR APM logs #915

Closed
dselans opened this issue May 29, 2024 · 3 comments
Closed

uber/zap WithField(...) not showing up in NR APM logs #915

dselans opened this issue May 29, 2024 · 3 comments
Assignees
Labels

Comments

@dselans
Copy link

dselans commented May 29, 2024

Description

Not sure if I'm doing something wrong but it can't seem to get WithField() to work - fields set either on a core or on a logger, do not show up in NR APM logs. The only attributes that show up are ones that are added via z.Info("foo", zap.String("bar", "baz")) - any existing, initial fields do not show up.

Steps to Reproduce

Create a zap core wrapped with NR zap shim -> set initial fields -> log something -> expect log message in NR to show up with extra attributes.

Example 1

// Setup go-agent
app, err := newrelic.NewApplication(
	newrelic.ConfigAppName(d.Config.NewRelicAppName),
	newrelic.ConfigLicense(d.Config.NewRelicLicenseKey),
	newrelic.ConfigAppLogForwardingEnabled(true),
	newrelic.ConfigZapAttributesEncoder(false), // <- switching this doesn't seem to have any visible effect
)

// Create a new zap core
zc := zap.NewDevelopmentConfig()
zc.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder

core = zapcore.NewCore(zapcore.NewConsoleEncoder(zc.EncoderConfig),
	zapcore.AddSync(os.Stdout),
	zap.DebugLevel,
)

// Wrap it with NR
core, _ = nrzap.WrapBackgroundCore(core, d.NewRelicApp)
if err != nil {
	return errors.Wrap(err, "unable to wrap zap core with newrelic")
}

// Try to add initial fields to core
core = core.With([]zapcore.Field{
	zap.String("foo", "bar"),
})

// Create a logger + log something
zap.New(core).Info("Logger initialized", zap.String("baz", "qux")

Example 2:

// Setup NR + zap core as before
// ...

// Create a new logger from an existing logger
logger := zap.New(core).With(zap.String("foo", "bar"))
logger.Info("New logger created")

Expected Behavior

In the above example 1, would expect "foo" field to show up in "Logger initialized" log message in NR but only see "baz" attribute.

In example 2, would expect "foo" field to show up in "New logger created" message in NR.

NR Diag results

Logs on STDOUT include the additional fields as expected.

Your Environment

Go 1.22.0 darwin/arm64
github.com/newrelic/go-agent/v3 v3.33.0
github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrzap v1.2.0
github.com/newrelic/go-agent/v3/integrations/nrhttprouter v1.1.0

Reproduction case

Shown above.

Additional context

Not sure if this is a missing feature, bug or something I'm not doing right.

Passing fields/attributes via direct calls to the log method works as expected (ie. z.Info("foo", zap.Any("bar", "baz")).

Thank you!

@iamemilio
Copy link
Contributor

iamemilio commented Jun 10, 2024

fix in review

@iamemilio
Copy link
Contributor

#919

@iamemilio
Copy link
Contributor

Released in 3.33.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants