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

Go agent configuration

You can edit configuration settings for the Go agent to control some aspects of how New Relic monitors your app. For example:

  • Turn high-security mode on.
  • Add custom tags for filtering and sorting in the UI.
  • Turn off the collection of errors, transaction events, transaction traces, and custom events.

Configuration methods and precedence

The primary way to configure the Go agent is by modifying the newrelic.Config struct as part of calling newrelic.NewApplication(), which is part of the standard installation process. With Go agent versions 2.7.0 or higher, you can also set a limited number of configuration options using server-side configuration in the UI.

The Go agent follows this order of precedence for configuration. If enabled, server-side configuration overrides all corresponding values in the newrelic.Config struct, even if the server-side values are left blank.

New Relic Go agent: config order of precedence

If server-side configuration is enabled with the Go agent, it overrides all corresponding values in the newrelic.Config struct, even if the server-side values are left blank.

Here are detailed descriptions of each configuration method:

Change configuration settings

To make Go agent configuration changes, set the values in the newrelic.Config struct from within a custom newrelic.ConfigOption. For example, to turn New Relic monitoring off temporarily for testing purposes, change the Enabled value to false:

app, err := newrelic.NewApplication(
newrelic.ConfigAppName("Your Application Name"),
newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
func(config *newrelic.Config) {
config.Enabled = false
},
)

In this and the following examples, config represents your New Relic config struct, although you may have given it a different variable name when you installed the Go agent and initiated the configuration in your app.

General configuration settings

If you're using New Relic CodeStream to monitor performance from your IDE you may also want to associate repositories with your services and associate build SHAs or release tags with errors.

Configuring from the environment

For greater flexibility, you can set many configuration options by setting environment variables instead of hardcoding them into your application's source code. In order to use them, add a call to ConfigFromEnvironment() among your other configuration options:

app, err := newrelic.NewApplication(
newrelic.ConfigAppName("Your Application Name"),
newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
newrelic.ConfigFromEnvironment(),
)

Note that the environment variables will be read, and their corresponding entries in the newrelic.Config struct will be updated, at the point in the list of options where newrelic.ConfigFromEnvironment() appears. If there are additional configuration options listed after ConfigFromEnvironment, they may override the values set by ConfigFromEnvironment.

For example, if the following environment variables are set:

NEW_RELIC_LICENSE_KEY="your_license_key_here"
NEW_RELIC_APP_NAME="Your Application Name"
NEW_RELIC_CODE_LEVEL_METRICS_ENABLED="true"
NEW_RELIC_CODE_LEVEL_METRICS_PATH_PREFIX="myproject/src"
NEW_RELIC_LABELS="Env:Dev;Label2:label2;Label3:label3;Label4:label4"

then the following code:

app, err := newrelic.NewApplication(
newrelic.ConfigFromEnvironment(),
)

will accomplish the same result as the hard-coded equivalent:

app, err := newrelic.NewApplication(
newrelic.ConfigAppName("Your Application Name"),
newrelic.ConfigLicense("your_license_key_here"),
newrelic.ConfigCodeLevelMetricsEnabled(true),
newrelic.ConfigCodeLevelMetricsPathPrefix("myproject/src"),
func(config *newrelic.Config) {
config.Labels = map[string]string{
"Env": "Dev",
"Label2": "label2",
"Label3": "label3",
"Label4": "label4",
}
},
)

Not all possible configuration options may be set via environment variables. The table of environment variables and functions in the collapser below lists all of the available configuration functions and their corresponding environment variables. Although any named configuration option may be set by directly assigning a value to the corresponding field in the Config structure, we recommend using configuration functions and/or environment variables whenever possible.

Set version tag

Setting NEW_RELIC_METADATA_SERVICE_VERSION will create a tag, tag.service.version on event data. In this context, the service version is the version of your code that is deployed, in many cases a semantic version such as 1.2.3 but not always. Sending this information allows you to facet your telemetry by the version of the software deployed so you can quickly identify which versions of your software are producing the errors.

AI monitoring

This section includes Go agent configurations for setting up AI monitoring.

Important

If distributed tracing is disabled or high security mode is enabled, AI monitoring will not collect AI data.

Custom events configuration

You can create custom events and make them available for querying and analysis.

Transaction events configuration

Transaction events are used in collecting events corresponding to web requests and background tasks. Event data allows the New Relic UI to show additional information such as histograms and percentiles.

Error collector configuration

The following settings are used to configure the error collector:

Tip

For an overview of error configuration in New Relic, see Manage errors in APM.

Transaction tracer configuration

Here are settings for changing transaction tracer configuration. For more information about transaction traces, see Transaction traces.

Datastore tracer configuration

Here are datastore settings, including slow query enabling and settings.

Cross application tracing configuration

Here are settings for changing the cross application tracing feature.

Important

Cross application tracing has been deprecated in favor of Distributed tracing and will be removed in a future agent version.

Distributed tracing configuration

Important

Enabling distributed tracing requires Go agent version 2.1.0 or higher, and it disables cross application tracing. It also has effects on other features. Before enabling, read the transition guide.

Distributed tracing lets you see the path that a request takes as it travels through a distributed system.

When distributed tracing is enabled, you can collect span events.

Span events configuration

Span events are reported for distributed tracing. Distributed tracing must be enabled to report span events. These settings control the collection of span events:

Infinite Tracing configuration

To enable Infinite Tracing, enable distributed tracing (set config.DistributedTracer.Enabled = true on the newrelic.Config struct) and add the additional settings below. For an example, see Language agents: Configure distributed tracing.

Application logging settings

The following settings are available for configuration of application logging in the agent. For tips on using Go agent logs in context, see Go logs in context.

Important

Requires Go agent version 3.17.0 or higher

Module dependency metrics settings

Module dependency metrics can be configured in a variety of ways in the Go agent. Module dependency metrics reports the list of imported modules used by your Go application to help facilitate code dependency management. It also includes the version information of the modules of your app.

Important

Requires Go agent version 3.20.0 or higher

New Relic IAST

New Relic Interactive Applications Security Testing (IAST) tests your applications for any exploitable vulnerability by replaying the generated HTTP request with vulnerable payloads. You can enable New Relic IAST by updating your Go app code with configurations that are passed to the INIT function. You can also make these configurations through a YAML file or with environment variables.

Options set using INIT functions take precedence over environment or YAML configurations. That said, we recommend enabling IAST using a YAML file because those configurations will pass to other agents in your environment.

Setup Instructions

Import the integration by adding the following direct dependency to you go.mod file.

import "github.com/newrelic/go-agent/v3/integrations/nrsecurityagent"

Next initialize and enable the security agent.

Enable IAST

Configure IAST

The security agent can be configured with the following options.

Instrument security sensitive parts of your application

The nrgin, nrgrpc, nrmicro, fasthttp, or nrmongo integrations now contain code to support security analysis of the data they handle.

Additionally, the Go agent will perform vulnerability scanning on instrumented code containing datastore segments, SQL operations, transactions, and wrapped HTTP calls and endpoints.

Copyright © 2024 New Relic Inc.

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