Options for Capacitor
Learn more about how the Sentry JavaScript SDK can be configured via options. These are being passed to the init function and therefore set when the SDK is first initialized.
dsn
| Type | string |
|---|
The DSN tells the SDK where to send the events. If this is not set, the SDK will not send any events. Learn more about DSN utilization.
Sentry.init({
dsn: "___PUBLIC_DSN___",
});
Sentry.init({
dsn: "___PUBLIC_DSN___",
});
orgId
| Type | `${number}` | number |
|---|
The organization ID for your Sentry project.
The SDK will try to extract the organization ID from the DSN. If it cannot be found, or if you need to override it, you can provide the ID with this option. The organization ID is used for trace propagation.
debug
| Type | boolean |
|---|---|
| Default | false |
Turns debug mode on or off. If debug is enabled SDK will attempt to print out useful debugging information about what the SDK is doing.
release
| Type | string |
|---|
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.
In the browser, the SDK will try to read this value from window.SENTRY_RELEASE.id if available.
environment
| Type | string |
|---|---|
| Default | production |
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
| Type | string |
|---|
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.
dataCollection
| Available since | 10.57.0 |
|---|---|
| Type | DataCollection |
Controls which categories of data the SDK collects automatically. All fields are optional. By default the SDK collects rich debugging context (including user identity, request/response bodies, and generative AI content) and scrubs values whose keys match the built-in sensitive denylist (auth, token, password, and similar).
In version 10 of the SDK, the defaults below apply only when you set the dataCollection option. Without it, the deprecated sendDefaultPii option controls data collection. Starting with version 11, the defaults always apply.
For more on what data Sentry collects and how to control it, see Data Management.
| Key | Type | Default | Description |
|---|---|---|---|
userInfo | boolean | true | Populate user.* fields (id, email, username, ip_address) from instrumentation. For example, the SDK infers the IP address from an incoming HTTP request. Data you set with Sentry.setUser() is always sent. |
cookies | CollectBehavior | true | Collect cookies. Cookie names are always included. The SDK replaces the values of sensitive cookies with [Filtered]. |
httpHeaders | CollectBehavior | { request?, response? } | both true | Collect HTTP request and response headers. Pass one CollectBehavior for both directions, or use { request, response } to control each direction. Header names are always included. |
httpBodies | HttpBodyCollectionTarget[] | all types | Body types to collect: "incomingRequest", "outgoingRequest", "incomingResponse", "outgoingResponse". Set to [] to disable. |
urlQueryParams | CollectBehavior | true | Collect URL query parameters. Parameter names are always included. The SDK replaces the values of sensitive parameters with [Filtered]. |
graphQL | { document?, variables? } | both true | document: Collect the GraphQL document (the query or mutation source text). variables: Collect the variables that are passed to GraphQL operations. The operation name and type are always collected. |
genAI | { inputs?, outputs? } | both true | inputs: Collect the content of generative AI inputs: system instructions, prompt messages, tool definitions, and tool call arguments. outputs: Collect the content of generative AI outputs, such as completion text and tool call results. Metadata, such as the model name and token counts, is always collected. Options set on an AI integration take precedence over these values. |
databaseQueryData | boolean | true | Collect the data associated with database queries: bound query parameters, data payloads for write operations, and returned result data. The sanitized or parameterized query text ( db.query.text) is not controlled by this option. Structural metadata, such as the database system, query summary, operation name, and table, is also always collected. |
queues | boolean | true | Collect the arguments passed to tasks within queues. For Kafka, this is the message key. Structural metadata, such as the messaging system, the destination name, and the operation, is always collected. |
stackFrameVariables | boolean | true | Capture local variable values in stack frames. |
frameContextLines | number | 5 | Number of source code lines captured above and below each stack frame. |
The cookies, httpHeaders, and urlQueryParams categories accept a CollectBehavior value:
type CollectBehavior = boolean | { allow: string[] } | { deny: string[] };
// true → collect all (sensitive denylist still scrubs values)
// false → collect nothing
// { deny: [] } → collect all, extending the denylist with the given terms
// { allow: [] } → only the listed keys send their real value
type CollectBehavior = boolean | { allow: string[] } | { deny: string[] };
// true → collect all (sensitive denylist still scrubs values)
// false → collect nothing
// { deny: [] } → collect all, extending the denylist with the given terms
// { allow: [] } → only the listed keys send their real value
The SDK matches denylist terms against key names. The match is partial and case-insensitive. For example, the term auth matches Authorization and X-Auth-Token. The built-in sensitive denylist always applies, also to keys in an allow list:
["auth", "token", "secret", "password", "passwd", "pwd", "key", "jwt", "bearer", "sso", "saml", "csrf", "xsrf", "credentials", "session", "sid", "identity"]
Some headers, cookies, and query parameters identify a user without being credentials, such as x-forwarded-for or x-user-id. To filter these values too, extend the denylist with these terms: ["forwarded", "-ip", "remote-", "via", "-user"].
dataCollection does not affect Session Replay. Use the Replay privacy options to control what Replay captures.
maxBreadcrumbs
| Type | number |
|---|---|
| Default | 100 |
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
| Type | boolean |
|---|---|
| Default | true |
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 messages captured with Sentry.captureMessage().
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.
initialScope
| Type | CaptureContext |
|---|
Data to be set to the initial scope. Initial scope can be defined either as an object or a callback function, as shown below.
// Using an object
Sentry.init({
dsn: "___PUBLIC_DSN___",
initialScope: {
tags: { "my-tag": "my value" },
user: { id: 42, email: "john.doe@example.com" },
},
});
// Using a callback function
Sentry.init({
dsn: "___PUBLIC_DSN___",
initialScope: (scope) => {
scope.setTags({ a: "b" });
return scope;
},
});
// Using an object
Sentry.init({
dsn: "___PUBLIC_DSN___",
initialScope: {
tags: { "my-tag": "my value" },
user: { id: 42, email: "john.doe@example.com" },
},
});
// Using a callback function
Sentry.init({
dsn: "___PUBLIC_DSN___",
initialScope: (scope) => {
scope.setTags({ a: "b" });
return scope;
},
});
maxValueLength
| Type | number |
|---|
Maximum number of characters every string property on events sent to Sentry can have before it will be truncated.
normalizeDepth
| Type | number |
|---|---|
| Default | 3 |
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
| Type | number |
|---|---|
| Default | 1000 |
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
| Type | boolean |
|---|---|
| Default | true |
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
| Type | boolean |
|---|---|
| Default | true |
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.
integrations
| Type | Array<Integration> | (integrations: Array<Integration>) => Array<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
| Type | undefined | 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.
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.
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.
transportOptions
| Type | TransportOptions |
|---|
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.fetchOptions: An object containing options to be passed to thefetchcall. Used by the SDK's fetch transport.
sampleRate
| Type | number |
|---|---|
| Default | 1.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.
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.
enhanceFetchErrorMessages
| Available since | 10.34.0 |
|---|---|
| Type | 'always' | 'report-only' | false |
| Default | always |
Controls whether fetch error messages are enhanced by appending the request’s hostname. When enabled, generic fetch errors like "Failed to fetch" will be enhanced to include the hostname (e.g., "Failed to fetch (example.com)") to provide better context in Sentry.
Available options:
'always'(default): Modifies the actual error message directly. This may break third-party packages that rely on exact message matching (e.g.,is-network-error,p-retry).'report-only': Only enhances the message when sending to Sentry. The original error message remains unchanged, preserving compatibility with third-party packages that also check error messages.false: Disables hostname enhancement completely.
ignoreErrors
| Type | Array<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.
denyUrls
| Type | Array<string | RegExp> |
|---|---|
| Default | [] |
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 option checks the source file URL in the stack trace, not the HTTP URL where the error was reported. For more fine grained filtering please refer to beforeSend.
This matching logic applies to captured exceptions not raw message events. By default, all errors are sent.
allowUrls
| Type | Array<string | RegExp> |
|---|---|
| Default | [] |
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 following to exclusively capture errors being created in scripts in these locations:
Sentry.init({
allowUrls: [/https?:\/\/((cdn|www)\.)?example\.com/],
});
Sentry.init({
allowUrls: [/https?:\/\/((cdn|www)\.)?example\.com/],
});
If you're using stream mode, tracing options work the same way as described but apply to service spans instead of transactions.
tracesSampleRate
| Type | number |
|---|
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 istrueif the parent transaction was sampled, andfalseif it was not.name: The name of the span as it was started.attributes: The initial attributes of the span.
tracePropagationTargets
| Type | Array<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.
If you want to disable trace propagation, you can set this option to [].
beforeSendSpan
| Type | (span: StreamedSpanJSON) => StreamedSpanJSON |
|---|
Called for each finished span before it is sent to Sentry, including service spans and their child spans. Return the modified span to rename it or remove sensitive data. Check span.is_segment to apply changes only to service spans.
beforeSendSpan can only modify spans. It cannot drop them or return null. Use ignoreSpans to drop spans.
The callback receives a serialized StreamedSpanJSON object, not a Span instance. Sentry.spanToJSON() returns the same shape.
With traceLifecycle: 'static', wrap the callback with Sentry.withStaticSpan() to receive and return SpanJSON. The static callback runs for the transaction and its child spans. A callback that doesn't match the trace lifecycle is ignored.
beforeSendTransaction
| Type | (event: TransactionEvent, hint: EventHint) => TransactionEvent | null |
|---|
This callback has no effect in stream mode. Use beforeSendSpan to modify spans and check span.is_segment to target service spans. Use ignoreSpans to drop spans.
With traceLifecycle: 'static', this callback receives a transaction event and an event hint after all event processors have run. Return the modified event to change its data, or null to drop the transaction and its child spans.
ignoreSpans
| Available since | 10.2.0 |
|---|---|
| Type | Array<string | RegExp | {name?: string | RegExp, op?: string | RegExp, attributes?: Record<string, string | number | boolean | null | undefined>}> |
| Default | [] |
A list of strings or regex patterns matching spans that shouldn't be 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. You can also provide an object with name, op, and attributes properties to match on multiple conditions. At least one property must be provided.
If a matching span is a service span, its child spans are also dropped. If a child span matches, its children will be reparented to the dropped span's parent span. By default, no spans are ignored.
In stream mode, ignoreSpans is evaluated at span start, so only the span name and attributes available at that point are taken into account. Any name updates or additional attributes added while the span is active won't influence whether the span is dropped.
In transaction mode, ignoreSpans is evaluated when the transaction ends, using the span's final name and attributes.
To inspect the initial names of automatically created spans, enable SDK debug logging during development with debug: true.
ignoreTransactions
| Type | Array<string | RegExp> |
|---|---|
| Default | [] |
This option has no effect in stream mode. Use ignoreSpans to filter spans by name, operation, or attributes.
With traceLifecycle: 'static', this option filters transaction names against a list of strings and regular expressions. Strings match part of the name. Use a regular expression anchored with ^ and $ for an exact match. A matching transaction and its child spans are dropped.
propagateTraceparent
| Available since | 10.10.0 |
|---|---|
| Type | boolean |
| Default | false |
If set to true, the SDK adds the W3C traceparent header to outgoing Http requests made via fetch or XMLHttpRequest. This header is attached in addition to the sentry-trace and baggage headers. Set this option to true if your backend services are instrumented with e.g. OpenTelemetry or other W3C Trace Context compatible libraries and you want to continue traces from the client.
Important: Make sure that your backend services' CORS configuration allows the traceparent header. Otherwise, requests might be blocked. Use the tracePropagationTargets option to control which requests the traceparent header is attached to. See Dealing with CORS Issues for more information.
If your backend uses an OTel collector with tail-based sampling, see Sentry with OTel for an important interaction with this option.
traceLifecycle
| Available since | 10.53.1 |
|---|---|
| Type | 'static' | 'stream' |
| Default | 'stream' (since version 11.0.0) |
Controls how spans are sent to Sentry:
- In stream mode (
'stream', the default), spans are sent in batches as they finish. - In transaction mode (
'static'), spans are collected in memory and sent as a transaction once the root span ends. This mode is available for backwards compatibility.
To opt out of span streaming, set traceLifecycle: 'static'. If you use beforeSendSpan, wrap it with Sentry.withStaticSpan() to receive the SpanJSON format:
Sentry.init({
traceLifecycle: "static",
beforeSendSpan: Sentry.withStaticSpan((span) => {
span.description = "[filtered]";
return span;
}),
});
Sentry.init({
traceLifecycle: "static",
beforeSendSpan: Sentry.withStaticSpan((span) => {
span.description = "[filtered]";
return span;
}),
});
On SDK versions below 10.71.0, logs are opt-in. Set enableLogs: true in your Sentry.init to send them.
beforeSendLog
| Type | (log: Log) => Log | null |
|---|
This function is called with a log object, and can return a modified log object, or null to skip sending this log to Sentry. This can be used, for instance, for manual PII stripping before sending, or to add custom attributes to all logs.
beforeSendMetric
| Type | (metric: Metric) => Metric | null |
|---|
This function is called with a metric object, and can return a modified metric object, or null to skip sending this metric to Sentry. This can be used, for instance, for manual PII scrubbing before sending, or to add custom attributes to all metrics.
replaysSessionSampleRate
| Type | number |
|---|
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
| Type | number |
|---|
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.
profileSessionSampleRate
| Available since | 10.27.0 |
|---|---|
| Type | number |
| Default | 0 |
A number between 0 and 1 that sets the percentage of how many sessions should have profiling enabled. 1.0 enables profiling in every session, 0.5 enables profiling for 50% of the sessions, and 0 enables it for none. The sampling decision is made once at the beginning of a session. This option is required to enable profiling (default is 0).
In a server environment, a profiling session starts when the Sentry SDK is initialized and stops when the service terminates. Therefore, the sampling decision is re-evaluated on service restart or redeployment.
In a browser environment, a profiling session corresponds to a user session. A user session starts with a new SDK initialization on page load and ends when the browser tab is closed.
profileLifecycle
| Available since | 10.27.0 |
|---|---|
| Type | "trace" | "manual" |
| Default | "manual" |
Determines how profiling sessions are controlled. It has two modes:
'manual'(default): You control when profiling starts and stops using thestartProfiler()andstopProfiler()functions. In this mode, profile sampling is only affected byprofileSessionSampleRate.'trace': Profiling starts and stops automatically with transactions, as long as tracing is enabled. The profiler runs as long as there is at least one sampled transaction. In this mode, profiling is affected by bothprofileSessionSampleRateand your tracing sample rate (tracesSampleRateortracesSampler).
experimental
| Type | Object |
|---|
An optional property that configures which features are in experimental mode. This property is either an Object Type with properties or a key/value TypedDict, depending the language. Experimental features are still in-progress and may have bugs. We recognize the irony.
enableNative
| Type | boolean |
|---|---|
| Default | true |
Set this option to false to disable the native SDK. This will disable all native crash and error handling and, instead, the SDK will only capture errors on the upper layer.
enableAutoSessionTracking
| Type | boolean |
|---|---|
| Default | true |
Set this option to false to disable the release health feature.
sessionTrackingIntervalMillis
| Type | number |
|---|---|
| Default | 30000 |
Set this to change the default interval to end a session (release health) if the app goes to the background. Default is 30,000.
enableNdkScopeSync
| Type | boolean |
|---|---|
| Default | true |
Set this option to false to disable the scope sync from Java to NDK on Android.
attachThreads
| Type | boolean |
|---|---|
| Default | false |
Set this option to true to automatically attach all threads to all logged events on Android.
enableOutOfMemoryTracking
Set this option to false to disable out of memory tracking on iOS.
enableNativeCrashHandling
| Type | boolean |
|---|---|
| Default | true |
Set this option to false to disable hard crash handling from the native layer. Doing so means that the SDK won't capture events for hard crashes on Android and iOS if the error was caused by native code.
enableNativeNagger
| Type | boolean |
|---|---|
| Default | true |
Set this option to false to disable the native nagger alert being shown.
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").