SDK Options

Learn more about how to configure the SDK. These options are set when the SDK is first initialized, passed to the init function as an object.

Options are passed to the init() function as an object:

Copied
Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
  debug: true,
});

    dsn

    Typestring

    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

    Typeboolean
    Defaultfalse

    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

    Typestring

    Sets the release. 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.

    By default, the SDK will try to read this value from window.SENTRY_RELEASE.id if available.

    environment

    Typestring
    Defaultproduction

    Sets the environment. Defaults to development or production depending on whether the application is packaged.

    Environments tell you where an error occurred, whether that's in your production system, your staging server, or elsewhere.

    Sentry automatically creates an environment when it receives an event with the environment parameter set.

    Environments are case-sensitive. The environment name can't contain newlines, spaces or forward slashes, can't be the string "None", or exceed 64 characters. You can't delete environments, but you can hide them.

    tunnel

    Typestring

    Sets the URL that will be used to transport captured events. This can be used to work around ad-blockers or to have more granular control over events sent to Sentry. Adding your DSN is still required when using this option so necessary attributes can be set on the generated Sentry data. This option requires the implementation of a custom server endpoint. Learn more and find examples in Dealing with Ad-Blockers.

    sampleRate

    Typenumber
    Default1.0

    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 will be sent. If set to 0.1, only 10% of error events will be sent. Events are picked randomly.

    maxBreadcrumbs

    Typenumber
    Default100

    This variable controls the total amount of breadcrumbs that should be captured. You should be aware that Sentry has a maximum payload size and any events exceeding that payload size will be dropped.

    attachStacktrace

    Typeboolean
    Defaultfalse

    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.

    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.

    serverName

    Typestring
    Only available onServer

    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.

    ignoreErrors

    TypeArray<string | RegExp>
    Default[]

    A list of strings or regex patterns that match error messages that shouldn't be sent to Sentry. Messages that match these strings or regular expressions will be filtered out before they're sent to Sentry. When using strings, partial matches will be filtered out, so if you need to filter by exact match, use regex patterns instead. By default, all errors are sent.

    ignoreTransactions

    TypeArray<string | RegExp>
    Default[]

    A list of strings or regex patterns that match transaction names that shouldn't be sent to Sentry. Transactions that match these strings or regular expressions will be filtered out before they're sent to Sentry. When using strings, partial matches will be filtered out, so if you need to filter by exact match, use regex patterns instead. By default, transactions spanning typical API health check requests are filtered out.

    denyUrls

    TypeArray<string | RegExp>
    Default[]
    Only available onClient

    An array of strings or regex patterns that match the URLs of scripts where errors have been created. Errors that have been created on these URLs won't be sent to Sentry. If you use this option, errors will not be sent when the top stack frame file URL contains or matches at least one entry in the denyUrls array. All string entries in the array will be matched with stackFrameUrl.contains(entry), while all RegEx entries will be matched with stackFrameUrl.match(entry).

    This matching logic applies to captured exceptions not raw message events. By default, all errors are sent.

    allowUrls

    TypeArray<string | RegExp>
    Default[]
    Only available onClient

    An array of strings or regex patterns that match the URLs of scripts where errors have been created. Only errors that have been created on these URLs will be sent to Sentry. If you use this option, errors will only be sent when the top stack frame file URL contains or matches at least one entry in the allowUrls array. All string entries in the array will be matched with stackFrameUrl.contains(entry), while all RegEx entries will be matched with stackFrameUrl.match(entry).

    For example, if you add 'foo.com' to the array, errors created on https://bar.com/myfile/foo.com will be captured because URL will be matched with "contains" logic and the last segment of the URL contains foo.com.

    This matching logic applies for captured exceptions, not raw message events. By default, all errors are sent.

    If your scripts are loaded from cdn.example.com and your site is example.com, you can set allowUrls to the follwing to exclusively capture errors being created in scripts in these locations:

    Copied
    Sentry.init({
      allowUrls: [/https?:\/\/((cdn|www)\.)?example\.com/],
    });
    

    initialScope

    TypeCaptureContext

    Data to be set to the initial scope. Initial scope can be defined either as an object or a callback function, as shown below.

    Copied
    // Using an object
    Sentry.init({
      dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
      initialScope: {
        tags: { "my-tag": "my value" },
        user: { id: 42, email: "john.doe@example.com" },
      },
    });
    
    // Using a callback function
    Sentry.init({
      dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
      initialScope: (scope) => {
        scope.setTags({ a: "b" });
        return scope;
      },
    });
    

    maxValueLength

    Typenumber
    Default250

    Maximum number of characters a single value can have before it will be truncated.

    normalizeDepth

    Typenumber
    Default3

    Sentry SDKs normalize any contextual data to a given depth. Any data beyond this depth will be trimmed and marked using its type instead ([Object] or [Array]), without walking the tree any further. By default, walking is performed three levels deep.

    normalizeMaxBreadth

    Typenumber
    Default1000

    This is the maximum number of properties or entries that will be included in any given object or array when the SDK is normalizing contextual data. Any data beyond this depth will be dropped.

    enabled

    Typeboolean
    Defaulttrue

    Specifies whether this SDK should send events to Sentry. Setting this to enabled: false doesn't prevent all overhead from Sentry instrumentation. To disable Sentry completely, depending on environment, call Sentry.init conditionally.

    sendClientReports

    Typeboolean
    Defaulttrue

    Set this option 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.

    includeLocalVariables

    Typeboolean
    Defaultfalse
    Only available onServer

    Set this option to true to add stack local variables to stack traces.

    For more advanced configuration options, see the documentation on the Local Variables integration options.

    integrations

    TypeArray<Integration>
    Default[]

    Pass additional integrations that should be initialized with the SDK. Integrations are pieces of code that can be used to extend the SDK's functionality. They can be used to add custom event processors, context providers, or to hook into the SDK's lifecycle.

    See integration docs for more information.

    defaultIntegrations

    Typeundefined | false

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

    See integration docs to see how you can modify the default integrations.

    transport

    Type(transportOptions: TransportOptions) => Transport

    The JavaScript SDK uses a transport to send events to Sentry. On modern browsers, most transports use the browsers' fetch API to send events. Transports will drop an event if it fails to send due to a lack of connection.

    In the browser, a fetch-based transport is used by default.

    On the server, a https-based transport is used by default.

    transportOptions

    TypeTransportOptions

    Options used to configure the transport. This is an object with the following possible optional keys:

    • headers: An object containing headers to be sent with every request. - proxy: A proxy used for outbound requests. Can be http or https. - caCerts: A path or list of paths to a CA certificate, or a buffer of CA certificates. - httpModule: A custom HTTP module to use for requests. Defaults to the the native http and https modules. - keepAlive: Determines whether to keep the socket alive between requests. Defaults to false.
    • headers: An object containing headers to be sent with every request. Used by the SDK's fetch and XHR transports. - fetchOptions: An object containing options to be passed to the fetch call. Used by the SDK's fetch transport.

    shutdownTimeout

    Typenumber
    Default2000
    Only available onServer

    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.

    beforeSend

    Type(event: Event, hint: EventHint) => Event | null

    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 beforeSend is executed, all scope data has already been applied to the event. Further modification of the scope won't have any effect.

    beforeSendTransaction

    Type(event: TransactionEvent, hint: EventHint) => TransactionEvent | null

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

    beforeSendSpan

    Type(span: SpanJSON) => SpanJSON | null

    This function is called with a serialized span object, and can return a modified span object, or null to skip sending the span. This might be useful for manually stripping PII from spans or to remove individual spans from the span tree. This function is only called for child spans of the root span. If you want to modify or drop the root span, including all of its child spans, use beforeSendTransaction instead.

    beforeBreadcrumb

    Type(breadcrumb: Breadcrumb, hint?: BreadcrumbHint) => Breadcrumb | null

    This function is called with a 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 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.

    tracesSampleRate

    Typenumber

    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 tracesSampler must be defined to enable tracing.

    tracesSampler

    Type(samplingContext: SamplingContext) => number | boolean

    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 tracesSampleRate must be defined to enable tracing.

    The samplingContext object passed to the function has the following properties:

    • parentSampled: The sampling decision of the parent transaction. This is true if the parent transaction was sampled, and false if it was not.
    • name: The name of the span as it was started.
    • attributes: The initial attributes of the span.
      • normalizedRequest: Request information of the currently active HTTP server request, if applicable.

    tracePropagationTargets

    TypeArray<string | RegExp>

    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.

    On the browser, all outgoing requests to the same origin will be propagated by default.

    On the server, all outgoing requests will be propagated by default.

    If you want to disable trace propagation, you can set this option to [].

    replaysSessionSampleRate

    Typenumber
    Only available onClient

    The sample rate for replays that begin recording immediately and last the entirety of the user's session. 1.0 collects all replays, and 0 collects none.

    replaysOnErrorSampleRate

    Typenumber
    Only available onClient

    The sample rate for replays that are recorded when an error happens. This type of replay will record up to a minute of events prior to the error and continue recording until the session ends. 1.0 collects all sessions with an error, and 0 collects none.

    profilesSampleRate

    Typenumber

    A number between 0 and 1, controlling the percentage chance a given sampled transaction will be profiled. (0 represents 0% while 1 represents 100%.) Applies equally to all transactions created in the app. This is relative to the tracing sample rate - e.g. 0.5 means 50% of sampled transactions will be profiled.

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