Configuration
Full reference for Sophonz Browser SDK initialization options, and the remote configuration that turns instrumentation on and off from the server.
Complete reference for all options accepted by SophonzSDK.init() and the remote configuration that lets you control instrumentation from the server side.
Configuration Options
| Option name | Type | Required | Description |
|---|---|---|---|
collectorUrl | string | optional | URL of the collector endpoint. Defaults to https://in.sophonz.ai. |
authorizationToken | string | optional | Authentication token sent to the collector. |
appName | string | optional | App name (must match the package name registered in the console). Required for telemetry storage. |
appKey | string | optional | App key issued by the Sophonz console. Required for telemetry storage. |
appVersion | string | optional | App version. Required for telemetry storage. A warning is raised if the value is empty or not a string. In WebView environments the native SDK supplies this value. |
project | string | optional | Project. Required when monitoring multiple services (Android, iOS, Web, etc.) as a unified group. If empty, service.namespace is not sent. |
deploymentEnvironment | string | optional | Deployment environment (e.g. production, staging). Sets the environment attribute propagated via setGlobalAttributes(). |
defaultAttributes | Attributes | optional | Default resource attributes added to every Span as global attributes. |
samplingProbability | number | string | optional | Sampling probability between 0 and 1. Defaults to 1 (sample everything). |
advancedNetworkCapture | boolean | optional | Enables detailed capture of network request and response bodies. Defaults to false. |
blockClass | string | optional | CSS class of elements that should be masked in session replay. |
consoleCapture | boolean | optional | Enables console log capture. Defaults to false. |
debug | boolean | optional | Enables debug mode with additional logging. Defaults to false. |
disableIntercom | boolean | optional | Disables the Intercom integration. Defaults to false. |
disableReplay | boolean | optional | Disables session replay. Defaults to true. |
ignoreClass | string | optional | CSS class of elements to ignore in session replay. |
ignoreUrls | Array<string | RegExp> | optional | URL patterns to exclude from tracing. Accepts strings or regular expressions; partial and exact matches are excluded. |
instrumentations | Instrumentations | optional | Per-instrumentation configuration overrides. Defaults to {}. |
maskAllInputs | boolean | optional | Masks all input element values. Defaults to true. |
maskAllText | boolean | optional | Masks all text content. Defaults to false. |
maskClass | string | optional | CSS class whose text content will be masked. |
recordCanvas | boolean | optional | Enables recording of canvas element content. Defaults to false. |
sampling | number | optional | Session recorder sampling rate between 0 and 1. |
tracePropagationTargets | Array<string | RegExp> | optional | Domains or regular expressions to which trace headers are propagated automatically. |
webVitals | boolean | optional | Enables Web Vitals instrumentation. Defaults to true. |
websocket | boolean | optional | Enables WebSocket instrumentation. Defaults to false. |
socketio | boolean | optional | Enables Socket.IO instrumentation. Defaults to false. |
captureMetrics | boolean | optional | Reserved. Defaults to false. See the option details below for what it currently does. |
disablePreflight | boolean | optional | Disables CORS preflight (OPTIONS) requests. Defaults to false. |
exporterProtocol | json | proto | optional | Exporter protocol. Defaults to json. |
screenNameOption | ScreenNameOption | optional | Screen name collection options. Defaults to { screenNameType: "routeOnly", urlWithSearchParams: false }. |
sanitizeUrl | (url: string) => string | optional | Replaces the default URL sanitizer. URL redaction is applied whether or not you set this — see Data Redaction. |
attributeScrubbers | AttributeScrubber[] | optional | Per-key redaction rules applied to every Span and log record attribute. No default rules — omit it and nothing changes. |
spanLimits | SpanLimits | optional | Per-Span attribute, event and link limits. Omit to keep the OpenTelemetry SDK defaults. |
logRecordLimits | LogRecordLimits | optional | Per-log-record attribute limits. Omit to keep the OpenTelemetry SDK defaults. |
batchProcessorConfig | BufferConfig | optional | Batch processor queue size and export interval. Omit to keep the OpenTelemetry SDK defaults. |
restrictedProtocols | string[] | optional | Protocols on which the SDK refuses to initialize. Defaults to ['file:']. |
Remote Configuration
Sophonz Browser SDK can dynamically manage an app's instrumentation state by communicating with the server. This allows you to enable or disable instrumentation from the server side, and automatically stop instrumentation when the exporter fails.
Remote configuration API
Sophonz Browser SDK calls the remote configuration API (/control/status) during initialization to check the app's state.
How it works
- State check on init: When
init()is called, the previously storedisCollectingvalue is read. - Disable instrumentation: If the stored
isCollectingisfalse, instrumentation is disabled. - Background update: The remote configuration API is called in the background and the latest state is saved to localStorage.
- Applied on next session: If the server returns
isCollecting: false, instrumentation will be disabled on the nextinit()call.
Server response format
interface AgentControlResponse {
/** Whether data collection is enabled — false disables instrumentation on next init */
isCollecting: boolean;
/** Whether auto-stop is active */
autoStop: boolean;
/** Failure threshold — instrumentation stops when the exporter fails this many times */
autoStopThreshold: number;
/** Token issued by the server */
token: string;
}Auto-stop (on exporter failure)
Instrumentation stops automatically when the exporter fails consecutively.
Once the collector is unreachable, every further export is a request that was never going to be stored — paid for on the user's browser and again on the server. Auto-stop exists to keep the SDK from generating that traffic. During a collector outage or maintenance window, when many clients are failing at once, it also keeps a recovering server from being buried in retries.
How it works
- Failure tracking:
ExporterFailureTrackertracks exporter success and failure. - Threshold reached: When the consecutive failure count reaches
autoStopThreshold,deinit()is called automatically. - Failure counter reset: The failure counter is only reset when
init()is called. It is not reset on success.
Exporter events
Sophonz notifies you of exporter success and failure via CustomEvent.
// Example: listening to exporter events
window.addEventListener('sophonz:exporter', (event) => {
const { type } = event.detail; // 'success' | 'failure'
console.log(`Exporter ${type}`);
});NOTE — Auto-stop activation condition
Auto-stop is only activated when the remote configuration API response includes autoStop: true. Once activated, the exporter switches to XHR mode so that real network failures can be detected.
WARNING — Auto-stop cautions
When auto-stop is active, instrumentation may stop prematurely in unstable network environments:
- Affected environments: elevators, underground car parks, tunnels, subways — anywhere with intermittent connectivity.
- Potential data loss: if exporter failures caused by a temporary network outage reach
autoStopThreshold, instrumentation stops and data from the later part of the session may not be collected. - Mobile caution: mobile devices frequently switch networks (Wi-Fi ↔ LTE/5G) which can trigger repeated drops, potentially causing data integrity loss.
Auto-stop is useful for reducing server load and avoiding unnecessary network requests, but use it carefully when complete session data is required in the environments above.
Resource attributes
Every Span, log record and metric the SDK exports carries the same resource. Alongside the app identity taken from your init() options, it includes:
| Attribute | Source | Availability |
|---|---|---|
user_agent.original | navigator.userAgent | Everywhere |
browser.language | navigator.language | Omitted when the browser reports none |
browser.brands | UA Client Hints | Chromium-based browsers only |
browser.platform | UA Client Hints | Chromium-based browsers only |
browser.mobile | UA Client Hints | Chromium-based browsers only |
The three UA Client Hints attributes are read from navigator.userAgentData, which Safari and Firefox do not implement. There they are simply absent rather than empty, and user_agent.original remains available everywhere. Only the synchronous low-entropy values are read, so nothing is requested over the network and nothing is awaited.
Export retry
Failed exports are retried automatically. This is not configurable from init().
- Retried on HTTP
429,502,503and504, and on network errors and timeouts. Other statuses —400,401,403,404— are never retried, because a malformed or unauthorized batch will not succeed on a second attempt. - Up to 5 retries after the initial send. Backoff starts at 1000 ms, is multiplied by 1.5 each time and capped at 5000 ms, with plus or minus 20% jitter, under an overall 30000 ms budget across every attempt.
- A
Retry-Afterresponse header is honoured when present, in both its seconds and HTTP-date forms. - Retries are never scheduled or executed while the page is hidden. A hidden tab may be unloading, where a delayed request either achieves nothing or gets in the way.
- This applies to the XHR and fetch paths.
navigator.sendBeaconis excluded: it is fire-and-forget and reports only whether the request was queued, so there is nothing to retry against.
Backoff waits are timer-based and never block the main thread.
Option details
collectorUrl
(
string, optional)
URL of the collector that receives telemetry data. Defaults to https://in.sophonz.ai.
CAUTION — URL format
collectorUrl must be a fully-qualified URL starting with http:// or https://. Providing a URL without a scheme (e.g. collector.yourdomain.com) will cause initialization to fail.
// ✅ Correct
collectorUrl: 'https://collector.yourdomain.com'
collectorUrl: 'http://192.168.1.100:4318'
// ❌ Incorrect (initialization will fail)
collectorUrl: 'collector.yourdomain.com'
collectorUrl: '//collector.yourdomain.com'WARNING — Integration with Sophonz Mobile SDK
- When instrumenting a web browser environment, you must provide
collectorUrl. - When instrumenting a WebView via the Android/iOS SDK, the native SDK passes
collectorUrlautomatically — no need to set it manually. - When instrumenting both WebView and browser environments, the WebView uses the value supplied by the native SDK while the browser uses the value you provide directly.
authorizationToken
(
string, optional)
Token used for authentication with the collector. Use this when the collector requires security credentials.
project
(
string, optional)
Project. Required when monitoring multiple services (Android, iOS, Web, etc.) as a unified group. If left empty, service.namespace is not sent.
TIP — Integration with Sophonz v4.0.0 and above
Sophonz v4.0.0 and above supports project to unify monitoring of multiple platforms (Android, iOS, Web, etc.) under the same project, giving you an at-a-glance view of the whole project.
appName
(
string, optional)
App name as registered in Sophonz. This value identifies the app and is used for telemetry storage and analysis. appName must match the package name entered when registering the app and may only contain a-z, A-Z, 0-9, -, _, and ..
WARNING — Integration with Sophonz Mobile SDK
- When instrumenting a web browser environment, you must provide
appName. - When instrumenting a WebView via the Android/iOS SDK, the native SDK passes
appNameautomatically. - When instrumenting both environments, the WebView uses the native SDK value while the browser uses the value you provide directly.
appKey
(
string, optional)
App key issued by Sophonz. Sign in to the Sophonz console, add an app to a project with Add App, and use the app key issued on the app's App Management page.
WARNING — Integration with Sophonz Mobile SDK
- When instrumenting a web browser environment, you must provide
appKey. - When instrumenting a WebView via the Android/iOS SDK, the native SDK passes
appKeyautomatically. - When instrumenting both environments, the WebView uses the native SDK value while the browser uses the value you provide directly.
appVersion
(
string, optional)
App version. Used to distinguish versions in telemetry storage and analysis.
NOTE — appVersion separation in WebView environments
In WebView environments, appVersion is handled separately for native and web versions:
-
WebView environment:
appVersion: the app version supplied by the native SDKweb.version: the web version derived from theappVersionyou passed toinit()
-
Standard browser environment:
appVersionandweb.versionare set to the same value.
This allows both the native app version and the web content version to be tracked in WebView.
WARNING — Integration with Sophonz Mobile SDK
- When instrumenting a web browser environment, you must provide
appVersion. - When instrumenting a WebView via the Android/iOS SDK, the native SDK passes
appVersionautomatically. - When instrumenting both environments, the WebView uses the native SDK value while the browser uses the value you provide directly.
TIP — Version management in WebView environments
In WebView environments, appVersion and web.version are handled separately:
appVersion: the app version from the native SDK (Android/iOS).web.version: the web content version you passed asappVersionat Browser SDK initialization.
In a standard browser environment, the appVersion option value is applied identically to both appVersion and web.version.
Web content version (web.version)
There is no webVersion option. The web content version is derived from the appVersion you pass and emitted as the web.version resource attribute.
Behavior:
- WebView environment: the
appVersionyou passed stays asweb.version, whileappVersionbecomes the version the native SDK supplied. This is the only case where the two differ. - Standard browser environment:
web.versionandappVersionare the same value.
// WebView example: native app version 1.0.0, web content version 2.3.1
SophonzSDK.init({
appVersion: '2.3.1', // kept as web.version in WebView
// appVersion will be 1.0.0 as supplied by the native SDK
});deploymentEnvironment
(
string, optional)
Deployment environment. Set values such as production or staging to distinguish data by environment.
defaultAttributes
(
Attributes, optional)
Global attributes added to every Span. Use this to enrich telemetry data with custom properties.
samplingProbability
(
number | string, optional)
Sampling probability. Accepts a value between 0 and 1. Defaults to 1, which samples all transactions.
advancedNetworkCapture
(
boolean, optional)
Enables detailed capture of network requests and responses. Defaults to false. When enabled, more detailed network data is collected.
WARNING — Privacy
Enabling this feature includes http.request.header and http.request.body data. Use caution as sensitive information may be captured.
What it captures and the configuration interface are covered in Instrumentation › fetch.
blockClass
(
string, optional)
CSS class of elements to mask in session replay. Use this to hide elements containing sensitive information.
consoleCapture
(
boolean, optional)
Whether to capture console logs. Defaults to false. When enabled, console output is also collected as telemetry data.
Each captured call produces a log record with the OpenTelemetry event name browser.console and a browser.console.method attribute naming the console method that was called.
What it captures and the configuration interface are covered in Instrumentation › console.
debug
(
boolean, optional)
Enables debug mode. Defaults to false. When enabled, additional logs are printed to help with troubleshooting.
disableIntercom
(
boolean, optional)
Disables the Intercom integration. Defaults to false. When enabled, the Intercom integration is turned off.
disableReplay
(
boolean, optional)
Disables session replay. Defaults to true. When set to false, session replay is active. This feature is currently under development and will be enabled in a future release.
WARNING — Session replay
This feature is currently under development and will be enabled in a future release.
sessionStorage
(
StorageType, optional)
type StorageType = 'cookie' | 'localStorage';Storage type used for the session ID. Defaults to cookie. Can be changed to localStorage. Generally cookie is recommended; use localStorage for hybrid app WebViews where browser cookies are unavailable.
WARNING — Mobile WebView configuration
When using the localStorage option, the WebView's localStorage must be enabled.
Android:
webview.settings.domStorageEnabled = trueiOS (explicit configuration when required):
let config = WKWebViewConfiguration()
config.websiteDataStore = WKWebsiteDataStore.default()
let webView = WKWebView(frame: .zero, configuration: config)Usage:
SophonzSDK.init({
collectorUrl: 'https://in.sophonz.ai',
appName: '{{YOUR_APP_NAME}}',
appVersion: '{{YOUR_APP_VERSION}}',
appKey: '{{YOUR_APP_KEY}}',
sessionStorage: 'localStorage' // or 'cookie'
});ignoreClass
(
string, optional)
CSS class of elements to ignore in session replay. Use this when specific elements should not be recorded.
ignoreUrls
(
Array<string | RegExp>, optional)
URL patterns to exclude from tracing. Accepts strings or regular expressions. Partial and exact matches are excluded from telemetry data.
maskAllInputs
(
boolean, optional)
Masks all input element values. Defaults to true. When enabled, all input field values are masked before storage. Recommended when inputs may contain sensitive information.
maskAllText
(
boolean, optional)
Masks all text content. Defaults to false. When enabled, all text is masked before storage. Recommended when text may contain sensitive information.
maskClass
(
string, optional)
CSS class whose text content will be masked. Text in elements with this class is masked before storage. Recommended when elements may contain sensitive information.
recordCanvas
(
boolean, optional)
Whether to record canvas element content. Defaults to false. When enabled, the contents of canvas elements are recorded.
sampling
(
number, optional)
Session recorder sampling rate. Defaults to 1. Accepts a value between 0 and 1. Determines how many sessions the recorder captures.
tracePropagationTargets
(
Array<string | RegExp>, optional)
Domains or regular expressions to which trace headers are automatically propagated. Requests to domains in this list will include trace headers. Accepts strings or regular expressions.
What it captures and the configuration interface are covered in Instrumentation › fetch.
webVitals
(
boolean, optional)
Enables Web Vitals instrumentation. Defaults to true. Set it to false to stop collecting Core Web Vitals.
Collected metrics: lcp, inp, cls, fcp and ttfb. Each is reported at most once per page load. FID is not collected — it was superseded by INP.
Each reported vital is sent in three forms: a browser.web_vital event, a zero-duration Span carrying app.span.type = "webvitals", and a webvitals histogram metric.
WARNING — The web-vital.* attributes were replaced
The SDK no longer emits web-vital.name, web-vital.value, web-vital.delta, web-vital.rating or web-vital.navigation_type. They were replaced by browser.web_vital.*, the values of browser.web_vital.name are lower-case, and browser.web_vital.id was added. Queries on the old names return nothing. See Web Vitals.
websocket
(
boolean, optional)
Enables WebSocket instrumentation. Defaults to false. When enabled, WebSocket connection events are automatically instrumented. Useful for monitoring real-time data transfer.
What it captures and the configuration interface are covered in Instrumentation › websocket.
socketio
(
boolean, optional)
Enables Socket.IO instrumentation. Defaults to false. When enabled, Socket.IO client events are automatically instrumented. Useful for monitoring real-time communication.
What it captures and the configuration interface are covered in Instrumentation › socketio.
captureMetrics
(
boolean, optional)
Reserved for metric collection. Defaults to false.
NOTE — This option currently has no effect
No code reads it. The Web Vitals histogram — the only metric the browser SDK records — is emitted whenever the Web Vitals instrumentation is enabled, regardless of this setting. Use webVitals to control it. Earlier documentation named this option captureMetric, without the trailing s; the accepted name is captureMetrics.
disablePreflight
(
boolean, optional)
WARNING — Preflight requests
Disabling preflight requests causes data to be sent with Content-Type: text/plain. Cross-origin requests may be blocked by servers that do not allow this content type.
- Controls whether CORS preflight (OPTIONS) requests are disabled. Defaults to
false. When enabled, preflight requests are skipped. - This setting is automatically set to
truewhenexporterProtocolisproto, because the proto protocol does not require preflight requests. - When set to
true, the Sophonz collector or your proxy must allow this content type.
exporterProtocol
(
json|proto, optional)
Exporter protocol. Defaults to json.
json: sends data in JSON format (application/json) via the Beacon API.proto: sends data in protobuf format (application/x-protobuf) via the Fetch API. Settingprotoautomatically setsdisablePreflighttotrue.
NOTE — Beacon API vs Fetch API
Beacon API
The Beacon API is designed to allow browsers to send data even when the page is being unloaded.
- Guarantees delivery on page unload:
sendBeaconcontinues sending in the background even when the user closes or navigates away from the page. - Asynchronous and fast: ideal for logs, analytics, traces, and session-end events.
- CORS support: handles cross-origin requests.
- Data size limit: typically limited to 64 KB.
- One-way communication: cannot receive a server response.
- Format restriction: supports only JSON and Text formats.
Fetch API
The Fetch API is a modern network request API that works Promise-based.
- More control: fine-grained control over HTTP requests including headers, method, and response handling.
- Promise-based: simplifies asynchronous processing.
- CORS support: handles cross-origin requests.
- No data size limit: suitable for large payloads.
- Two-way communication: can send data and receive a response.
- No format restriction: supports JSON, Text, Blob, and more.
screenNameOption
(
ScreenNameOption, optional)
Screen name collection options.
type ScreenNameType = 'routeOnly' | 'titleOnly' | 'full';
type ScreenNameOption = {
screenNameType?: ScreenNameType; // default: 'routeOnly'
urlWithSearchParams?: boolean; // default: false
};screenNameTypeaccepts one ofrouteOnly,titleOnly, orfull.routeOnly: URL path onlytitleOnly: page title onlyfull: both page title and URL path. Defaults torouteOnly.
urlWithSearchParams: whentrue, query parameters are included in the URL. Defaults tofalse.
Example: include only the page title and append query parameters:
SophonzSDK.init({
collectorUrl: 'https://in.sophonz.ai',
appName: '{{YOUR_APP_NAME}}',
appVersion: '{{YOUR_APP_VERSION}}',
appKey: '{{YOUR_APP_KEY}}',
screenNameOption: {
screenNameType: 'titleOnly',
urlWithSearchParams: true
}
});sanitizeUrl
(
(url: string) => string, optional)
Sanitizes the URL used for the url.full attribute and for the screen name, immediately before it is recorded.
URL redaction is applied whether or not you set this option: omit it and the SDK uses defaultSanitizeUrl, which redacts user:password@ credentials and the values of 19 well-known sensitive query parameters. Passing your own function replaces that default rather than adding to it.
See Data Redaction for the default parameter list, the matching rules, and how to extend the defaults instead of replacing them.
attributeScrubbers
(
AttributeScrubber[], optional)
Per-key redaction rules applied to the attributes of every Span and every log record.
There are no default rules. Omit the option and your telemetry is identical to having never configured it — the processor is not constructed at all.
SophonzSDK.init({
collectorUrl: 'https://in.sophonz.ai',
appName: '{{YOUR_APP_NAME}}',
appVersion: '{{YOUR_APP_VERSION}}',
appKey: '{{YOUR_APP_KEY}}',
attributeScrubbers: [
{ keys: ['app.user.email'] },
{ keyPattern: /^http\.request\.header\./ },
{
keys: ['app.query'],
scrub: (_key, value) =>
typeof value === 'string' ? value.slice(0, 64) : value,
},
],
});See Data Redaction for the full rule shape and failure behaviour.
spanLimits
(
SpanLimits, optional)
Caps on the number of attributes, events and links per Span, and on attribute value length. Passed straight through to @opentelemetry/sdk-trace-base. Omit it to keep the OpenTelemetry SDK defaults.
logRecordLimits
(
LogRecordLimits, optional)
Caps on the number of attributes per log record, and on attribute value length. Passed straight through to @opentelemetry/sdk-logs. Omit it to keep the OpenTelemetry SDK defaults.
batchProcessorConfig
(
BufferConfig, optional)
Queue size and export cadence for both the Span and log record batch processors: maxQueueSize, maxExportBatchSize, scheduledDelayMillis and exportTimeoutMillis. Omit it to keep the OpenTelemetry SDK defaults.
SophonzSDK.init({
collectorUrl: 'https://in.sophonz.ai',
appName: '{{YOUR_APP_NAME}}',
appVersion: '{{YOUR_APP_VERSION}}',
appKey: '{{YOUR_APP_KEY}}',
batchProcessorConfig: {
maxQueueSize: 2048,
scheduledDelayMillis: 5000,
},
});restrictedProtocols
(
string[], optional)
Protocols on which the SDK does not initialize, compared against location.protocol. Defaults to ['file:'], which keeps telemetry from file:// pages and packaged apps out of your data.
A match is not an error: init() reports through diag and returns, leaving the SDK inert rather than throwing into your page. Pass restrictedProtocols: [] to disable the guard.
instrumentations
(
Instrumentations, optional)
Disables or configures instrumentations individually. Defaults to an empty
object, {}.
false turns one off; an object is layered over what the SDK supplies. The
rules and the configuration interface each instrumentation accepts are covered
in Instrumentation.
SophonzSDK.init({
// ...
instrumentations: {
longtask: false,
interactions: { events: { click: true, submit: false } },
},
});