Basic Options

SDKs are configurable using a variety of options. The options are largely standardized among SDKs, but there are some differences to better accommodate platform peculiarities. Options are set when the SDK is first initialized.

Options are passed to the init() function as optional keyword arguments:

Copied
import sentry_sdk

sentry_sdk.init(
    dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
    max_breadcrumbs=50,
    debug=True,
    enable_tracing=True,

    # By default the SDK will try to use the SENTRY_RELEASE
    # environment variable, or infer a git commit
    # SHA as release, however you may want to set
    # something more human-readable.
    # release="myapp@1.0.0",
)

The list of common options across SDKs. These work more or less the same in all SDKs, but some subtle differences will exist to better support the platform. Options that can be read from an environment variable (SENTRY_DSN, SENTRY_ENVIRONMENT, SENTRY_RELEASE) are read automatically.

dsn

The DSN tells the SDK where to send the events. If this value is not provided, the SDK will try to read it from the SENTRY_DSN environment variable. If that variable also does not exist, the SDK will just not send any events.

In runtimes without a process environment (such as the browser) that fallback does not apply.

Learn more about DSN utilization.

debug

Turns debug mode on or off. If debug is enabled SDK will attempt to print out useful debugging information if something goes wrong with sending the event. The default is always false. It's generally not recommended to turn it on in production, though turning debug mode on will not cause any safety concerns.

release

Sets the release. Some SDKs will try to automatically configure a release out of the box but it's a better idea to manually set it to guarantee that the release is in sync with your deploy integrations or source map uploads. Release names are strings, but some formats are detected by Sentry and might be rendered differently. Learn more about how to send release data so Sentry can tell you about regressions between releases and identify the potential source in the releases documentation or the sandbox.

By default the SDK will try to read this value from the SENTRY_RELEASE environment variable (in the browser SDK, this will be read off of the window.SENTRY_RELEASE.id if available).

environment

Sets the environment. This string is freeform and set to production by default. A release can be associated with more than one environment to separate them in the UI (think staging vs production or similar).

By default the SDK will try to read this value from the SENTRY_ENVIRONMENT environment variable.

sample_rate

Configures the sample rate for error events, in the range of 0.0 to 1.0. The default is 1.0 which means that 100% of error events are sent. If set to 0.1 only 10% of error events will be sent. Events are picked randomly.

error_sampler

Dynamically configures the sample rate for error events on a per-event basis. This configuration option accepts a function, which takes two parameters (the event and the hint), and which returns a boolean (indicating whether the event should be sent to Sentry) or a floating-point number between 0.0 and 1.0, inclusive (where the number indicates the probability the event is sent to Sentry; the SDK will randomly decide whether to send the event with the given probability).

If this configuration option is specified, the sample_rate option is ignored.

max_breadcrumbs

This variable controls the total amount of breadcrumbs that should be captured. This defaults to 100, but you can set this to any number. However, you should be aware that Sentry has a maximum payload size and any events exceeding that payload size will be dropped.

attach_stacktrace

When enabled, stack traces are automatically attached to all messages logged. Stack traces are always attached to exceptions; however, when this option is set, stack traces are also sent with messages. This option, for instance, means that stack traces appear next to all log messages.

This option is turned off by default.

Grouping in Sentry is different for events with stack traces and without. As a result, you will get new groups as you enable or disable this flag for certain events.

send_default_pii

If this flag is enabled, certain personally identifiable information (PII) is added by active integrations. By default, no such data is sent.

This option is turned off by default.

If you enable this option, be sure to manually remove what you don't want to send using our features for managing Sensitive Data.

event_scrubber

If send_default_pii is turned off, scrubs the event payload for sensitive information from a denylist. See how to configure the scrubber here.

include_source_context

When enabled, source context will be included in events sent to Sentry. This source context includes the five lines of code above and below the line of code where an error happened.

The option is enabled by default.

include_local_variables

When enabled, the SDK will capture a snapshot of local variables to send with the event to help with debugging.

This option is on by default.

server_name

This option can be used to supply a "server name." When provided, the name of the server is sent along and persisted in the event. For many integrations, the server name actually corresponds to the device hostname, even in situations where the machine is not actually a server.

Most SDKs will attempt to auto-discover this value.

in_app_include

A list of string prefixes of module names that belong to the app. This option takes precedence over in-app-exclude.

Sentry differentiates stack frames that are directly related to your application ("in application") from stack frames that come from other packages such as the standard library, frameworks, or other dependencies. The application package is automatically marked as inApp. The difference is visible in sentry.io, where only the "in application" frames are displayed by default.

in_app_exclude

A list of string prefixes of module names that do not belong to the app, but rather to third-party packages. Modules considered not part of the app will be hidden from stack traces by default.

This option can be overridden using in_app_include.

max_request_body_size

This parameter controls whether integrations should capture HTTP request bodies. It can be set to one of the following values:

  • never: Request bodies are never sent.
  • small: Only small request bodies will be captured. The cutoff for small depends on the SDK (typically 4KB).
  • medium: Medium and small requests will be captured (typically 10KB).
  • always: The SDK will always capture the request body as long as Sentry can make sense of it.

max_value_length

The number of characters after which the values containing text in the event payload will be truncated (defaults to 1024).

ca_certs

A path to an alternative CA bundle file in PEM-format.

request_bodies

Has been renamed to max_request_body_size.

with_locals

Has been renamed to include_local_variables.

send_client_reports

Set this boolean to false to disable sending of client reports. Client reports are a protocol feature that let clients send status reports about themselves to Sentry. They are currently mainly used to emit outcomes for events that were never sent.

For many platform SDKs integrations can be configured alongside it. On some platforms that happen as part of the init() call, in some others, different patterns apply.

integrations

In some SDKs, the integrations are configured through this parameter on library initialization. For more information, please see our documentation for a specific integration.

default_integrations

This can be used to disable integrations that are added by default. When set to false, no default integrations are added.

auto_enabling_integrations

This can be used to disable integrations that are enabled by default if the SDK detects that the corresponding framework or library is installed. When set to false, none of these integrations will be enabled by default, even if the corresponding framework/library is detected.

These options can be used to hook the SDK in various ways to customize the reporting of events.

before_send

This function is called with an SDK-specific message or error event object, and can return a modified event object, or null to skip reporting the event. This can be used, for instance, for manual PII stripping before sending.

By the time before_send is executed, all scope data has already been applied to the event. Further modification of the scope won't have any effect.

before_send_transaction

This function is called with an SDK-specific transaction event object, and can return a modified transaction event object, or null to skip reporting the event. One way this might be used is for manual PII stripping before sending.

before_breadcrumb

This function is called with an SDK-specific breadcrumb object before the breadcrumb is added to the scope. When nothing is returned from the function, the breadcrumb is dropped. To pass the breadcrumb through, return the first argument, which contains the breadcrumb object. The callback typically gets a second argument (called a "hint") which contains the original object from which the breadcrumb was created to further customize what the breadcrumb should look like.

Transports are used to send events to Sentry. Transports can be customized to some degree to better support highly specific deployments.

transport

Switches out the transport used to send events. How this works depends on the SDK. It can, for instance, be used to capture events for unit-testing or to send it through some more complex setup that requires proxy authentication.

http_proxy

When set, a proxy can be configured that should be used for outbound requests. This is also used for HTTPS requests unless a separate https-proxy is configured. However, not all SDKs support a separate HTTPS proxy. SDKs will attempt to default to the system-wide configured proxy, if possible. For instance, on Unix systems, the http_proxy environment variable will be picked up.

https_proxy

Configures a separate proxy for outgoing HTTPS requests. This value might not be supported by all SDKs. When not supported the http-proxy value is also used for HTTPS requests at all times.

proxy_headers

A dict containing additional proxy headers (usually for authentication) to be forwarded to urllib3's ProxyManager.

shutdown_timeout

Controls how many seconds to wait before shutting down. Sentry SDKs send events from a background queue. This queue is given a certain amount to drain pending events. The default is SDK specific but typically around two seconds. Setting this value too low may cause problems for sending events from command line applications. Setting the value too high will cause the application to block for a long time for users experiencing network connectivity problems.

keep_alive

Determines whether to keep the connection alive between requests. This can be useful in environments where you encounter frequent network issues such as connection resets.

socket_options

An optional list of socket options to use. These provide fine-grained, low-level control over the way the SDK connects to Sentry. If provided, the options will override the default urllib3 socket options.

Copied
import socket
from urllib3.connection import HTTPConnection

sentry_sdk.init(
    socket_options=HTTPConnection.default_socket_options + [
        (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
    ],
)

enable_tracing

A boolean value, if true, transactions and trace data will be generated and captured. This will set the traces-sample-rate to the recommended default of 1.0 if traces-sample-rate is not defined. Note that traces-sample-rate and traces-sampler take precedence over this option.

traces_sample_rate

A number between 0 and 1, controlling the percentage chance a given transaction will be sent to Sentry. (0 represents 0% while 1 represents 100%.) Applies equally to all transactions created in the app. Either this or traces_sampler must be defined to enable tracing.

If traces_sample_rate is 0, this means that no new traces will be created. However, if you have another service (for example a JS frontend) that makes requests to your service that include trace information, those traces will be continued and thus transactions will be sent to Sentry.

If you want to disable all tracing you need to set traces_sample_rate=None or set enable_tracing=False. In this case, no new traces will be started and no incoming traces will be continued.

traces_sampler

A function responsible for determining the percentage chance a given transaction will be sent to Sentry. It will automatically be passed information about the transaction and the context in which it's being created, and must return a number between 0 (0% chance of being sent) and 1 (100% chance of being sent). Can also be used for filtering transactions, by returning 0 for those that are unwanted. Either this or traces_sample_rate must be defined to enable tracing.

trace_propagation_targets

An optional property that controls which downstream services receive tracing data, in the form of a sentry-trace and a baggage header attached to any outgoing HTTP requests.

The option may contain a list of strings or regex against which the URLs of outgoing requests are matched. If one of the entries in the list matches the URL of an outgoing request, trace data will be attached to that request. String entries do not have to be full matches, meaning the URL of a request is matched when it contains a string provided through the option.

If trace_propagation_targets is not provided, trace data is attached to every outgoing request from the instrumented client.

functions_to_trace

An optional list of functions that should be set up for performance monitoring. For each function in the list, a span will be created when the function is executed. Functions in the list are represented as strings containing the fully qualified name of the function.

This is a convenient option, making it possible to have one central place for configuring what functions to trace, instead of having custom instrumentation scattered all over your code base.

To learn more, see the Custom Instrumentation documentation.

enable_backpressure_handling

When enabled, a new monitor thread will be spawned to perform health checks on the SDK. If the system is unhealthy, the SDK will keep halving the traces_sample_rate set by you in 10 second intervals until recovery. This downsampling helps ensure that the system stays stable and reduces SDK overhead under high load.

This option is enabled by default.

enable_db_query_source

When enabled, the source location will be added to database queries.

This option is enabled by default.

db_query_source_threshold_ms

The threshold in milliseconds for adding the source location to database queries. The query location will be added to the query for queries slower than the specified threshold.

Default is 100 ms.

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").