@embrace-io/web-sdk
Version:
369 lines • 16.6 kB
text/typescript
import { LogManager } from "../api-logs/manager/types.cjs";
import "../api-logs/index.cjs";
import { PageManager } from "../api-page/manager/types.cjs";
import "../api-sessions/index.cjs";
import { TraceManager } from "../api-traces/manager/types.cjs";
import "../api-traces/index.cjs";
import { UserManager } from "../api-users/manager/types.cjs";
import { AttributeScrubber, VisibilityStateDocument } from "../common/types.cjs";
import { NamespacedStorage } from "../utils/NamespacedStorage/NamespacedStorage.cjs";
import { PerformanceManager } from "../utils/PerformanceManager/types.cjs";
import "../utils/index.cjs";
import { LimitManagerInternal } from "../managers/EmbraceLimitManager/types.cjs";
import "../managers/index.cjs";
import { DocumentLoadInstrumentationConfig } from "../instrumentations/document-load/DocumentLoadInstrumentation/types.cjs";
import { EmptyRootInstrumentationArgs } from "../instrumentations/empty-root/EmptyRootInstrumentation/types.cjs";
import { ClicksInstrumentationArgs } from "../instrumentations/clicks/ClicksInstrumentation/types.cjs";
import { ElementTimingInstrumentationArgs } from "../instrumentations/element-timing/ElementTimingInstrumentation/types.cjs";
import { GlobalExceptionInstrumentationArgs } from "../instrumentations/exceptions/GlobalExceptionInstrumentation/types.cjs";
import { FirstInteractionInstrumentationArgs } from "../instrumentations/first-interaction/FirstInteractionInstrumentation/types.cjs";
import { LoafInstrumentationArgs } from "../instrumentations/loaf/LoafInstrumentation/types.cjs";
import { MaxScrollDepthInstrumentationArgs } from "../instrumentations/max-scroll-depth/MaxScrollDepthInstrumentation/types.cjs";
import { NavigationInstrumentationArgs } from "../instrumentations/navigation/NavigationInstrumentation/types.cjs";
import { RageClickInstrumentationArgs } from "../instrumentations/rage-click/RageClickInstrumentation/types.cjs";
import { ServerTimingInstrumentationArgs } from "../instrumentations/server-timing/ServerTimingInstrumentation/types.cjs";
import { SignalBuffer } from "../processors/utils/SignalBuffer.cjs";
import { SoftNavigationPerformanceInstrumentationArgs } from "../instrumentations/soft-navigation-performance/SoftNavigationPerformanceInstrumentation/types.cjs";
import { UserTimingInstrumentationArgs } from "../instrumentations/user-timing/UserTimingInstrumentation/types.cjs";
import { WebVitalsInstrumentationConfig } from "../instrumentations/web-vitals/WebVitalsInstrumentation/types.cjs";
import "../instrumentations/index.cjs";
import "../processors/index.cjs";
import { UserSessionManager } from "../api-sessions/manager/types.cjs";
import { UserSessionManagerInternal } from "../managers/EmbraceUserSessionManager/types.cjs";
import { ContextManager, DiagLogLevel, DiagLogger, TextMapPropagator } from "@opentelemetry/api";
import { SpanExporter, SpanProcessor } from "@opentelemetry/sdk-trace";
import { Instrumentation } from "@opentelemetry/instrumentation";
import { FetchInstrumentationConfig } from "@opentelemetry/instrumentation-fetch";
import { XMLHttpRequestInstrumentationConfig } from "@opentelemetry/instrumentation-xml-http-request";
import { Resource } from "@opentelemetry/resources";
import { BatchLogRecordProcessor, LogRecordExporter, LogRecordProcessor } from "@opentelemetry/sdk-logs";
//#region src/sdk/types.d.ts
interface DynamicSDKConfig {
/**
* Pct of users that are sampled. 100% means all users are sampled.
*
* **default**: 100
*/
samplingPct: number;
/**
* Pct of users that should have traceparent headers added to their network spans.
*
* **default**: 0
*/
networkSpansForwardingThreshold?: number;
/**
* @deprecated The empty session avoidance feature has been removed. This field is ignored and will be removed in a future major version.
*/
emptySessionAvoidanceEnabledPct?: number;
/**
* Maximum duration of a user session, in seconds. Driven by remote config.
*
* **default**: 43200 seconds (12 hours)
*/
userSessionMaxDurationSeconds?: number;
/**
* Inactivity timeout that ends a user session, in seconds. Driven by remote
* config.
*
* **default**: 1800 seconds (30 minutes)
*/
userSessionInactivityTimeoutSeconds?: number;
/**
* Inactivity timeout that ends a session part (and its enclosing user
* session) while the tab is foregrounded, in seconds. Driven by remote
* config. Distinct from `userSessionInactivityTimeoutSeconds`, which drives
* the lazy deadline after a backgrounding.
*
* **default**: 1800 seconds (30 minutes)
*/
userSessionForegroundInactivityTimeoutSeconds?: number;
}
interface DynamicConfigManager {
refreshRemoteConfig: () => Promise<void>;
setConfig: (config: Partial<DynamicSDKConfig>) => void;
getConfig: () => DynamicSDKConfig;
}
type BaseSDKInitConfig = {
/**
* appVersion is used to distinguish between different releases of your application. It can be set here if the value
* is known in code, otherwise our CLI tool can be used to inject the value at build time.
*
* **default**: undefined
*/
appVersion?: string;
/**
* defaultInstrumentationConfig can be used pass options to the default instrumentations by Embrace or turn certain
* ones off entirely. Note that only some default instrumentations support configuration in this manner.
*
* **default**: undefined
*/
defaultInstrumentationConfig?: DefaultInstrumentationConfig;
/**
* instrumentations can be set to include instrumentations beyond the default ones provided by Embrace. This does not
* override Embrace's default instrumentations, to control those set `defaultInstrumentationConfig` instead.
*
* **default**: []
*/
instrumentations?: Instrumentation[];
/**
* propagator defines a custom context propagator that will be attached to the TracerProvider setup by the SDK
*
* **default**: null
*/
propagator?: TextMapPropagator | null;
/**
* contextManager defines a custom context manager that will be attached to the TracerProvider setup by the SDK
*
* **default**: StackContextManager
*/
contextManager?: ContextManager | null;
/**
* resource defines a custom Resource that will be merged with the resource defined in `src/resources/webSdkResource.ts`
* and included with all produced telemetry
*
* **default**: Resource.empty()
*/
resource?: Resource;
/**
* spanProcessors
* Span processor is an interface which allows hooks for span start and end method invocations.
* They are invoked in the same order as they were registered.
* Processors created by the sdk are inserted after processors in this list.
*
* **default**: []
*/
spanProcessors?: SpanProcessor[];
/**
* logProcessors
* LogRecordProcessor is an interface which allows hooks for LogRecord emitting.
* They are invoked in the same order as they were registered.
* Processors created by the sdk are inserted after processors in this list.
*
* **default**: []
*/
logProcessors?: LogRecordProcessor[];
/**
* logLevel controls the verbosity of the SDK console logging
*
* **default**: DiagLogLevel.ERROR
*/
logLevel?: DiagLogLevel;
/**
* AttributeScrubber is an interface that allows scrubbing potentially sensitive data before being emitted by the SDK.
* Each scrubber specifies an attribute key it is concerned with and a function which is supplied with the string from
* an AttributeValue whenever that key is encountered on a Log or Span. The string returned by the function is then
* used in place of the original value
*
* **default**: []
*/
attributeScrubbers?: AttributeScrubber[];
/**
* enableDefaultAttributeScrubbing specifies whether the default attribute scrubbers provided the SDK should be used.
* These default scrubbers redact sensitive information in various url.* attributes following the recommendations
* from: https://github.com/open-telemetry/semantic-conventions/blob/3b64cb31022feaacb410bfd6e571c1f19b5fbce0/docs/registry/attributes/url.md?plain=1#L33
*
* **default**: true
*/
enableDefaultAttributeScrubbing?: boolean;
/**
* additionalQueryParamsToScrub specifies a list of query string parameter keys whose values will be scrubbed by the
* default attribute scrubber. This list is in addition to the default keys that are checked by the SDK one provided
* by the SDK, see DEFAULT_SENSITIVE_TOKENS in src/sdk/defaultAttributeScrubbers.ts
*
* **default**: []
*/
additionalQueryParamsToScrub?: string[];
diagLogger?: DiagLogger;
/**
* embraceDataURL is used to specify a custom Embrace data URL. This is only used for testing purposes.
*/
embraceDataURL?: string;
/**
* embraceConfigURL is used to specify a custom Embrace configuration URL. This is only used for testing purposes.
*/
embraceConfigURL?: string;
/**
* dynamicSDKConfigManager is used to manage dynamic SDK configuration. The manager can connect to a
* remote configuration service to fetch the latest configuration. By default, the SDK will use a config manager that
* fetches configuration from the Embrace dashboard if an appID is provided.
*
* **default**: undefined
*/
dynamicSDKConfigManager?: DynamicConfigManager;
/**
* dynamicSDKConfig is an optional object that can be used to configure the SDK. Everything in this configuration
* can be set dynamically at any time after the SDK has been initialized.
* If an Embrace appID is provided, the configuration can be set remotely through the Embrace dashboard.
*
* **default**: EmbraceDynamicConfigManager
*/
dynamicSDKConfig?: Partial<DynamicSDKConfig>;
/**
* registerGlobally is used to specify whether the SDK should register itself globally. This is useful when
* the SDK is used in multiple applications on the same page, and you want to avoid telemetry from one application
* to interfere with another.
*/
registerGlobally?: boolean;
/**
* Whether the SDK injects a traceparent header on network requests is normally decided through a sample percentage
* retrieved from remote configuration. When blockNetworkSpanForwarding is true the SDK never injects these headers
* even if set through remote configuration.
*
* **default**: false
*/
blockNetworkSpanForwarding?: boolean;
/**
* restrictedProtocols defines a set of protocols where the SDK should not operate. In `initSDK` if the current
* `window.location` is on one of these protocols the SDK will stop initialization. Note that when adding protocols
* the final ":" should be included as per https://developer.mozilla.org/en-US/docs/Web/API/URL/protocol
*
* **default**: new Set(['file:'])
*/
restrictedProtocols?: Set<string>;
/**
* useDocumentTitleAsPageLabel enables the fallback to document.title for page label when a custom label is not set.
*
* **default**: true
*/
useDocumentTitleAsPageLabel?: boolean;
};
type EmbraceExportSDKInitConfig = {
/**
* appID is a unique identifier for your application. It is used to identify your application in Embrace, and can be
* found in the Embrace dashboard. This can only be omitted if at least one spanExporter or logExporter is setup to
* send data to a collector other than Embrace.
*
* **default**: undefined
*/
appID: string;
spanExporters?: SpanExporter[];
logExporters?: LogRecordExporter[];
};
type LogExportSDKInitConfig = {
/**
* logExporters can be set to export logs to a collector other than Embrace. If `appID` is omitted at lease one
* exporter needs to be set here, or in `spanExporters`.
*
* **default**: []
*/
logExporters: [LogRecordExporter, ...LogRecordExporter[]];
appID?: string;
spanExporters?: SpanExporter[];
};
type SpanExportSDKInitConfig = {
/**
* spanExporters can be set to export span to a collector other than Embrace. If `appID` is omitted at lease one
* exporter needs to be set here, or in `logExporters`.
*
* **default**: []
*/
spanExporters: [SpanExporter, ...SpanExporter[]];
appID?: string;
logExporters?: LogRecordExporter[];
};
type SDKInitConfig = BaseSDKInitConfig & (EmbraceExportSDKInitConfig | LogExportSDKInitConfig | SpanExportSDKInitConfig);
interface SDKControl {
/**
* @deprecated Will be removed in a future major version. The SDK exports
* spans when a session part ends, so this method does not flush Embrace's
* own span buffer. Call `session.endUserSession()` instead to end the
* active user session and trigger a real export of buffered spans.
*
* Currently flushes logs and any user-supplied span exporter, but leaves
* Embrace's span buffer untouched.
*/
flush: () => Promise<void>;
setDynamicConfig: (config: Partial<DynamicSDKConfig>) => void;
log: LogManager;
trace: TraceManager;
session: UserSessionManager;
user: UserManager;
page: PageManager;
}
interface SetupUserArgs {
registerGlobally?: boolean;
sdkLocalStorage: NamespacedStorage;
}
interface SetupUserSessionArgs {
limitManager: LimitManagerInternal;
perf: PerformanceManager;
registerGlobally?: boolean;
sdkLocalStorage: NamespacedStorage;
visibilityDoc: VisibilityStateDocument;
dynamicConfigManager: DynamicConfigManager;
}
interface SetupTracesArgs {
resource: Resource;
userManager: UserManager;
spanExporters?: SpanExporter[];
spanProcessors: SpanProcessor[];
propagator?: TextMapPropagator | null;
contextManager?: ContextManager | null;
attributeScrubbers: AttributeScrubber[];
dynamicSDKConfig?: DynamicSDKConfig;
registerGlobally?: boolean;
embraceSpanProcessor?: SpanProcessor;
pageManager: PageManager;
signalBuffer?: SignalBuffer;
}
interface SetupLogsArgs {
resource: Resource;
userManager: UserManager;
logExporters?: LogRecordExporter[];
logProcessors: LogRecordProcessor[];
userSessionManager: UserSessionManagerInternal;
limitManager: LimitManagerInternal;
attributeScrubbers: AttributeScrubber[];
perf: PerformanceManager;
registerGlobally?: boolean;
embraceLogProcessor?: BatchLogRecordProcessor;
sdkLocalStorage: NamespacedStorage;
pageManager: PageManager;
visibilityDoc: VisibilityStateDocument;
signalBuffer?: SignalBuffer;
}
interface SetupPageArgs {
useDocumentTitleAsPageLabel?: boolean;
registerGlobally?: boolean;
userSessionManager: UserSessionManagerInternal;
perf: PerformanceManager;
}
type OptionalInstrumentations = 'exception' | 'click' | 'rage-click' | 'max-scroll-depth' | 'first-interaction' | 'web-vital' | 'loaf' | 'user-timing' | 'element-timing' | 'server-timing' | 'soft-navigation-performance' | 'document-load' | '@opentelemetry/instrumentation-fetch' | '@opentelemetry/instrumentation-xml-http-request';
interface NetworkInstrumentationArgs {
ignoreUrls?: Array<string | RegExp>;
}
interface SetupDefaultInstrumentationsArgs {
logManager?: LogManager;
userSessionManager?: UserSessionManagerInternal;
pageManager?: PageManager;
limitManager?: LimitManagerInternal;
signalBuffer?: SignalBuffer;
}
interface DefaultInstrumentationConfig {
omit?: Set<OptionalInstrumentations>;
exception?: GlobalExceptionInstrumentationArgs;
click?: ClicksInstrumentationArgs;
'rage-click'?: RageClickInstrumentationArgs;
'max-scroll-depth'?: MaxScrollDepthInstrumentationArgs;
'first-interaction'?: FirstInteractionInstrumentationArgs;
'web-vital'?: WebVitalsInstrumentationConfig;
loaf?: LoafInstrumentationArgs;
'user-timing'?: UserTimingInstrumentationArgs;
'element-timing'?: ElementTimingInstrumentationArgs;
'server-timing'?: ServerTimingInstrumentationArgs;
'soft-navigation-performance'?: SoftNavigationPerformanceInstrumentationArgs;
'document-load'?: DocumentLoadInstrumentationConfig;
navigation?: NavigationInstrumentationArgs;
network?: NetworkInstrumentationArgs;
'@opentelemetry/instrumentation-fetch'?: Omit<FetchInstrumentationConfig, 'enabled'>;
'@opentelemetry/instrumentation-xml-http-request'?: Omit<XMLHttpRequestInstrumentationConfig, 'enabled'>;
'empty-root'?: EmptyRootInstrumentationArgs;
}
interface SDKRegistryManager {
register: (sdk: SDKControl) => void;
clear: () => void;
registered: () => SDKControl | null;
}
//#endregion
export { DefaultInstrumentationConfig, DynamicConfigManager, DynamicSDKConfig, SDKControl, SDKInitConfig, SDKRegistryManager, SetupDefaultInstrumentationsArgs, SetupLogsArgs, SetupPageArgs, SetupTracesArgs, SetupUserArgs, SetupUserSessionArgs };
//# sourceMappingURL=types.d.cts.map