@dash0/sdk-web 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +496 -0
- package/dist/dash0.iife.js +2 -0
- package/dist/dash0.iife.js.map +1 -0
- package/dist/dash0.js +2 -0
- package/dist/dash0.js.map +1 -0
- package/dist/dash0.umd.cjs +2 -0
- package/dist/dash0.umd.cjs.map +1 -0
- package/dist/modules/api/attributes.js +16 -0
- package/dist/modules/api/debug.js +5 -0
- package/dist/modules/api/events.js +30 -0
- package/dist/modules/api/identify.js +29 -0
- package/dist/modules/api/init.js +130 -0
- package/dist/modules/api/report-error.js +4 -0
- package/dist/modules/api/session.js +88 -0
- package/dist/modules/attributes/common.js +26 -0
- package/dist/modules/attributes/index.js +2 -0
- package/dist/modules/attributes/url.js +25 -0
- package/dist/modules/entrypoint/npm-package.js +12 -0
- package/dist/modules/entrypoint/script.js +60 -0
- package/dist/modules/instrumentations/errors/async-function-wrapping.js +105 -0
- package/dist/modules/instrumentations/errors/event-handlers.js +52 -0
- package/dist/modules/instrumentations/errors/index.js +10 -0
- package/dist/modules/instrumentations/errors/timers.js +46 -0
- package/dist/modules/instrumentations/errors/unhandled-error.js +137 -0
- package/dist/modules/instrumentations/errors/unhandled-promise-rejection.js +29 -0
- package/dist/modules/instrumentations/http/fetch.js +164 -0
- package/dist/modules/instrumentations/http/utils.js +35 -0
- package/dist/modules/instrumentations/navigation/event.js +44 -0
- package/dist/modules/instrumentations/navigation/index.js +6 -0
- package/dist/modules/instrumentations/navigation/page-load.js +83 -0
- package/dist/modules/instrumentations/navigation/page-transition.js +72 -0
- package/dist/modules/instrumentations/web-vitals.js +32 -0
- package/dist/modules/semantic-conventions.js +79 -0
- package/dist/modules/transport/batcher.js +48 -0
- package/dist/modules/transport/fetch.js +58 -0
- package/dist/modules/transport/index.js +66 -0
- package/dist/modules/utils/constants.js +2 -0
- package/dist/modules/utils/debug.js +19 -0
- package/dist/modules/utils/fn.js +3 -0
- package/dist/modules/utils/globals.js +36 -0
- package/dist/modules/utils/id.js +16 -0
- package/dist/modules/utils/id_test.js +33 -0
- package/dist/modules/utils/ignore-rules.js +48 -0
- package/dist/modules/utils/index.js +16 -0
- package/dist/modules/utils/listeners.js +18 -0
- package/dist/modules/utils/local-storage.js +19 -0
- package/dist/modules/utils/math.js +3 -0
- package/dist/modules/utils/obj.js +10 -0
- package/dist/modules/utils/on-last-chance.js +31 -0
- package/dist/modules/utils/origin.js +14 -0
- package/dist/modules/utils/otel/attributes.js +55 -0
- package/dist/modules/utils/otel/attributes_test.js +158 -0
- package/dist/modules/utils/otel/error.js +30 -0
- package/dist/modules/utils/otel/http.js +7 -0
- package/dist/modules/utils/otel/index.js +4 -0
- package/dist/modules/utils/otel/span.js +56 -0
- package/dist/modules/utils/otel/trace-context.js +60 -0
- package/dist/modules/utils/performance.js +162 -0
- package/dist/modules/utils/pick.js +17 -0
- package/dist/modules/utils/pick_test.js +104 -0
- package/dist/modules/utils/rate-limit.js +20 -0
- package/dist/modules/utils/session-storage.js +21 -0
- package/dist/modules/utils/tab-id.js +29 -0
- package/dist/modules/utils/time.js +28 -0
- package/dist/modules/utils/timers.js +62 -0
- package/dist/modules/utils/url.js +11 -0
- package/dist/modules/utils/wrap.js +22 -0
- package/dist/modules/vars.js +25 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/api/attributes.d.ts +12 -0
- package/dist/types/api/debug.d.ts +1 -0
- package/dist/types/api/events.d.ts +36 -0
- package/dist/types/api/identify.d.ts +9 -0
- package/dist/types/api/init.d.ts +31 -0
- package/dist/types/api/report-error.d.ts +2 -0
- package/dist/types/api/session.d.ts +3 -0
- package/dist/types/attributes/common.d.ts +6 -0
- package/dist/types/attributes/index.d.ts +2 -0
- package/dist/types/attributes/url.d.ts +2 -0
- package/dist/types/entrypoint/npm-package.d.ts +8 -0
- package/dist/types/entrypoint/script.d.ts +1 -0
- package/dist/types/instrumentations/errors/async-function-wrapping.d.ts +8 -0
- package/dist/types/instrumentations/errors/event-handlers.d.ts +1 -0
- package/dist/types/instrumentations/errors/index.d.ts +1 -0
- package/dist/types/instrumentations/errors/timers.d.ts +1 -0
- package/dist/types/instrumentations/errors/unhandled-error.d.ts +5 -0
- package/dist/types/instrumentations/errors/unhandled-promise-rejection.d.ts +2 -0
- package/dist/types/instrumentations/http/fetch.d.ts +1 -0
- package/dist/types/instrumentations/http/utils.d.ts +5 -0
- package/dist/types/instrumentations/navigation/event.d.ts +1 -0
- package/dist/types/instrumentations/navigation/index.d.ts +1 -0
- package/dist/types/instrumentations/navigation/page-load.d.ts +7 -0
- package/dist/types/instrumentations/navigation/page-transition.d.ts +7 -0
- package/dist/types/instrumentations/web-vitals.d.ts +1 -0
- package/dist/types/semantic-conventions.d.ts +68 -0
- package/dist/types/transport/batcher.d.ts +4 -0
- package/dist/types/transport/fetch.d.ts +1 -0
- package/dist/types/transport/index.d.ts +3 -0
- package/dist/types/utils/constants.d.ts +2 -0
- package/dist/types/utils/debug.d.ts +7 -0
- package/dist/types/utils/fn.d.ts +1 -0
- package/dist/types/utils/globals.d.ts +14 -0
- package/dist/types/utils/id.d.ts +6 -0
- package/dist/types/utils/id_test.d.ts +1 -0
- package/dist/types/utils/ignore-rules.d.ts +3 -0
- package/dist/types/utils/index.d.ts +16 -0
- package/dist/types/utils/listeners.d.ts +2 -0
- package/dist/types/utils/local-storage.d.ts +4 -0
- package/dist/types/utils/math.d.ts +1 -0
- package/dist/types/utils/obj.d.ts +5 -0
- package/dist/types/utils/on-last-chance.d.ts +5 -0
- package/dist/types/utils/origin.d.ts +1 -0
- package/dist/types/utils/otel/attributes.d.ts +9 -0
- package/dist/types/utils/otel/attributes_test.d.ts +1 -0
- package/dist/types/utils/otel/error.d.ts +24 -0
- package/dist/types/utils/otel/http.d.ts +2 -0
- package/dist/types/utils/otel/index.d.ts +4 -0
- package/dist/types/utils/otel/span.d.ts +10 -0
- package/dist/types/utils/otel/trace-context.d.ts +8 -0
- package/dist/types/utils/performance.d.ts +45 -0
- package/dist/types/utils/pick.d.ts +9 -0
- package/dist/types/utils/pick_test.d.ts +1 -0
- package/dist/types/utils/rate-limit.d.ts +5 -0
- package/dist/types/utils/session-storage.d.ts +4 -0
- package/dist/types/utils/tab-id.d.ts +8 -0
- package/dist/types/utils/time.d.ts +6 -0
- package/dist/types/utils/timers.d.ts +6 -0
- package/dist/types/utils/url.d.ts +6 -0
- package/dist/types/utils/wrap.d.ts +1 -0
- package/dist/types/vars.d.ts +123 -0
- package/package.json +124 -0
- package/src/api/attributes.ts +19 -0
- package/src/api/debug.ts +6 -0
- package/src/api/events.ts +67 -0
- package/src/api/identify.ts +43 -0
- package/src/api/init.ts +221 -0
- package/src/api/report-error.ts +6 -0
- package/src/api/session.ts +113 -0
- package/src/attributes/common.ts +42 -0
- package/src/attributes/index.ts +2 -0
- package/src/attributes/url.ts +25 -0
- package/src/entrypoint/npm-package.ts +14 -0
- package/src/entrypoint/script-tag.html +23 -0
- package/src/entrypoint/script.ts +82 -0
- package/src/instrumentations/errors/async-function-wrapping.ts +157 -0
- package/src/instrumentations/errors/event-handlers.ts +77 -0
- package/src/instrumentations/errors/index.ts +11 -0
- package/src/instrumentations/errors/timers.ts +52 -0
- package/src/instrumentations/errors/unhandled-error.ts +187 -0
- package/src/instrumentations/errors/unhandled-promise-rejection.ts +30 -0
- package/src/instrumentations/http/fetch.ts +194 -0
- package/src/instrumentations/http/utils.ts +49 -0
- package/src/instrumentations/navigation/event.ts +66 -0
- package/src/instrumentations/navigation/index.ts +7 -0
- package/src/instrumentations/navigation/page-load.ts +96 -0
- package/src/instrumentations/navigation/page-transition.ts +100 -0
- package/src/instrumentations/web-vitals.ts +37 -0
- package/src/semantic-conventions.ts +91 -0
- package/src/transport/batcher.ts +59 -0
- package/src/transport/fetch.ts +72 -0
- package/src/transport/index.ts +77 -0
- package/src/utils/constants.ts +3 -0
- package/src/utils/debug.ts +25 -0
- package/src/utils/fn.ts +3 -0
- package/src/utils/globals.ts +42 -0
- package/src/utils/id.ts +17 -0
- package/src/utils/id_test.ts +41 -0
- package/src/utils/ignore-rules.ts +59 -0
- package/src/utils/index.ts +16 -0
- package/src/utils/listeners.ts +18 -0
- package/src/utils/local-storage.ts +25 -0
- package/src/utils/math.ts +3 -0
- package/src/utils/obj.ts +12 -0
- package/src/utils/on-last-chance.ts +36 -0
- package/src/utils/origin.ts +15 -0
- package/src/utils/otel/attributes.ts +67 -0
- package/src/utils/otel/attributes_test.ts +181 -0
- package/src/utils/otel/error.ts +63 -0
- package/src/utils/otel/http.ts +9 -0
- package/src/utils/otel/index.ts +4 -0
- package/src/utils/otel/span.ts +70 -0
- package/src/utils/otel/trace-context.ts +84 -0
- package/src/utils/performance.ts +203 -0
- package/src/utils/pick.ts +19 -0
- package/src/utils/pick_test.ts +134 -0
- package/src/utils/rate-limit.ts +34 -0
- package/src/utils/session-storage.ts +27 -0
- package/src/utils/tab-id.ts +33 -0
- package/src/utils/time.ts +37 -0
- package/src/utils/timers.ts +79 -0
- package/src/utils/url.ts +12 -0
- package/src/utils/wrap.ts +33 -0
- package/src/vars.ts +169 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AnyValue, KeyValue } from "../../../types/otlp";
|
|
2
|
+
type PrimitiveAttributeValue = string | number | boolean;
|
|
3
|
+
export type AttributeValueType = PrimitiveAttributeValue | Array<PrimitiveAttributeValue> | Record<string, PrimitiveAttributeValue>;
|
|
4
|
+
export declare function toAnyValue(value: AttributeValueType | AnyValue): AnyValue;
|
|
5
|
+
export declare function toAnyValue(value?: AttributeValueType | AnyValue): AnyValue | undefined;
|
|
6
|
+
export declare function toKeyValue(key: string, value: AttributeValueType | AnyValue): KeyValue;
|
|
7
|
+
export declare function addAttribute(attributes: KeyValue[], key: string, value: AttributeValueType | AnyValue): void;
|
|
8
|
+
export declare function removeAttribute(attributes: KeyValue[], key: string): void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { InProgressSpan } from "./span";
|
|
2
|
+
import { SpanStatus } from "../../../types/otlp";
|
|
3
|
+
interface ExceptionWithCode {
|
|
4
|
+
code: string | number;
|
|
5
|
+
name?: string;
|
|
6
|
+
message?: string;
|
|
7
|
+
stack?: string;
|
|
8
|
+
}
|
|
9
|
+
interface ExceptionWithMessage {
|
|
10
|
+
code?: string | number;
|
|
11
|
+
message: string;
|
|
12
|
+
name?: string;
|
|
13
|
+
stack?: string;
|
|
14
|
+
}
|
|
15
|
+
interface ExceptionWithName {
|
|
16
|
+
code?: string | number;
|
|
17
|
+
message?: string;
|
|
18
|
+
name: string;
|
|
19
|
+
stack?: string;
|
|
20
|
+
}
|
|
21
|
+
export type Exception = ExceptionWithCode | ExceptionWithMessage | ExceptionWithName | string;
|
|
22
|
+
export declare function recordException(span: InProgressSpan, exception: Exception): void;
|
|
23
|
+
export declare function errorToSpanStatus(e: Exception): SpanStatus;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { KeyValue, Span, SpanStatus } from "../../../types/otlp";
|
|
2
|
+
export type InProgressSpan = Omit<Span, "endTimeUnixNano">;
|
|
3
|
+
export declare function startSpan(name: string): InProgressSpan;
|
|
4
|
+
export declare function endSpan(span: InProgressSpan, status: SpanStatus | undefined, durationNano: number | undefined): Span;
|
|
5
|
+
/**
|
|
6
|
+
* Adds an event to a span. Can optionally accept the events timestamp and attributes for the event.
|
|
7
|
+
* The timestamp needs to be specified as nanoseconds since unix epoch in string format.
|
|
8
|
+
*/
|
|
9
|
+
export declare function addSpanEvent(span: InProgressSpan, name: string, attributesOrTs?: string | KeyValue[] | undefined, attributes?: KeyValue[] | undefined): void;
|
|
10
|
+
export declare function setSpanStatus(span: InProgressSpan, code: SpanStatus["code"], message?: string): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { InProgressSpan } from "./span";
|
|
2
|
+
type TraceContext = {
|
|
3
|
+
traceId?: string;
|
|
4
|
+
spanId?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function getTraceContextForPageLoad(): TraceContext | undefined;
|
|
7
|
+
export declare function addTraceContextHttpHeaders(fn: (name: string, value: string) => void, ctx: unknown, span: InProgressSpan): void;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export declare const isResourceTimingAvailable: boolean;
|
|
2
|
+
export declare const isPerformanceObserverAvailable: any;
|
|
3
|
+
export declare const PerformanceTimingNames: Readonly<{
|
|
4
|
+
CONNECT_END: "connectEnd";
|
|
5
|
+
CONNECT_START: "connectStart";
|
|
6
|
+
DECODED_BODY_SIZE: "decodedBodySize";
|
|
7
|
+
DOM_COMPLETE: "domComplete";
|
|
8
|
+
DOM_CONTENT_LOADED_EVENT_END: "domContentLoadedEventEnd";
|
|
9
|
+
DOM_CONTENT_LOADED_EVENT_START: "domContentLoadedEventStart";
|
|
10
|
+
DOM_INTERACTIVE: "domInteractive";
|
|
11
|
+
DOMAIN_LOOKUP_END: "domainLookupEnd";
|
|
12
|
+
DOMAIN_LOOKUP_START: "domainLookupStart";
|
|
13
|
+
ENCODED_BODY_SIZE: "encodedBodySize";
|
|
14
|
+
FETCH_START: "fetchStart";
|
|
15
|
+
LOAD_EVENT_END: "loadEventEnd";
|
|
16
|
+
LOAD_EVENT_START: "loadEventStart";
|
|
17
|
+
NAVIGATION_START: "navigationStart";
|
|
18
|
+
REDIRECT_END: "redirectEnd";
|
|
19
|
+
REDIRECT_START: "redirectStart";
|
|
20
|
+
REQUEST_START: "requestStart";
|
|
21
|
+
RESPONSE_END: "responseEnd";
|
|
22
|
+
RESPONSE_START: "responseStart";
|
|
23
|
+
SECURE_CONNECTION_START: "secureConnectionStart";
|
|
24
|
+
START_TIME: "startTime";
|
|
25
|
+
UNLOAD_EVENT_END: "unloadEventEnd";
|
|
26
|
+
UNLOAD_EVENT_START: "unloadEventStart";
|
|
27
|
+
}>;
|
|
28
|
+
export type ObserveResourcePerformanceResult = {
|
|
29
|
+
duration: number;
|
|
30
|
+
resource?: PerformanceResourceTiming | null;
|
|
31
|
+
};
|
|
32
|
+
type ObserveResourcePerformanceResultCallback = (arg: ObserveResourcePerformanceResult) => any;
|
|
33
|
+
type ObserveResourcePerformanceOptions = {
|
|
34
|
+
resourceMatcher: (arg: PerformanceResourceTiming) => boolean;
|
|
35
|
+
maxWaitForResourceMillis: number;
|
|
36
|
+
maxToleranceForResourceTimingsMillis: number;
|
|
37
|
+
onEnd: ObserveResourcePerformanceResultCallback;
|
|
38
|
+
};
|
|
39
|
+
type PerformanceObservationContoller = {
|
|
40
|
+
start: () => void;
|
|
41
|
+
end: () => void;
|
|
42
|
+
cancel: () => void;
|
|
43
|
+
};
|
|
44
|
+
export declare function observeResourcePerformance(opts: ObserveResourcePerformanceOptions): PerformanceObservationContoller;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new object by picking specified properties from the source object.
|
|
3
|
+
* Similar to TypeScript's Pick<T, K> utility type but as a runtime function.
|
|
4
|
+
*
|
|
5
|
+
* @param obj - The source object to pick properties from
|
|
6
|
+
* @param keys - Array of property keys to pick from the source object
|
|
7
|
+
* @returns A new object containing only the specified properties
|
|
8
|
+
*/
|
|
9
|
+
export declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare let tabId: string | null;
|
|
2
|
+
/**
|
|
3
|
+
* We want to be able to identify what browser tab the user is looking at. We do this by identifying tabs through
|
|
4
|
+
* random-generated IDs that are kept in session storage. To quote MDN:
|
|
5
|
+
*
|
|
6
|
+
* > sessionStorage is partitioned by both origin and browser tabs (top-level browsing contexts)
|
|
7
|
+
*/
|
|
8
|
+
export declare function initializeTabId(): void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type TimeInput = number | Date;
|
|
2
|
+
export declare function now(): number;
|
|
3
|
+
export declare function nowNanos(): string;
|
|
4
|
+
export declare function toNanosTs(time: TimeInput): string;
|
|
5
|
+
export declare function getTimeOrigin(): number;
|
|
6
|
+
export declare function domHRTimestampToNanos(ts: number): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { WindowType } from "./globals";
|
|
2
|
+
export declare const isRunningZoneJs: boolean;
|
|
3
|
+
export declare function setTimeout(..._: Parameters<WindowType["setTimeout"]>): ReturnType<WindowType["setTimeout"]>;
|
|
4
|
+
export declare function clearTimeout(..._: Parameters<WindowType["clearTimeout"]>): ReturnType<WindowType["clearTimeout"]>;
|
|
5
|
+
export declare function setInterval(..._: Parameters<WindowType["setInterval"]>): ReturnType<WindowType["setInterval"]>;
|
|
6
|
+
export declare function clearInterval(..._: Parameters<WindowType["clearInterval"]>): ReturnType<WindowType["clearInterval"]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function wrap<ModuleType extends object, TargetNameType extends keyof ModuleType>(module: ModuleType, target: TargetNameType, wrapper: (original: ModuleType[TargetNameType]) => ModuleType[TargetNameType]): void;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { AnyValue, InstrumentationScope, KeyValue, Resource } from "../types/otlp";
|
|
2
|
+
import { AttributeValueType } from "./utils/otel";
|
|
3
|
+
export type Endpoint = {
|
|
4
|
+
/**
|
|
5
|
+
* OTLP HTTP URL excluding the /v1/* prefix
|
|
6
|
+
*/
|
|
7
|
+
url: string;
|
|
8
|
+
/**
|
|
9
|
+
* Will be placed into `Authorization: Bearer {auth_token}` header. Has the form
|
|
10
|
+
* `auth_abc123`.
|
|
11
|
+
*/
|
|
12
|
+
authToken: string;
|
|
13
|
+
/**
|
|
14
|
+
* Optionally specify what dataset should be placed into. Can also be configured within Dash0
|
|
15
|
+
* through the auth token.
|
|
16
|
+
*/
|
|
17
|
+
dataset?: string;
|
|
18
|
+
};
|
|
19
|
+
export type PageViewMeta = {
|
|
20
|
+
/**
|
|
21
|
+
* Defaults to document.title
|
|
22
|
+
*/
|
|
23
|
+
title?: string;
|
|
24
|
+
attributes?: Record<string, AttributeValueType | AnyValue>;
|
|
25
|
+
};
|
|
26
|
+
export type PageViewInstrumentationSettings = {
|
|
27
|
+
/**
|
|
28
|
+
* Allows the selection of custom page metadata, falls back to default behaviour if undefined is returned.
|
|
29
|
+
*/
|
|
30
|
+
generateMetadata?: (url: URL) => PageViewMeta | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Whether the sdk should track virtual page views by instrumenting the history api.
|
|
33
|
+
* Only relevant for websites utilizing virtual navigation.
|
|
34
|
+
* Defaults to true.
|
|
35
|
+
*/
|
|
36
|
+
trackVirtualPageViews?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Additionally generate virtual page views when these url parts change.
|
|
39
|
+
* - "HASH" include changes to the urls hash / fragment
|
|
40
|
+
* - "SEARCH" include changes to the urls search / query parameters
|
|
41
|
+
*/
|
|
42
|
+
includeParts?: Array<"HASH" | "SEARCH">;
|
|
43
|
+
};
|
|
44
|
+
export type Vars = {
|
|
45
|
+
/**
|
|
46
|
+
* Telemetry endpoints to which the generated telemetry should be sent
|
|
47
|
+
*/
|
|
48
|
+
endpoints: Endpoint[];
|
|
49
|
+
/**
|
|
50
|
+
* OpenTelemetry resource used for all the telemetry we emit.
|
|
51
|
+
*/
|
|
52
|
+
resource: Resource;
|
|
53
|
+
/**
|
|
54
|
+
* OpenTelemetry scope used for all the telemetry we emit.
|
|
55
|
+
*/
|
|
56
|
+
scope: InstrumentationScope;
|
|
57
|
+
/**
|
|
58
|
+
* Attributes that are supposed to be added to all outgoing signals
|
|
59
|
+
* at the time they are **added** to the transport layer.
|
|
60
|
+
*/
|
|
61
|
+
signalAttributes: KeyValue[];
|
|
62
|
+
/**
|
|
63
|
+
* An array of URL regular expression for which no data should be
|
|
64
|
+
* collected. These regular expressions are evaluated against
|
|
65
|
+
* the document, XMLHttpRequest, fetch and resource URLs.
|
|
66
|
+
*/
|
|
67
|
+
ignoreUrls: RegExp[];
|
|
68
|
+
/**
|
|
69
|
+
* An array of error message regular expressions for which no data
|
|
70
|
+
* should be collected.
|
|
71
|
+
*/
|
|
72
|
+
ignoreErrorMessages: RegExp[];
|
|
73
|
+
/**
|
|
74
|
+
* Whether we should automatically wrap DOM event handlers
|
|
75
|
+
* added via addEventlistener for improved uncaught error tracking.
|
|
76
|
+
* This results in improved uncaught error tracking for cross-origin
|
|
77
|
+
* errors, but may have adverse effects on website performance and
|
|
78
|
+
* stability.
|
|
79
|
+
*
|
|
80
|
+
* @default true
|
|
81
|
+
*/
|
|
82
|
+
wrapEventHandlers: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Whether we should automatically wrap timers
|
|
85
|
+
* added via setTimeout / setInterval for improved uncaught error tracking.
|
|
86
|
+
* This results in improved uncaught error tracking for cross-origin
|
|
87
|
+
* errors, but may have adverse effects on website performance and
|
|
88
|
+
* stability.
|
|
89
|
+
*
|
|
90
|
+
* @default true
|
|
91
|
+
*/
|
|
92
|
+
wrapTimers: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* An array of URL regular expressions
|
|
95
|
+
* for which trace context headers should be sent across origins by http client instrumentations.
|
|
96
|
+
*/
|
|
97
|
+
propagateTraceHeadersCorsURLs: RegExp[];
|
|
98
|
+
/**
|
|
99
|
+
* How long to wait after an XMLHttpRequest or fetch request has finished
|
|
100
|
+
* for the retrieval of resource timing data. Performance timeline events
|
|
101
|
+
* are placed on the low priority task queue and therefore high values
|
|
102
|
+
* might be necessary.
|
|
103
|
+
*
|
|
104
|
+
* @default 10000
|
|
105
|
+
*/
|
|
106
|
+
maxWaitForResourceTimingsMillis: number;
|
|
107
|
+
/**
|
|
108
|
+
* The number of milliseconds of tolerance between resolution of a http request promise and the end time of performanceEntries
|
|
109
|
+
* applied when matching a request to its respective performance entry. A higher value might increase match frequency at
|
|
110
|
+
* the cost of potential incorrect matches. Matching is performed based on request timing and url.
|
|
111
|
+
*
|
|
112
|
+
* @default 3000
|
|
113
|
+
*/
|
|
114
|
+
maxToleranceForResourceTimingsMillis: number;
|
|
115
|
+
/**
|
|
116
|
+
* A set of regular expressions that will be matched against HTTP request headers to be
|
|
117
|
+
* captured in `XMLHttpRequest` and `fetch` Instrumentations.
|
|
118
|
+
* These headers will be transferred as span attributes
|
|
119
|
+
*/
|
|
120
|
+
headersToCapture: RegExp[];
|
|
121
|
+
pageViewInstrumentation: PageViewInstrumentationSettings;
|
|
122
|
+
};
|
|
123
|
+
export declare const vars: Vars;
|
package/package.json
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dash0/sdk-web",
|
|
3
|
+
"version": "0.6.2",
|
|
4
|
+
"description": "Dash0's Web SDK to collect telemetry from end-users' web browsers",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/dash0.umd.cjs",
|
|
7
|
+
"module": "dist/dash0.js",
|
|
8
|
+
"unpkg": "dist/dash0.iife.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/types/entrypoint/npm-package.d.ts",
|
|
12
|
+
"require": "./dist/dash0.umd.cjs",
|
|
13
|
+
"default": "./dist/dash0.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"types": "./dist/types/entrypoint/npm-package.d.ts",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "run-s build:clean build:typescript build:rollup build:stats",
|
|
19
|
+
"build:clean": "rm -rf dist",
|
|
20
|
+
"build:typescript": "tsc -b",
|
|
21
|
+
"build:rollup": "rollup -c -m",
|
|
22
|
+
"build:stats": "echo \"\nFile Stats:\" && ls dist/*.js | xargs -I '%' bash -c 'echo \"%: $(./node_modules/.bin/gzip-size % --include-original) (gzip)\"'",
|
|
23
|
+
"prettier:all": "prettier . --write --cache --list-different",
|
|
24
|
+
"prettier:check": "prettier . --check",
|
|
25
|
+
"lint": "eslint 'src/**/*.ts'",
|
|
26
|
+
"lint:fix": "eslint 'src/**/*.ts' --fix",
|
|
27
|
+
"test": "run-s test:unit test:e2e",
|
|
28
|
+
"test:unit": "vitest run",
|
|
29
|
+
"test:unit:watch": "vitest",
|
|
30
|
+
"test:e2e": "wdio run ./test/e2e/wdio.conf.ts",
|
|
31
|
+
"test:e2e:local": "pnpm run build && wdio run ./test/e2e/wdio.local.conf.ts",
|
|
32
|
+
"test:e2e:server": "SERVER_PORTS='8010,8011,8012' node test/e2e/server/index.mjs",
|
|
33
|
+
"test:e2e:tunnel": "dotenv -- bash -c './.lambdatest/v3/LT --user $LT_USERNAME --key $LT_ACCESS_KEY'",
|
|
34
|
+
"test:e2e:live": "run-p test:e2e:server test:e2e:tunnel",
|
|
35
|
+
"test:coverage": "vitest run --coverage",
|
|
36
|
+
"ci": "run-s lint prettier:check test:unit build",
|
|
37
|
+
"prepare": "husky",
|
|
38
|
+
"release": "release-it"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"performance",
|
|
42
|
+
"observability",
|
|
43
|
+
"opentelemetry",
|
|
44
|
+
"otel",
|
|
45
|
+
"logs",
|
|
46
|
+
"spans",
|
|
47
|
+
"tracing",
|
|
48
|
+
"Core Web Vitals",
|
|
49
|
+
"CLS",
|
|
50
|
+
"INP",
|
|
51
|
+
"LCP"
|
|
52
|
+
],
|
|
53
|
+
"files": [
|
|
54
|
+
"src",
|
|
55
|
+
"dist",
|
|
56
|
+
"LICENSE"
|
|
57
|
+
],
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">=18"
|
|
60
|
+
},
|
|
61
|
+
"author": "Dash0 Inc.",
|
|
62
|
+
"license": "Apache-2.0",
|
|
63
|
+
"repository": {
|
|
64
|
+
"type": "git",
|
|
65
|
+
"url": "https://github.com/dash0hq/dash0-sdk-web.git"
|
|
66
|
+
},
|
|
67
|
+
"bugs": {
|
|
68
|
+
"url": "https://github.com/dash0hq/dash0-sdk-web/issues"
|
|
69
|
+
},
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"@babel/core": "^7.26.10",
|
|
72
|
+
"@babel/preset-env": "^7.26.9",
|
|
73
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
74
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
75
|
+
"web-vitals": "^4.2.4",
|
|
76
|
+
"ts-deepmerge": "^7.0.3"
|
|
77
|
+
},
|
|
78
|
+
"devDependencies": {
|
|
79
|
+
"dotenv-cli": "^8.0.0",
|
|
80
|
+
"@release-it/conventional-changelog": "^10.0.1",
|
|
81
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
82
|
+
"@rollup/plugin-replace": "^6.0.2",
|
|
83
|
+
"@types/body-parser": "^1.19.5",
|
|
84
|
+
"@types/express": "^5.0.1",
|
|
85
|
+
"@types/mocha": "^10.0.10",
|
|
86
|
+
"@types/multiparty": "^4.2.1",
|
|
87
|
+
"@types/node": "^22.14.1",
|
|
88
|
+
"@types/serve-index": "^1.9.4",
|
|
89
|
+
"@typescript-eslint/eslint-plugin": "^8.29.1",
|
|
90
|
+
"@typescript-eslint/parser": "^8.29.1",
|
|
91
|
+
"@wdio/cli": "^9.12.5",
|
|
92
|
+
"@wdio/globals": "^9.12.5",
|
|
93
|
+
"@wdio/local-runner": "^9.12.5",
|
|
94
|
+
"@wdio/mocha-framework": "^9.12.5",
|
|
95
|
+
"@wdio/sauce-service": "^9.12.5",
|
|
96
|
+
"@wdio/spec-reporter": "^9.12.3",
|
|
97
|
+
"wdio-lambdatest-service": "^4.0.0",
|
|
98
|
+
"body-parser": "^2.2.0",
|
|
99
|
+
"eslint": "^9.24.0",
|
|
100
|
+
"express": "^5.1.0",
|
|
101
|
+
"google-closure-compiler": "^20240317.0.0",
|
|
102
|
+
"gzip-size-cli": "^5.1.0",
|
|
103
|
+
"husky": "^9.1.7",
|
|
104
|
+
"jsdom": "^26.0.0",
|
|
105
|
+
"multiparty": "^4.2.3",
|
|
106
|
+
"npm-run-all": "^4.1.5",
|
|
107
|
+
"prettier": "^3.5.3",
|
|
108
|
+
"release-it": "^19.0.1",
|
|
109
|
+
"rollup": "^4.39.0",
|
|
110
|
+
"serve-index": "^1.9.1",
|
|
111
|
+
"tsx": "^4.19.4",
|
|
112
|
+
"typescript": "^5.8.3",
|
|
113
|
+
"uuid": "^11.1.0",
|
|
114
|
+
"vitest": "^3.1.1",
|
|
115
|
+
"webdriverio": "^9.12.5"
|
|
116
|
+
},
|
|
117
|
+
"resolutions": {
|
|
118
|
+
"conventional-changelog-conventionalcommits": "8.0.0"
|
|
119
|
+
},
|
|
120
|
+
"packageManager": "pnpm@9.15.1",
|
|
121
|
+
"publishConfig": {
|
|
122
|
+
"access": "public"
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AnyValue } from "../../types/otlp";
|
|
2
|
+
import { addAttribute, AttributeValueType, removeAttribute } from "../utils/otel";
|
|
3
|
+
import { vars } from "../vars";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Adds a signal attribute to be transmitted with every signal.
|
|
7
|
+
* Note: if you need to ensure attributes are included with signals transmitted on initial page load, you should use
|
|
8
|
+
* the "additionalSignalAttributes" property of the init call instead
|
|
9
|
+
*/
|
|
10
|
+
export function addSignalAttribute(name: string, value: AttributeValueType | AnyValue) {
|
|
11
|
+
addAttribute(vars.signalAttributes, name, value);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Removes a previously added signal attribute
|
|
16
|
+
*/
|
|
17
|
+
export function removeSignalAttribute(name: string) {
|
|
18
|
+
removeAttribute(vars.signalAttributes, name);
|
|
19
|
+
}
|
package/src/api/debug.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { AnyValue, KeyValue } from "../../types/otlp";
|
|
2
|
+
import { EVENT_NAME, EVENT_NAMES, EVENT_TITLE, LOG_SEVERITIES, LOG_SEVERITY_TEXT } from "../semantic-conventions";
|
|
3
|
+
import { sendLog } from "../transport";
|
|
4
|
+
import { addCommonAttributes } from "../attributes";
|
|
5
|
+
import { addAttribute, AttributeValueType, toAnyValue } from "../utils/otel";
|
|
6
|
+
import { nowNanos, TimeInput, toNanosTs, warn } from "../utils";
|
|
7
|
+
|
|
8
|
+
type EventOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* Human readable title for the event.
|
|
11
|
+
* Should summarize the event in a single short sentence.
|
|
12
|
+
* Transmitted via the `dash0.event.title` attribute.
|
|
13
|
+
*/
|
|
14
|
+
title?: string;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The timestamp at which the event happened.
|
|
18
|
+
* Defaults to now
|
|
19
|
+
*/
|
|
20
|
+
timestamp?: TimeInput;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The event body
|
|
24
|
+
*/
|
|
25
|
+
data?: AttributeValueType | AnyValue;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Attributes to include with the event
|
|
29
|
+
*/
|
|
30
|
+
attributes?: Record<string, AttributeValueType | AnyValue>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The events log severity
|
|
34
|
+
*/
|
|
35
|
+
severity?: LOG_SEVERITY_TEXT;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Sends a custom event.
|
|
40
|
+
* @param name The event name. Can not be any of the internal event names. See: EVENT_NAMES in src/semantic-conventions.
|
|
41
|
+
* @param opts Additional event details.
|
|
42
|
+
*/
|
|
43
|
+
export function sendEvent(name: string, opts?: EventOptions) {
|
|
44
|
+
if (Object.values(EVENT_NAMES).includes(name)) {
|
|
45
|
+
warn(
|
|
46
|
+
`Unable to send custom event ${name}. You are not allowed to use an internal event name while sending a custom event. Dropping event...`
|
|
47
|
+
);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const attributes: KeyValue[] = [];
|
|
52
|
+
addCommonAttributes(attributes);
|
|
53
|
+
Object.entries(opts?.attributes ?? {}).forEach(([key, value]) => addAttribute(attributes, key, value));
|
|
54
|
+
|
|
55
|
+
addAttribute(attributes, EVENT_NAME, name);
|
|
56
|
+
if (opts?.title) {
|
|
57
|
+
addAttribute(attributes, EVENT_TITLE, opts.title);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
sendLog({
|
|
61
|
+
timeUnixNano: opts?.timestamp != null ? toNanosTs(opts.timestamp) : nowNanos(),
|
|
62
|
+
attributes,
|
|
63
|
+
body: toAnyValue(opts?.data),
|
|
64
|
+
severityText: opts?.severity,
|
|
65
|
+
severityNumber: opts?.severity ? LOG_SEVERITIES[opts.severity] : undefined,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { vars } from "../vars";
|
|
2
|
+
import { addAttribute, removeAttribute } from "../utils/otel";
|
|
3
|
+
import { USER_EMAIL, USER_FULL_NAME, USER_HASH, USER_ID, USER_NAME, USER_ROLES } from "../semantic-conventions";
|
|
4
|
+
|
|
5
|
+
type IdentifyOpts = {
|
|
6
|
+
name?: string;
|
|
7
|
+
fullName?: string;
|
|
8
|
+
email?: string;
|
|
9
|
+
hash?: string;
|
|
10
|
+
roles?: string[];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function identify(id?: string, opts?: IdentifyOpts) {
|
|
14
|
+
removeAttribute(vars.signalAttributes, USER_ID);
|
|
15
|
+
if (id != null) {
|
|
16
|
+
addAttribute(vars.signalAttributes, USER_ID, id);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
removeAttribute(vars.signalAttributes, USER_NAME);
|
|
20
|
+
if (opts?.name != null) {
|
|
21
|
+
addAttribute(vars.signalAttributes, USER_NAME, opts.name);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
removeAttribute(vars.signalAttributes, USER_FULL_NAME);
|
|
25
|
+
if (opts?.fullName != null) {
|
|
26
|
+
addAttribute(vars.signalAttributes, USER_FULL_NAME, opts.fullName);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
removeAttribute(vars.signalAttributes, USER_EMAIL);
|
|
30
|
+
if (opts?.email != null) {
|
|
31
|
+
addAttribute(vars.signalAttributes, USER_EMAIL, opts.email);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
removeAttribute(vars.signalAttributes, USER_HASH);
|
|
35
|
+
if (opts?.hash != null) {
|
|
36
|
+
addAttribute(vars.signalAttributes, USER_HASH, opts.hash);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
removeAttribute(vars.signalAttributes, USER_ROLES);
|
|
40
|
+
if (opts?.roles != null) {
|
|
41
|
+
addAttribute(vars.signalAttributes, USER_ROLES, opts.roles);
|
|
42
|
+
}
|
|
43
|
+
}
|