Configuration
Client options, environment variables, debug mode, and event sampling behavior.
This spec defines the configuration surface of the Sentry Client — the options passed to Sentry.init(), environment variable support, debug mode behavior, and event sampling.
Related specs:
- Client — client lifecycle and event pipeline
- Hooks —
before_sendandbefore_breadcrumbcallback details
Core options that all SDKs MUST or SHOULD support:
| Option | Type | Description |
|---|---|---|
dsn | string | Data Source Name. Empty/missing = no-op mode. MUST support. |
release | string | Application release version. Can only be set in options, not on scopes. |
environment | string | Deployment environment. Defaults to production if not set. |
sample_rate | float [0,1] | Error event sample rate. Default 1.0. |
debug | bool | Enable debug logging. Default false. MUST support. |
before_send | callback | Hook for error events. Return null to discard. MUST support. See Hooks. |
before_send_transaction | callback | Hook for transaction events. SHOULD support. See Hooks. |
before_breadcrumb | callback | Hook for breadcrumbs. See Hooks. |
integrations | array | Integration instances. MUST support. |
max_breadcrumbs | int | Breadcrumb ring buffer size. |
send_default_pii | bool | Whether to include PII (cookies, user IP, etc.) by default. |
max_attachment_size | int | Maximum attachment size in bytes. Default 20 MiB. |
traces_sample_rate | float [0,1] | Trace/transaction sample rate. |
traces_sampler | callback | Dynamic per-transaction sample rate. |
trace_propagation_targets | array | URL patterns for outgoing trace header injection. |
context_tags | array | List of logging context keys to convert to Sentry tags. See Log Context. |
max_request_body_size | string | Controls how large request bodies may be before the SDK skips attaching them. Server SDKs only. See Request Body Size. |
Sentry SDKs SHOULD support a set of common environment variables that allow users to configure SDK behavior without modifying their code. This is particularly useful for containerized deployments, serverless environments, or when users need to adjust settings without redeploying their application.
The following environment variables SHOULD be supported across Sentry server-side SDKs:
| Variable | Description |
|---|---|
SENTRY_DSN | The Data Source Name that tells the SDK where to send events. |
SENTRY_RELEASE | The release version of the application. Used to associate events with source maps and track regressions. |
SENTRY_ENVIRONMENT | The environment name, such as production, staging, or development. |
SENTRY_SAMPLE_RATE | Controls the percentage of error events sent to Sentry (0.0 to 1.0). |
SENTRY_TRACES_SAMPLE_RATE | Controls the percentage of transactions sent for tracing (0.0 to 1.0). |
SENTRY_PROFILES_SAMPLE_RATE | Controls the percentage of transactions that include profiling data (0.0 to 1.0). Requires tracing to be enabled. |
SENTRY_DEBUG | Enables debug mode for troubleshooting SDK issues. |
SDKs MAY support additional SDK-specific environment variables beyond this common set. Any additional environment variables SHOULD be documented in the SDK's user-facing documentation.
Some SDKs may also offer additional SDK-specific environment variables beyond this common set. Check the platform-specific documentation for the full list of supported options.
When both environment variables and code-based configuration are present, code-based configuration MUST take precedence. If the user explicitly passes a value to the SDK's init function, the environment variable MUST be ignored.
To use environment variables, users omit the option from their init call and the SDK reads from the environment automatically:
// SDK will read from SENTRY_DSN automatically
Sentry.init({
// dsn omitted, will use SENTRY_DSN
});
Environment variables work differently in client-side environments like web browsers, where the concept of environment variables doesn't exist at runtime. For frontend SDKs, values MUST be injected by users at build time or configured directly in code.
For server-side SDKs (Node.js, Python, Ruby, Java, .NET, Go, PHP, etc.), environment variables are read at runtime when the SDK initializes.
Every SDK must implement a debug mode, which is disabled by default. Users can enable it by setting the option debug to true. If the debug mode is enabled, the SDK prints out useful debugging information for two main purposes:
- It helps users identify and fix SDK problems, such as misconfigurations or something going wrong with sending data to Sentry.
- It can help Sentry SDK engineers investigate issues in Sentry SDKs, which can be done while developing or by asking a user to enable the debug mode and share the debug logs.
As the log output can add unnecessary overhead, we advise users to refrain from enabling the debug mode in production. Still, SDKs may log fatal error messages even when the debug mode is disabled. When using debug mode extensively for the second use case, we recommend adding the diagnostic level because users could easily miss error or fatal log messages.
SDKs may offer an optional diagnostic level, which controls the verbosity of the debug mode. There are five different levels:
debug: The most verbose modeinfo: Informational messageswarning: Warning that something might not be righterror: Only SDK internal errors are printedfatal: Only critical errors are printed
The default level can be debug or error depending on the SDK's usage of log messages. When the volume of log message is low, the default can be debug. When it is high, users might easily miss errors or fatal messages. In that case, the SDK should set the default level to error. This choice must be clearly documented in the user-facing docs.
So users can easily spot errors during development, the SDK can automatically enable debug mode when it reliably detects it's running in a debug build. When doing so, the SDK must communicate this in the docs and with a log message when initializing the SDK. When the user explicitly sets the debug option to false, the SDK must disable the debug mode.
SDKs should allow the user to configure what percentage of events are actually sent to the server (the rest should be silently ignored). For example:
sample_rate = options.get('sample_rate', 1.0)
# assuming random() returns a value between 0.0 (inclusive) and 1.0 (exclusive)
if random() < sample_rate:
transport.capture_event(event)
To further simplify ignoring certain events from being sent to sentry, it is also suggested to provide ignoreTransactions and ignoreErrors (or exception, choose terminology which is best for the platform). The array for ignoreTransactions specifically should contain an array of transaction names, as is stored in the transaction event schema (ie GET /info). These options should provide a simple way to allow users to discard events (ignore) from before they are sent to sentry. Prevents sending data which is undesired and may consume quota or resources on the Sentry server.
ignore_transactions = ['GET /api/health','/api/v1/*']
Server SDKs SHOULD support attaching the incoming HTTP request body to events. The max_request_body_size option controls the maximum body size the SDK will attach. The SDK defines the actual byte thresholds for each setting:
| Value | Max Size |
|---|---|
none | Never attach the body |
small | 1,000 bytes |
medium | 10,000 bytes (default) |
always | No limit |
Some logging frameworks provide an option to set logging context. In Java this is called MDC (Mapped Diagnostic Context).
SDKs that integrate with platform logging frameworks SHOULD support a context_tags configuration option. This option accepts a list of logging context keys whose values the SDK converts to Sentry tags on captured events.
sentry_sdk.init(
context_tags=["request_id", "tenant"],
)
| Version | Date | Summary |
|---|---|---|
1.0.0 | 2025-02-24 | Initial spec, consolidated from client spec, expected features, and environment variables |
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").