When you enable code-level metrics, the Go agent will attach attributes to trace data. These attributes show the location in your application source code responsible for the actions instrumented by those traces. The data you can see includes:
- Source file name
- Source file line number
- Function name
Take a look at the Go agent configuration settings to help you control the collection of code-level metrics. After you complete the configuration, if you need help finding the data, see View your metrics. If you want more control over how the metrics are collected, see Go agent code-level metrics instrumentation.
This feature is available for transactions as of Go agent version 3.18.0, and is turned off by default. To enable it, you must add
newrelic.ConfigCodeLevelMetricsEnabled(true) to your application's configuration as explained below.
newrelic.NewApplication to configure the Go agent in your application, you can enable code-level metrics by including the
newrelic.ConfigCodeLevelMetricsEnabled option, like so:
app, err := newrelic.NewApplication(newrelic.ConfigAppName("Your Application Name"),newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),newrelic.ConfigCodeLevelMetricsEnabled(true),)
With that simple step, the Go agent will add the source code context information in the following agent attributes on transactions:
The name of the function which started the transaction. Note that this may be automatically generated by the Go compiler in some cases.
The package/namespace where the function is located. The combination of
The pathname of the source file containing the function being reported. Normally this is the full, absolute pathname; see below for a configuration option which allows you to change this to a relative path.
The line number within
There are additional configuration options you may wish to use to further refine the collection of code-level metrics in your application.
Once you've configured code-level metrics, you can see your data in the New Relic UI. Here's one way you can see traces for a particular service:
- Go to one.newrelic.com > APM & services.
- Click your entity (service).
- In the left pane's Monitor section, click Transactions.
- Under Transaction traces, click on an individual trace.
- Look under Agent attributes for the four attributes beginning with