• ログイン今すぐ開始

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.

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.

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:

ヒント

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.

Distributed tracing configuration

重要

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.

For help getting a valid Infinite Tracing trace observer host entry, see Find or create a trace observer endpoint.

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.

重要

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.

重要

Requires Go agent version 3.20.0 or higher

Copyright © 2022 New Relic Inc.

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