@dash0/sdk-web 0.13.4 → 0.14.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.
Files changed (64) hide show
  1. package/README.md +21 -0
  2. package/dist/dash0.iife.js +1 -1
  3. package/dist/dash0.iife.js.map +1 -1
  4. package/dist/dash0.js +1 -1
  5. package/dist/dash0.js.map +1 -1
  6. package/dist/dash0.umd.cjs +1 -1
  7. package/dist/dash0.umd.cjs.map +1 -1
  8. package/dist/modules/api/init.js +19 -4
  9. package/dist/modules/api/init_test.js +86 -0
  10. package/dist/modules/attributes/url.js +22 -12
  11. package/dist/modules/attributes/url_test.js +326 -0
  12. package/dist/modules/types/errors.js +1 -0
  13. package/dist/modules/types/globals.js +1 -0
  14. package/dist/modules/types/options.js +1 -0
  15. package/dist/modules/types/otlp.js +1 -0
  16. package/dist/modules/utils/fn.js +3 -0
  17. package/dist/modules/vars.js +2 -1
  18. package/dist/tsconfig.tsbuildinfo +1 -1
  19. package/dist/types/api/attributes.d.ts +1 -1
  20. package/dist/types/api/events.d.ts +1 -1
  21. package/dist/types/api/init.d.ts +1 -30
  22. package/dist/types/api/init_test.d.ts +1 -0
  23. package/dist/types/api/report-error.d.ts +1 -1
  24. package/dist/types/attributes/common.d.ts +1 -1
  25. package/dist/types/attributes/url.d.ts +11 -1
  26. package/dist/types/attributes/url_test.d.ts +1 -0
  27. package/dist/types/entrypoint/npm-package.d.ts +1 -1
  28. package/dist/types/instrumentations/errors/unhandled-error.d.ts +1 -1
  29. package/dist/types/transport/index.d.ts +1 -1
  30. package/dist/types/types/errors.d.ts +8 -0
  31. package/dist/types/types/globals.d.ts +12 -0
  32. package/dist/types/types/options.d.ts +35 -0
  33. package/dist/types/types/otlp.d.ts +104 -0
  34. package/dist/types/utils/fn.d.ts +1 -0
  35. package/dist/types/utils/otel/attributes.d.ts +1 -1
  36. package/dist/types/utils/otel/error.d.ts +1 -1
  37. package/dist/types/utils/otel/span.d.ts +1 -1
  38. package/dist/types/vars.d.ts +11 -1
  39. package/package.json +1 -1
  40. package/src/api/attributes.ts +1 -1
  41. package/src/api/events.ts +1 -1
  42. package/src/api/init.ts +25 -52
  43. package/src/api/init_test.ts +108 -0
  44. package/src/api/report-error.ts +1 -1
  45. package/src/attributes/common.ts +1 -1
  46. package/src/attributes/common_test.ts +1 -1
  47. package/src/attributes/url.ts +35 -13
  48. package/src/attributes/url_test.ts +417 -0
  49. package/src/entrypoint/npm-package.ts +2 -1
  50. package/src/instrumentations/errors/unhandled-error.ts +2 -2
  51. package/src/instrumentations/navigation/event.ts +1 -1
  52. package/src/instrumentations/navigation/page-load.ts +1 -1
  53. package/src/instrumentations/web-vitals.ts +1 -1
  54. package/src/transport/index.ts +1 -1
  55. package/src/types/errors.ts +9 -0
  56. package/src/types/globals.ts +19 -0
  57. package/src/types/options.ts +56 -0
  58. package/src/types/otlp.ts +121 -0
  59. package/src/utils/fn.ts +4 -0
  60. package/src/utils/otel/attributes.ts +1 -1
  61. package/src/utils/otel/attributes_test.ts +1 -1
  62. package/src/utils/otel/error.ts +1 -1
  63. package/src/utils/otel/span.ts +1 -1
  64. package/src/vars.ts +14 -3
@@ -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
+ };
package/src/utils/fn.ts CHANGED
@@ -1,3 +1,7 @@
1
1
  export function noop() {
2
2
  // This function is intentionally empty.
3
3
  }
4
+
5
+ export function identity<T>(a: T) {
6
+ return a;
7
+ }
@@ -1,4 +1,4 @@
1
- import { AnyValue, KeyValue } from "../../../types/otlp";
1
+ import { AnyValue, KeyValue } from "../../types/otlp";
2
2
 
3
3
  type PrimitiveAttributeValue = string | number | boolean;
4
4
  export type AttributeValueType =
@@ -1,6 +1,6 @@
1
1
  import { expect, describe, it } from "vitest";
2
2
  import { addAttribute, toAnyValue } from "./attributes";
3
- import { AnyValue, KeyValue } from "../../../types/otlp";
3
+ import { AnyValue, KeyValue } from "../../types/otlp";
4
4
 
5
5
  describe("toAnyValue", () => {
6
6
  describe("primitive values", () => {
@@ -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;
@@ -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,7 @@
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";
3
+ import { UrlAttributeScrubber } from "./attributes";
4
+ import { identity } from "./utils";
5
5
 
6
6
  export type Endpoint = {
7
7
  /**
@@ -140,6 +140,16 @@ export type Vars = {
140
140
  */
141
141
  headersToCapture: RegExp[];
142
142
 
143
+ /**
144
+ * Allows the application of a custom scrubbing function to url attributes before they are applied to signals.
145
+ * This is invoked for each url processed for inclusion in signal attributes. For example this applies both to `page.url.*`
146
+ * and `url.*` attribute namespaces.
147
+ * Sensitive parts of the url attributes should be replaced with `REDACTED`,
148
+ * avoid partially or fully dropping attributes to preserve telemetry quality.
149
+ * Note: basic auth credentials in urls are automatically redacted before this is invoked.
150
+ */
151
+ urlAttributeScrubber: UrlAttributeScrubber;
152
+
143
153
  pageViewInstrumentation: PageViewInstrumentationSettings;
144
154
  };
145
155
 
@@ -162,6 +172,7 @@ export const vars: Vars = {
162
172
  maxWaitForResourceTimingsMillis: 10000,
163
173
  maxToleranceForResourceTimingsMillis: 50,
164
174
  headersToCapture: [],
175
+ urlAttributeScrubber: identity,
165
176
  pageViewInstrumentation: {
166
177
  trackVirtualPageViews: true,
167
178
  includeParts: [],