Options

Learn more about how the SDK can be configured via options. These are being passed to the init function and therefore set when the SDK is first initialized.

    dsn

    Typestring

    Note: Electron main process only.

    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.

    Copied
    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

    Typeboolean
    Defaultfalse

    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

    Typestring

    Note: Electron main process only.

    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.

    The SDK will read properties from the Electron app module to create the release in the format appName@version.

    environment

    Typestring
    Defaultproduction

    Note: Electron main process only.

    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.

    sendDefaultPii

    Typeboolean
    Defaultfalse

    Set this option to true to send default PII data to Sentry. Among other things, enabling this will enable automatic IP address collection on events.

    For backwards compatibility, sendDefaultPii: true behaves like enabling all dataCollection categories. If both options are set, dataCollection takes precedence.

    dataCollection

    Available since10.57.0
    TypeDataCollection

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

    For more on what data Sentry collects and how to control it, see Data Management.

    KeyTypeDefaultDescription
    userInfobooleantruePopulate user.* fields (id, email, username, ip_address) from instrumentation.
    cookiesCollectBehaviortrueCollect cookies.
    httpHeaders{ request?, response? }both trueCollect HTTP request and response headers.
    httpBodiesHttpBodyCollectionTarget[]all typesBody types to collect: "incomingRequest", "outgoingRequest", "incomingResponse", "outgoingResponse". Set to [] to disable.
    urlQueryParamsCollectBehaviortrueCollect URL query parameters.
    genAI{ inputs?, outputs? }both trueCollect generative AI input/output content. Metadata is always collected.
    stackFrameVariablesbooleantrueCapture local variable values in stack frames.
    frameContextLinesnumber5Source code lines captured around each stack frame.

    The cookies, httpHeaders, and urlQueryParams categories accept a CollectBehavior value:

    Copied
    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
    

    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

    Enabled per Electron process.

    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.

    autoSessionTracking

    Typeboolean
    Defaulttrue

    Note: Electron main process only.

    When not set to false, the SDK tracks sessions linked to the lifetime of the Electron main process.

    initialScope

    TypeCaptureContext

    Note: Electron main process only.

    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: "___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

    Typenumber

    Maximum number of characters every string property on events sent to Sentry 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.

    integrations

    TypeArray<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

    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.

    beforeBreadcrumb

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

    Controls breadcrumb capture in the Electron process where callback is set.

    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

    In the Electron main process, the default transport handles queuing events when the users device is offline. In Electron renderer processes, the default transport forwards events to the main process.

    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.
    • fetchOptions: An object containing options to be passed to the fetch call. Used by the SDK's fetch transport.

    Options for Electron offline support:

    The Electron SDK provides built-in offline support that queues events when the app is offline and automatically sends them once the connection is restored. These options let you configure the following behavior:

    • maxAgeDays: The maximum number of days to keep an envelope in the queue.
    • maxQueueSize: The maximum number of envelopes to keep in the queue.
    • flushAtStartup: Whether the offline store should flush shortly after application startup. Defaults to false.
    • shouldSend: Called before the SDK attempts to send an envelope to Sentry. If this function returns false, shouldStore will be called to determine if the envelope should be stored. Defaults to () => true.
    • shouldStore: Called before an event is stored. Return false to drop the envelope rather than store it. Defaults to () => true.

    Check out the Offline Support documentation for a complete example.

    ipcMode

    Type'IPCMode.Classic' | 'IPCMode.Protocol' | 'IPCMode.Both'
    Default'IPCMode.Both'

    Note: Electron main process only.

    Inter-process communication mode to receive event and scope updates from renderer processes.

    Available options are:

    • IPCMode.Classic - Configures Electron IPC modules
    • IPCMode.Protocol - Configures a custom protocol and fetch
    • IPCMode.Both (default) - Configures both modes for maximum compatibility

    ipcNamespace

    Typestring

    Custom namespace for the inter-process communication (IPC) channels used by the Sentry Electron SDK. This is useful when your Electron application uses multiple IPC channels and you want to prevent potential conflicts between them.

    Copied
    import * as Sentry from "@sentry/electron/main";
    
    Sentry.init({
      dsn: "___PUBLIC_DSN___",
      ipcNamespace: "myCustomNamespace",
    });
    

    When set, the IPC channels used by Sentry will be prefixed with the specified namespace. Note that you need to configure the same namespace in your main process, renderer processes, and preload scripts for proper communication. See the Custom IPC Namespace section for complete setup instructions.

    getSessions

    Type() => Electron.Session[]
    Default() => [session.defaultSession]

    A function that returns an array of Electron session objects. These sessions are used to configure communication between the Electron main and renderer processes.

    getRendererName

    Type(contents: WebContents) => string | undefined

    Callback function that allows custom naming of renderer processes. If the callback is not set, or it returns undefined, the default naming scheme is used.

    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.

    In the Electron main process sampleRate applies to events captured all processes. In Electron renderer processes, the sampleRate only applies to that process.

    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.

    In the Electron main process beforeSend is called for events captured in all processes. In Electron renderer processes, beforeSend only applies to that process.

    enhanceFetchErrorMessages

    Available since10.34.0
    Type'always' | 'report-only' | false
    Defaultalways

    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

    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.

    In the Electron main process ignoreErrors applies to events captured in all processes. In Electron renderer processes, ignoreErrors applies only to that process.

    Note: For Electron, tracing options apply to the process where these options are set.

    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.

    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.

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

    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

    This function is called with a serialized span object, and can return a modified span object. This might be useful for manually stripping PII from spans. This function is called for root spans as well as for all child spans. If you want to drop the root span, including all of its child spans, use beforeSendTransaction instead.

    Please note that the span you receive as an argument is a serialized object, not a Span class instance.

    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.

    ignoreSpans

    Available since10.2.0
    TypeArray<string | RegExp | {name?: string | RegExp, op?: string | RegExp}>
    Default[]

    A list of strings or regex patterns matching span names 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 a name and op property to match both the span name and the operation name. Note that at least name or op must be provided.

    If a root span matches any of the specified patterns, the entire local trace will be dropped. If a child span matches, its children will be reparented to the dropped span's parent span.

    By default, no spans are ignored.

    Here are some predefined matches for common spans to get you started:

    Copied
    Sentry.init({
      ignoreSpans: [
        // Browser connection events
        { op: /^browser\.(cache|connect|DNS)$/ },
    
        // Fonts
        { op: "resource.other", name: /.+\.(woff2|woff|ttf|eot)$/ },
    
        // CSS files
        { op: "resource.link", name: /.+\.css.*$/ },
    
        // JS files
        { op: /resource\.(link|script)/, name: /.+\.js.*$/ },
    
        // Images
        {
          op: /resource\.(other|img)/,
          name: /.+\.(png|svg|jpe?g|gif|bmp|tiff?|webp|avif|heic?|ico).*$/,
        },
    
        // Measure spans
        { op: "measure" },
      ],
    });
    

    propagateTraceparent

    Available since10.10.0
    Typeboolean
    Defaultfalse

    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.

    streamGenAiSpans

    Available since10.53.0
    Typeboolean
    Defaulttrue (since version 10.61.0)

    When enabled, gen_ai spans are sent as standalone envelope items instead of being bundled in the transaction payload. This prevents AI spans with large inputs and outputs from being dropped due to transaction payload size limits.

    This is enabled by default starting with SDK version 10.61.0 (before that, it defaulted to false). Set it to false to send gen_ai spans as part of the transaction instead.

    Self-hosted Sentry users should set this option to false, as standalone gen_ai spans may not be ingested by their Sentry instance.

    Note: For Electron, log options apply to the process where these options are set.

    enableLogs

    Typeboolean
    Defaultfalse

    Set this option to true to enable log capturing in Sentry. Only when this is enabled will the logger APIs actually send logs to Sentry.

    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.

    Note: For Electron, metric options apply to the process where these options are set.

    enableMetrics

    Typeboolean
    Defaulttrue

    Set this option to false to disable metric capturing in Sentry (enabled by default). Only when this option is enabled will the metrics APIs actually send metrics to Sentry.

    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.

    profileSessionSampleRate

    Available since7.4.0
    Typenumber

    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.

    profileLifecycle

    Available since7.4.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 the startProfiler() and stopProfiler() functions. In this mode, profile sampling is only affected by profileSessionSampleRate.
      Read more about these functions in the profiling API documentation.
    • '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 both profileSessionSampleRate and your tracing sample rate (tracesSampleRate or tracesSampler).

    profilesSampleRate

    Typenumber

    Deprecated: Use profileSessionSampleRate instead to configure continuous profiling from version 7.4.0 onwards.

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