@dash0/sdk-web 0.16.3 → 0.18.0
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/README.md +41 -25
- 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/api/events.js +3 -2
- package/dist/modules/instrumentations/errors/unhandled-error.js +4 -2
- package/dist/modules/utils/otel/attributes.js +23 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/types/errors.d.ts +7 -1
- package/dist/types/utils/otel/attributes.d.ts +19 -0
- package/package.json +1 -1
- package/src/api/events.ts +6 -2
- package/src/instrumentations/errors/unhandled-error.ts +8 -2
- package/src/types/errors.ts +8 -1
- package/src/utils/otel/attributes.ts +24 -0
package/src/api/events.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EVENT_NAME, EVENT_NAMES, WEB_EVENT_TITLE, LOG_SEVERITIES, LOG_SEVERITY_TEXT } from "../semantic-conventions";
|
|
2
2
|
import { sendLog } from "../transport";
|
|
3
3
|
import { addCommonAttributes } from "../attributes";
|
|
4
|
-
import { addAttribute, AttributeValueType, toAnyValue } from "../utils/otel";
|
|
4
|
+
import { addAttribute, addAttributes, AttributeValueType, toAnyValue } from "../utils/otel";
|
|
5
5
|
import { nowNanos, TimeInput, toNanosTs, warn } from "../utils";
|
|
6
6
|
import { AnyValue, KeyValue } from "../types/otlp";
|
|
7
7
|
|
|
@@ -49,14 +49,18 @@ export function sendEvent(name: string, opts?: EventOptions) {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
const attributes: KeyValue[] = [];
|
|
52
|
+
|
|
52
53
|
addCommonAttributes(attributes);
|
|
53
|
-
Object.entries(opts?.attributes ?? {}).forEach(([key, value]) => addAttribute(attributes, key, value));
|
|
54
54
|
|
|
55
55
|
addAttribute(attributes, EVENT_NAME, name);
|
|
56
|
+
|
|
56
57
|
if (opts?.title) {
|
|
57
58
|
addAttribute(attributes, WEB_EVENT_TITLE, opts.title);
|
|
58
59
|
}
|
|
59
60
|
|
|
61
|
+
// Add custom attributes last to allow overrides
|
|
62
|
+
addAttributes(attributes, opts?.attributes);
|
|
63
|
+
|
|
60
64
|
sendLog({
|
|
61
65
|
timeUnixNano: opts?.timestamp != null ? toNanosTs(opts.timestamp) : nowNanos(),
|
|
62
66
|
attributes,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
EXCEPTION_TYPE,
|
|
11
11
|
LOG_SEVERITIES,
|
|
12
12
|
} from "../../semantic-conventions";
|
|
13
|
-
import { addAttribute } from "../../utils/otel";
|
|
13
|
+
import { addAttribute, addAttributes } from "../../utils/otel";
|
|
14
14
|
import { addCommonAttributes } from "../../attributes";
|
|
15
15
|
import { KeyValue, LogRecord } from "../../types/otlp";
|
|
16
16
|
import { ReportErrorOpts, ErrorLike } from "../../types/errors";
|
|
@@ -118,8 +118,12 @@ function onUnhandledError({ message, type, stack, opts }: UnhandledErrorArgs) {
|
|
|
118
118
|
trackedError.seenCount++;
|
|
119
119
|
} else {
|
|
120
120
|
const attributes: KeyValue[] = [];
|
|
121
|
+
|
|
122
|
+
addCommonAttributes(attributes);
|
|
123
|
+
|
|
121
124
|
addAttribute(attributes, EVENT_NAME, EVENT_NAMES.ERROR);
|
|
122
125
|
addAttribute(attributes, EXCEPTION_MESSAGE, message);
|
|
126
|
+
|
|
123
127
|
if (type) {
|
|
124
128
|
addAttribute(attributes, EXCEPTION_TYPE, type);
|
|
125
129
|
}
|
|
@@ -129,7 +133,9 @@ function onUnhandledError({ message, type, stack, opts }: UnhandledErrorArgs) {
|
|
|
129
133
|
if (opts?.componentStack) {
|
|
130
134
|
addAttribute(attributes, EXCEPTION_COMPONENT_STACK, opts?.componentStack.substring(0, 2048));
|
|
131
135
|
}
|
|
132
|
-
|
|
136
|
+
|
|
137
|
+
// Add custom attributes last to allow overrides
|
|
138
|
+
addAttributes(attributes, opts?.attributes);
|
|
133
139
|
|
|
134
140
|
trackedError = {
|
|
135
141
|
seenCount: 1,
|
package/src/types/errors.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { AttributeValueType } from "../utils/otel";
|
|
2
|
+
import { AnyValue } from "./otlp";
|
|
3
|
+
|
|
1
4
|
export type ErrorLike = {
|
|
2
5
|
message: string;
|
|
3
6
|
name?: string;
|
|
@@ -5,5 +8,9 @@ export type ErrorLike = {
|
|
|
5
8
|
};
|
|
6
9
|
|
|
7
10
|
export type ReportErrorOpts = {
|
|
8
|
-
componentStack
|
|
11
|
+
componentStack?: string | null | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Additional attributes to add to the error span
|
|
14
|
+
*/
|
|
15
|
+
attributes?: Record<string, AttributeValueType | AnyValue>;
|
|
9
16
|
};
|
|
@@ -55,12 +55,36 @@ export function toKeyValue(key: string, value: AttributeValueType | AnyValue): K
|
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Adds a single attribute to the provided attributes array
|
|
60
|
+
*/
|
|
58
61
|
export function addAttribute(attributes: KeyValue[], key: string, value: AttributeValueType | AnyValue) {
|
|
59
62
|
if (!key) return;
|
|
60
63
|
|
|
61
64
|
attributes.push(toKeyValue(key, value));
|
|
62
65
|
}
|
|
63
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Adds multiple attributes to the provided attributes array
|
|
69
|
+
*/
|
|
70
|
+
export function addAttributes(
|
|
71
|
+
/**
|
|
72
|
+
* The attributes array to add to
|
|
73
|
+
*/
|
|
74
|
+
attributes: KeyValue[],
|
|
75
|
+
/**
|
|
76
|
+
* Additional attributes to add
|
|
77
|
+
* If no attributes are provided, nothing is added
|
|
78
|
+
*/
|
|
79
|
+
attrs: Record<string, AttributeValueType | AnyValue> | undefined
|
|
80
|
+
) {
|
|
81
|
+
if (!attrs) return;
|
|
82
|
+
Object.entries(attrs).forEach(([key, value]) => addAttribute(attributes, key, value));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Removes an attribute from the provided attributes array by its key
|
|
87
|
+
*/
|
|
64
88
|
export function removeAttribute(attributes: KeyValue[], key: string) {
|
|
65
89
|
const index = attributes.findIndex((attr) => attr["key"] === key);
|
|
66
90
|
if (index !== -1) {
|