/** * * Copyright 2020-2026 Splunk Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ import { Attributes } from '@opentelemetry/api'; import { InstrumentationConfig } from '@opentelemetry/instrumentation'; import { FetchInstrumentationConfig } from '@opentelemetry/instrumentation-fetch'; import { XMLHttpRequestInstrumentationConfig } from '@opentelemetry/instrumentation-xml-http-request'; import { ReadableSpan, SpanProcessor } from '@opentelemetry/sdk-trace-base'; import { WebTracerConfig } from '@opentelemetry/sdk-trace-web'; import type { SpanEmitterProcessor } from '../span-processors/span-emitter-processor'; import { SocketIoClientInstrumentationConfig, SplunkErrorInstrumentationConfig, SplunkFrustrationSignalsInstrumentationConfig, SplunkPostDocLoadResourceInstrumentationConfig, SplunkUserInteractionInstrumentationConfig, SplunkWebVitalsInstrumentationConfig } from '../instrumentations'; import { ExternalSessionMetadata } from './external-session-metadata'; export interface SplunkXhrInstrumentationConfig extends XMLHttpRequestInstrumentationConfig { /** * When true, XHR requests start a new root trace instead of inheriting the active span's * trace context. The parent span is referenced via link.interaction.traceId and * link.interaction.spanId attributes on the new root span. * @default false */ separateTraces?: boolean; } export interface SplunkFetchInstrumentationConfig extends FetchInstrumentationConfig { /** * When true, fetch requests start a new root trace instead of inheriting the active span's * trace context. The parent span is referenced via link.interaction.traceId and * link.interaction.spanId attributes on the new root span. * @default false */ separateTraces?: boolean; } export interface SplunkOtelWebOptionsInstrumentations { connectivity?: boolean | InstrumentationConfig; document?: boolean | InstrumentationConfig; errors?: boolean | SplunkErrorInstrumentationConfig; fetch?: boolean | SplunkFetchInstrumentationConfig; frustrationSignals?: boolean | SplunkFrustrationSignalsInstrumentationConfig; interactions?: boolean | SplunkUserInteractionInstrumentationConfig; longtask?: boolean | InstrumentationConfig; postload?: boolean | SplunkPostDocLoadResourceInstrumentationConfig; socketio?: boolean | SocketIoClientInstrumentationConfig; visibility?: boolean | InstrumentationConfig; websocket?: boolean | InstrumentationConfig; webvitals?: boolean | SplunkWebVitalsInstrumentationConfig; xhr?: boolean | SplunkXhrInstrumentationConfig; } export interface ContextManagerConfig { /** Enable async tracking of span parents */ async?: boolean; onBeforeContextEnd?: () => void; onBeforeContextStart?: () => void; } export type UserTrackingMode = 'noTracking' | 'anonymousTracking'; export interface SplunkOtelWebExporterOptions { /** * Allows remapping Span's attributes right before they're serialized. * One potential use case of this method is to remove PII from the attributes. */ onAttributesSerializing?: (attributes: Attributes, span: ReadableSpan) => Attributes; /** * Switch from zipkin to otlp for exporting * Defaults to true when beaconEndpoint is omitted. */ otlp?: boolean; } export type PersistenceType = 'cookie' | 'localStorage'; export declare function isPersistenceType(value: string): value is PersistenceType; type SensitivityRule = { rule: 'mask' | 'unmask' | 'exclude'; selector: string; }; export interface SplunkOtelWebConfig { /** * Experimental: Captures additional browser and device debug attributes and attaches * them to spans through global attributes. * * This includes browser-exposed navigator diagnostics such as hardware concurrency, * device memory, touch/language/vendor hints, network connection hints, storage * quota/usage, and high-entropy User-Agent Client Hints when available. * * These attributes can be high cardinality and should be enabled only while investigating * issues. The exact list of captured attributes can change without notice. No versioning * guarantees are given for this option. * @default false */ _experimental_captureBrowserDebugAttributes?: boolean; /** * Experimental: Data attribute names to capture from elements during user interactions. * * When specified, these data attributes will be collected from interacted elements and attached * to interaction spans as span attributes. Only data-* attributes are captured. * Currently supported for click and rage click spans. Not yet supported for thrashed cursor spans. * * Attribute names can be specified in either format: * - Hyphenated: `'data-test-id'`, `'data-user-name'` * - CamelCase: `'testId'`, `'userName'` (without `data-` prefix) * * Both formats are normalized to `dataset.camelCase` in the span attributes. * @example ['data-test-id', 'userName'] // Both are valid */ _experimental_dataAttributesToCapture?: string[]; /** * If true, adjusts the session start time of newly created sessions to the page's * time origin (performance.timeOrigin) instead of using the current wall clock time. * This ensures the session start aligns with when the tab was actually opened. * @default true */ adjustSessionStartToTimeOrigin?: boolean; /** Allows http beacon urls */ allowInsecureBeacon?: boolean; /** Application name */ applicationName?: string; /** Destination for the captured data */ beaconEndpoint?: string; /** Options for context manager */ context?: ContextManagerConfig; /** Sets session cookie to this domain */ cookieDomain?: string; /** Turns on/off internal debug logging */ debug?: boolean; /** * Sets a value for the `environment` attribute (persists through calls to `setGlobalAttributes()`) * */ deploymentEnvironment?: string; disableAutomationFrameworks?: boolean; disableBots?: boolean; /** * If true, no additional span will be sent after 15 minutes of user inactivity (it will be dropped). * @default true */ discardDataAfterInactivity?: boolean; /** Allows configuring how telemetry data is sent to the backend */ exporter?: SplunkOtelWebExporterOptions; /** Sets attributes added to every Span. */ globalAttributes?: Attributes; /** * Applies for XHR, Fetch and Websocket URLs. URLs that partially match any regex in ignoreUrls will not be traced. * In addition, URLs that are _exact matches_ of strings in ignoreUrls will also not be traced. * */ ignoreUrls?: Array; /** Configuration for instrumentation modules. */ instrumentations?: SplunkOtelWebOptionsInstrumentations; /** * Specifies where session data should be stored. * * Available options: * - `'cookie'` (default): Session data will be stored in a browser cookie. * * - `'localStorage'`: Session data will be stored in the browser's localStorage. * * If not specified, `'cookie'` will be used as the default storage method. */ persistence?: PersistenceType; /** * Configuration for privacy regarding collecting text from clicks. * - `'maskAllText'` (default: true): Masks all text from text nodes, unless unmask rule applies. * - `'sensitivityRules'`: Array of rules for determining sensitivity of text in the document. Rules are applied * based on CSS selectors. The later rules override the earlier ones. */ privacy?: { maskAllText?: boolean; sensitivityRules?: SensitivityRule[]; }; /** * The name of your organization’s realm. Automatically configures beaconUrl with correct URL */ realm?: string; /** * Publicly-visible rum access token value. Please do not paste any other access token or auth value into here, as this * will be visible to every user of your app */ rumAccessToken?: string; /** * When true, XHR and fetch requests create new root traces instead of inheriting * trace context from parent spans (e.g., user interactions). * The parent span reference is preserved as parent.traceId and parent.spanId attributes. * link.traceId and link.spanId remain available for Server-Timing (backend span reference). * This setting applies to both XHR and fetch instrumentations. * Can be overridden per-instrumentation via instrumentations.xhr.separateTraces or instrumentations.fetch.separateTraces. * @default false */ separateTraces?: boolean; sessionMetadata?: NonNullable; /** * Enables SPA (Single Page Application) metrics. * * Currently supported metrics: * - **Page Completion Time (PCT)**: Measures the time from a route change until all network * requests (fetch/XHR) and media elements have finished loading * * @default true (enabled) * * @example * ```typescript * // Enable with defaults * spaMetrics: true * * // Enable with custom configuration * spaMetrics: { * ignoreUrls: [/analytics\.example\.com/], * quietTime: 1000, * maxResourcesToWatch: 100 * } * * // Disable SPA metrics * spaMetrics: false * ``` */ spaMetrics?: boolean | { /** URLs to exclude from PCT tracking (e.g., analytics, third-party scripts) */ ignoreUrls?: Array; /** Maximum number of concurrent resources to track. @default 100 */ maxResourcesToWatch?: number; /** Time in milliseconds to wait after last resource loads before considering page complete. @default 1000 */ quietTime?: number; }; spanEmitter?: SpanEmitterProcessor; spanProcessors?: Array; /** * Config options passed to web tracer */ tracer?: WebTracerConfig; user?: { /** * Controls whether the agent creates and attaches an anonymous user ID to spans. * Use `noTracking` to avoid generating or storing any anonymous user ID. * Use `anonymousTracking` (default) to generate a persistent anonymous user ID, stored via the configured * persistence method (default: cookie). This enables the correlation of user behavior across sessions, * helping analyze user journeys, diagnose issues, and improve the overall digital experience without * identifying individual users. */ trackingMode?: UserTrackingMode; }; /** * Sets a value for the 'app.version' attribute */ version?: string; } export {};