@dash0/sdk-web 0.13.3 → 0.13.5
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/dist/dash0.iife.js +1 -1
- package/dist/dash0.iife.js.map +1 -1
- package/dist/dash0.js +1 -1
- package/dist/dash0.js.map +1 -1
- package/dist/dash0.umd.cjs +1 -1
- package/dist/dash0.umd.cjs.map +1 -1
- package/dist/modules/attributes/common.js +2 -2
- package/dist/modules/attributes/url.js +11 -10
- package/dist/modules/instrumentations/http/fetch.js +3 -3
- package/dist/modules/semantic-conventions.js +1 -0
- package/dist/modules/types/errors.js +1 -0
- package/dist/modules/types/globals.js +1 -0
- package/dist/modules/types/otlp.js +1 -0
- package/dist/modules/utils/otel/attributes.js +8 -0
- package/dist/modules/vars.js +0 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/api/attributes.d.ts +1 -1
- package/dist/types/api/events.d.ts +1 -1
- package/dist/types/api/init.d.ts +1 -1
- package/dist/types/api/report-error.d.ts +1 -1
- package/dist/types/attributes/common.d.ts +4 -1
- package/dist/types/attributes/url.d.ts +3 -2
- package/dist/types/instrumentations/errors/unhandled-error.d.ts +1 -1
- package/dist/types/semantic-conventions.d.ts +1 -0
- package/dist/types/transport/index.d.ts +1 -1
- package/dist/types/types/errors.d.ts +8 -0
- package/dist/types/types/globals.d.ts +12 -0
- package/dist/types/types/otlp.d.ts +104 -0
- package/dist/types/utils/otel/attributes.d.ts +3 -1
- package/dist/types/utils/otel/error.d.ts +1 -1
- package/dist/types/utils/otel/span.d.ts +1 -1
- package/dist/types/vars.d.ts +1 -1
- package/package.json +1 -1
- package/src/api/attributes.ts +1 -1
- package/src/api/events.ts +1 -1
- package/src/api/init.ts +1 -1
- package/src/api/report-error.ts +1 -1
- package/src/attributes/common.ts +6 -2
- package/src/attributes/common_test.ts +1 -1
- package/src/attributes/url.ts +13 -11
- package/src/instrumentations/errors/unhandled-error.ts +2 -2
- package/src/instrumentations/http/fetch.ts +3 -3
- package/src/instrumentations/navigation/event.ts +1 -1
- package/src/instrumentations/navigation/page-load.ts +1 -1
- package/src/instrumentations/web-vitals.ts +1 -1
- package/src/semantic-conventions.ts +1 -0
- package/src/transport/index.ts +1 -1
- package/src/types/errors.ts +9 -0
- package/src/types/globals.ts +19 -0
- package/src/types/otlp.ts +121 -0
- package/src/utils/otel/attributes.ts +12 -1
- package/src/utils/otel/attributes_test.ts +1 -1
- package/src/utils/otel/error.ts +1 -1
- package/src/utils/otel/span.ts +1 -1
- package/src/vars.ts +1 -3
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { KeyValue } from "
|
|
1
|
+
import { KeyValue } from "../types/otlp";
|
|
2
2
|
type Options = {
|
|
3
|
+
/**
|
|
4
|
+
* Override url to be used instead of window.location.href
|
|
5
|
+
*/
|
|
3
6
|
url?: string | URL;
|
|
4
7
|
};
|
|
5
8
|
export declare function addCommonAttributes(attributes: KeyValue[], options?: Options): void;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { AttrPrefix } from "../utils/otel";
|
|
2
|
+
import { KeyValue } from "../types/otlp";
|
|
3
|
+
export declare function addUrlAttributes(attributes: KeyValue[], url: string | URL, prefix?: AttrPrefix): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReportErrorOpts, ErrorLike } from "../../types/errors";
|
|
2
2
|
export declare function ignoreNextOnErrorEvent(): void;
|
|
3
3
|
export declare function startOnErrorInstrumentation(): void;
|
|
4
4
|
export declare function reportError(error: string | ErrorLike, opts?: ReportErrorOpts): void;
|
|
@@ -24,6 +24,7 @@ export declare const EXCEPTION_MESSAGE = "exception.message";
|
|
|
24
24
|
export declare const EXCEPTION_TYPE = "exception.type";
|
|
25
25
|
export declare const EXCEPTION_STACKTRACE = "exception.stacktrace";
|
|
26
26
|
export declare const ERROR_TYPE = "error.type";
|
|
27
|
+
export declare const PAGE_URL_ATTR_PREFIX = "page";
|
|
27
28
|
export declare const URL_DOMAIN = "url.domain";
|
|
28
29
|
export declare const URL_FRAGMENT = "url.fragment";
|
|
29
30
|
export declare const URL_FULL = "url.full";
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { LOG_SEVERITY_NUMBER, LOG_SEVERITY_TEXT } from "../semantic-conventions";
|
|
2
|
+
export type AnyValue = {
|
|
3
|
+
["stringValue"]?: string;
|
|
4
|
+
["boolValue"]?: boolean;
|
|
5
|
+
/** Format: int64 */
|
|
6
|
+
["intValue"]?: string;
|
|
7
|
+
/** Format: double */
|
|
8
|
+
["doubleValue"]?: number;
|
|
9
|
+
["arrayValue"]?: ArrayValue;
|
|
10
|
+
["kvlistValue"]?: KeyValueList;
|
|
11
|
+
/** Format: byte */
|
|
12
|
+
["bytesValue"]?: string;
|
|
13
|
+
};
|
|
14
|
+
export type ArrayValue = {
|
|
15
|
+
["values"]: AnyValue[];
|
|
16
|
+
};
|
|
17
|
+
export type KeyValue = {
|
|
18
|
+
["key"]: string;
|
|
19
|
+
["value"]: AnyValue;
|
|
20
|
+
};
|
|
21
|
+
export type KeyValueList = {
|
|
22
|
+
["values"]: KeyValue[];
|
|
23
|
+
};
|
|
24
|
+
export type Resource = {
|
|
25
|
+
["attributes"]: KeyValue[];
|
|
26
|
+
};
|
|
27
|
+
export type InstrumentationScope = {
|
|
28
|
+
["name"]?: string;
|
|
29
|
+
["version"]?: string;
|
|
30
|
+
["attributes"]: KeyValue[];
|
|
31
|
+
};
|
|
32
|
+
export type ExportLogsServiceRequest = {
|
|
33
|
+
resourceLogs: ResourceLogs[];
|
|
34
|
+
};
|
|
35
|
+
export type ResourceLogs = {
|
|
36
|
+
resource: Resource;
|
|
37
|
+
scopeLogs: ScopeLogs[];
|
|
38
|
+
};
|
|
39
|
+
export type ScopeLogs = {
|
|
40
|
+
scope?: InstrumentationScope;
|
|
41
|
+
logRecords: LogRecord[];
|
|
42
|
+
schemaUrl?: string;
|
|
43
|
+
};
|
|
44
|
+
export type LogRecord = {
|
|
45
|
+
/** Format: uint64 */
|
|
46
|
+
timeUnixNano: string;
|
|
47
|
+
severityNumber?: LOG_SEVERITY_NUMBER;
|
|
48
|
+
severityText?: LOG_SEVERITY_TEXT;
|
|
49
|
+
body?: AnyValue;
|
|
50
|
+
attributes: KeyValue[];
|
|
51
|
+
/** Format: byte */
|
|
52
|
+
traceId?: string;
|
|
53
|
+
/** Format: byte */
|
|
54
|
+
spanId?: string;
|
|
55
|
+
};
|
|
56
|
+
export type ExportTraceServiceRequest = {
|
|
57
|
+
resourceSpans: ResourceSpans[];
|
|
58
|
+
};
|
|
59
|
+
export type ResourceSpans = {
|
|
60
|
+
resource: Resource;
|
|
61
|
+
scopeSpans: ScopeSpans[];
|
|
62
|
+
};
|
|
63
|
+
export type ScopeSpans = {
|
|
64
|
+
scope?: InstrumentationScope;
|
|
65
|
+
spans: Span[];
|
|
66
|
+
};
|
|
67
|
+
export type SpanStatus = {
|
|
68
|
+
message?: string;
|
|
69
|
+
code: 0 | 1 | 2;
|
|
70
|
+
};
|
|
71
|
+
export type SpanEvent = {
|
|
72
|
+
timeUnixNano: string;
|
|
73
|
+
name: string;
|
|
74
|
+
attributes: KeyValue[];
|
|
75
|
+
};
|
|
76
|
+
export type SpanLink = {
|
|
77
|
+
/** Format: byte */
|
|
78
|
+
traceId: string;
|
|
79
|
+
/** Format: byte */
|
|
80
|
+
spanId: string;
|
|
81
|
+
traceState?: string;
|
|
82
|
+
attributes: KeyValue[];
|
|
83
|
+
droppedAttributesCount: number;
|
|
84
|
+
flags?: number;
|
|
85
|
+
};
|
|
86
|
+
export type Span = {
|
|
87
|
+
/** Format: byte */
|
|
88
|
+
traceId: string;
|
|
89
|
+
/** Format: byte */
|
|
90
|
+
spanId: string;
|
|
91
|
+
traceState?: string;
|
|
92
|
+
/** Format: byte */
|
|
93
|
+
parentSpanId?: string;
|
|
94
|
+
name: string;
|
|
95
|
+
kind: number;
|
|
96
|
+
startTimeUnixNano: string;
|
|
97
|
+
endTimeUnixNano: string;
|
|
98
|
+
attributes: KeyValue[];
|
|
99
|
+
events: SpanEvent[];
|
|
100
|
+
/** Format: int64 */
|
|
101
|
+
droppedEventsCount?: number;
|
|
102
|
+
links: SpanLink[];
|
|
103
|
+
status: SpanStatus;
|
|
104
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyValue, KeyValue } from "
|
|
1
|
+
import { AnyValue, KeyValue } from "../../types/otlp";
|
|
2
2
|
type PrimitiveAttributeValue = string | number | boolean;
|
|
3
3
|
export type AttributeValueType = PrimitiveAttributeValue | Array<PrimitiveAttributeValue> | Record<string, PrimitiveAttributeValue>;
|
|
4
4
|
export declare function toAnyValue(value: AttributeValueType | AnyValue): AnyValue;
|
|
@@ -6,4 +6,6 @@ export declare function toAnyValue(value?: AttributeValueType | AnyValue): AnyVa
|
|
|
6
6
|
export declare function toKeyValue(key: string, value: AttributeValueType | AnyValue): KeyValue;
|
|
7
7
|
export declare function addAttribute(attributes: KeyValue[], key: string, value: AttributeValueType | AnyValue): void;
|
|
8
8
|
export declare function removeAttribute(attributes: KeyValue[], key: string): void;
|
|
9
|
+
export type AttrPrefix = string | string[];
|
|
10
|
+
export declare function withPrefix(prefix?: AttrPrefix): (attr: string) => string;
|
|
9
11
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { KeyValue, Span, SpanStatus } from "
|
|
1
|
+
import { KeyValue, Span, SpanStatus } from "../../types/otlp";
|
|
2
2
|
export type InProgressSpan = Omit<Span, "endTimeUnixNano">;
|
|
3
3
|
export declare function startSpan(name: string): InProgressSpan;
|
|
4
4
|
export declare function endSpan(span: InProgressSpan, status: SpanStatus | undefined, durationNano: number | undefined): Span;
|
package/dist/types/vars.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AnyValue, InstrumentationScope, KeyValue, Resource } from "../types/otlp";
|
|
2
1
|
import { AttributeValueType } from "./utils/otel";
|
|
2
|
+
import { AnyValue, InstrumentationScope, KeyValue, Resource } from "./types/otlp";
|
|
3
3
|
export type Endpoint = {
|
|
4
4
|
/**
|
|
5
5
|
* OTLP HTTP URL excluding the /v1/* prefix
|
package/package.json
CHANGED
package/src/api/attributes.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AnyValue } from "../../types/otlp";
|
|
2
1
|
import { addAttribute, AttributeValueType, removeAttribute } from "../utils/otel";
|
|
3
2
|
import { vars } from "../vars";
|
|
3
|
+
import { AnyValue } from "../types/otlp";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Adds a signal attribute to be transmitted with every signal.
|
package/src/api/events.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { AnyValue, KeyValue } from "../../types/otlp";
|
|
2
1
|
import { EVENT_NAME, EVENT_NAMES, WEB_EVENT_TITLE, LOG_SEVERITIES, LOG_SEVERITY_TEXT } from "../semantic-conventions";
|
|
3
2
|
import { sendLog } from "../transport";
|
|
4
3
|
import { addCommonAttributes } from "../attributes";
|
|
5
4
|
import { addAttribute, AttributeValueType, toAnyValue } from "../utils/otel";
|
|
6
5
|
import { nowNanos, TimeInput, toNanosTs, warn } from "../utils";
|
|
6
|
+
import { AnyValue, KeyValue } from "../types/otlp";
|
|
7
7
|
|
|
8
8
|
type EventOptions = {
|
|
9
9
|
/**
|
package/src/api/init.ts
CHANGED
|
@@ -25,10 +25,10 @@ import { startWebVitalsInstrumentation } from "../instrumentations/web-vitals";
|
|
|
25
25
|
import { startErrorInstrumentation } from "../instrumentations/errors";
|
|
26
26
|
import { addAttribute, AttributeValueType } from "../utils/otel";
|
|
27
27
|
import { instrumentFetch } from "../instrumentations/http/fetch";
|
|
28
|
-
import { AnyValue } from "../../types/otlp";
|
|
29
28
|
import { startNavigationInstrumentation } from "../instrumentations/navigation";
|
|
30
29
|
import { merge } from "ts-deepmerge";
|
|
31
30
|
import { initializeTabId } from "../utils/tab-id";
|
|
31
|
+
import { AnyValue } from "../types/otlp";
|
|
32
32
|
|
|
33
33
|
export type InitOptions = {
|
|
34
34
|
serviceName: string;
|
package/src/api/report-error.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ErrorLike, ReportErrorOpts } from "../../types/errors";
|
|
2
1
|
import { reportError as reportErrorInternal } from "../instrumentations/errors/unhandled-error";
|
|
2
|
+
import { ReportErrorOpts, ErrorLike } from "../types/errors";
|
|
3
3
|
|
|
4
4
|
export function reportError(error: string | ErrorLike, opts?: ReportErrorOpts) {
|
|
5
5
|
reportErrorInternal(error, opts);
|
package/src/attributes/common.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { KeyValue } from "../../types/otlp";
|
|
2
1
|
import { generateUniqueId, nav, NO_VALUE_FALLBACK, WEB_EVENT_ID_BYTES, win } from "../utils";
|
|
3
2
|
import {
|
|
4
3
|
BROWSER_TAB_ID,
|
|
5
4
|
NETWORK_CONNECTION_TYPE,
|
|
5
|
+
PAGE_URL_ATTR_PREFIX,
|
|
6
6
|
SESSION_ID,
|
|
7
7
|
WEB_EVENT_ID,
|
|
8
8
|
WINDOW_HEIGHT,
|
|
@@ -13,8 +13,12 @@ import { vars } from "../vars";
|
|
|
13
13
|
import { addAttribute } from "../utils/otel";
|
|
14
14
|
import { addUrlAttributes } from "./url";
|
|
15
15
|
import { tabId } from "../utils/tab-id";
|
|
16
|
+
import { KeyValue } from "../types/otlp";
|
|
16
17
|
|
|
17
18
|
type Options = {
|
|
19
|
+
/**
|
|
20
|
+
* Override url to be used instead of window.location.href
|
|
21
|
+
*/
|
|
18
22
|
url?: string | URL;
|
|
19
23
|
};
|
|
20
24
|
|
|
@@ -27,7 +31,7 @@ export function addCommonAttributes(attributes: KeyValue[], options?: Options):
|
|
|
27
31
|
attributes.push(vars.signalAttributes[i]!);
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
addUrlAttributes(attributes, options?.url ?? win?.location.href ?? NO_VALUE_FALLBACK);
|
|
34
|
+
addUrlAttributes(attributes, options?.url ?? win?.location.href ?? NO_VALUE_FALLBACK, PAGE_URL_ATTR_PREFIX);
|
|
31
35
|
|
|
32
36
|
if (sessionId) {
|
|
33
37
|
addAttribute(attributes, SESSION_ID, sessionId);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
2
|
import { addCommonAttributes } from "./common";
|
|
3
|
-
import { KeyValue } from "../../types/otlp";
|
|
4
3
|
import * as utils from "../utils";
|
|
5
4
|
import * as varsModule from "../vars";
|
|
6
5
|
import * as urlModule from "./url";
|
|
7
6
|
import * as sessionApi from "../api/session";
|
|
8
7
|
import * as tabIdModule from "../utils/tab-id";
|
|
8
|
+
import { KeyValue } from "../types/otlp";
|
|
9
9
|
|
|
10
10
|
describe("addCommonAttributes", () => {
|
|
11
11
|
beforeEach(() => {
|
package/src/attributes/url.ts
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { addAttribute } from "../utils/otel";
|
|
1
|
+
import { addAttribute, AttrPrefix, withPrefix } from "../utils/otel";
|
|
3
2
|
import { URL_DOMAIN, URL_FRAGMENT, URL_FULL, URL_PATH, URL_QUERY, URL_SCHEME } from "../semantic-conventions";
|
|
4
|
-
import { parseUrl } from "../utils
|
|
3
|
+
import { parseUrl } from "../utils";
|
|
4
|
+
import { KeyValue } from "../types/otlp";
|
|
5
|
+
|
|
6
|
+
export function addUrlAttributes(attributes: KeyValue[], url: string | URL, prefix?: AttrPrefix) {
|
|
7
|
+
const applyPrefix = withPrefix(prefix);
|
|
5
8
|
|
|
6
|
-
export function addUrlAttributes(attributes: KeyValue[], url: string | URL) {
|
|
7
9
|
try {
|
|
8
10
|
const parsed = parseUrl(url);
|
|
9
11
|
if (parsed.username) parsed.username = "REDACTED";
|
|
10
12
|
if (parsed.password) parsed.password = "REDACTED";
|
|
11
13
|
|
|
12
|
-
addAttribute(attributes, URL_FULL, parsed.href);
|
|
13
|
-
addAttribute(attributes, URL_PATH, parsed.pathname);
|
|
14
|
-
addAttribute(attributes, URL_DOMAIN, parsed.hostname);
|
|
15
|
-
addAttribute(attributes, URL_SCHEME, parsed.protocol.replace(":", ""));
|
|
14
|
+
addAttribute(attributes, applyPrefix(URL_FULL), parsed.href);
|
|
15
|
+
addAttribute(attributes, applyPrefix(URL_PATH), parsed.pathname);
|
|
16
|
+
addAttribute(attributes, applyPrefix(URL_DOMAIN), parsed.hostname);
|
|
17
|
+
addAttribute(attributes, applyPrefix(URL_SCHEME), parsed.protocol.replace(":", ""));
|
|
16
18
|
if (parsed.hash) {
|
|
17
|
-
addAttribute(attributes, URL_FRAGMENT, parsed.hash.replace("#", ""));
|
|
19
|
+
addAttribute(attributes, applyPrefix(URL_FRAGMENT), parsed.hash.replace("#", ""));
|
|
18
20
|
}
|
|
19
21
|
if (parsed.search) {
|
|
20
|
-
addAttribute(attributes, URL_QUERY, parsed.search.replace("?", ""));
|
|
22
|
+
addAttribute(attributes, applyPrefix(URL_QUERY), parsed.search.replace("?", ""));
|
|
21
23
|
}
|
|
22
24
|
} catch (_e) {
|
|
23
|
-
addAttribute(attributes, URL_FULL, String(url));
|
|
25
|
+
addAttribute(attributes, applyPrefix(URL_FULL), String(url));
|
|
24
26
|
}
|
|
25
27
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { KeyValue, LogRecord } from "../../../types/otlp";
|
|
2
1
|
import { hasOwnProperty, nowNanos, win } from "../../utils";
|
|
3
|
-
import { ErrorLike, ReportErrorOpts } from "../../../types/errors";
|
|
4
2
|
import { isErrorMessageIgnored } from "../../utils/ignore-rules";
|
|
5
3
|
import { sendLog } from "../../transport";
|
|
6
4
|
import {
|
|
@@ -14,6 +12,8 @@ import {
|
|
|
14
12
|
} from "../../semantic-conventions";
|
|
15
13
|
import { addAttribute } from "../../utils/otel";
|
|
16
14
|
import { addCommonAttributes } from "../../attributes";
|
|
15
|
+
import { KeyValue, LogRecord } from "../../types/otlp";
|
|
16
|
+
import { ReportErrorOpts, ErrorLike } from "../../types/errors";
|
|
17
17
|
|
|
18
18
|
type TrackedError = {
|
|
19
19
|
seenCount: number;
|
|
@@ -24,7 +24,7 @@ import { vars } from "../../vars";
|
|
|
24
24
|
import { httpRequestHeaderKey, httpResponseHeaderKey } from "../../utils/otel/http";
|
|
25
25
|
import { sendSpan } from "../../transport";
|
|
26
26
|
import { addResourceNetworkEvents, addResourceSize, HTTP_METHOD_OTHER, isWellKnownHttpMethod } from "./utils";
|
|
27
|
-
import { addCommonAttributes } from "../../attributes";
|
|
27
|
+
import { addCommonAttributes, addUrlAttributes } from "../../attributes";
|
|
28
28
|
|
|
29
29
|
export function instrumentFetch() {
|
|
30
30
|
if (!win || !win.fetch || !win.Request) {
|
|
@@ -64,8 +64,8 @@ function wrapFetch(original: typeof fetch) {
|
|
|
64
64
|
const method = isWellKnownMethodMatchingLeniently ? originalMethod.toUpperCase() : HTTP_METHOD_OTHER;
|
|
65
65
|
|
|
66
66
|
const span = startSpan(`HTTP ${method}`);
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
addCommonAttributes(span.attributes);
|
|
68
|
+
addUrlAttributes(span.attributes, url);
|
|
69
69
|
addGraphQlProperties(input, init, span);
|
|
70
70
|
addAttribute(span.attributes, HTTP_REQUEST_METHOD, method);
|
|
71
71
|
if (!isWellKnownMethod) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { KeyValue, LogRecord } from "../../../types/otlp";
|
|
2
1
|
import { addAttribute, getTraceContextForPageLoad } from "../../utils/otel";
|
|
3
2
|
import {
|
|
4
3
|
EVENT_NAME,
|
|
@@ -13,6 +12,7 @@ import { doc, NO_VALUE_FALLBACK } from "../../utils";
|
|
|
13
12
|
import { addCommonAttributes } from "../../attributes";
|
|
14
13
|
import { sendLog } from "../../transport";
|
|
15
14
|
import { PageViewMeta, vars } from "../../vars";
|
|
15
|
+
import { KeyValue, LogRecord } from "../../types/otlp";
|
|
16
16
|
|
|
17
17
|
function getPageViewMeta(url?: URL): PageViewMeta {
|
|
18
18
|
if (!url) return {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { addEventListener, debug, doc, win, roundToTwoDecimals, error, toNanosTs, getTimeOrigin } from "../../utils";
|
|
2
|
-
import { KeyValue, LogRecord } from "../../../types/otlp";
|
|
3
2
|
import { EVENT_NAME, EVENT_NAMES, LOG_SEVERITIES } from "../../semantic-conventions";
|
|
4
3
|
import { sendLog } from "../../transport";
|
|
5
4
|
import { getTraceContextForPageLoad, addAttribute } from "../../utils/otel";
|
|
6
5
|
import { addCommonAttributes } from "../../attributes";
|
|
7
6
|
import { transmitPageViewEvent } from "./event";
|
|
7
|
+
import { KeyValue, LogRecord } from "../../types/otlp";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Tracks page loads as per this OTel spec:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { onLCP, onINP, onCLS, Metric } from "web-vitals";
|
|
2
|
-
import { KeyValue, LogRecord } from "
|
|
2
|
+
import { KeyValue, LogRecord } from "../types/otlp";
|
|
3
3
|
import { EVENT_NAME, EVENT_NAMES, LOG_SEVERITIES } from "../semantic-conventions";
|
|
4
4
|
import { nowNanos, roundToTwoDecimals } from "../utils";
|
|
5
5
|
import { sendLog } from "../transport";
|
|
@@ -35,6 +35,7 @@ export const EXCEPTION_STACKTRACE = "exception.stacktrace";
|
|
|
35
35
|
export const ERROR_TYPE = "error.type";
|
|
36
36
|
|
|
37
37
|
// URL Attribute Keys
|
|
38
|
+
export const PAGE_URL_ATTR_PREFIX = "page";
|
|
38
39
|
export const URL_DOMAIN = "url.domain";
|
|
39
40
|
export const URL_FRAGMENT = "url.fragment";
|
|
40
41
|
export const URL_FULL = "url.full";
|
package/src/transport/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ExportLogsServiceRequest, ExportTraceServiceRequest, LogRecord, Span } from "../../types/otlp";
|
|
2
1
|
import { newBatcher } from "./batcher";
|
|
3
2
|
import { send } from "./fetch";
|
|
4
3
|
import { vars } from "../vars";
|
|
5
4
|
import { createRateLimiter } from "../utils/rate-limit";
|
|
6
5
|
import { debug, error } from "../utils";
|
|
6
|
+
import { ExportLogsServiceRequest, ExportTraceServiceRequest, LogRecord, Span } from "../types/otlp";
|
|
7
7
|
|
|
8
8
|
const logBatcher = newBatcher<LogRecord>(sendLogs);
|
|
9
9
|
const spanBatcher = newBatcher<Span>(sendSpans);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Ensure this is treated as a module.
|
|
2
|
+
export {};
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
Zone?: any;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type ErrorLike = {
|
|
10
|
+
message: string;
|
|
11
|
+
stack?: string;
|
|
12
|
+
|
|
13
|
+
// to permit ['foo'] based access that doesn't break
|
|
14
|
+
// when pushed through the Closure compiler
|
|
15
|
+
[key: string]: number | string | null | undefined;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
let __sdkVersion: string;
|
|
19
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { LOG_SEVERITY_NUMBER, LOG_SEVERITY_TEXT } from "../semantic-conventions";
|
|
2
|
+
|
|
3
|
+
export type AnyValue = {
|
|
4
|
+
["stringValue"]?: string;
|
|
5
|
+
["boolValue"]?: boolean;
|
|
6
|
+
/** Format: int64 */
|
|
7
|
+
["intValue"]?: string;
|
|
8
|
+
/** Format: double */
|
|
9
|
+
["doubleValue"]?: number;
|
|
10
|
+
["arrayValue"]?: ArrayValue;
|
|
11
|
+
["kvlistValue"]?: KeyValueList;
|
|
12
|
+
/** Format: byte */
|
|
13
|
+
["bytesValue"]?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type ArrayValue = {
|
|
17
|
+
["values"]: AnyValue[];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type KeyValue = {
|
|
21
|
+
["key"]: string;
|
|
22
|
+
["value"]: AnyValue;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type KeyValueList = {
|
|
26
|
+
["values"]: KeyValue[];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type Resource = {
|
|
30
|
+
["attributes"]: KeyValue[];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type InstrumentationScope = {
|
|
34
|
+
["name"]?: string;
|
|
35
|
+
["version"]?: string;
|
|
36
|
+
["attributes"]: KeyValue[];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type ExportLogsServiceRequest = {
|
|
40
|
+
resourceLogs: ResourceLogs[];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type ResourceLogs = {
|
|
44
|
+
resource: Resource;
|
|
45
|
+
scopeLogs: ScopeLogs[];
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type ScopeLogs = {
|
|
49
|
+
scope?: InstrumentationScope;
|
|
50
|
+
logRecords: LogRecord[];
|
|
51
|
+
schemaUrl?: string;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type LogRecord = {
|
|
55
|
+
/** Format: uint64 */
|
|
56
|
+
timeUnixNano: string;
|
|
57
|
+
severityNumber?: LOG_SEVERITY_NUMBER;
|
|
58
|
+
severityText?: LOG_SEVERITY_TEXT;
|
|
59
|
+
body?: AnyValue;
|
|
60
|
+
attributes: KeyValue[];
|
|
61
|
+
/** Format: byte */
|
|
62
|
+
traceId?: string;
|
|
63
|
+
/** Format: byte */
|
|
64
|
+
spanId?: string;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type ExportTraceServiceRequest = {
|
|
68
|
+
resourceSpans: ResourceSpans[];
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export type ResourceSpans = {
|
|
72
|
+
resource: Resource;
|
|
73
|
+
scopeSpans: ScopeSpans[];
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export type ScopeSpans = {
|
|
77
|
+
scope?: InstrumentationScope;
|
|
78
|
+
spans: Span[];
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export type SpanStatus = {
|
|
82
|
+
message?: string;
|
|
83
|
+
code: 0 | 1 | 2;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export type SpanEvent = {
|
|
87
|
+
timeUnixNano: string;
|
|
88
|
+
name: string;
|
|
89
|
+
attributes: KeyValue[];
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export type SpanLink = {
|
|
93
|
+
/** Format: byte */
|
|
94
|
+
traceId: string;
|
|
95
|
+
/** Format: byte */
|
|
96
|
+
spanId: string;
|
|
97
|
+
traceState?: string;
|
|
98
|
+
attributes: KeyValue[];
|
|
99
|
+
droppedAttributesCount: number;
|
|
100
|
+
flags?: number;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export type Span = {
|
|
104
|
+
/** Format: byte */
|
|
105
|
+
traceId: string;
|
|
106
|
+
/** Format: byte */
|
|
107
|
+
spanId: string;
|
|
108
|
+
traceState?: string;
|
|
109
|
+
/** Format: byte */
|
|
110
|
+
parentSpanId?: string;
|
|
111
|
+
name: string;
|
|
112
|
+
kind: number;
|
|
113
|
+
startTimeUnixNano: string;
|
|
114
|
+
endTimeUnixNano: string;
|
|
115
|
+
attributes: KeyValue[];
|
|
116
|
+
events: SpanEvent[];
|
|
117
|
+
/** Format: int64 */
|
|
118
|
+
droppedEventsCount?: number;
|
|
119
|
+
links: SpanLink[];
|
|
120
|
+
status: SpanStatus;
|
|
121
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyValue, KeyValue } from "
|
|
1
|
+
import { AnyValue, KeyValue } from "../../types/otlp";
|
|
2
2
|
|
|
3
3
|
type PrimitiveAttributeValue = string | number | boolean;
|
|
4
4
|
export type AttributeValueType =
|
|
@@ -67,3 +67,14 @@ export function removeAttribute(attributes: KeyValue[], key: string) {
|
|
|
67
67
|
attributes.splice(index, 1);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
+
|
|
71
|
+
export type AttrPrefix = string | string[];
|
|
72
|
+
export function withPrefix(prefix?: AttrPrefix): (attr: string) => string {
|
|
73
|
+
if (!prefix) return (attr) => attr;
|
|
74
|
+
|
|
75
|
+
if (Array.isArray(prefix)) {
|
|
76
|
+
return (attr) => [...prefix, attr].join(".");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return (attr) => `${prefix}.${attr}`;
|
|
80
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { expect, describe, it } from "vitest";
|
|
2
2
|
import { addAttribute, toAnyValue } from "./attributes";
|
|
3
|
-
import { AnyValue, KeyValue } from "
|
|
3
|
+
import { AnyValue, KeyValue } from "../../types/otlp";
|
|
4
4
|
|
|
5
5
|
describe("toAnyValue", () => {
|
|
6
6
|
describe("primitive values", () => {
|
package/src/utils/otel/error.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { addSpanEvent, InProgressSpan } from "./span";
|
|
2
|
-
import { KeyValue, SpanStatus } from "../../../types/otlp";
|
|
3
2
|
import { addAttribute } from "./attributes";
|
|
4
3
|
import {
|
|
5
4
|
SPAN_EVENT_NAME_EXCEPTION,
|
|
@@ -8,6 +7,7 @@ import {
|
|
|
8
7
|
EXCEPTION_TYPE,
|
|
9
8
|
SPAN_STATUS_ERROR,
|
|
10
9
|
} from "../../semantic-conventions";
|
|
10
|
+
import { KeyValue, SpanStatus } from "../../types/otlp";
|
|
11
11
|
|
|
12
12
|
interface ExceptionWithCode {
|
|
13
13
|
code: string | number;
|
package/src/utils/otel/span.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { KeyValue, Span, SpanStatus } from "../../../types/otlp";
|
|
2
1
|
import { nowNanos } from "../time";
|
|
3
2
|
import { SPAN_KIND_CLIENT, SPAN_STATUS_UNSET, WEB_EVENT_ID } from "../../semantic-conventions";
|
|
4
3
|
import { sessionId } from "../../api/session";
|
|
5
4
|
import { generateTraceId } from "../trace-id";
|
|
6
5
|
import { generateSpanId } from "../span-id";
|
|
7
6
|
import { addAttribute } from "./attributes";
|
|
7
|
+
import { KeyValue, Span, SpanStatus } from "../../types/otlp";
|
|
8
8
|
|
|
9
9
|
export type InProgressSpan = Omit<Span, "endTimeUnixNano">;
|
|
10
10
|
|
package/src/vars.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
// TODO use OTel types here?
|
|
2
|
-
|
|
3
|
-
import { AnyValue, InstrumentationScope, KeyValue, Resource } from "../types/otlp";
|
|
4
1
|
import { AttributeValueType } from "./utils/otel";
|
|
2
|
+
import { AnyValue, InstrumentationScope, KeyValue, Resource } from "./types/otlp";
|
|
5
3
|
|
|
6
4
|
export type Endpoint = {
|
|
7
5
|
/**
|