import { Attributes } from '@opentelemetry/api'; import { CoralogixDomainsApiUrlMap } from './constants'; import { CoralogixLogSeverity } from './types-external'; import { ErrorSource } from './instrumentations/CoralogixErrorInstrumentation'; import { FetchSource } from './instrumentations/CoralogixFetchInstrumentation'; import { LogSource } from './instrumentations/CoralogixCustomLogInstrumentation'; import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; import { StackFrame } from 'error-stack-parser'; import { UrlBasedLabelProvider } from './label-providers/url-based-label-provider'; import { CoralogixInternalEvent } from './instrumentations/CoralogixInternalInstrumentation'; import { SnapshotContext } from './snapshot/snapshot.model'; export declare enum CoralogixEventType { ERROR = "error", NETWORK_REQUEST = "network-request", LOG = "log", USER_INTERACTION = "user-interaction", WEB_VITALS = "web-vitals", LONG_TASK = "longtask", RESOURCES = "resources", INTERNAL = "internal", NAVIGATION = "navigation" } export type WebVitalsRating = 'good' | 'needs-improvement' | 'poor'; export type CoralogixDomain = keyof typeof CoralogixDomainsApiUrlMap; export type CoralogixRumLabels = Record; export interface UserContextConfig { user_id: string; user_name: string; user_email?: string; user_metadata?: { [key: string]: any; }; } export interface ViewContextConfig { view: string; } export interface CustomTargetElement extends HTMLElement { type: string; value: string; } export interface ApplicationContextConfig { application: string; version: string; } export interface TraceHeaderConfiguration { enabled: boolean; options?: { /** urls outside of origin that should also add Traceparent to header */ propagateTraceHeaderCorsUrls?: Array; /** provides HTTP header propagation for systems that are using AWS X-Amzn-Trace-Id format. */ propagateAwsXrayTraceHeader?: boolean; /** provides HTTP header propagation for systems that are using B3 format. */ propagateB3TraceHeader?: { singleHeader?: boolean; multiHeader?: boolean; }; }; } export interface CoralogixOtelWebOptionsInstrumentations { errors?: boolean; fetch?: boolean; custom?: boolean; sslFetch?: boolean; } interface SendLog { log: (severity: CoralogixLogSeverity, message: string, data?: any) => void; debug: (message: string, data?: any) => void; verbose: (message: string, data?: any) => void; info: (message: string, data?: any) => void; warn: (message: string, data?: any) => void; error: (message: string, data?: any) => void; critical: (message: string, data?: any) => void; } export type UrlBlueprinter = (url: string) => string; export interface UrlBlueprinters { pageUrlBlueprinters?: UrlBlueprinter[]; networkUrlBlueprinters?: UrlBlueprinter[]; } export type BeforeSendResult = EditableCxRumEvent | null; export interface CoralogixBrowserSdkConfig { /** Publicly-visible `public_key` value */ public_key: string; /** Sets a value for the `application` attribute */ application: string; /** Coralogix account domain */ coralogixDomain: CoralogixDomain; /** Sets a value for the 'app.version' attribute */ version: string; /** Configuration for user context. */ user_context?: UserContextConfig; /** Configuration for view context. */ view_context?: ViewContextConfig; /** Turns on/off internal debug logging */ debug?: boolean; /** Sets labels added to every Span. */ labels?: CoralogixRumLabels; /** * Applies for XHR and Fetch 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; /** A pattern for error messages which should not be sent to Coralogix. By default, all errors will be sent. * */ ignoreErrors?: Array; /** Configuration for instrumentation modules. */ instrumentations?: CoralogixOtelWebOptionsInstrumentations; /** Add trace context propagation in headers across service boundaries */ traceParentInHeader?: TraceHeaderConfiguration; /** Sets a value for the `environment` attribute */ environment?: string; /** Stringify custom log data property */ stringifyCustomLogData?: boolean; /** Percentage of overall sessions being tracked, defaults to 100% */ sessionSampleRate?: number; /** Mask input types, defaults to ['password', 'email', 'tel'] */ maskInputTypes?: InputType[]; /** Class name that will mask elements, string or RegExp. defaults to 'cx-mask' */ maskClass?: string | RegExp; /** Enable event access and modification before sending to Coralogix, supporting content modification, and event discarding. */ beforeSend?: (event: EditableCxRumEvent) => BeforeSendResult; } export interface CoralogixOtelWebType extends SendLog { /** * Init CoralogixRum. */ init: (options: CoralogixBrowserSdkConfig) => void; /** * Turn CoralogixRum off. */ shutdown: () => void; /** Sets labels to be added to every log after CoralogixRum initialization. */ setLabels: (labels: CoralogixRumLabels) => void; /** * Provides access to computed, final value of global attributes, which are applied to all created logs. */ getLabels: () => CoralogixRumLabels; /** Sets user context to be added to every log after CoralogixRum initialization. */ setUserContext: (userContext: UserContextConfig) => void; /** Sets user context to be added to every log after CoralogixRum initialization. */ setViewContext: (viewContext: ViewContextConfig) => void; /** Sets application context to be added to every log after CoralogixRum initialization. */ setApplicationContext: (applicationContext: ApplicationContextConfig) => void; /** * Provides access to computed, final value of user context, which applied to all created logs. */ getUserContext: () => UserContextConfig | undefined; /** * Provides the session id. */ getSessionId: () => string | undefined; readonly isInited: boolean; } export interface ErrorContext { error_type?: string; error_message?: string; original_stacktrace?: Partial[]; } export interface LogContext { message: string; data?: any; } export interface InternalContext { event: CoralogixInternalEvent; data?: any; } export interface NetworkRequestContext { method: string; status_code: number; url: string; url_blueprint: string; fragments: string; host: string; schema: string; status_text: string; response_content_length: string; duration: number; } export interface InteractionContext { target_element: string; target_element_inner_text: string; target_element_inner_html: string; target_element_type: string; event_name: string; element_id: string; element_classes: string; } export interface LongTaskContext extends Omit { id: string; } export interface WebVitalsContext { } export interface ResourceContext extends Omit { responseStatus?: number; deliveryType?: string; firstInterimResponseStart?: number; renderBlockingStatus?: string; } export interface EventTypeContext { error_context?: ErrorContext; log_context?: LogContext; internal_context?: InternalContext; network_request_context?: NetworkRequestContext; interaction_context?: InteractionContext; web_vitals_context?: WebVitalsContext; longtask_context?: LongTaskContext; resource_context?: ResourceContext; snapshot_context?: SnapshotContext; } export interface UserMetadata { user_id: string; user_name?: string; user_email?: string; user_metadata?: { [key: string]: any; }; } export interface SessionContext extends UserMetadata { session_id: string; session_creation_date: number; prev_session?: { session_id: string; session_creation_date: number; hasRecording: boolean; }; hasRecording: boolean; os: string | undefined; osVersion: string | number | undefined; } export interface DeviceContext { device: string | undefined; deviceName: string | undefined; emulator: boolean | undefined; os: string | undefined; osVersion: string | number | undefined; userAgent: string | undefined; } export interface DeviceState { battery: number | string | undefined; firstInstallTime: number | undefined; } export type EventSource = ErrorSource | FetchSource | LogSource; export interface EventContext { type: CoralogixEventType; source: EventSource; severity: CoralogixLogSeverity; } interface SpanContext { readonly spanId: string; readonly traceId: string; } interface OtelResource { attributes: Attributes; } interface InstrumentationData { otelSpan: Partial & SpanContext; otelResource: OtelResource; } interface VersionMetaData { app_name: string; app_version: string; } export interface PageContext { page_url: string; page_url_blueprint: string; page_fragments: string; } export interface CxRumEvent extends EventTypeContext { mobile_sdk: { sdk_version: string; framework: string; }; platform: string; version_metadata: VersionMetaData; session_context: SessionContext; device_context: DeviceContext; device_state: DeviceState; view_context: ViewContextConfig; event_context: EventContext; labels: CoralogixRumLabels; spanId: string; traceId: string; environment: string; timestamp: number; isSnapshotEvent?: boolean; } export interface CxSpan { version_metadata: VersionMetaData; applicationName: string; subsystemName: string; timestamp: number; severity: CoralogixLogSeverity; isErrorWithStacktrace: boolean; instrumentation_data?: InstrumentationData; text: { cx_rum: CxRumEvent; }; } export interface Session { sessionId: string; sessionCreationDate: number; sessionExpirationDate: number; } export interface PrevSession extends Session { hasRecording: boolean; } export declare enum OtelNetworkAttrs { METHOD = "http.method", URL = "http.url", STATUS_CODE = "http.status_code", HOST = "http.host", SCHEME = "http.scheme", STATUS_TEXT = "http.status_text", RESPONSE_CONTENT_LENGTH = "http.response_content_length", OtelNetworkAttrs = "OtelNetworkAttrs" } export type Browser = 'Chrome' | 'Edge' | 'Firefox' | 'Safari' | 'Opera' | 'IE' | 'Unknown'; export type OS = 'Windows' | 'MacOS' | 'Linux' | 'iOS' | 'Android' | 'Unknown'; export type Device = 'Mobile' | 'Tablet' | 'Desktop' | 'Unknown'; export type EventName = keyof HTMLElementEventMap; export interface PatternReplacement { pattern: RegExp; replacement: string; } export declare enum UrlType { PAGE = "page", NETWORK_REQUEST = "network_request" } export type LabelProviderLabels = Record; export interface GenericLabelProvider { urlType?: UrlType; providerFunc: (url: string, event: CxRumEvent) => LabelProviderLabels; } export type LabelProvider = UrlBasedLabelProvider | GenericLabelProvider; export type InputType = 'button' | 'checkbox' | 'color' | 'date' | 'datetime-local' | 'email' | 'file' | 'hidden' | 'image' | 'month' | 'number' | 'password' | 'radio' | 'range' | 'reset' | 'search' | 'submit' | 'tel' | 'text' | 'time' | 'url' | 'week'; export interface EditableCxRumEvent extends Omit { session_context: Pick; } export {};