newrelic / go-agent

New Relic Go Agent
Apache License 2.0
764 stars 294 forks source link

No link between log message and application #743

Closed EugeneBalybin closed 1 year ago

EugeneBalybin commented 1 year ago

Description

Got the following setup: Go application with newrelic/go-agent v3.20.3

newRelic, err := newrelic.NewApplication(
    newrelic.ConfigAppName(*cfg.NewRelic.AppName),
    newrelic.ConfigLicense(*cfg.NewRelic.LicenseKey),
    newrelic.ConfigAppLogForwardingEnabled(false),
    newrelic.ConfigDistributedTracerEnabled(true),
    newrelic.ConfigAppLogDecoratingEnabled(true),
);
writer := zerologWriter.New(os.Stdout, newRelic)
logger := zerolog.New(writer)
logger.Info().Msg("test message")

nri-bundle running for log forwarding to NewRelic

With the code above I'm getting the log message to stdout: {"level":"info","message":"test message"} NR-LINKING|xxxYYYzzzQQQ|HostName|AppName|

nri-bundle gets the message, sends it to the NewRelic, and I can find it in the New Relic logs, but they are in the global logs section, not in the APM -> Logs.

In the New Relic UI there is no "NR-LINKING" part, just json which is properly decoded into a message fields. And among the fiends there are no entity.name or entity.guid fields

BUT I can see log metrics on the APM summary page

Expected Behavior

entity.name and entity.guid are present and logs discoverable in the APM section

EugeneBalybin commented 1 year ago

So I played around and found that NR-LINKING part should not omit pipes when outside the transaction Like this {"level":"info","message":"test message"} NR-LINKING|xxxYYYzzzQQQ|HostName|||AppName|

EugeneBalybin commented 1 year ago

https://github.com/newrelic/go-agent/pull/744

iamemilio commented 1 year ago

Thanks and sorry it took so long to correct this. You are absolutely correct.

If outside a transaction, the trace.id and span.id portions are excluded, but the delimiters MUST remain to simplify extraction in the backend.
iamemilio commented 1 year ago

The next go agent release will include this.