Configuration

Client options, environment variables, debug mode, and event sampling behavior.

Statusstable
Version1.0.0(changelog)

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
  • Hooksbefore_send and before_breadcrumb callback details

Stablespecified since 1.0.0

Core options that all SDKs MUST or SHOULD support:

OptionTypeDescription
dsnstringData Source Name. Empty/missing = no-op mode. MUST support.
releasestringApplication release version. Can only be set in options, not on scopes.
environmentstringDeployment environment. Defaults to production if not set.
sample_ratefloat [0,1]Error event sample rate. Default 1.0.
debugboolEnable debug logging. Default false. MUST support.
before_sendcallbackHook for error events. Return null to discard. MUST support. See Hooks.
before_send_transactioncallbackHook for transaction events. SHOULD support. See Hooks.
before_breadcrumbcallbackHook for breadcrumbs. See Hooks.
integrationsarrayIntegration instances. MUST support.
max_breadcrumbsintBreadcrumb ring buffer size.
send_default_piiboolWhether to include PII (cookies, user IP, etc.) by default.
max_attachment_sizeintMaximum attachment size in bytes. Default 20 MiB.
traces_sample_ratefloat [0,1]Trace/transaction sample rate.
traces_samplercallbackDynamic per-transaction sample rate.
trace_propagation_targetsarrayURL patterns for outgoing trace header injection.
context_tagsarrayList of logging context keys to convert to Sentry tags. See Log Context.
max_request_body_sizestringControls how large request bodies may be before the SDK skips attaching them. Server SDKs only. See Request Body Size.
Stablespecified since 1.0.0

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:

VariableDescription
SENTRY_DSNThe Data Source Name that tells the SDK where to send events.
SENTRY_RELEASEThe release version of the application. Used to associate events with source maps and track regressions.
SENTRY_ENVIRONMENTThe environment name, such as production, staging, or development.
SENTRY_SAMPLE_RATEControls the percentage of error events sent to Sentry (0.0 to 1.0).
SENTRY_TRACES_SAMPLE_RATEControls the percentage of transactions sent for tracing (0.0 to 1.0).
SENTRY_PROFILES_SAMPLE_RATEControls the percentage of transactions that include profiling data (0.0 to 1.0). Requires tracing to be enabled.
SENTRY_DEBUGEnables 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.

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:

Copied
// 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.

Stablespecified since 1.0.0

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:

  1. It helps users identify and fix SDK problems, such as misconfigurations or something going wrong with sending data to Sentry.
  2. 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 mode
  • info: Informational messages
  • warning: Warning that something might not be right
  • error: Only SDK internal errors are printed
  • fatal: 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.

Stablespecified since 1.0.0

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:

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

Copied
ignore_transactions = ['GET /api/health','/api/v1/*']
Stablespecified since 1.0.0

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:

ValueMax Size
noneNever attach the body
small1,000 bytes
medium10,000 bytes (default)
alwaysNo limit
Stablespecified since 1.0.0

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.

Copied
sentry_sdk.init(
    context_tags=["request_id", "tenant"],
)

VersionDateSummary
1.0.02025-02-24Initial spec, consolidated from client spec, expected features, and environment variables
Was this helpful?
Help improve this content
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").