---
title: Go agent attributes
source: https://docs.newrelic.com/docs/apm/agents/go-agent/instrumentation/go-agent-attributes
---

[Attributes](https://docs.newrelic.com/docs/features/agent-attributes) are key-value pairs containing information for transaction events, error events, and traced errors. You can adjust the destinations of default attributes and create custom attributes for the attributes collected by [New Relic's Go language agent](https://docs.newrelic.com/docs/agents/go-agent/get-started/new-relic-go), including:

-   Error traces
-   Transaction events
-   Page views

For an extra level of monitoring detail, [create custom attributes](https://docs.newrelic.com/docs/agents/go-agent/go-agent-attributes#custom-attributes).

## Go agent attributes [#attributes]

The Go agent receives the following [default attributes](https://docs.newrelic.com/docs/agents/manage-apm-agents/agent-metrics/agent-attributes) from your app. You can adjust these default settings and [turn attributes on or off](#change-attribute-destination) for certain destinations.

**host.displayName**

The name of the server host under which the current script is executing, called with `newrelic.AttributeHostDisplayName`.

Default settings:

-   Transaction traces: Enabled
-   Error collector (traced errors): Enabled
-   Transaction events: Disabled

    Example of excluding this attribute:

    ```go
    config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.AttributeHostDisplayName)
    ```

**httpResponseCode**

The response status code for a web request, called with `newrelic.AttributeResponseCodeDeprecated`

Default settings:

-   Transaction traces: Enabled
-   Error collector (traced errors): Enabled
-   Transaction events: Enabled

    Example of excluding this attribute:

    ```go
    config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.AttributeResponseCodeDeprecated)
    ```

    > #### ⚠️ IMPORTANT
    >
    > As of Go agent v3.0.0, this attribute has been marked deprecated and been renamed to `http.statusCode`. The v3.x agent will continue to produce this attribute, but it will be removed in v4.0.0.

**request.headers.accept**

The type as read from the HTTP request's `Accept` header, called with `newrelic.AttributeRequestAccept`

Default settings:

-   Transaction traces: Enabled
-   Error collector (traced errors): Enabled
-   Transaction events: Enabled

    Example of excluding this attribute:

    ```go
    config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.AttributeRequestAccept)
    ```

**request.headers.contentLength**

The incoming request size in bytes as read from the `Content-Length` request header, called with `newrelic.AttributeRequestContentLength`.

Default settings:

-   Transaction traces: Enabled
-   Error collector (traced errors): Enabled
-   Transaction events: Enabled

    Example of excluding this attribute:

    ```go
    config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.AttributeRequestContentLength)
    ```

**request.headers.contentType**

The incoming request content type as read from the `Content-Type` request header, called with `newrelic.AttributeRequestContentType`.

Default settings:

-   Transaction traces: Enabled
-   Error collector (traced errors): Enabled
-   Transaction events: Enabled

    Example of excluding this attribute:

    ```go
    config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.AttributeRequestContentType)
    ```

**request.headers.host**

The name from the HTTP host request header, called with `newrelic.AttributeRequestHost`.

Default settings:

-   Transaction traces: Enabled
-   Error collector (traced errors): Enabled
-   Transaction events: Enabled

    Example of excluding this attribute:

    ```go
    config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.AttributeRequestHost)
    ```

**request.headers.referer**

The incoming request referer as read from the `Referer` request header, called with `newrelic.AttributeRequestReferer`.

Default settings:

-   Transaction traces: Enabled
-   Error collector (traced errors): Enabled
-   Transaction events: Disabled

    Example of excluding this attribute:

    ```go
    config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.AttributeRequestReferer)
    ```

**request.headers.User-Agent**

The contents of the `User-Agent` HTTP header, called with `newrelic.AttributeRequestUserAgentDeprecated`

Default settings:

-   Transaction traces: Enabled
-   Error collector (traced errors): Enabled
-   Transaction events: Disabled

    Example of excluding this attribute:

    ```go
    config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.AttributeRequestUserAgentDeprecated)
    ```

    > #### ⚠️ IMPORTANT
    >
    > As of Go agent v3.0.0, this attribute has been marked deprecated and been renamed to `request.headers.userAgent`. The v3.x agent will continue to produce this attribute, but it will be removed in v4.0.0.

**request.headers.userAgent**

The contents of the `User-Agent` HTTP header, called with `newrelic.AttributeRequestUserAgent`

Default settings:

-   Transaction traces: Enabled
-   Error collector (traced errors): Enabled
-   Transaction events: Disabled

    Example of excluding this attribute:

    ```go
    config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.AttributeRequestUserAgent)
    ```

    > #### ⚠️ IMPORTANT
    >
    > This attribute was added in v3.0.0 of the agent and the original `request.headers.User-Agent` will eventually be removed. Therefore the v3.x agents will produce two attributes representing the the contents of the User-Agent HTTP header. To completely exclude the attribute when using the v3.x agent, you must include both the old and new attributes. For example:
    >
    > ```go
    > config.Attributes.Exclude = append(config.Attributes.Exclude,
    >     newrelic.AttributeRequestUserAgent,
    >     newrelic.AttributeRequestUserAgentDeprecated,
    > )
    > ```

**request.method**

The HTTP method of the incoming request, called with `newrelic.AttributeRequestMethod`

Default settings:

-   Transaction traces: Enabled
-   Error collector (traced errors): Enabled
-   Transaction events: Enabled

    Example of excluding this attribute:

    ```go
    config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.AttributeRequestMethod)
    ```

**response.headers.contentLength**

The outgoing response size in bytes as read from the Content-Length response header, called with `newrelic.AttributeResponseContentLength`.

Default settings:

-   Transaction traces: Enabled
-   Error collector (traced errors): Enabled
-   Transaction events: Enabled

    Example of excluding this attribute:

    ```go
    config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.AttributeResponseContentLength)
    ```

**response.headers.contentType**

The outgoing response content-type as read from the Content-Type response header, called with `newrelic.AttributeResponseContentType`.

Default settings:

-   Transaction traces: Enabled
-   Error collector (traced errors): Enabled
-   Transaction events: Enabled

    Example of excluding this attribute:

    ```go
    config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.AttributeResponseContentType)
    ```

**http.statusCode**

The response status code for a web request, called with `newrelic.AttributeResponseCode`

Default settings:

-   Transaction traces: Enabled
-   Error collector (traced errors): Enabled
-   Transaction events: Enabled

    Example of excluding this attribute:

    ```go
    config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.AttributeResponseCode)
    ```

    > #### ⚠️ IMPORTANT
    >
    > This attribute was added in v3.0.0 of the agent and the original `httpResponseCode` will eventually be removed. Therefore the v3.x agents will produce two attributes representing the response status code for a web request. To completely exclude the attribute when using the v3.x agent, you must include both the old and new attributes. For example:
    >
    > ```go
    > config.Attributes.Exclude = append(config.Attributes.Exclude,
    >     newrelic.AttributeResponseCode,
    >     newrelic.AttributeResponseCodeDeprecated,
    > )
    > ```

## Span and segment attributes [#span-and-segment-attributes]

If you have [Go agent v2.6.0 or higher](https://docs.newrelic.com/docs/release-notes/agent-release-notes/go-release-notes), you can configure attributes on spans and segments. The Go agent receives the following [default attributes](https://docs.newrelic.com/docs/agents/manage-apm-agents/agent-metrics/agent-attributes) from your app. These attributes are only found on span events and transaction trace segments. You can adjust these default settings and [turn attributes on or off](#change-attribute-destination) for certain destinations.

**db.collection**

For [datastore segments](https://docs.newrelic.com/docs/agents/go-agent/get-started/instrument-go-segments#go-datastore-segments), this is the collection used and represents the table or group, called with `newrelic.SpanAttributeDBCollection`.

Default settings:

-   Transaction trace segments: Enabled
-   Span events: Enabled

    Example of excluding this attribute:

    ```go
    config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.SpanAttributeDBCollection)
    ```

**db.instance**

For [datastore segments](https://docs.newrelic.com/docs/agents/go-agent/get-started/instrument-go-segments#go-datastore-segments) this is the database name and represents the name of the database where the query is being executed, called with `newrelic.SpanAttributeDBInstance`.

Default settings:

-   Transaction trace segments: Enabled
-   Span events: Enabled

    Example of excluding this attribute:

    ```go
    config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.SpanAttributeDBInstance)
    ```

**db.statement**

For [datastore segments](https://docs.newrelic.com/docs/agents/go-agent/get-started/instrument-go-segments#go-datastore-segments) this is the parameterized query being executed and represents the query being performed, called with `newrelic.SpanAttributeDBStatement`.

Default settings:

-   Transaction trace segments: Enabled
-   Span events: Enabled

    Example of excluding this attribute:

    ```go
    config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.SpanAttributeDBStatement)
    ```

**http.method**

For [external segments](https://docs.newrelic.com/docs/agents/go-agent/get-started/instrument-go-segments#go-external-segments) this is the http method of the outgoing request, called with `newrelic.SpanAttributeHTTPMethod`.

Default settings:

-   Transaction trace segments: Enabled
-   Span events: Enabled

    Example of excluding this attribute:

    ```go
    config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.SpanAttributeHTTPMethod)
    ```

**http.url**

For [external segments](https://docs.newrelic.com/docs/agents/go-agent/get-started/instrument-go-segments#go-external-segments) this is the url of the outgoing request, called with `newrelic.SpanAttributeHTTPURL`.

Default settings:

-   Transaction trace segments: Enabled
-   Span events: Enabled

    Example of excluding this attribute:

    ```go
    config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.SpanAttributeHTTPURL)
    ```

**peer.address**

For [datastore segments](https://docs.newrelic.com/docs/agents/go-agent/get-started/instrument-go-segments#go-datastore-segments) this is the hostname plus port of the database being queried, called with `newrelic.SpanAttributePeerAddress`.

Default settings:

-   Transaction trace segments: Enabled
-   Span events: Enabled

    Example of excluding this attribute:

    ```go
    config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.SpanAttributePeerAddress)
    ```

**peer.hostname**

For [datastore segments](https://docs.newrelic.com/docs/agents/go-agent/get-started/instrument-go-segments#go-datastore-segments) this is the hostname of the database being queried, called with `newrelic.SpanAttributePeerHostname`.

Default settings:

-   Transaction trace segments: Enabled
-   Span events: Enabled

    Example of excluding this attribute:

    ```go
    config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.SpanAttributePeerHostname)
    ```

## Change attribute destination

Use these options to change attribute destinations:

**Turn destinations on or off**

To open or close an entire destination to attributes, set the `.Enabled` flag to `true` or `false`.

For example, to turn off APM error collection: After the [config](https://github.com/newrelic/go-agent/blob/master/GUIDE.md#config-and-application), add:

````go
config.ErrorCollector.Attributes.Enabled = false
```

````

**Turn attributes on or off**

To turn specific attributes on or off, use the `.Include` or `.Exclude` methods.

For example, to disable `AttributeResponseCode`: After the [config](https://github.com/newrelic/go-agent/blob/master/GUIDE.md#config-and-application), add:

````go
config.Attributes.Exclude = append(config.Attributes.Exclude, newrelic.AttributeResponseCode)
```

````

## Create custom attributes [#custom-attributes]

Add custom attributes by using this method in a transaction:

```go
txn.AddAttribute("key", "value")
```

The `txn` variable is the one [instrumented for the Go transaction](https://docs.newrelic.com/docs/agents/go-agent/get-started/instrument-go-transactions#go-txn). For example:

```go
txn.AddAttribute("product", "widget")
txn.AddAttribute("price", 19.99)
txn.AddAttribute("importantCustomer", true)
```

Default settings for custom attribute destinations:

-   Error collector (traced errors): Enabled
-   Transaction events: Enabled
