- Configure logs in context for Go | New Relic Documentation
- go-agent/_integrations/logcontext/nrlogrusplugin at master · newrelic/go-agent · GitHub
- Review the Compatibility and Requirements for setting up Logs in Context for the Go agent:
- Ensure you have distributed tracing enabled for the Go agent.
- Double check that you have installed and implemented Logrus as the logger for your application.
- If you aren’t using Logrus in your application you will need to manually add our context metadata to your logs by using the Agent API.
- Make sure you have imported the necessary packages in every file where Logrus is configured.
import ( log "github.com/sirupsen/logrus" "github.com/newrelic/go-agent/v3/integrations/logcontext/nrlogrusplugin" "github.com/newrelic/go-agent/v3/newrelic" )
- Check that you have set the Logrus formatter to New Relic’s ContextFormatter:
- After implementing this your looger should now look for
newrelic.Transactioninside its context and decorate logs accordingly
- You can read more about Logrus formatters in their github repo here:
- Review your existing logging calls and check that they are using our contextual logger rather than the standard logger.
- You can see examples for each of the steps above in our documentation here:
- Once you have configured the ContextFormatter it is a good idea to examine your logs to check that they are formatted as JSON and contain the following fields:
- Should be the application name set in APM for the service you’ve configured Logs in Context for.
- Should be the string “SERVICE”
- The ID of the entity.
- Will only be present if distributed tracing is enabled and a corresponding transaction generates a log.
- Will only be present if distributed tracing is enabled and a corresponding span generates a log.
- This should be the hostname gathered by the APM agent.
Make sure your APM language agent is installed and set up correctly.
Make sure that you have Distributed Tracing configured correctly for your application. If you do not you will not see a
trace.idin your log metadata.
If you aren’t seeing logs in the Logs UI. Ensure that you have installed and configured a New Relic plugin for a compatible log forwarder:
Check your Logs UI in New Relic and query using the the following:
- has: span.id has:trace.id
Check your configuration against our examples on Github:
Double check that you are using your logger within a Go agent transaction. If you are not then your logs will not have linkage with APM.