---
title: Go agent configuration
source: https://docs.newrelic.com/docs/apm/agents/go-agent/configuration/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 [#options]

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](https://docs.newrelic.com/docs/agents/go-agent/installation/install-new-relic-go). With [Go agent versions 2.7.0 or higher](https://docs.newrelic.com/docs/release-notes/agent-release-notes/go-release-notes), you can also set a limited number of configuration options using [server-side configuration in the UI](#server-side-configuration).

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](https://docs.newrelic.com/images/apm_diagram_Go-agent-config-precedence.webp "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:

**Server-side configuration (2.7.0 or higher)**

[Server-side configuration](https://docs.newrelic.com/docs/agents/manage-apm-agents/configuration/server-side-agent-configuration) is available with [Go agent versions 2.7.0 or higher](https://docs.newrelic.com/docs/release-notes/agent-release-notes/go-release-notes). This allows you to configure certain settings in the UI. This applies your changes automatically to all agents even if they run across multiple hosts. Where available, this document includes the UI labels for server-side config under individual config options as the **Server-side label**.

You must still call `newrelic.NewApplication()` in your application process following the steps described in the [in-process configuration](#in-process-config). Configuration options set server-side will overwrite those set locally. Since not all configuration options are available server side, you may want to still update your `newrelic.Config` struct.

> #### ⚠️ CAUTION
>
> If server-side config is enabled, the agent ignores any value in the `newrelic.Config` struct that **could** be set in the UI. Even if the UI value is empty, the agent treats this as an empty value and doesn't use the `newrelic.Config` value.

**In process `newrelic.Config` struct**

You configure your Go agent from the local in process `newrelic.Config` struct. This struct can be accessed when calling `newrelic.NewApplication()`.

1.  Add the following in the `main` function or in an `init` block:

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

    Note the use of `os.Getenv` to read your license key from the environment rather than hard-coding it as a string literal value passed to `newrelic.ConfigLicense`. We recommend that you don't place license keys or other sensitive information in your source code, as that may result in them being stored in your SCM repository and possibly revealed to unauthorized parties.
2.  Update values on the `newrelic.Config` struct to configure your application using `newrelic.ConfigOption`s. These are functions that accept a pointer to the `newrelic.Config` struct. Add additional `newrelic.ConfigOption`s to further configure your application. For example, you can use one of the predefined options to do common configurations:

    ```go
    app, err := newrelic.NewApplication(
        newrelic.ConfigAppName("Your Application Name"),
        newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
        // add debug level logging to stdout
        newrelic.ConfigDebugLogger(os.Stdout),
    )
    ```
3.  Or, you can create your own `newrelic.ConfigOption` to do more complex configurations:

    ```go
    app, err := newrelic.NewApplication(
        newrelic.ConfigAppName("Your Application Name"),
        newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
        newrelic.ConfigDebugLogger(os.Stdout),
        func(config *newrelic.Config) {
        // add more specific configuration of the agent within a custom ConfigOption
        config.HighSecurity = true
            config.CrossApplicationTracer.Enabled = false
        },
    )
    ```

## Change configuration settings [#make-config-changes]

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`:

```go
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](https://docs.newrelic.com/docs/agents/go-agent/get-started/get-new-relic-go) and initiated the configuration in your app.

## General configuration settings [#general-settings]

**License (REQUIRED)**

| Type               | String                   |
| ------------------ | ------------------------ |
| Default            | (none)                   |
| [Set in](#options) | `newrelic.Config` struct |

Specifies your New Relic [license key](https://docs.newrelic.com/docs/subscriptions/license-key), used to associate your app's metrics with a New Relic account. The license and the app name are both set as part of the [New Relic installation process](https://docs.newrelic.com/docs/apm/agents/go-agent/installation/install-new-relic-go/#get-new-relic).

**AppName (REQUIRED)**

| Type               | String                   |
| ------------------ | ------------------------ |
| Default            | `(none)`                 |
| [Set in](#options) | `newrelic.Config` struct |

This is the [application name](https://docs.newrelic.com/docs/apm/agents/manage-apm-agents/app-naming/name-your-application/) used to aggregate data in the New Relic UI. You set both the license and the app name as part of the [New Relic installation process](https://docs.newrelic.com/docs/apm/agents/go-agent/installation/install-new-relic-go/#get-new-relic).

To report data to [multiple apps at the same time](https://docs.newrelic.com/docs/apm/agents/manage-apm-agents/app-naming/use-multiple-names-app/), specify a list of names separated with a semicolon. Do not put a space before the semicolon itself. For example:

````go
app, err := newrelic.NewApplication(
    newrelic.ConfigAppName("YOUR_APP_NAME;APP_GROUP_1;ALL_APPS"),
    newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
)
```

````

**Enabled**

| Type               | Boolean                  |
| ------------------ | ------------------------ |
| Default            | `true`                   |
| [Set in](#options) | `newrelic.Config` struct |

When `true`, the agent sends data from your app to the [New Relic collector](https://docs.newrelic.com/docs/new-relic-solutions/get-started/glossary/#collector).

To turn off New Relic monitoring, set this to `false`.

For example:

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

You may make use of the `ConfigEnabled` option to make this easier:

```go
app, err: = newrelic.NewApplication(
    newrelic.ConfigAppName("Your Application Name"),
    newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
    newrelic.ConfigEnabled(false),
)
```

This can be useful for installing New Relic in a development environment or for troubleshooting purposes. When `Enabled` is set to `false`:

* The New Relic Go agent won't communicate with the New Relic collector.
* The agent won't spawn goroutines.
* The license key isn't required during installation.

````

**Labels**

| Type               | map\[string]string       |
| ------------------ | ------------------------ |
| Default            | (none)                   |
| [Set in](#options) | `newrelic.Config` struct |

Add [tags](https://docs.newrelic.com/docs/new-relic-solutions/new-relic-one/core-concepts/use-tags-help-organize-find-your-data/).

**Creating four tag pairs**

Here's an example of setting four tags:

````go
app, err := newrelic.NewApplication(
    newrelic.ConfigAppName("Your Application Name"),
    newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
    func(config *newrelic.Config) {
        config.Labels = map[string]string{
            "Env":    "Dev",
            "Label2": "label2",
            "Label3": "label3",
            "Label4": "label4",
        }
    },
)
```

````

**Logger**

| Type                                                                                                       | Interface                |
| ---------------------------------------------------------------------------------------------------------- | ------------------------ |
| Default                                                                                                    | (none)                   |
| [Set in](https://docs.newrelic.com/docs/apm/agents/go-agent/configuration/go-agent-configuration/#options) | `newrelic.Config` struct |

You can use the `Logger` interface to [write Go log files](https://docs.newrelic.com/docs/apm/agents/go-agent/configuration/go-agent-logging/) to a specific location or logging system.

**HighSecurity**

| Type               | Boolean                  |
| ------------------ | ------------------------ |
| Default            | `false`                  |
| [Set in](#options) | `newrelic.Config` struct |

> #### ⚠️ IMPORTANT
>
> This feature requires [Enterprise tier](https://www.newrelic.com/pricing).

[High-security mode](https://docs.newrelic.com/docs/accounts-partnerships/accounts/security/high-security) enforces certain security settings and prevents them from being overridden, so that the agent sends no sensitive data. High-security mode does the following:

-   Turns SSL on
-   Turns off reporting of error message strings
-   Turns off reporting of custom events

    This setting must match the corresponding account setting in the UI. For example:

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

    The agent communicates with New Relic via HTTPS by default, and New Relic [requires HTTPS](https://docs.newrelic.com/docs/apis/rest-api-v2/troubleshooting/301-response-rest-api-calls) for all traffic to APM and our REST API.

**UseTLS (DEPRECATED)**

| Type               | Boolean                  |
| ------------------ | ------------------------ |
| Default            | `true`                   |
| [Set in](#options) | `newrelic.Config` struct |

> #### ⚠️ IMPORTANT
>
> This option was removed in [agent version 2.0](https://docs.newrelic.com/docs/release-notes/agent-release-notes/go-release-notes/go-agent-20).

Controls whether HTTPS or HTTP is used to send data to New Relic. The agent communicates with New Relic via HTTPS by default (which uses TLS protocol), and New Relic [requires HTTPS](https://docs.newrelic.com/docs/apis/rest-api-v2/troubleshooting/301-response-rest-api-calls) for all traffic to APM and the New Relic REST API.

**HostDisplayName**

| Type               | String                   |
| ------------------ | ------------------------ |
| Default            | (none)                   |
| [Set in](#options) | `newrelic.Config` struct |

This sets the [hostname displayed in the APM UI](https://docs.newrelic.com/docs/apm/agents/manage-apm-agents/configuration/add-rename-remove-hosts/#display_name). This is an optional configuration.

**Transport**

| Type               | [http.RoundTripper](https://golang.org/pkg/net/http/#RoundTripper) |
| ------------------ | ------------------------------------------------------------------ |
| Default            | (none)                                                             |
| [Set in](#options) | `newrelic.Config` struct                                           |

This customizes [http.Client](https://golang.org/pkg/net/http/#Client) communication with New Relic collectors. You can use this to configure a proxy.

**RuntimeSampler.Enabled**

| Type               | Boolean                  |
| ------------------ | ------------------------ |
| Default            | `true`                   |
| [Set in](#options) | `newrelic.Config` struct |

When `true`, the agent captures runtime statistics.

If you're using New Relic CodeStream to monitor performance from your IDE you may also want to [associate repositories with your services](https://docs.newrelic.com/docs/codestream/observability/repo-association) and [associate build SHAs or release tags with errors](https://docs.newrelic.com/docs/codestream/observability/error-investigation/#buildsha).

## Configuring from the environment [#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:

```go
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:

```ini
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:

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

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

```go
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](#env-var-table) 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.

**Table of environment variables and functions**

Here are some tips for how to use the table:

-   If an environment variable is listed in the table, then you may set the corresponding option by setting the named environment variable. You must also include the `ConfigFromEnvironment()` function, which will cause the agent to accept all `NEW_RELIC_*` environment variables.
-   If a configuration function is listed, you can use that function to set the corresponding option instead of using `ConfigFromEnvironment()`. Keep in mind that the configuration functions listed in the program, including `ConfigFromEnvironment()`, are resolved in the order they appear in the code. This means that if you create an environment variable and call the function `ConfigFromEnvironment()`, it will overwrite corresponding configurations you may have set previously using a specific function. Subsequent configuration options after `ConfigFromEnvironment()` will override previous configuration functions and environment variables.
-   See the documentation here and at [the Go documentation site](https://pkg.go.dev/github.com/newrelic/go-agent/v3@v3.20.0/newrelic#ConfigOption) for more information about how to use each function.

    | Configuration field                              | Configuration functions                                                                                                            | Environment variables                                         |
    | ------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
    | `AppName`                                        | `ConfigAppName`                                                                                                                    | `NEW_RELIC_APP_NAME`                                          |
    | `ApplicationLogging.Enabled`                     | `ConfigAppLogForwardingEnabled` `ConfigAppLogEnabled` (See [note 1](#table-note-one) below)                                        | `NEW_RELIC_APPLICATION_LOGGING_ENABLED`                       |
    | `ApplicationLogging.Forwarding.Enabled`          | `ConfigAppLogForwardingEnabled` `ConfigAppLogDecoratingEnabled` `ConfigAppLogMetricsEnabled` (See [note 1](#table-note-one) below) | `NEW_RELIC_APPLICATION_LOGGING_FORWARDING_ENABLED`            |
    | `ApplicationLogging.Forwarding.MaxSamplesStored` | `ConfigAppLogForwardingEnabled` `ConfigAppLogForwardingMaxSamplesStored` (See [note 1](#table-note-one) below)                     | `NEW_RELIC_APPLICATION_LOGGING_FORWARDING_MAX_SAMPLES_STORED` |
    | `ApplicationLogging.LocalDecorating.Enabled`     | `ConfigAppLogDecoratingEnabled`                                                                                                    | `NEW_RELIC_APPLICATION_LOGGING_LOCAL_DECORATING_ENABLED`      |
    | `ApplicationLogging.Metrics.Enabled`             | `ConfigAppLogMetricsEnabled`                                                                                                       | `NEW_RELIC_APPLICATION_LOGGING_METRICS_ENABLED`               |
    | `Attributes.Enabled`                             |                                                                                                                                    |                                                               |
    | `Attributes.Exclude`                             |                                                                                                                                    | `NEW_RELIC_ATTRIBUTES_EXCLUDE`                                |
    | `Attributes.Include`                             |                                                                                                                                    | `NEW_RELIC_ATTRIBUTES_INCLUDE`                                |
    | `BrowserMonitoring.Attributes.Enabled`           |                                                                                                                                    |                                                               |
    | `BrowserMonitoring.Attributes.Exclude`           |                                                                                                                                    |                                                               |
    | `BrowserMonitoring.Attributes.Include`           |                                                                                                                                    |                                                               |
    | `BrowserMonitoring.Enabled`                      |                                                                                                                                    |                                                               |
    | `CodeLevelMetrics.Enabled`                       | `ConfigCodeLevelMetricsEnabled`                                                                                                    | `NEW_RELIC_CODE_LEVEL_METRICS_ENABLED`                        |
    | `CodeLevelMetrics.IgnoredPrefixes`               | `ConfigCodeLevelMetricsIngoredPrefixes`                                                                                            | `NEW_RELIC_CODE_LEVEL_METRICS_IGNORED_PREFIXES`               |
    | `CodeLevelMetrics.PathPrefixes`                  | `ConfigCodeLevelMetricsPathPrefixes`                                                                                               | `NEW_RELIC_CODE_LEVEL_METRICS_PATH_PREFIXES`                  |
    | `CodeLevelMetrics.RedactIgnoredPrefixes`         | `ConfigCodeLevelMetricsRedactIgnoredPrefixes`                                                                                      | `NEW_RELIC_CODE_LEVEL_METRICS_REDACT_IGNORED_PREFIXES`        |
    | `CodeLevelMetrics.RedactPathPrefixes`            | `ConfigCodeLevelMetricsRedactPathPrefixes`                                                                                         | `NEW_RELIC_CODE_LEVEL_METRICS_REDACT_PATH_PREFIXES`           |
    | `CodeLevelMetrics.Scope`                         | `ConfigCodeLevelMetricsScope`                                                                                                      | `NEW_RELIC_CODE_LEVEL_METRICS_SCOPE`                          |
    | `CrossApplicationTracer.Enabled`                 |                                                                                                                                    |                                                               |
    | `CustomInsightsEvents.Enabled`                   | `ConfigCustomInsightsEventsEnabled`                                                                                                |                                                               |
    | `CustomInsightsEvents.MaxSamplesStored`          | `ConfigCustomInsightsEventsMaxSamplesStored`                                                                                       |                                                               |
    | `DatastoreTracer.DatabaseNameReporting.Enabled`  |                                                                                                                                    |                                                               |
    | `DatastoreTracer.InstanceReporting.Enabled`      |                                                                                                                                    |                                                               |
    | `DatastoreTracer.QueryParameters.Enabled`        |                                                                                                                                    |                                                               |
    | `DatastoreTracer.SlowQuery.Enabled`              |                                                                                                                                    |                                                               |
    | `DatastoreTracer.SlowQuery.Threshold`            |                                                                                                                                    |                                                               |
    | `DistributedTracer.Enabled`                      | `ConfigDistributedTracerEnabled`                                                                                                   | `NEW_RELIC_DISTRIBUTED_TRACING_ENABLED`                       |
    | `DistributedTracer.ExcludeNewRelicHeader`        |                                                                                                                                    |                                                               |
    | `DistributedTracer.ReservoirLimit`               | `ConfigDistributedTracerReservoirLimit`                                                                                            |                                                               |
    | `Enabled`                                        | `ConfigEnabled`                                                                                                                    | `NEW_RELIC_ENABLED`                                           |
    | `ErrorCollector.Attributes.Enabled`              |                                                                                                                                    |                                                               |
    | `ErrorCollector.Attributes.Exclude`              |                                                                                                                                    |                                                               |
    | `ErrorCollector.Attributes.Include`              |                                                                                                                                    |                                                               |
    | `ErrorCollector.CaptureEvents`                   |                                                                                                                                    |                                                               |
    | `ErrorCollector.Enabled`                         |                                                                                                                                    |                                                               |
    | `ErrorCollector.IgnoreStatusCodes`               |                                                                                                                                    |                                                               |
    | `ErrorCollector.RecordPanics`                    |                                                                                                                                    |                                                               |
    | `Error`                                          |                                                                                                                                    |                                                               |
    | `Heroku.DynoNamePrefixesToShorten`               |                                                                                                                                    |                                                               |
    | `Heroku.UseDynoNames`                            |                                                                                                                                    |                                                               |
    | `HighSecurity`                                   |                                                                                                                                    | `NEW_RELIC_HIGH_SECURITY`                                     |
    | `HostDisplayName`                                |                                                                                                                                    | `NEW_RELIC_PROCESS_HOST_DISPLAY_NAME`                         |
    | `Host`                                           |                                                                                                                                    | `NEW_RELIC_HOST`                                              |
    | `InfiniteTracing.SpanEvents.QueueSize`           |                                                                                                                                    | `NEW_RELIC_INFINITE_TRACING_SPAN_EVENTS_QUEUE_SIZE`           |
    | `InfiniteTracing.TraceObserver.Host`             |                                                                                                                                    | `NEW_RELIC_INFINITE_TRACING_TRACE_OBSERVER_HOST`              |
    | `InfiniteTracing.TraceObserver.Port`             |                                                                                                                                    | `NEW_RELIC_INFINITE_TRACING_TRACE_OBSERVER_PORT`              |
    | `Labels`                                         |                                                                                                                                    | `NEW_RELIC_LABELS`                                            |
    | `License`                                        | `ConfigLicense`                                                                                                                    | `NEW_RELIC_LICENSE_KEY`                                       |
    | `Logger`                                         | `ConfigLogger` `ConfigInfoLogger` `ConfigDebugLogger` (See [note 2](#table-note-two) below)                                        | `NEW_RELIC_LOG` `NEW_RELIC_LOG_LEVEL`                         |
    | `ModuleDependencyMetrics.Enabled`                | `ConfigModuleDependencyMetricsEnabled`                                                                                             | `NEW_RELIC_MODULE_DEPENDENCY_METRICS_ENABLED`                 |
    | `ModuleDependencyMetrics.IgnoredPrefixes`        | `ConfigModuleDependencyMetricsIgnoredPrefixes`                                                                                     | `NEW_RELIC_MODULE_DEPENDENCY_METRICS_IGNORED_PREFIXES`        |
    | `ModuleDependencyMetrics.RedaceIgnoredPrefixes`  | `ConfigModuleDependencyMetricsRedactIgnoredPrefixes`                                                                               | `NEW_RELIC_MODULE_DEPENDENCY_METRICS_REDACT_IGNORED_PREFIXES` |
    | `RuntimeSampler.Enabled`                         |                                                                                                                                    |                                                               |
    | `SecurityPoliciesToken`                          |                                                                                                                                    | `NEW_RELIC_SECURITY_POLICIES_TOKEN`                           |
    | `Segments.Attributes.Enabled`                    |                                                                                                                                    |                                                               |
    | `Segments.Attributes.Exclude`                    |                                                                                                                                    |                                                               |
    | `Segments.Attributes.Include`                    |                                                                                                                                    |                                                               |
    | `Segments.StackTraceThreshold`                   |                                                                                                                                    |                                                               |
    | `Segments.Threshold`                             |                                                                                                                                    |                                                               |
    | `ServerlessMode.AccountID`                       |                                                                                                                                    |                                                               |
    | `ServerlessMode.ApdexThreshold`                  |                                                                                                                                    |                                                               |
    | `ServerlessMode.Enabled`                         |                                                                                                                                    |                                                               |
    | `ServerlessMode.PrimaryAppID`                    |                                                                                                                                    |                                                               |
    | `ServerlessMode.TrustedAccountKey`               |                                                                                                                                    |                                                               |
    | `SpanEvents.Attributes.Enabled`                  |                                                                                                                                    |                                                               |
    | `SpanEvents.Attributes.Exclude`                  |                                                                                                                                    |                                                               |
    | `SpanEvents.Attributes.Include`                  |                                                                                                                                    |                                                               |
    | `SpanEvents.Enabled`                             |                                                                                                                                    |                                                               |
    | `TransactionEvents.Attributes.Enabled`           |                                                                                                                                    |                                                               |
    | `TransactionEvents.Attributes.Exclude`           |                                                                                                                                    |                                                               |
    | `TransactionEvents.Attributes.Include`           |                                                                                                                                    |                                                               |
    | `TransactionEvents.Enabled`                      |                                                                                                                                    |                                                               |
    | `TransactionEvents.MaxSamplesStored`             |                                                                                                                                    |                                                               |
    | `TransactionTracer.Attributes.Enabled`           |                                                                                                                                    |                                                               |
    | `TransactionTracer.Attributes.Exclude`           |                                                                                                                                    |                                                               |
    | `TransactionTracer.Attributes.Include`           |                                                                                                                                    |                                                               |
    | `TransactionTracer.Enabled`                      |                                                                                                                                    |                                                               |
    | `TransactionTracer.Threshold.Duration`           |                                                                                                                                    |                                                               |
    | `TransactionTracer.Threshold.IsApdexFailing`     |                                                                                                                                    |                                                               |
    | `Transport`                                      |                                                                                                                                    |                                                               |
    | `Utilization.BillingHostname`                    |                                                                                                                                    | `NEW_RELIC_UTILIZATION_BILLING_HOSTNAME`                      |
    | `Utilization.DetectAWS`                          |                                                                                                                                    |                                                               |
    | `Utilization.DetectAzure`                        |                                                                                                                                    |                                                               |
    | `Utilization.DetectDocker`                       |                                                                                                                                    |                                                               |
    | `Utilization.DetectGCP`                          |                                                                                                                                    |                                                               |
    | `Utilization.DetectKubernetes`                   |                                                                                                                                    |                                                               |
    | `Utilization.DetectPCF`                          |                                                                                                                                    |                                                               |
    | `Utilization.LocalRAMMIB`                        |                                                                                                                                    | `NEW_RELIC_UTILIZATION_TOTAL_RAM_MIB`                         |
    | `Utilization.LogicalProcessors`                  |                                                                                                                                    | `NEW_RELIC_UTILIZATION_LOGICAL_PROCESSORS`                    |

    ### Table note 1: [#table-note-one]

    Calling one of the listed functions to enable a subordinate feature also enables the main feature and/or sets other configuration values:

    -   `ConfigAppLogForwardingEnabled(true)` sets `ApplicationLogging.Forwarding.Enabled=true` but also sets `ApplicationLogging.Enabled=true`.
    -   `ConfigAppLogForwardingEnabled(false)` sets `ApplicationLogging.Forwarding.Enabled=false` but also sets `ApplicationLogging.Forwarding.MaxSamplesStored=0`.
    -   `ConfigAppLogDecoratingEnabled(true)` sets `ApplicationLogging.LocalDecorating.Enabled=true` but also sets `ApplicationLogging.Enabled=true`.
    -   `ConfigAppLogDecoratingEnabled(false)` sets `ApplicationLogging.LocalDecorating.Enabled=false` but does not affect `ApplicationLogging.Enabled`.
    -   `ConfigAppLogMetricsEnabled(true)` sets `ApplicationLogging.Metrics.Enabled=true` but also sets `ApplicationLogging.Enabled=true`.
    -   `ConfigAppLogMetricsEnabled(false)` sets `ApplicationLogging.Metrics.Enabled=false` but does not affect `ApplicationLogging.Enabled`.

        ### Table note 2: [#table-note-two]

        When setting `Logger` via the `NEW_RELIC_LOG` environment variable, the type of logger used depends on the value of `NEW_RELIC_LOG_LEVEL`. If the latter variable is defined and has the value `debug`, `Debug`, `DEBUG`, `d`, or `D`, then a debug-level logger is used instead of a standard one. `NEW_RELIC_LOG` may have the values `stdout`, `Stdout`, `STDOUT`, `stderr`, `Stderr`, or `STDERR`.

    > #### 💡 TIP
    >
    > Environment variables must have a non-empty value in order to be read by `newrelic.ConfigFromEnvironment`.

## Set version tag [#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 [#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.

> #### ⚠️ IMPORTANT
>
> When enabled, AI monitoring  records a streaming copy of inputs and outputs sent to and from the models you choose to monitor, including any personal information contained therein.
> You're responsible for obtaining consent from your model users that their interactions may be recorded by a third party (New Relic) for the purpose of providing the AI monitoring feature.

**AIMonitoring.Enabled**

| Type                             | Boolean                              |
| -------------------------------- | ------------------------------------ |
| Default                          | `false`                              |
| [Environ variable](#environment) | `NEW_RELIC_AI_MONITORING_ENABLED`    |
| Configuration function           | `newrelic.ConfigAIMonitoringEnabled` |

When set to `true`, enables AI monitoring.

**AIMonitoring.Streaming.Enabled **

| Type                             | Boolean                                       |
| -------------------------------- | --------------------------------------------- |
| Default                          | `true`                                        |
| [Environ variable](#environment) | `NEW_RELIC_AI_MONITORING_STREAMING_ENABLED`   |
| Configuration function           | `newrelic.ConfigAIMonitoringStreamingEnabled` |

When set to `true`, enables the agent to capture streamed responses. If set to `false`, agent won't capture event data about streamed responses, but the agent can still capture metrics and spans. The span duration will end when the LLM function call exits. When set to `true`, the span duration ends when the final result is read from the stream.

**AIMonitoring.RecordContent.Enabled**

| Type                             | Boolean                                             |
| -------------------------------- | --------------------------------------------------- |
| Default                          | `true`                                              |
| [Environ variable](#environment) | `NEW_RELIC_AI_MONITORING_RECORD_CONTENT_ENABLED`    |
| Configuration function           | `newrelic.ConfigAIMonitoringRecordContentEnabled()` |

If set to `false`, agent will omit input and output content (like text strings from prompts and responses) captured in LLM events. This is an optional security setting if you don’t want to record sensitive data sent to and received from your LLMs.

## Custom events configuration [#custom-insights-events-settings]

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

**CustomInsightsEvents.Enabled**

| Type               | Boolean                  |
| ------------------ | ------------------------ |
| Default            | `true`                   |
| [Set in](#options) | `newrelic.Config` struct |

When `true`, the agent [sends custom events](https://docs.newrelic.com/docs/data-apis/custom-data/custom-events/apm-report-custom-events-attributes/#go) to [New Relic](https://docs.newrelic.com/docs/insights/new-relic-insights/understanding-insights/new-relic-insights). This setting is overridden by [`HighSecurity`](#high_security), which disables custom events.

To disable custom events, place the following in your Go app after the [New Relic config](https://docs.newrelic.com/docs/agents/go-agent/get-started/get-new-relic-go#get-new-relic) is initiated:

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

````

## Transaction events configuration [#transaction-events-settings]

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](https://docs.newrelic.com/docs/applications-menu/histograms-viewing-data-distribution) and [percentiles](https://docs.newrelic.com/docs/applications-menu/percentiles-comparing-ranked-data).

**TransactionEvents.Enabled**

| Type               | Boolean                  |
| ------------------ | ------------------------ |
| Default            | `true`                   |
| [Set in](#options) | `newrelic.Config` struct |

When `true`, the agent collects transaction events.

**TransactionEvents.Attributes**

| Type               | Struct                   |
| ------------------ | ------------------------ |
| Default            | Enabled, no exclusions   |
| [Set in](#options) | `newrelic.Config` struct |

`TransactionEvents.Attributes` is a struct with three fields:

````go
Enabled bool
Include []string
Exclude []string
```

Use `TransactionEvents.Attributes.Enabled` to turn attribute collection on or off for transaction events. Use `Include` and `Exclude` to include or exclude specific attributes.

An example of excluding an attribute slice named `allAgentAttributeNames` from transaction events:

```go
app, err := newrelic.NewApplication(
    newrelic.ConfigAppName("Your Application Name"),
    newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
    func(config *newrelic.Config) {
        config.TransactionEvents.Attributes.Exclude = allAgentAttributeNames
    },
)
```

````

**TransactionEvents.MaxSamplesStored**

| Type               | Integer                  |
| ------------------ | ------------------------ |
| Default            | `10000`                  |
| [Set in](#options) | `newrelic.Config` struct |

Defines the maximum number of transaction events per minute to be sent to New Relic, up to the default maximum of 10,000 transaction events.

## Error collector configuration [#error-collector]

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](https://docs.newrelic.com/docs/agents/manage-apm-agents/agent-data/manage-errors-apm-collect-ignore-mark-expected).

**ErrorCollector.Enabled**

| Type                                            | Boolean                                      |
| ----------------------------------------------- | -------------------------------------------- |
| Default                                         | `true`                                       |
| [Set in](#options)                              | `newrelic.Config` struct, Server-side config |
| [Server-side label](#server-side-configuration) | `Error Collection on/off`                    |

When `false`, the agent collects no errors or error traces.

**ErrorCollector.CaptureEvents**

| Type               | Boolean                  |
| ------------------ | ------------------------ |
| Default            | `true`                   |
| [Set in](#options) | `newrelic.Config` struct |

When `true`, the agent collects error analytic events.

**ErrorCollector.ErrorGroupCallback**

| Type               | ErrorGroupCallback       |                                                              |
| ------------------ | ------------------------ | ------------------------------------------------------------ |
| Default            | nil                      |                                                              |
| [Set in](#options) | `newrelic.Config` struct | `newrelic.ConfigSetErrorGroupCallbackFunction` config option |

When not nil, the agent will apply the user defined callback function to all noticed errors at harvest time, applying an error group to them.

**ErrorCollector.IgnoreStatusCodes**

| Type                                            | Integer                                          |
| ----------------------------------------------- | ------------------------------------------------ |
| Default                                         | Error codes 399 and below, and 404, are ignored. |
| [Set in](#options)                              | `newrelic.Config` struct, Server-side config     |
| [Server-side label](#server-side-configuration) | `Error Collection: Ignore from error collection` |

This controls which HTTP response codes are ignored as errors.

Response codes that are greater than or equal to 100 and strictly less than 400 are ignored by default and never have to be specified when calling this function. Response codes 0, 5, and 404 are included on the list by default, but must be specified when adding to the ignore list.

This function's default form is:

````go
config.ErrorCollector.IgnoreStatusCodes = []int{
    0,                   // gRPC OK
    5,                   // gRPC NOT_FOUND
    http.StatusNotFound, // 404
}
```

You can also add response codes as HTTPs, as `http.StatusNotFound` above.

<Callout variant="important">
  If used, [server-side configuration](#server-side-configuration) will override any values set on the `newrelic.Config` struct. Therefore to ignore 404 when server-side configuration is enabled, you must include 404 in the configuration set in the UI.
</Callout>

<CollapserGroup>
  <Collapser
    id="ignore-error-example"
    title="Example of ignoring error code"
  >
    To add HTTP response code 418 to the default ignore list, which includes 0, 5, and 404:

    ```go
    app, err := newrelic.NewApplication(
        newrelic.ConfigAppName("Your Application Name"),
        newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
        func(config *newrelic.Config) {
            config.ErrorCollector.IgnoreStatusCodes = []int{0, 5, 404, 418}
        },
    )
    ```
  </Collapser>
</CollapserGroup>

````

**ErrorCollector.ExpectStatusCodes**

| Type               | Integer                                        |
| ------------------ | ---------------------------------------------- |
| Default            | No error codes are set as expected by default. |
| [Set in](#options) | `newrelic.Config` struct                       |

This controls which HTTP response codes are expected as errors.

Response codes that are expected will not affect your application's apdex or error alerts, but they will still be recorded.

This function's default form is:

````go
config.ErrorCollector.ExpectStatusCodes = []int{
    100,
    http.StatusAccepted,
}
```

You can also add response codes as HTTPs such as `http.StatusAccepted` described above.

<CollapserGroup>
  <Collapser
    id="expected-error-example"
    title="Example of marking error codes as expected"
  >
    To add HTTP response codes 418 and 502 to the expected list:

    ```go
    app, err := newrelic.NewApplication(
        newrelic.ConfigAppName("Your Application Name"),
        newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
        func(config *newrelic.Config) {
            config.ErrorCollector.ExpectStatusCodes = []int{418, 502}
        },
    )
    ```
  </Collapser>
</CollapserGroup>

````

**ErrorCollector.Attributes**

| Type               | Struct                   |
| ------------------ | ------------------------ |
| Default            | Enabled, no exclusions   |
| [Set in](#options) | `newrelic.Config` struct |

`ErrorCollector.Attributes` is a struct with three fields:

````go
Enabled bool
Include []string
Exclude []string
```

Use `ErrorCollector.Attributes.Enabled` to turn attribute collection on or off for errors. Use `Include` and `Exclude` to include or exclude specific attributes.

An example of excluding an attribute slice named `allAgentAttributeNames` from errors:

```go
app, err := newrelic.NewApplication(
    newrelic.ConfigAppName("Your Application Name"),
    newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
    func(config *newrelic.Config) {
        config.ErrorCollector.Attributes.Exclude = allAgentAttributeNames
    },
)
```

````

## Transaction tracer configuration [#transaction-tracer]

Here are settings for changing transaction tracer configuration. For more information about transaction traces, see [Transaction traces](https://docs.newrelic.com/docs/traces/transaction-traces).

**TransactionTracer.Enabled**

| Type                                            | Boolean                                      |
| ----------------------------------------------- | -------------------------------------------- |
| Default                                         | `true`                                       |
| [Set in](#options)                              | `newrelic.Config` struct, Server-side config |
| [Server-side label](#server-side-configuration) | `Transaction Tracing on/off`                 |

When `true`, the agent collects [transaction traces](https://docs.newrelic.com/docs/apm/transactions/transaction-traces/transaction-traces) (detailed information about slow transactions).

**TransactionTracer.Threshold.IsApdexFailing**

| Type                                            | Boolean                                      |
| ----------------------------------------------- | -------------------------------------------- |
| Default                                         | `true`                                       |
| [Set in](#options)                              | `newrelic.Config` struct, Server-side config |
| [Server-side label](#server-side-configuration) | `Transaction Tracing: Threshold`             |

Controls whether the transaction trace threshold is based on Apdex.

-   If `true`, then the trace threshold is four times the [Apdex threshold](https://docs.newrelic.com/docs/apm/new-relic-apm/apdex/apdex-measuring-user-satisfaction).
-   If `false`, the agent uses [`Threshold.Duration`](https://docs.newrelic.com/docs/go-agent-configuration#txn-tracer-threshold-duration) as the transaction trace threshold.

**TransactionTracer.Threshold.Duration**

| Type                                            | time.Millisecond                             |
| ----------------------------------------------- | -------------------------------------------- |
| Default                                         | `500`                                        |
| [Set in](#options)                              | `newrelic.Config` struct, Server-side config |
| [Server-side label](#server-side-configuration) | `Transaction Tracing: Threshold`             |

If `Threshold.IsApdexFailing` is set to `false`, the agent uses this duration as the transaction trace threshold.

**TransactionTracer.Segments.Threshold**

| Type               | time.Millisecond         |
| ------------------ | ------------------------ |
| Default            | `2`                      |
| [Set in](#options) | `newrelic.Config` struct |

This is the threshold at which segments will be added to the trace.

**TransactionTracer.Segments.Attributes**

> #### ⚠️ IMPORTANT
>
> Available for Go agent version 2.6.0 or higher.

| Type               | Struct                   |
| ------------------ | ------------------------ |
| Default            | Enabled, no exclusions   |
| [Set in](#options) | `newrelic.Config` struct |

`TransactionTracer.Segments.Attributes` is a struct with three fields:

````go
Enabled bool
Include []string
Exclude []string
```

Use `TransactionTracer.Segments.Attributes.Enabled` to turn attribute collection on or off for transaction trace segments. Use `Include` and `Exclude` to include or exclude specific attributes.

An example of excluding an attribute slice named `allSegmentAttributeNames` from traces:

```go
app, err := newrelic.NewApplication(
    newrelic.ConfigAppName("Your Application Name"),
    newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
    func(config *newrelic.Config) {
        config.TransactionTracer.Segments.Attributes.Exclude = allSegmentAttributeNames
    },
)
```

````

**TransactionTracer.Segments.StackTraceThreshold**

| Type                                            | time.Millisecond                             |
| ----------------------------------------------- | -------------------------------------------- |
| Default                                         | `500`                                        |
| [Set in](#options)                              | `newrelic.Config` struct, Server-side config |
| [Server-side label](#server-side-configuration) | `Transaction Tracing: Stack trace threshold` |

This is the threshold at which segments will be given a stack trace in the transaction trace.

> #### ⚠️ CAUTION
>
> Lowering this setting may drastically increase agent overhead.

**TransactionTracer.Attributes**

| Type                                                                                                    | Struct                   |
| ------------------------------------------------------------------------------------------------------- | ------------------------ |
| Default                                                                                                 | Enabled, no exclusions   |
| [Set in](https://docs.newrelic.com/docs/agents/go-agent/instrumentation/go-agent-configuration#options) | `newrelic.Config` struct |

`TransactionTracer.Attributes` is a struct with three fields:

````go
Enabled bool
Include []string
Exclude []string
```

Use `TransactionTracer.Attributes.Enabled` to turn attribute collection on or off for transaction traces. Use `Include` and `Exclude` to include or exclude specific attributes.

An example of excluding an attribute slice named `allAgentAttributeNames` from traces:

```go
app, err := newrelic.NewApplication(
    newrelic.ConfigAppName("Your Application Name"),
    newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
    func(config *newrelic.Config) {
        config.TransactionTracer.Attributes.Exclude = allAgentAttributeNames
    },
)
```

````

## Datastore tracer configuration [#datastore-tracer]

Here are datastore settings, including [slow query](https://docs.newrelic.com/docs/apm/applications-menu/monitoring/viewing-slow-query-details) enabling and settings.

**DatastoreTracer.InstanceReporting.Enabled**

| Type               | Boolean                  |
| ------------------ | ------------------------ |
| Default            | `true`                   |
| [Set in](#options) | `newrelic.Config` struct |

This enables collection of datastore instance metrics (such as the host and port) for some database drivers. These are reported on transaction traces and as part of [slow query data](https://docs.newrelic.com/docs/apm/applications-menu/monitoring/viewing-slow-query-details).

**DatastoreTracer.NameReporting.Enabled**

| Type               | Boolean                  |
| ------------------ | ------------------------ |
| Default            | `true`                   |
| [Set in](#options) | `newrelic.Config` struct |

Use this to enable collection of the database name on slow query traces and transaction traces. The default value of attribute enabled is `true`.

**DatastoreTracer.QueryParameters.Enabled**

| Type               | Boolean                  |
| ------------------ | ------------------------ |
| Default            | `true`                   |
| [Set in](#options) | `newrelic.Config` struct |

When `true`, the agent collects datastore call query parameters.

**DatastoreTracer.SlowQuery.Enabled**

| Type               | Boolean                  |
| ------------------ | ------------------------ |
| Default            | `true`                   |
| [Set in](#options) | `newrelic.Config` struct |

Controls whether [slow queries](https://docs.newrelic.com/docs/apm/applications-menu/monitoring/viewing-slow-query-details) are captured.

**DatastoreTracer.SlowQuery.Threshold**

| Type               | time.Millisecond         |
| ------------------ | ------------------------ |
| Default            | `10`                     |
| [Set in](#options) | `newrelic.Config` struct |

The agent captures [slow query data](https://docs.newrelic.com/docs/apm/applications-menu/monitoring/viewing-slow-query-details) for queries slower than this.

## Cross application tracing configuration [#cross-application-tracing]

Here are settings for changing the [cross application tracing](https://docs.newrelic.com/docs/agents/go-agent/features/cross-application-tracing-go) feature.

> #### ⚠️ IMPORTANT
>
> Cross application tracing has been deprecated in favor of [Distributed tracing](https://docs.newrelic.com/docs/agents/go-agent/features/distributed-tracing-go) and will be removed in a future agent version.

**CrossApplicationTracer.Enabled**

| Type                                            | Boolean                                      |
| ----------------------------------------------- | -------------------------------------------- |
| Default                                         | `true`                                       |
| [Set in](#options)                              | `newrelic.Config` struct, Server-side config |
| [Server-side label](#server-side-configuration) | `Cross-application tracing on/off`           |

When `true`, the agent will add cross application tracing headers in outbound requests, and scan incoming requests for cross application tracing headers.

Distributed tracing and cross application tracing cannot be used simultaneously. The default configuration for the Go agent disables distributed tracing and enables cross application tracing.

## Distributed tracing configuration [#distributed-tracing]

> #### ⚠️ IMPORTANT
>
> Enabling distributed tracing requires Go agent version 2.1.0 or higher, and it disables [cross application tracing](#cross-application-tracing). It also has effects on other features. Before enabling, read the [transition guide](https://docs.newrelic.com/docs/transition-guide-distributed-tracing).

[Distributed tracing](https://docs.newrelic.com/docs/agents/go-agent/features/distributed-tracing-go) 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](https://docs.newrelic.com/docs/apm/distributed-tracing/ui-data/span-event).

**DistributedTracer.Enabled**

| Type               | Boolean                  |
| ------------------ | ------------------------ |
| Default            | `true`                   |
| [Set in](#options) | `newrelic.Config` struct |

Standard tracing is on by default in Go agent versions 3.16.0 and higher. This means the agent will automatically add distributed tracing headers in outbound requests, and scan incoming requests for distributed tracing headers. To disable distributed tracing, set the value to `false`.

For more information about setting up distributed tracing, see [Enable distributed tracing for your Go applications](https://docs.newrelic.com/docs/apm/agents/go-agent/instrumentation/distributed-tracing-go-agent).

> #### ⚠️ IMPORTANT
>
> Enabling distributed tracing disables [cross application tracing](#cross-application-tracing).

**DistributedTracer.ExcludeNewRelicHeader**

| Type               | Boolean                  |
| ------------------ | ------------------------ |
| Default            | `false`                  |
| [Set in](#options) | `newrelic.Config` struct |

Set this to `true` to exclude the New Relic header that is attached to outbound requests, and instead only rely on W3C Trace Context Headers for distributed tracing. If this is `false` then both types of headers are used.

## Span events configuration [#span-events]

[Span events](https://docs.newrelic.com/docs/apm/distributed-tracing/ui-data/span-event) are reported for [distributed tracing](https://docs.newrelic.com/docs/agents/java-agent/configuration/java-agent-configuration-config-file#distributed-tracing). Distributed tracing must be enabled to report span events. These settings control the collection of span events:

**SpanEvents.Enabled**

| Type               | Boolean                  |
| ------------------ | ------------------------ |
| Default            | `true`                   |
| [Set in](#options) | `newrelic.Config` struct |

When `true`, the agent will collect span events.

**SpanEvents.Attributes**

> #### ⚠️ IMPORTANT
>
> Available for Go agent version 2.6.0 or higher.

| Type               | Struct                   |
| ------------------ | ------------------------ |
| Default            | Enabled, no exclusions   |
| [Set in](#options) | `newrelic.Config` struct |

`SpanEvents.Attributes` is a struct with three fields:

````go
Enabled bool
Include []string
Exclude []string
```

Use `SpanEvents.Attributes.Enabled` to enable or disable attribute collection for span events. Use `Include` and `Exclude` to include or exclude specific attributes.

An example of excluding an attribute slice named `allSpanAttributeNames` from traces:

```go
app, err := newrelic.NewApplication(
    newrelic.ConfigAppName("Your Application Name"),
    newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
    func(config *newrelic.Config) {
        config.TransactionTracer.Segments.Attributes.Exclude = allSpanAttributeNames
    },
)
```

````

## Infinite Tracing configuration [#infinite-tracing]

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](https://docs.newrelic.com/docs/understand-dependencies/distributed-tracing/enable-configure/language-agents-enable-distributed-tracing#go-config).

**InfiniteTracing.TraceObserver.Host**

| Type               | string                   |
| ------------------ | ------------------------ |
| Default            | (none)                   |
| [Set in](#options) | `newrelic.Config` struct |

For help getting a valid Infinite Tracing trace observer host entry, see [Find or create a trace observer endpoint](https://docs.newrelic.com/docs/understand-dependencies/distributed-tracing/enable-configure/language-agents-enable-distributed-tracing#provision-trace-observer).

## Application logging settings [#application-logging]

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](https://docs.newrelic.com/docs/logs/logs-context/configure-logs-context-go).

> #### ⚠️ IMPORTANT
>
> Requires Go agent version 3.17.0 or higher

**ApplicationLogging.Enabled**

| Type               | Boolean                  |
| ------------------ | ------------------------ |
| Default            | `true`                   |
| [Set in](#options) | `newrelic.Config` struct |

If `true`, enables the collection of log events and logging metrics if these sub-feature configurations are also enabled.  If `false`, no logging instrumentation features are enabled.

Configure ApplicationLogging by calling `ConfigAppLogEnabled()`.

````go
app, err := newrelic.NewApplication(
    newrelic.ConfigAppLogEnabled(true),
)
```

````

**ApplicationLogging.Forwarding.Enabled**

| Type               | Boolean                  |
| ------------------ | ------------------------ |
| Default            | `false`                  |
| [Set in](#options) | `newrelic.Config` struct |

If `true`, the agent captures log records emitted by your application and forwards them to New Relic. `ApplicationLogging.Enabled` must also be `true` for this setting to take effect.

Enable log forwarding by calling `ConfigAppLogForwardingEnabled()`.

````go
app, err := newrelic.NewApplication(
    newrelic.ConfigAppLogForwardingEnabled(true),
)
```

````

**ApplicationLogging.Forwarding.MaxSamplesStored**

| Type               | Integer                  |
| ------------------ | ------------------------ |
| Default            | `10000`                  |
| [Set in](#options) | `newrelic.Config` struct |

Number of log records to send per minute to New Relic. This setting controls overall memory consumption when using the log forwarding feature.

Configure `ApplicationLogging.Forwarding.MaxSamplesStored` by calling `ConfigAppLogForwardingMaxSamplesStored()`.

````go
app, err := newrelic.NewApplication(
    newrelic.ConfigAppLogForwardingMaxSamplesStored(1000),
)
```

Set this to a lower value to reduce the amount of log lines sent (may cause log sampling). Set this to a higher value to send more log lines.

Each log receives the same priority as its associated transaction. Logs that occur outside of a transaction will receive a random priority. Some logs may not be included because they are limited by `MaxSamplesStored`. For example, if logging `MaxSamplesStored` is set to 10,000 and transaction 1 has 10,000 log entries, only log entries for transaction 1 will be recorded. If transaction 1 has less than 10,000 logs, you receive all logs for transaction 1. If there is still space, you receive all the logs for transaction 2, and so on.

If after all the logs for sampled transactions are recorded, and they haven't reached the limit in `MaxSamplesStored`, then log messages for transactions that were not in our sampling are sent. If there are any left, log messages outside of transactions are recorded.

````

**ApplicationLogging.Metrics.Enabled**

| Type               | Boolean                  |
| ------------------ | ------------------------ |
| Default            | `true`                   |
| [Set in](#options) | `newrelic.Config` struct |

If `true`, the agent captures metrics related to the log lines being sent up by your application. `ApplicationLogging.Enabled` must also be `true` for this setting to take effect.

Configure ApplicationLogging.Metrics.Enabled by calling `ConfigAppLogMetricsEnabled()`.

````go
app, err := newrelic.NewApplication(
    newrelic.ConfigAppLogMetricsEnabled(true),
)
```

````

## Module dependency metrics settings [#mdm]

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

**ModuleDependencyMetrics.Enabled**

| Type               | Boolean                  |
| ------------------ | ------------------------ |
| Default            | `true`                   |
| [Set in](#options) | `newrelic.Config` struct |

If `true`, enables the collection of module dependency data.  If `false`, no module dependency information is collected.

Configure ModuleDependencyMetrics by calling `ConfigModuleDependencyMetricsEnabled`.

````go
app, err := newrelic.NewApplication(
    newrelic.ConfigModuleDependencyMetricsEnabled(true),
)
```

You can enable the setting of your Go agent options via environment variables by inserting `ConfigFromEnvironment()` into your call to `NewApplication`. If you've done this you can enable or disable module dependency metrics collection by setting the environment variable.

```ini
NEW_RELIC_MODULE_DEPENDENCY_METRICS_ENABLED=true
```

````

**ModuleDependencyMetrics.IgnoredPrefixes**

| Type               | String(s)                |
| ------------------ | ------------------------ |
| Default            | `nil`                    |
| [Set in](#options) | `newrelic.Config` struct |

This list of module path prefixes specifies that you want to exclude some modules from the dependency information reported by the agent.
Any module whose `import` path begins with any of the listed prefix strings will be excluded. The default is an empty list, which means
to report all modules found.

Specify a list of path prefix strings to be excluded by calling `ConfigModuleDependencyMetricsIgnoredPrefixes`.

````go
app, err := newrelic.NewApplication(
    newrelic.ConfigModuleDependencyMetricsIgnoredPrefixes("example.com/packageAlpha", "example.com/packageBeta"),
)
```

If you enabled the setting of your Go agent options via environment variables by inserting `ConfigFromEnvironment()` into your call to `NewApplication`, you can list the path prefixes by setting the environment variable.

```ini
NEW_RELIC_MODULE_DEPENDENCY_METRICS_IGNORED_PREFIXES="example.com/packageAlpha,example.com/packageBeta"
```

````

**ModuleDependencyMetrics.RedactIgnoredPrefixes**

| Type               | Boolean                  |
| ------------------ | ------------------------ |
| Default            | `true`                   |
| [Set in](#options) | `newrelic.Config` struct |

Normally all of the options you set as part of your agent configuration are reported and visible in the New Relic UI. If you choose to exclude some modules from being reported via the `ConfigModuleDependencyIgnoredPrefixes` option, you can also redact them from the configuration data as well. For example, if the modules were excluded for reasons of confidentiality.

Enable or disable the redaction of excluded paths by calling `ConfigModuleDependencyMetricsRedactIgnoredPrefixes`.
If `true`, the list of excluded module prefixes won't be reported. If `false`, they are reported.

````go
app, err := newrelic.NewApplication(
    newrelic.ConfigModuleDependencyMetricsRedactIgnoredPrefixes(false),
)
```

If you enabled the setting of your Go agent options via environment variables by inserting `ConfigFromEnvironment()` into your call to `NewApplication`, you can list the path prefixes by setting the environment variable.

```ini
NEW_RELIC_MODULE_DEPENDENCY_METRICS_REDACT_IGNORED_PREFIXES=false
```

````

## New Relic IAST [#go-IAST]

[New Relic Interactive Applications Security Testing](https://docs.newrelic.com/docs/iast/introduction/) (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.

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

Next initialize and enable the security agent.

### Enable IAST

**Enable with option functions**

````go
err: = nrsecurityagent.InitSecurityAgent(
    app,
    nrsecurityagent.ConfigSecurityMode("IAST"),
    nrsecurityagent.ConfigSecurityValidatorServiceEndPointUrl("wss://csec.nr-data.net"),
    nrsecurityagent.ConfigSecurityEnable(true),
)
```


````

**Enable with environment variables**

ConfigSecurityFromEnvironment directs the nrsecurityagent integration to obtain all of its configuration information from environment variables.

````go
 err: = nrsecurityagent.InitSecurityAgent(
     app,
     ConfigSecurityFromEnvironment(),
 )
```

````

**Enable from YAML file**

ConfigSecurityFromYaml directs the nrsecurityagent integration to read an external YAML-formatted file to obtain its configuration values. The path to this file must be provided by setting the environment variable NEW_RELIC_SECURITY_CONFIG_PATH.

````go
err: = nrsecurityagent.InitSecurityAgent(
    app,
    ConfigSecurityFromYaml(),
)
```

The default YAML file looks like this.

```yaml
enabled: true

# NR security provides two modes IAST and RASP
# Default is IAST
mode: IAST

# New Relic’s SaaS connection URLs
validator_service_url: wss://csec.nr-data.net

# Following category of security events
# can be disabled from generating.
detection:
  rxss:
    enabled: true
request:
  body_limit: 300
```

````

### Configure IAST

The security agent can be configured with the following options.

**cfg.Security.Agent.Enabled**

| Type                 | Boolean                                                                              |
| -------------------- | ------------------------------------------------------------------------------------ |
| Config Function      | ````go func(cfg *SecurityConfig) {     cfg.Security.Agent.Enabled = true } ```  ```` |
| Environment Variable | `NEW_RELIC_SECURITY_AGENT_ENABLED`                                                   |
| Default              | `true`                                                                               |

To completely disable all security functionality, set this flag to false. By importing and initializing the security agent in go, its assumed that you intend to use it, so this value defaults to `true`. Note that this is the oposite behavior from automatically instrumenting agents. This property is read only once at application start.

**cfg.Security.Enabled**

| Type                 | Boolean                                       |
| -------------------- | --------------------------------------------- |
| Config Function      | `nrsecurityagent.ConfigSecurityEnable(false)` |
| Environment Variable | `NEW_RELIC_SECURITY_ENABLED`                  |
| Default              | `false`                                       |

Determines whether the security data is sent to New Relic or not. When this is disabled and agent.enabled is true, the security module will run but data will not be sent. Default is false.

**cfg.Security.Mode**

| Type                 | String                                       |
| -------------------- | -------------------------------------------- |
| Config Function      | `nrsecurityagent.ConfigSecurityMode("IAST")` |
| Environment Variable | `NEW_RELIC_SECURITY_MODE`                    |
| Default              | `IAST`                                       |

New Relic Security provide mode: IAST. Default is IAST. Due to the invasive nature of IAST scanning, DO NOT enable this mode in either a production environment or an environment where production data is processed.

**cfg.Security.Validator_service_url**

| Type                 | String                                                                                |
| -------------------- | ------------------------------------------------------------------------------------- |
| Config Function      | `nrsecurityagent.ConfigSecurityValidatorServiceEndPointUrl("wss://csec.nr-data.net")` |
| Environment Variable | `NEW_RELIC_SECURITY_VALIDATOR_SERVICE_URL`                                            |
| Default              | `wss://csec.nr-data.net`                                                              |

New Relic Security’s SaaS connection URL. This is the endpoint that the security agent sends data to, it should match that environment that you have set for the APM Java agent.

US Production: wss://csec.nr-data.net

**cfg.Security.Detection.Rxss.Enabled**

| Type                 | Boolean                                                    |
| -------------------- | ---------------------------------------------------------- |
| Config Function      | `nrsecurityagent.ConfigSecurityDetectionDisableRxss(true)` |
| Environment Variable | `NEW_RELIC_SECURITY_DETECTION_RXSS_ENABLED`                |
| Default              | `true`                                                     |

Enable RXSS security event detection. Default is true.

**cfg.Security.Request.BodyLimit**

| Type                 | Int                                                   |
| -------------------- | ----------------------------------------------------- |
| Config Function      | `nrsecurityagent.ConfigSecurityRequestBodyLimit(300)` |
| Environment Variable | `NEW_RELIC_SECURITY_REQUEST_BODY_LIMIT`               |
| Default              | 300                                                   |

Security Request Body Limit sets a limit on read the amount of memory that can be consumed when reading from a request body in kb. By default, this is "300".

### 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.
