Code-level metrics allow developers using the New Relic CodeStream extension to see data displayed contextually in their IDE, alongside individual methods in the code. This allows developers to be more proactive about addressing performance issues as they write and review code.
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.
Code-level metrics are available for Go agent version 3.18.0 or higher, and enabled by default for version 3.24.0 and higher. 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.
View your metrics
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 > All capabilities > 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