# Configuration Options

## Configure Relay to suit the needs of your organization.

Configuration for Relay is typically recorded in the file `.relay/config.yml` (relative to the working directory). Configuration options can be overridden through environment variables. To change the config location, pass the `--config` option to any Relay command:

```shell
❯ ./relay run --config /path/to/folder
```

All configuration keys are `snake_case`.

## [Credentials](#credentials)

Credentials can be initiated as described in the [getting started page](/product/relay/getting-started/), but can be overridden by setting the following environment variables:

* Secret key: `RELAY_SECRET_KEY`.
* Public key: `RELAY_PUBLIC_KEY`.
* ID: `RELAY_ID`.

## [Relay](#relay)

| key                          | type    | value                                                                                         | description                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ---------------------------- | ------- | --------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| relay.mode                   | String  | default value: `managed` possible values: `managed, static, proxy, capture` optional: `false` | Controls how Relay obtains the project configuration for events. For detailed explanation of these modes, see [Relay Modes](/product/relay/modes/). `Environment variable: "RELAY_MODE."`                                                                                                                                                                                                                                                       |
| relay.upstream               | String  | default value: `https://sentry.io` optional: `false`                                          | Fully qualified URL of the upstream Relay or Sentry instance. `Environment variable: "RELAY_UPSTREAM_URL".`##### ImportantRelay doesn't check for cycles. Don't set this option to an endpoint that will cause events to be cycled back here.                                                                                                                                                                                                   |
| relay.host                   | String  | default value: `0.0.0.0 in Docker, otherwise 127.0.0.1` optional: `false`                     | The host to which Relay should bind (network interface). `Environment variable: "RELAY_HOST".`                                                                                                                                                                                                                                                                                                                                                  |
| relay.port                   | Integer | default value: `3000` optional: `false`                                                       | The port to which Relay should bind for the unencrypted Relay HTTP server. `Environment variable: "RELAY_PORT".`                                                                                                                                                                                                                                                                                                                                |
| relay.override\_project\_ids | Boolean | optional: `true`                                                                              | Overrides project identifiers stated in client DSNs with the identifier used at the Sentry upstream. By default, Relay rejects data on project ID mismatch. Set this setting to `true` when Relay redirects traffic to a migrated Sentry instance, such as when moving from self-hosted to Sentry SaaS. Validation of project identifiers can be safely omitted in these cases, and you can continue to use the previous DSNs in your services. |

## [HTTP](#http)

These settings control network-related configurations.

| key                       | type    | value           | description                                                                                                                                                                                                                                 |
| ------------------------- | ------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| http.timeout              | Integer | default: `5`    | Timeout for upstream requests in seconds. This timeout covers the period of time from when a request is sent to when response headers are received. It doesn’t cover the connection process, handshakes, or reading of the response body.   |
| http.connection\_timeout  | Integer | default: `3`    | Timeout for establishing connections with the upstream in seconds. Relay reuses connections when the upstream supports connection keep-alive. Connections are retained for a maximum of 75 seconds of activity or 15 seconds of inactivity. |
| http.max\_retry\_interval | Integer | default: `60`   | Maximum interval between failed request retries in seconds.                                                                                                                                                                                 |
| http.host\_header         | String  | default: `null` | Custom HTTP Host header to be sent to the upstream.                                                                                                                                                                                         |

## [Caching](#caching)

These settings fine tune caching of project states.

| key                          | type    | value                             | description                                                                                                                                                                                                                                         |
| ---------------------------- | ------- | --------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| cache.project\_expiry        | Integer | default: `300 (5 minutes)`        | The cache timeout for project configurations in seconds. Irrelevant if you use the "simple proxy mode", where your project config is stored in local files.                                                                                         |
| cache.project\_grace\_period | Integer | default: `0 (seconds)`            | The number of seconds you can continue using this project configuration after cache expiry while a new state is being fetched. This is added on top of `cache.project_expiry` and `cache.miss_expiry`.                                              |
| cache.relay\_expiry          | Integer | default: `3600 (1 hour)`          | The cache timeout for downstream Relay info (public keys) in seconds. This is only relevant if you plan to connect further Relays to this one.                                                                                                      |
| cache.envelope\_expiry       | Integer | default: `600 (10 minutes)`       | The maximum amount of time Relay buffers incoming payloads in its cache in case of network issues or backlogs. This applies to all types of data sent to Relay, including events, attachments, and sessions. See also `cache.envelope_buffer_size`. |
| cache.miss\_expiry           | Integer | default: `60 (1 minute)`          | The cache timeout for non-existing entries.                                                                                                                                                                                                         |
| cache.batch\_interval        | Integer | default: `100 (100 milliseconds)` | The buffer timeout for batched queries before they are sent upstream **in milliseconds**.                                                                                                                                                           |
| cache.batch\_size            | Integer | default: `500`                    | The maximum number of project configs to be fetched from Sentry at once.                                                                                                                                                                            |
| cache.file\_interval         | Integer | default: `10 (10 seconds)`        | The interval for watching local cache override files in seconds.                                                                                                                                                                                    |
| cache.envelope\_buffer\_size | Integer | default: `1000`                   | The maximum number of incoming payloads that are buffered if network issues or backlogs happen. This applies to all types of data sent to Relay, including events, attachments, and sessions. See also `cache.envelope_expiry`.                     |
| cache.eviction\_interval     | Integer | default: `60 (seconds)`           | The interval for evicting outdated project configs from memory.                                                                                                                                                                                     |

## [Spooling](#spooling)

| key                               | type    | value            | description                                                                                                                                                                                                                     |
| --------------------------------- | ------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| spool.envelopes.path              | String  | default: `null`  | The path to the spool file used to save envelopes to disk. If provided, enables on-disk spooling. Relay will create the directory structure if needed. Note that `~` is interpreted as a literal and not as the home directory. |
| spool.envelopes.max\_memory\_size | String  | default: `500MB` | The maximum in-memory buffer for incoming envelopes. The buffer will be spooled to disk when the configured size is reached.                                                                                                    |
| spool.envelopes.max\_disk\_size   | String  | default: `500MB` | The maximum on-disk spool size.                                                                                                                                                                                                 |
| spool.envelopes.max\_connections  | Integer | default: `20`    | The maximum number of connections in the pool to manage on-disk spooling.                                                                                                                                                       |
| spool.envelopes.min\_connections  | Integer | default: `10`    | The minimum number of connections in the pool to manage on-disk spooling.                                                                                                                                                       |

## [Size Limits](#size-limits)

These settings control HTTP-related limits. All values are either integers, or are human-readable strings of a number and a human-readable unit, such as:

* `500B`
* `1kB` (*1,000* bytes)
* `1KB` or `1KiB` (*1,024* bytes)
* `1MB` (*1,000,000* bytes)
* `1MiB` (*1,048,576* bytes)

| key                                  | type    | value                     | description                                                                                                                                                                                                                                                                                                            |
| ------------------------------------ | ------- | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| limits.max\_concurrent\_requests     | Integer | default: `100`            | The maximum number of concurrent connections upstream. If supported by the upstream, Relay supports connection keep-alive.                                                                                                                                                                                             |
| limits.max\_concurrent\_queries      | Integer | default: `5`              | The maximum number of queries that can be sent concurrently from Relay upstream before Relay starts buffering requests. Queries are all requests made upstream for obtaining information and explicitly exclude event submission. The concurrency of queries is additionally constrained by `max_concurrent_requests`. |
| limits.max\_event\_size              | String  | default: `1MiB`           | The maximum payload size for events.                                                                                                                                                                                                                                                                                   |
| limits.max\_attachment\_size         | String  | default: `100MiB`         | The maximum attachment size.                                                                                                                                                                                                                                                                                           |
| limits.max\_attachments\_size        | String  | default: `100MiB`         | The maximum combined size for all attachments in an envelope or request.                                                                                                                                                                                                                                               |
| limits.max\_envelope\_size           | String  | default: `100MiB`         | The maximum payload size for an entire envelope. Individual limits still apply.                                                                                                                                                                                                                                        |
| limits.max\_session\_count           | Integer | default: `100`            | The maximum number of session items per envelope.                                                                                                                                                                                                                                                                      |
| limits.max\_api\_payload\_size       | String  | default: `20MiB`          | The maximum payload size for general API requests.                                                                                                                                                                                                                                                                     |
| limits.max\_api\_file\_upload\_size  | String  | default: `40MiB`          | The maximum payload size for file uploads and chunks.                                                                                                                                                                                                                                                                  |
| limits.max\_api\_chunk\_upload\_size | String  | default: `100MiB`         | The maximum payload size for chunks.                                                                                                                                                                                                                                                                                   |
| limits.max\_thread\_count            | Integer | default: `number of cpus` | The maximum number of threads spawned for each CPU and web worker. The total number of threads spawned will roughly be `2 * limits.max_thread_count + N`, where `N` is a fixed set of management threads.                                                                                                              |
| limits.query\_timeout                | Integer | default: `30 (seconds)`   | The maximum number of seconds a query can take across retries. Individual requests have lower timeouts.                                                                                                                                                                                                                |
| limits.shutdown\_timeout             | Integer | default: `10 (seconds)`   | The maximum number of seconds you'd have to wait for pending events after receiving a shutdown signal. `Environment variable: "SHUTDOWN_TIMEOUT".`                                                                                                                                                                     |

## [Logging](#logging)

| key                        | type    | value                                                                    | description                                                                                                                                                                                                                            |
| -------------------------- | ------- | ------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| logging.level              | String  | default: `info` possible values: `off, error, warn, info, debug, trace`. | The log level for the relay.##### WarningOn `debug` and `trace` levels, Relay emits extremely verbose messages which can have severe impact on application performance.. `Environment variable: "RELAY_LOG_LEVEL"`                     |
| logging.format             | String  | default: `auto` possible values: `auto, pretty, simplified, json`        | Controls the log format. `auto`: Auto detect (pretty for TTY, simplified for other) `pretty`: Human readable format with colors `simplified`: Simplified human readable log output `json`: JSON records, suitable for logging software |
| logging.enable\_backtraces | Boolean | default: `true`                                                          | Writes back traces for all internal errors to the log stream and includes them in Sentry errors.                                                                                                                                       |

## [StatsD Metrics](#statsd-metrics)

| key                   | type                      | value                   | description                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| --------------------- | ------------------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| metrics.statsd        | String                    | optional: `true`        | If set to a host/port string then metrics will be reported to this StatsD instance.                                                                                                                                                                                                                                                                                                                                                                                |
| metrics.prefix        | String                    | default: `sentry.relay` | The prefix that should be added to all metrics.                                                                                                                                                                                                                                                                                                                                                                                                                    |
| metrics.default\_tags | Map of strings to strings | default: `empty`        | A set of default tags that should be attached to all outgoing StatsD metrics.                                                                                                                                                                                                                                                                                                                                                                                      |
| metrics.hostname\_tag | String                    | optional: `true`        | If set, adds a tag of the given name and sets it to the hostname of the machine that is running Relay. This configuration is useful to distinguish multiple Relays.                                                                                                                                                                                                                                                                                                |
| metrics.buffering     | Boolean                   | default: `true`         | Determines if the emitted metrics will be buffered before sending to StatsD server. This generally improves performance, but comes with a caveat that with low traffic volume, metrics might take a few more seconds to propagate.                                                                                                                                                                                                                                 |
| metrics.sample\_rate  | Float                     | default: `1.0`          | Global sample rate for all emitted metrics. Should be between 0.0 and 1.0. If outside that range, the value will be normalized (negative values would become 0.0, positive larger than 1.0 would become 1.0). For instance, the value of 0.3 means that only 30% of the emitted metrics will be sent. Note that the implemented sampling approach isn't aware of metric types. For example, it won't rescale counter values when the sample rate is less than 1.0. |

## [Internal Error Reporting](#internal-error-reporting)

Configures error reporting for errors happening within Relay. Disabled by default.

| key            | type    | value            | description                                                                                                                                                                          |
| -------------- | ------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| sentry.enabled | Boolean | default: `false` | Determines whether to report internal errors to a separate DSN. `false` means that no internal errors will be sent, but will still be logged.                                        |
| sentry.dsn     | String  | optional: `true` | Sentry DSN to which you can report internal Relay failures. We recommend setting this to a value that sends Relay errors directly to Sentry instead of sending them to itself first. |

## [GeoIP](#geoip)

By default, Relay does not include geographical location information in events. Set the MaxMind database file path to add GeoIP info in events.

| key        | type   | value           | description                                                                                                              |
| ---------- | ------ | --------------- | ------------------------------------------------------------------------------------------------------------------------ |
| geoip.path | String | default: `null` | The path to the MaxMind GeoIP City database file. When set the additional GeoIP information will be added to the events. |
