• EnglishEspañol日本語한국어Português
  • Log inStart now

Go agent code-level metrics configuration

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
  • Namespace

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.

Important

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.

Configuration methods

When calling 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:

Name

Description

code.function

The name of the function which started the transaction. Note that this may be automatically generated by the Go compiler in some cases.

code.namespace

The package/namespace where the function is located. The combination of code.namespace and code.function, joined with a delimiter such as a dot (.), is expected to uniquely identify the function.

code.filepath

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.

code.lineno

The line number within code.filepath where the transaction was started. See the instrumentation guide for ways to control this.

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:

  1. Go to one.newrelic.com > All capabilities > APM & services.
  2. Click your entity (service).
  3. In the left pane's Monitor section, click Transactions.
  4. Under Transaction traces, click on an individual trace.
  5. Look under Agent attributes for the four attributes beginning with code..
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.