@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.
Files changed (194) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +496 -0
  3. package/dist/dash0.iife.js +2 -0
  4. package/dist/dash0.iife.js.map +1 -0
  5. package/dist/dash0.js +2 -0
  6. package/dist/dash0.js.map +1 -0
  7. package/dist/dash0.umd.cjs +2 -0
  8. package/dist/dash0.umd.cjs.map +1 -0
  9. package/dist/modules/api/attributes.js +16 -0
  10. package/dist/modules/api/debug.js +5 -0
  11. package/dist/modules/api/events.js +30 -0
  12. package/dist/modules/api/identify.js +29 -0
  13. package/dist/modules/api/init.js +130 -0
  14. package/dist/modules/api/report-error.js +4 -0
  15. package/dist/modules/api/session.js +88 -0
  16. package/dist/modules/attributes/common.js +26 -0
  17. package/dist/modules/attributes/index.js +2 -0
  18. package/dist/modules/attributes/url.js +25 -0
  19. package/dist/modules/entrypoint/npm-package.js +12 -0
  20. package/dist/modules/entrypoint/script.js +60 -0
  21. package/dist/modules/instrumentations/errors/async-function-wrapping.js +105 -0
  22. package/dist/modules/instrumentations/errors/event-handlers.js +52 -0
  23. package/dist/modules/instrumentations/errors/index.js +10 -0
  24. package/dist/modules/instrumentations/errors/timers.js +46 -0
  25. package/dist/modules/instrumentations/errors/unhandled-error.js +137 -0
  26. package/dist/modules/instrumentations/errors/unhandled-promise-rejection.js +29 -0
  27. package/dist/modules/instrumentations/http/fetch.js +164 -0
  28. package/dist/modules/instrumentations/http/utils.js +35 -0
  29. package/dist/modules/instrumentations/navigation/event.js +44 -0
  30. package/dist/modules/instrumentations/navigation/index.js +6 -0
  31. package/dist/modules/instrumentations/navigation/page-load.js +83 -0
  32. package/dist/modules/instrumentations/navigation/page-transition.js +72 -0
  33. package/dist/modules/instrumentations/web-vitals.js +32 -0
  34. package/dist/modules/semantic-conventions.js +79 -0
  35. package/dist/modules/transport/batcher.js +48 -0
  36. package/dist/modules/transport/fetch.js +58 -0
  37. package/dist/modules/transport/index.js +66 -0
  38. package/dist/modules/utils/constants.js +2 -0
  39. package/dist/modules/utils/debug.js +19 -0
  40. package/dist/modules/utils/fn.js +3 -0
  41. package/dist/modules/utils/globals.js +36 -0
  42. package/dist/modules/utils/id.js +16 -0
  43. package/dist/modules/utils/id_test.js +33 -0
  44. package/dist/modules/utils/ignore-rules.js +48 -0
  45. package/dist/modules/utils/index.js +16 -0
  46. package/dist/modules/utils/listeners.js +18 -0
  47. package/dist/modules/utils/local-storage.js +19 -0
  48. package/dist/modules/utils/math.js +3 -0
  49. package/dist/modules/utils/obj.js +10 -0
  50. package/dist/modules/utils/on-last-chance.js +31 -0
  51. package/dist/modules/utils/origin.js +14 -0
  52. package/dist/modules/utils/otel/attributes.js +55 -0
  53. package/dist/modules/utils/otel/attributes_test.js +158 -0
  54. package/dist/modules/utils/otel/error.js +30 -0
  55. package/dist/modules/utils/otel/http.js +7 -0
  56. package/dist/modules/utils/otel/index.js +4 -0
  57. package/dist/modules/utils/otel/span.js +56 -0
  58. package/dist/modules/utils/otel/trace-context.js +60 -0
  59. package/dist/modules/utils/performance.js +162 -0
  60. package/dist/modules/utils/pick.js +17 -0
  61. package/dist/modules/utils/pick_test.js +104 -0
  62. package/dist/modules/utils/rate-limit.js +20 -0
  63. package/dist/modules/utils/session-storage.js +21 -0
  64. package/dist/modules/utils/tab-id.js +29 -0
  65. package/dist/modules/utils/time.js +28 -0
  66. package/dist/modules/utils/timers.js +62 -0
  67. package/dist/modules/utils/url.js +11 -0
  68. package/dist/modules/utils/wrap.js +22 -0
  69. package/dist/modules/vars.js +25 -0
  70. package/dist/tsconfig.tsbuildinfo +1 -0
  71. package/dist/types/api/attributes.d.ts +12 -0
  72. package/dist/types/api/debug.d.ts +1 -0
  73. package/dist/types/api/events.d.ts +36 -0
  74. package/dist/types/api/identify.d.ts +9 -0
  75. package/dist/types/api/init.d.ts +31 -0
  76. package/dist/types/api/report-error.d.ts +2 -0
  77. package/dist/types/api/session.d.ts +3 -0
  78. package/dist/types/attributes/common.d.ts +6 -0
  79. package/dist/types/attributes/index.d.ts +2 -0
  80. package/dist/types/attributes/url.d.ts +2 -0
  81. package/dist/types/entrypoint/npm-package.d.ts +8 -0
  82. package/dist/types/entrypoint/script.d.ts +1 -0
  83. package/dist/types/instrumentations/errors/async-function-wrapping.d.ts +8 -0
  84. package/dist/types/instrumentations/errors/event-handlers.d.ts +1 -0
  85. package/dist/types/instrumentations/errors/index.d.ts +1 -0
  86. package/dist/types/instrumentations/errors/timers.d.ts +1 -0
  87. package/dist/types/instrumentations/errors/unhandled-error.d.ts +5 -0
  88. package/dist/types/instrumentations/errors/unhandled-promise-rejection.d.ts +2 -0
  89. package/dist/types/instrumentations/http/fetch.d.ts +1 -0
  90. package/dist/types/instrumentations/http/utils.d.ts +5 -0
  91. package/dist/types/instrumentations/navigation/event.d.ts +1 -0
  92. package/dist/types/instrumentations/navigation/index.d.ts +1 -0
  93. package/dist/types/instrumentations/navigation/page-load.d.ts +7 -0
  94. package/dist/types/instrumentations/navigation/page-transition.d.ts +7 -0
  95. package/dist/types/instrumentations/web-vitals.d.ts +1 -0
  96. package/dist/types/semantic-conventions.d.ts +68 -0
  97. package/dist/types/transport/batcher.d.ts +4 -0
  98. package/dist/types/transport/fetch.d.ts +1 -0
  99. package/dist/types/transport/index.d.ts +3 -0
  100. package/dist/types/utils/constants.d.ts +2 -0
  101. package/dist/types/utils/debug.d.ts +7 -0
  102. package/dist/types/utils/fn.d.ts +1 -0
  103. package/dist/types/utils/globals.d.ts +14 -0
  104. package/dist/types/utils/id.d.ts +6 -0
  105. package/dist/types/utils/id_test.d.ts +1 -0
  106. package/dist/types/utils/ignore-rules.d.ts +3 -0
  107. package/dist/types/utils/index.d.ts +16 -0
  108. package/dist/types/utils/listeners.d.ts +2 -0
  109. package/dist/types/utils/local-storage.d.ts +4 -0
  110. package/dist/types/utils/math.d.ts +1 -0
  111. package/dist/types/utils/obj.d.ts +5 -0
  112. package/dist/types/utils/on-last-chance.d.ts +5 -0
  113. package/dist/types/utils/origin.d.ts +1 -0
  114. package/dist/types/utils/otel/attributes.d.ts +9 -0
  115. package/dist/types/utils/otel/attributes_test.d.ts +1 -0
  116. package/dist/types/utils/otel/error.d.ts +24 -0
  117. package/dist/types/utils/otel/http.d.ts +2 -0
  118. package/dist/types/utils/otel/index.d.ts +4 -0
  119. package/dist/types/utils/otel/span.d.ts +10 -0
  120. package/dist/types/utils/otel/trace-context.d.ts +8 -0
  121. package/dist/types/utils/performance.d.ts +45 -0
  122. package/dist/types/utils/pick.d.ts +9 -0
  123. package/dist/types/utils/pick_test.d.ts +1 -0
  124. package/dist/types/utils/rate-limit.d.ts +5 -0
  125. package/dist/types/utils/session-storage.d.ts +4 -0
  126. package/dist/types/utils/tab-id.d.ts +8 -0
  127. package/dist/types/utils/time.d.ts +6 -0
  128. package/dist/types/utils/timers.d.ts +6 -0
  129. package/dist/types/utils/url.d.ts +6 -0
  130. package/dist/types/utils/wrap.d.ts +1 -0
  131. package/dist/types/vars.d.ts +123 -0
  132. package/package.json +124 -0
  133. package/src/api/attributes.ts +19 -0
  134. package/src/api/debug.ts +6 -0
  135. package/src/api/events.ts +67 -0
  136. package/src/api/identify.ts +43 -0
  137. package/src/api/init.ts +221 -0
  138. package/src/api/report-error.ts +6 -0
  139. package/src/api/session.ts +113 -0
  140. package/src/attributes/common.ts +42 -0
  141. package/src/attributes/index.ts +2 -0
  142. package/src/attributes/url.ts +25 -0
  143. package/src/entrypoint/npm-package.ts +14 -0
  144. package/src/entrypoint/script-tag.html +23 -0
  145. package/src/entrypoint/script.ts +82 -0
  146. package/src/instrumentations/errors/async-function-wrapping.ts +157 -0
  147. package/src/instrumentations/errors/event-handlers.ts +77 -0
  148. package/src/instrumentations/errors/index.ts +11 -0
  149. package/src/instrumentations/errors/timers.ts +52 -0
  150. package/src/instrumentations/errors/unhandled-error.ts +187 -0
  151. package/src/instrumentations/errors/unhandled-promise-rejection.ts +30 -0
  152. package/src/instrumentations/http/fetch.ts +194 -0
  153. package/src/instrumentations/http/utils.ts +49 -0
  154. package/src/instrumentations/navigation/event.ts +66 -0
  155. package/src/instrumentations/navigation/index.ts +7 -0
  156. package/src/instrumentations/navigation/page-load.ts +96 -0
  157. package/src/instrumentations/navigation/page-transition.ts +100 -0
  158. package/src/instrumentations/web-vitals.ts +37 -0
  159. package/src/semantic-conventions.ts +91 -0
  160. package/src/transport/batcher.ts +59 -0
  161. package/src/transport/fetch.ts +72 -0
  162. package/src/transport/index.ts +77 -0
  163. package/src/utils/constants.ts +3 -0
  164. package/src/utils/debug.ts +25 -0
  165. package/src/utils/fn.ts +3 -0
  166. package/src/utils/globals.ts +42 -0
  167. package/src/utils/id.ts +17 -0
  168. package/src/utils/id_test.ts +41 -0
  169. package/src/utils/ignore-rules.ts +59 -0
  170. package/src/utils/index.ts +16 -0
  171. package/src/utils/listeners.ts +18 -0
  172. package/src/utils/local-storage.ts +25 -0
  173. package/src/utils/math.ts +3 -0
  174. package/src/utils/obj.ts +12 -0
  175. package/src/utils/on-last-chance.ts +36 -0
  176. package/src/utils/origin.ts +15 -0
  177. package/src/utils/otel/attributes.ts +67 -0
  178. package/src/utils/otel/attributes_test.ts +181 -0
  179. package/src/utils/otel/error.ts +63 -0
  180. package/src/utils/otel/http.ts +9 -0
  181. package/src/utils/otel/index.ts +4 -0
  182. package/src/utils/otel/span.ts +70 -0
  183. package/src/utils/otel/trace-context.ts +84 -0
  184. package/src/utils/performance.ts +203 -0
  185. package/src/utils/pick.ts +19 -0
  186. package/src/utils/pick_test.ts +134 -0
  187. package/src/utils/rate-limit.ts +34 -0
  188. package/src/utils/session-storage.ts +27 -0
  189. package/src/utils/tab-id.ts +33 -0
  190. package/src/utils/time.ts +37 -0
  191. package/src/utils/timers.ts +79 -0
  192. package/src/utils/url.ts +12 -0
  193. package/src/utils/wrap.ts +33 -0
  194. package/src/vars.ts +169 -0
package/src/vars.ts ADDED
@@ -0,0 +1,169 @@
1
+ // TODO use OTel types here?
2
+
3
+ import { AnyValue, InstrumentationScope, KeyValue, Resource } from "../types/otlp";
4
+ import { AttributeValueType } from "./utils/otel";
5
+
6
+ export type Endpoint = {
7
+ /**
8
+ * OTLP HTTP URL excluding the /v1/* prefix
9
+ */
10
+ url: string;
11
+
12
+ /**
13
+ * Will be placed into `Authorization: Bearer {auth_token}` header. Has the form
14
+ * `auth_abc123`.
15
+ */
16
+ authToken: string;
17
+
18
+ /**
19
+ * Optionally specify what dataset should be placed into. Can also be configured within Dash0
20
+ * through the auth token.
21
+ */
22
+ dataset?: string;
23
+ };
24
+
25
+ export type PageViewMeta = {
26
+ /**
27
+ * Defaults to document.title
28
+ */
29
+ title?: string;
30
+ attributes?: Record<string, AttributeValueType | AnyValue>;
31
+ };
32
+
33
+ export type PageViewInstrumentationSettings = {
34
+ /**
35
+ * Allows the selection of custom page metadata, falls back to default behaviour if undefined is returned.
36
+ */
37
+ generateMetadata?: (url: URL) => PageViewMeta | undefined;
38
+
39
+ /**
40
+ * Whether the sdk should track virtual page views by instrumenting the history api.
41
+ * Only relevant for websites utilizing virtual navigation.
42
+ * Defaults to true.
43
+ */
44
+ trackVirtualPageViews?: boolean;
45
+
46
+ /**
47
+ * Additionally generate virtual page views when these url parts change.
48
+ * - "HASH" include changes to the urls hash / fragment
49
+ * - "SEARCH" include changes to the urls search / query parameters
50
+ */
51
+ includeParts?: Array<"HASH" | "SEARCH">;
52
+ };
53
+
54
+ export type Vars = {
55
+ /**
56
+ * Telemetry endpoints to which the generated telemetry should be sent
57
+ */
58
+ endpoints: Endpoint[];
59
+
60
+ /**
61
+ * OpenTelemetry resource used for all the telemetry we emit.
62
+ */
63
+ resource: Resource;
64
+
65
+ /**
66
+ * OpenTelemetry scope used for all the telemetry we emit.
67
+ */
68
+ scope: InstrumentationScope;
69
+
70
+ /**
71
+ * Attributes that are supposed to be added to all outgoing signals
72
+ * at the time they are **added** to the transport layer.
73
+ */
74
+ signalAttributes: KeyValue[];
75
+
76
+ /**
77
+ * An array of URL regular expression for which no data should be
78
+ * collected. These regular expressions are evaluated against
79
+ * the document, XMLHttpRequest, fetch and resource URLs.
80
+ */
81
+ ignoreUrls: RegExp[];
82
+
83
+ /**
84
+ * An array of error message regular expressions for which no data
85
+ * should be collected.
86
+ */
87
+ ignoreErrorMessages: RegExp[];
88
+
89
+ /**
90
+ * Whether we should automatically wrap DOM event handlers
91
+ * added via addEventlistener for improved uncaught error tracking.
92
+ * This results in improved uncaught error tracking for cross-origin
93
+ * errors, but may have adverse effects on website performance and
94
+ * stability.
95
+ *
96
+ * @default true
97
+ */
98
+ wrapEventHandlers: boolean;
99
+
100
+ /**
101
+ * Whether we should automatically wrap timers
102
+ * added via setTimeout / setInterval for improved uncaught error tracking.
103
+ * This results in improved uncaught error tracking for cross-origin
104
+ * errors, but may have adverse effects on website performance and
105
+ * stability.
106
+ *
107
+ * @default true
108
+ */
109
+ wrapTimers: boolean;
110
+
111
+ /**
112
+ * An array of URL regular expressions
113
+ * for which trace context headers should be sent across origins by http client instrumentations.
114
+ */
115
+ propagateTraceHeadersCorsURLs: RegExp[];
116
+
117
+ /**
118
+ * How long to wait after an XMLHttpRequest or fetch request has finished
119
+ * for the retrieval of resource timing data. Performance timeline events
120
+ * are placed on the low priority task queue and therefore high values
121
+ * might be necessary.
122
+ *
123
+ * @default 10000
124
+ */
125
+ maxWaitForResourceTimingsMillis: number;
126
+
127
+ /**
128
+ * The number of milliseconds of tolerance between resolution of a http request promise and the end time of performanceEntries
129
+ * applied when matching a request to its respective performance entry. A higher value might increase match frequency at
130
+ * the cost of potential incorrect matches. Matching is performed based on request timing and url.
131
+ *
132
+ * @default 3000
133
+ */
134
+ maxToleranceForResourceTimingsMillis: number;
135
+
136
+ /**
137
+ * A set of regular expressions that will be matched against HTTP request headers to be
138
+ * captured in `XMLHttpRequest` and `fetch` Instrumentations.
139
+ * These headers will be transferred as span attributes
140
+ */
141
+ headersToCapture: RegExp[];
142
+
143
+ pageViewInstrumentation: PageViewInstrumentationSettings;
144
+ };
145
+
146
+ export const vars: Vars = {
147
+ endpoints: [],
148
+ resource: {
149
+ attributes: [],
150
+ },
151
+ scope: {
152
+ name: "dash0-web-sdk",
153
+ version: __sdkVersion,
154
+ attributes: [],
155
+ },
156
+ signalAttributes: [],
157
+ ignoreUrls: [],
158
+ ignoreErrorMessages: [],
159
+ wrapEventHandlers: true,
160
+ wrapTimers: true,
161
+ propagateTraceHeadersCorsURLs: [],
162
+ maxWaitForResourceTimingsMillis: 10000,
163
+ maxToleranceForResourceTimingsMillis: 3000,
164
+ headersToCapture: [],
165
+ pageViewInstrumentation: {
166
+ trackVirtualPageViews: true,
167
+ includeParts: [],
168
+ },
169
+ };