@opentelemetry/sdk-trace-web 2.11.0-development.0 → 3.0.0-development.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 (117) hide show
  1. package/dist/StackContextManager.cjs +89 -0
  2. package/dist/StackContextManager.cjs.map +1 -0
  3. package/dist/StackContextManager.d.cts +53 -0
  4. package/dist/StackContextManager.d.cts.map +1 -0
  5. package/dist/StackContextManager.d.mts +53 -0
  6. package/dist/StackContextManager.d.mts.map +1 -0
  7. package/dist/StackContextManager.mjs +89 -0
  8. package/dist/StackContextManager.mjs.map +1 -0
  9. package/dist/WebTracerProvider.cjs +52 -0
  10. package/dist/WebTracerProvider.cjs.map +1 -0
  11. package/dist/WebTracerProvider.d.cts +27 -0
  12. package/dist/WebTracerProvider.d.cts.map +1 -0
  13. package/dist/WebTracerProvider.d.mts +27 -0
  14. package/dist/WebTracerProvider.d.mts.map +1 -0
  15. package/dist/WebTracerProvider.mjs +52 -0
  16. package/dist/WebTracerProvider.mjs.map +1 -0
  17. package/dist/enums/PerformanceTimingNames.cjs +31 -0
  18. package/dist/enums/PerformanceTimingNames.cjs.map +1 -0
  19. package/dist/enums/PerformanceTimingNames.d.cts +29 -0
  20. package/dist/enums/PerformanceTimingNames.d.cts.map +1 -0
  21. package/dist/enums/PerformanceTimingNames.d.mts +29 -0
  22. package/dist/enums/PerformanceTimingNames.d.mts.map +1 -0
  23. package/dist/enums/PerformanceTimingNames.mjs +31 -0
  24. package/dist/enums/PerformanceTimingNames.mjs.map +1 -0
  25. package/dist/index.cjs +90 -0
  26. package/dist/index.d.cts +7 -0
  27. package/dist/index.d.mts +7 -0
  28. package/dist/index.mjs +6 -0
  29. package/dist/semconv.cjs +26 -0
  30. package/dist/semconv.cjs.map +1 -0
  31. package/dist/semconv.mjs +25 -0
  32. package/dist/semconv.mjs.map +1 -0
  33. package/dist/types.d.cts +49 -0
  34. package/dist/types.d.cts.map +1 -0
  35. package/dist/types.d.mts +49 -0
  36. package/dist/types.d.mts.map +1 -0
  37. package/dist/utils.cjs +237 -0
  38. package/dist/utils.cjs.map +1 -0
  39. package/dist/utils.d.cts +83 -0
  40. package/dist/utils.d.cts.map +1 -0
  41. package/dist/utils.d.mts +83 -0
  42. package/dist/utils.d.mts.map +1 -0
  43. package/dist/utils.mjs +229 -0
  44. package/dist/utils.mjs.map +1 -0
  45. package/package.json +31 -29
  46. package/build/esm/StackContextManager.d.ts +0 -50
  47. package/build/esm/StackContextManager.js +0 -98
  48. package/build/esm/StackContextManager.js.map +0 -1
  49. package/build/esm/WebTracerProvider.d.ts +0 -25
  50. package/build/esm/WebTracerProvider.js +0 -65
  51. package/build/esm/WebTracerProvider.js.map +0 -1
  52. package/build/esm/enums/PerformanceTimingNames.d.ts +0 -26
  53. package/build/esm/enums/PerformanceTimingNames.js +0 -31
  54. package/build/esm/enums/PerformanceTimingNames.js.map +0 -1
  55. package/build/esm/index.d.ts +0 -10
  56. package/build/esm/index.js +0 -10
  57. package/build/esm/index.js.map +0 -1
  58. package/build/esm/semconv.d.ts +0 -21
  59. package/build/esm/semconv.js +0 -30
  60. package/build/esm/semconv.js.map +0 -1
  61. package/build/esm/types.d.ts +0 -47
  62. package/build/esm/types.js +0 -2
  63. package/build/esm/types.js.map +0 -1
  64. package/build/esm/utils.d.ts +0 -80
  65. package/build/esm/utils.js +0 -316
  66. package/build/esm/utils.js.map +0 -1
  67. package/build/esm/version.d.ts +0 -2
  68. package/build/esm/version.js +0 -7
  69. package/build/esm/version.js.map +0 -1
  70. package/build/esnext/StackContextManager.d.ts +0 -50
  71. package/build/esnext/StackContextManager.js +0 -98
  72. package/build/esnext/StackContextManager.js.map +0 -1
  73. package/build/esnext/WebTracerProvider.d.ts +0 -25
  74. package/build/esnext/WebTracerProvider.js +0 -65
  75. package/build/esnext/WebTracerProvider.js.map +0 -1
  76. package/build/esnext/enums/PerformanceTimingNames.d.ts +0 -26
  77. package/build/esnext/enums/PerformanceTimingNames.js +0 -31
  78. package/build/esnext/enums/PerformanceTimingNames.js.map +0 -1
  79. package/build/esnext/index.d.ts +0 -10
  80. package/build/esnext/index.js +0 -10
  81. package/build/esnext/index.js.map +0 -1
  82. package/build/esnext/semconv.d.ts +0 -21
  83. package/build/esnext/semconv.js +0 -30
  84. package/build/esnext/semconv.js.map +0 -1
  85. package/build/esnext/types.d.ts +0 -47
  86. package/build/esnext/types.js +0 -2
  87. package/build/esnext/types.js.map +0 -1
  88. package/build/esnext/utils.d.ts +0 -80
  89. package/build/esnext/utils.js +0 -316
  90. package/build/esnext/utils.js.map +0 -1
  91. package/build/esnext/version.d.ts +0 -2
  92. package/build/esnext/version.js +0 -7
  93. package/build/esnext/version.js.map +0 -1
  94. package/build/src/StackContextManager.d.ts +0 -50
  95. package/build/src/StackContextManager.js +0 -102
  96. package/build/src/StackContextManager.js.map +0 -1
  97. package/build/src/WebTracerProvider.d.ts +0 -25
  98. package/build/src/WebTracerProvider.js +0 -69
  99. package/build/src/WebTracerProvider.js.map +0 -1
  100. package/build/src/enums/PerformanceTimingNames.d.ts +0 -26
  101. package/build/src/enums/PerformanceTimingNames.js +0 -34
  102. package/build/src/enums/PerformanceTimingNames.js.map +0 -1
  103. package/build/src/index.d.ts +0 -10
  104. package/build/src/index.js +0 -37
  105. package/build/src/index.js.map +0 -1
  106. package/build/src/semconv.d.ts +0 -21
  107. package/build/src/semconv.js +0 -33
  108. package/build/src/semconv.js.map +0 -1
  109. package/build/src/types.d.ts +0 -47
  110. package/build/src/types.js +0 -3
  111. package/build/src/types.js.map +0 -1
  112. package/build/src/utils.d.ts +0 -80
  113. package/build/src/utils.js +0 -328
  114. package/build/src/utils.js.map +0 -1
  115. package/build/src/version.d.ts +0 -2
  116. package/build/src/version.js +0 -10
  117. package/build/src/version.js.map +0 -1
@@ -1,316 +0,0 @@
1
- /*
2
- * Copyright The OpenTelemetry Authors
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
- import { PerformanceTimingNames as PTN } from './enums/PerformanceTimingNames';
6
- import { hrTimeToNanoseconds, timeInputToHrTime, urlMatches, } from '@opentelemetry/core';
7
- import { ATTR_HTTP_RESPONSE_CONTENT_LENGTH, ATTR_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED, } from './semconv';
8
- // Used to normalize relative URLs
9
- let urlNormalizingAnchor;
10
- function getUrlNormalizingAnchor() {
11
- if (!urlNormalizingAnchor) {
12
- urlNormalizingAnchor = document.createElement('a');
13
- }
14
- return urlNormalizingAnchor;
15
- }
16
- /**
17
- * Helper function to be able to use enum as typed key in type and in interface when using forEach
18
- * @param obj
19
- * @param key
20
- */
21
- export function hasKey(obj, key) {
22
- return key in obj;
23
- }
24
- /**
25
- * Helper function for starting an event on span based on {@link PerformanceEntries}
26
- * @param span
27
- * @param performanceName name of performance entry for time start
28
- * @param entries
29
- * @param ignoreZeros
30
- */
31
- export function addSpanNetworkEvent(span, performanceName, entries, ignoreZeros = true) {
32
- if (hasKey(entries, performanceName) &&
33
- typeof entries[performanceName] === 'number' &&
34
- !(ignoreZeros && entries[performanceName] === 0)) {
35
- return span.addEvent(performanceName, entries[performanceName]);
36
- }
37
- return undefined;
38
- }
39
- /**
40
- * Helper function for adding network events and content length attributes.
41
- */
42
- export function addSpanNetworkEvents(span, resource, ignoreNetworkEvents = false, ignoreZeros, skipOldSemconvContentLengthAttrs) {
43
- if (ignoreZeros === undefined) {
44
- ignoreZeros = resource[PTN.START_TIME] !== 0;
45
- }
46
- if (!ignoreNetworkEvents) {
47
- addSpanNetworkEvent(span, PTN.FETCH_START, resource, ignoreZeros);
48
- addSpanNetworkEvent(span, PTN.DOMAIN_LOOKUP_START, resource, ignoreZeros);
49
- addSpanNetworkEvent(span, PTN.DOMAIN_LOOKUP_END, resource, ignoreZeros);
50
- addSpanNetworkEvent(span, PTN.CONNECT_START, resource, ignoreZeros);
51
- addSpanNetworkEvent(span, PTN.SECURE_CONNECTION_START, resource, ignoreZeros);
52
- addSpanNetworkEvent(span, PTN.CONNECT_END, resource, ignoreZeros);
53
- addSpanNetworkEvent(span, PTN.REQUEST_START, resource, ignoreZeros);
54
- addSpanNetworkEvent(span, PTN.RESPONSE_START, resource, ignoreZeros);
55
- addSpanNetworkEvent(span, PTN.RESPONSE_END, resource, ignoreZeros);
56
- }
57
- if (!skipOldSemconvContentLengthAttrs) {
58
- // This block adds content-length-related span attributes using the
59
- // *old* HTTP semconv (v1.7.0).
60
- const encodedLength = resource[PTN.ENCODED_BODY_SIZE];
61
- if (encodedLength !== undefined) {
62
- span.setAttribute(ATTR_HTTP_RESPONSE_CONTENT_LENGTH, encodedLength);
63
- }
64
- const decodedLength = resource[PTN.DECODED_BODY_SIZE];
65
- // Spec: Not set if transport encoding not used (in which case encoded and decoded sizes match)
66
- if (decodedLength !== undefined && encodedLength !== decodedLength) {
67
- span.setAttribute(ATTR_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED, decodedLength);
68
- }
69
- }
70
- }
71
- /**
72
- * sort resources by startTime
73
- * @param filteredResources
74
- */
75
- export function sortResources(filteredResources) {
76
- return filteredResources.slice().sort((a, b) => {
77
- const valueA = a[PTN.FETCH_START];
78
- const valueB = b[PTN.FETCH_START];
79
- if (valueA > valueB) {
80
- return 1;
81
- }
82
- else if (valueA < valueB) {
83
- return -1;
84
- }
85
- return 0;
86
- });
87
- }
88
- /** Returns the origin if present (if in browser context). */
89
- function getOrigin() {
90
- return typeof location !== 'undefined' ? location.origin : undefined;
91
- }
92
- /**
93
- * Get closest performance resource ignoring the resources that have been
94
- * already used.
95
- * @param spanUrl
96
- * @param startTimeHR
97
- * @param endTimeHR
98
- * @param resources
99
- * @param ignoredResources
100
- * @param initiatorType
101
- */
102
- export function getResource(spanUrl, startTimeHR, endTimeHR, resources, ignoredResources = new WeakSet(), initiatorType) {
103
- // de-relativize the URL before usage (does no harm to absolute URLs)
104
- const parsedSpanUrl = parseUrl(spanUrl);
105
- spanUrl = parsedSpanUrl.toString();
106
- const filteredResources = filterResourcesForSpan(spanUrl, startTimeHR, endTimeHR, resources, ignoredResources, initiatorType);
107
- if (filteredResources.length === 0) {
108
- return {
109
- mainRequest: undefined,
110
- };
111
- }
112
- if (filteredResources.length === 1) {
113
- return {
114
- mainRequest: filteredResources[0],
115
- };
116
- }
117
- const sorted = sortResources(filteredResources);
118
- if (parsedSpanUrl.origin !== getOrigin() && sorted.length > 1) {
119
- let corsPreFlightRequest = sorted[0];
120
- let mainRequest = findMainRequest(sorted, corsPreFlightRequest[PTN.RESPONSE_END], endTimeHR);
121
- const responseEnd = corsPreFlightRequest[PTN.RESPONSE_END];
122
- const fetchStart = mainRequest[PTN.FETCH_START];
123
- // no corsPreFlightRequest
124
- if (fetchStart < responseEnd) {
125
- mainRequest = corsPreFlightRequest;
126
- corsPreFlightRequest = undefined;
127
- }
128
- return {
129
- corsPreFlightRequest,
130
- mainRequest,
131
- };
132
- }
133
- else {
134
- return {
135
- mainRequest: filteredResources[0],
136
- };
137
- }
138
- }
139
- /**
140
- * Will find the main request skipping the cors pre flight requests
141
- * @param resources
142
- * @param corsPreFlightRequestEndTime
143
- * @param spanEndTimeHR
144
- */
145
- function findMainRequest(resources, corsPreFlightRequestEndTime, spanEndTimeHR) {
146
- const spanEndTime = hrTimeToNanoseconds(spanEndTimeHR);
147
- const minTime = hrTimeToNanoseconds(timeInputToHrTime(corsPreFlightRequestEndTime));
148
- let mainRequest = resources[1];
149
- let bestGap;
150
- const length = resources.length;
151
- for (let i = 1; i < length; i++) {
152
- const resource = resources[i];
153
- const resourceStartTime = hrTimeToNanoseconds(timeInputToHrTime(resource[PTN.FETCH_START]));
154
- const resourceEndTime = hrTimeToNanoseconds(timeInputToHrTime(resource[PTN.RESPONSE_END]));
155
- const currentGap = spanEndTime - resourceEndTime;
156
- if (resourceStartTime >= minTime && (!bestGap || currentGap < bestGap)) {
157
- bestGap = currentGap;
158
- mainRequest = resource;
159
- }
160
- }
161
- return mainRequest;
162
- }
163
- /**
164
- * Filter all resources that has started and finished according to span start time and end time.
165
- * It will return the closest resource to a start time
166
- * @param spanUrl
167
- * @param startTimeHR
168
- * @param endTimeHR
169
- * @param resources
170
- * @param ignoredResources
171
- */
172
- function filterResourcesForSpan(spanUrl, startTimeHR, endTimeHR, resources, ignoredResources, initiatorType) {
173
- const startTime = hrTimeToNanoseconds(startTimeHR);
174
- const endTime = hrTimeToNanoseconds(endTimeHR);
175
- let filteredResources = resources.filter(resource => {
176
- const resourceStartTime = hrTimeToNanoseconds(timeInputToHrTime(resource[PTN.FETCH_START]));
177
- const resourceEndTime = hrTimeToNanoseconds(timeInputToHrTime(resource[PTN.RESPONSE_END]));
178
- return (resource.initiatorType.toLowerCase() ===
179
- (initiatorType || 'xmlhttprequest') &&
180
- resource.name === spanUrl &&
181
- resourceStartTime >= startTime &&
182
- resourceEndTime <= endTime);
183
- });
184
- if (filteredResources.length > 0) {
185
- filteredResources = filteredResources.filter(resource => {
186
- return !ignoredResources.has(resource);
187
- });
188
- }
189
- return filteredResources;
190
- }
191
- /**
192
- * Parses url using URL constructor or fallback to anchor element.
193
- * @param url
194
- */
195
- export function parseUrl(url) {
196
- if (typeof URL === 'function') {
197
- return new URL(url, typeof document !== 'undefined'
198
- ? document.baseURI
199
- : typeof location !== 'undefined' // Some JS runtimes (e.g. Deno) don't define this
200
- ? location.href
201
- : undefined);
202
- }
203
- const element = getUrlNormalizingAnchor();
204
- element.href = url;
205
- return element;
206
- }
207
- /**
208
- * Parses url using URL constructor or fallback to anchor element and serialize
209
- * it to a string.
210
- *
211
- * Performs the steps described in https://html.spec.whatwg.org/multipage/urls-and-fetching.html#parse-a-url
212
- *
213
- * @param url
214
- */
215
- export function normalizeUrl(url) {
216
- const urlLike = parseUrl(url);
217
- return urlLike.href;
218
- }
219
- /**
220
- * Get element XPath
221
- * @param target - target element
222
- * @param optimised - when id attribute of element is present the xpath can be
223
- * simplified to contain id
224
- */
225
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
226
- export function getElementXPath(target, optimised) {
227
- if (target.nodeType === Node.DOCUMENT_NODE) {
228
- return '/';
229
- }
230
- const targetValue = getNodeValue(target, optimised);
231
- if (optimised && targetValue.indexOf('@id') > 0) {
232
- return targetValue;
233
- }
234
- let xpath = '';
235
- if (target.parentNode) {
236
- xpath += getElementXPath(target.parentNode, optimised);
237
- }
238
- xpath += targetValue;
239
- return xpath;
240
- }
241
- /**
242
- * get node index within the siblings
243
- * @param target
244
- */
245
- function getNodeIndex(target) {
246
- if (!target.parentNode) {
247
- return 0;
248
- }
249
- const allowedTypes = [target.nodeType];
250
- if (target.nodeType === Node.CDATA_SECTION_NODE) {
251
- allowedTypes.push(Node.TEXT_NODE);
252
- }
253
- let elements = Array.from(target.parentNode.childNodes);
254
- elements = elements.filter((element) => {
255
- const localName = element.localName;
256
- return (allowedTypes.indexOf(element.nodeType) >= 0 &&
257
- localName === target.localName);
258
- });
259
- if (elements.length >= 1) {
260
- return elements.indexOf(target) + 1; // xpath starts from 1
261
- }
262
- // if there are no other similar child xpath doesn't need index
263
- return 0;
264
- }
265
- /**
266
- * get node value for xpath
267
- * @param target
268
- * @param optimised
269
- */
270
- function getNodeValue(target, optimised) {
271
- const nodeType = target.nodeType;
272
- const index = getNodeIndex(target);
273
- let nodeValue;
274
- if (nodeType === Node.ELEMENT_NODE) {
275
- const id = target.getAttribute('id');
276
- if (optimised && id) {
277
- return `//*[@id="${id}"]`;
278
- }
279
- nodeValue = target.localName;
280
- }
281
- else if (nodeType === Node.TEXT_NODE ||
282
- nodeType === Node.CDATA_SECTION_NODE) {
283
- nodeValue = 'text()';
284
- }
285
- else if (nodeType === Node.COMMENT_NODE) {
286
- nodeValue = 'comment()';
287
- }
288
- else {
289
- return '';
290
- }
291
- // if index is 1 it can be omitted in xpath
292
- if (nodeValue && index > 1) {
293
- return `/${nodeValue}[${index}]`;
294
- }
295
- return `/${nodeValue}`;
296
- }
297
- /**
298
- * Checks if trace headers should be propagated
299
- * @param spanUrl
300
- * @private
301
- */
302
- export function shouldPropagateTraceHeaders(spanUrl, propagateTraceHeaderCorsUrls) {
303
- let propagateTraceHeaderUrls = propagateTraceHeaderCorsUrls || [];
304
- if (typeof propagateTraceHeaderUrls === 'string' ||
305
- propagateTraceHeaderUrls instanceof RegExp) {
306
- propagateTraceHeaderUrls = [propagateTraceHeaderUrls];
307
- }
308
- const parsedSpanUrl = parseUrl(spanUrl);
309
- if (parsedSpanUrl.origin === getOrigin()) {
310
- return true;
311
- }
312
- else {
313
- return propagateTraceHeaderUrls.some(propagateTraceHeaderUrl => urlMatches(spanUrl, propagateTraceHeaderUrl));
314
- }
315
- }
316
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAE,sBAAsB,IAAI,GAAG,EAAE,MAAM,gCAAgC,CAAC;AAE/E,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,UAAU,GACX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,iCAAiC,EACjC,8CAA8C,GAC/C,MAAM,WAAW,CAAC;AAEnB,kCAAkC;AAClC,IAAI,oBAAmD,CAAC;AACxD,SAAS,uBAAuB;IAC9B,IAAI,CAAC,oBAAoB,EAAE;QACzB,oBAAoB,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;KACpD;IAED,OAAO,oBAAoB,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,MAAM,CACpB,GAAM,EACN,GAAgB;IAEhB,OAAO,GAAG,IAAI,GAAG,CAAC;AACpB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAAc,EACd,eAAuB,EACvB,OAA2B,EAC3B,WAAW,GAAG,IAAI;IAElB,IACE,MAAM,CAAC,OAAO,EAAE,eAAe,CAAC;QAChC,OAAO,OAAO,CAAC,eAAe,CAAC,KAAK,QAAQ;QAC5C,CAAC,CAAC,WAAW,IAAI,OAAO,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QAC5C,wBAAwB,YAAY,MAAM,EAC1C;QACA,wBAAwB,GAAG,CAAC,wBAAwB,CAAC,CAAC;KACvD;IACD,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IAExC,IAAI,aAAa,CAAC,MAAM,KAAK,SAAS,EAAE,EAAE;QACxC,OAAO,IAAI,CAAC;KACb;SAAM;QACL,OAAO,wBAAwB,CAAC,IAAI,CAAC,uBAAuB,CAAC,EAAE,CAC7D,UAAU,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAC7C,CAAC;KACH;AACH,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n PerformanceEntries,\n PerformanceResourceTimingInfo,\n PropagateTraceHeaderCorsUrls,\n} from './types';\nimport { PerformanceTimingNames as PTN } from './enums/PerformanceTimingNames';\nimport type * as api from '@opentelemetry/api';\nimport {\n hrTimeToNanoseconds,\n timeInputToHrTime,\n urlMatches,\n} from '@opentelemetry/core';\nimport {\n ATTR_HTTP_RESPONSE_CONTENT_LENGTH,\n ATTR_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED,\n} from './semconv';\n\n// Used to normalize relative URLs\nlet urlNormalizingAnchor: HTMLAnchorElement | undefined;\nfunction getUrlNormalizingAnchor(): HTMLAnchorElement {\n if (!urlNormalizingAnchor) {\n urlNormalizingAnchor = document.createElement('a');\n }\n\n return urlNormalizingAnchor;\n}\n\n/**\n * Helper function to be able to use enum as typed key in type and in interface when using forEach\n * @param obj\n * @param key\n */\nexport function hasKey<O extends object>(\n obj: O,\n key: PropertyKey\n): key is keyof O {\n return key in obj;\n}\n\n/**\n * Helper function for starting an event on span based on {@link PerformanceEntries}\n * @param span\n * @param performanceName name of performance entry for time start\n * @param entries\n * @param ignoreZeros\n */\nexport function addSpanNetworkEvent(\n span: api.Span,\n performanceName: string,\n entries: PerformanceEntries,\n ignoreZeros = true\n): api.Span | undefined {\n if (\n hasKey(entries, performanceName) &&\n typeof entries[performanceName] === 'number' &&\n !(ignoreZeros && entries[performanceName] === 0)\n ) {\n return span.addEvent(performanceName, entries[performanceName]);\n }\n\n return undefined;\n}\n\n/**\n * Helper function for adding network events and content length attributes.\n */\nexport function addSpanNetworkEvents(\n span: api.Span,\n resource: PerformanceEntries,\n ignoreNetworkEvents = false,\n ignoreZeros?: boolean,\n skipOldSemconvContentLengthAttrs?: boolean\n): void {\n if (ignoreZeros === undefined) {\n ignoreZeros = resource[PTN.START_TIME] !== 0;\n }\n\n if (!ignoreNetworkEvents) {\n addSpanNetworkEvent(span, PTN.FETCH_START, resource, ignoreZeros);\n addSpanNetworkEvent(span, PTN.DOMAIN_LOOKUP_START, resource, ignoreZeros);\n addSpanNetworkEvent(span, PTN.DOMAIN_LOOKUP_END, resource, ignoreZeros);\n addSpanNetworkEvent(span, PTN.CONNECT_START, resource, ignoreZeros);\n addSpanNetworkEvent(\n span,\n PTN.SECURE_CONNECTION_START,\n resource,\n ignoreZeros\n );\n addSpanNetworkEvent(span, PTN.CONNECT_END, resource, ignoreZeros);\n addSpanNetworkEvent(span, PTN.REQUEST_START, resource, ignoreZeros);\n addSpanNetworkEvent(span, PTN.RESPONSE_START, resource, ignoreZeros);\n addSpanNetworkEvent(span, PTN.RESPONSE_END, resource, ignoreZeros);\n }\n\n if (!skipOldSemconvContentLengthAttrs) {\n // This block adds content-length-related span attributes using the\n // *old* HTTP semconv (v1.7.0).\n const encodedLength = resource[PTN.ENCODED_BODY_SIZE];\n if (encodedLength !== undefined) {\n span.setAttribute(ATTR_HTTP_RESPONSE_CONTENT_LENGTH, encodedLength);\n }\n\n const decodedLength = resource[PTN.DECODED_BODY_SIZE];\n // Spec: Not set if transport encoding not used (in which case encoded and decoded sizes match)\n if (decodedLength !== undefined && encodedLength !== decodedLength) {\n span.setAttribute(\n ATTR_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED,\n decodedLength\n );\n }\n }\n}\n\n/**\n * sort resources by startTime\n * @param filteredResources\n */\nexport function sortResources(\n filteredResources: PerformanceResourceTiming[]\n): PerformanceResourceTiming[] {\n return filteredResources.slice().sort((a, b) => {\n const valueA = a[PTN.FETCH_START];\n const valueB = b[PTN.FETCH_START];\n if (valueA > valueB) {\n return 1;\n } else if (valueA < valueB) {\n return -1;\n }\n return 0;\n });\n}\n\n/** Returns the origin if present (if in browser context). */\nfunction getOrigin(): string | undefined {\n return typeof location !== 'undefined' ? location.origin : undefined;\n}\n\n/**\n * Get closest performance resource ignoring the resources that have been\n * already used.\n * @param spanUrl\n * @param startTimeHR\n * @param endTimeHR\n * @param resources\n * @param ignoredResources\n * @param initiatorType\n */\nexport function getResource(\n spanUrl: string,\n startTimeHR: api.HrTime,\n endTimeHR: api.HrTime,\n resources: PerformanceResourceTiming[],\n ignoredResources: WeakSet<PerformanceResourceTiming> = new WeakSet<PerformanceResourceTiming>(),\n initiatorType?: string\n): PerformanceResourceTimingInfo {\n // de-relativize the URL before usage (does no harm to absolute URLs)\n const parsedSpanUrl = parseUrl(spanUrl);\n spanUrl = parsedSpanUrl.toString();\n\n const filteredResources = filterResourcesForSpan(\n spanUrl,\n startTimeHR,\n endTimeHR,\n resources,\n ignoredResources,\n initiatorType\n );\n\n if (filteredResources.length === 0) {\n return {\n mainRequest: undefined,\n };\n }\n if (filteredResources.length === 1) {\n return {\n mainRequest: filteredResources[0],\n };\n }\n const sorted = sortResources(filteredResources);\n\n if (parsedSpanUrl.origin !== getOrigin() && sorted.length > 1) {\n let corsPreFlightRequest: PerformanceResourceTiming | undefined = sorted[0];\n let mainRequest: PerformanceResourceTiming = findMainRequest(\n sorted,\n corsPreFlightRequest[PTN.RESPONSE_END],\n endTimeHR\n );\n\n const responseEnd = corsPreFlightRequest[PTN.RESPONSE_END];\n const fetchStart = mainRequest[PTN.FETCH_START];\n\n // no corsPreFlightRequest\n if (fetchStart < responseEnd) {\n mainRequest = corsPreFlightRequest;\n corsPreFlightRequest = undefined;\n }\n\n return {\n corsPreFlightRequest,\n mainRequest,\n };\n } else {\n return {\n mainRequest: filteredResources[0],\n };\n }\n}\n\n/**\n * Will find the main request skipping the cors pre flight requests\n * @param resources\n * @param corsPreFlightRequestEndTime\n * @param spanEndTimeHR\n */\nfunction findMainRequest(\n resources: PerformanceResourceTiming[],\n corsPreFlightRequestEndTime: number,\n spanEndTimeHR: api.HrTime\n): PerformanceResourceTiming {\n const spanEndTime = hrTimeToNanoseconds(spanEndTimeHR);\n const minTime = hrTimeToNanoseconds(\n timeInputToHrTime(corsPreFlightRequestEndTime)\n );\n\n let mainRequest: PerformanceResourceTiming = resources[1];\n let bestGap;\n\n const length = resources.length;\n for (let i = 1; i < length; i++) {\n const resource = resources[i];\n const resourceStartTime = hrTimeToNanoseconds(\n timeInputToHrTime(resource[PTN.FETCH_START])\n );\n\n const resourceEndTime = hrTimeToNanoseconds(\n timeInputToHrTime(resource[PTN.RESPONSE_END])\n );\n\n const currentGap = spanEndTime - resourceEndTime;\n\n if (resourceStartTime >= minTime && (!bestGap || currentGap < bestGap)) {\n bestGap = currentGap;\n mainRequest = resource;\n }\n }\n return mainRequest;\n}\n\n/**\n * Filter all resources that has started and finished according to span start time and end time.\n * It will return the closest resource to a start time\n * @param spanUrl\n * @param startTimeHR\n * @param endTimeHR\n * @param resources\n * @param ignoredResources\n */\nfunction filterResourcesForSpan(\n spanUrl: string,\n startTimeHR: api.HrTime,\n endTimeHR: api.HrTime,\n resources: PerformanceResourceTiming[],\n ignoredResources: WeakSet<PerformanceResourceTiming>,\n initiatorType?: string\n) {\n const startTime = hrTimeToNanoseconds(startTimeHR);\n const endTime = hrTimeToNanoseconds(endTimeHR);\n let filteredResources = resources.filter(resource => {\n const resourceStartTime = hrTimeToNanoseconds(\n timeInputToHrTime(resource[PTN.FETCH_START])\n );\n const resourceEndTime = hrTimeToNanoseconds(\n timeInputToHrTime(resource[PTN.RESPONSE_END])\n );\n\n return (\n resource.initiatorType.toLowerCase() ===\n (initiatorType || 'xmlhttprequest') &&\n resource.name === spanUrl &&\n resourceStartTime >= startTime &&\n resourceEndTime <= endTime\n );\n });\n\n if (filteredResources.length > 0) {\n filteredResources = filteredResources.filter(resource => {\n return !ignoredResources.has(resource);\n });\n }\n\n return filteredResources;\n}\n\n/**\n * The URLLike interface represents an URL and HTMLAnchorElement compatible fields.\n */\nexport interface URLLike {\n hash: string;\n host: string;\n hostname: string;\n href: string;\n readonly origin: string;\n password: string;\n pathname: string;\n port: string;\n protocol: string;\n search: string;\n username: string;\n}\n\n/**\n * Parses url using URL constructor or fallback to anchor element.\n * @param url\n */\nexport function parseUrl(url: string): URLLike {\n if (typeof URL === 'function') {\n return new URL(\n url,\n typeof document !== 'undefined'\n ? document.baseURI\n : typeof location !== 'undefined' // Some JS runtimes (e.g. Deno) don't define this\n ? location.href\n : undefined\n );\n }\n const element = getUrlNormalizingAnchor();\n element.href = url;\n return element;\n}\n\n/**\n * Parses url using URL constructor or fallback to anchor element and serialize\n * it to a string.\n *\n * Performs the steps described in https://html.spec.whatwg.org/multipage/urls-and-fetching.html#parse-a-url\n *\n * @param url\n */\nexport function normalizeUrl(url: string): string {\n const urlLike = parseUrl(url);\n return urlLike.href;\n}\n\n/**\n * Get element XPath\n * @param target - target element\n * @param optimised - when id attribute of element is present the xpath can be\n * simplified to contain id\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function getElementXPath(target: any, optimised?: boolean): string {\n if (target.nodeType === Node.DOCUMENT_NODE) {\n return '/';\n }\n const targetValue = getNodeValue(target, optimised);\n if (optimised && targetValue.indexOf('@id') > 0) {\n return targetValue;\n }\n let xpath = '';\n if (target.parentNode) {\n xpath += getElementXPath(target.parentNode, optimised);\n }\n xpath += targetValue;\n\n return xpath;\n}\n\n/**\n * get node index within the siblings\n * @param target\n */\nfunction getNodeIndex(target: HTMLElement): number {\n if (!target.parentNode) {\n return 0;\n }\n const allowedTypes = [target.nodeType];\n if (target.nodeType === Node.CDATA_SECTION_NODE) {\n allowedTypes.push(Node.TEXT_NODE);\n }\n let elements = Array.from(target.parentNode.childNodes);\n elements = elements.filter((element: Node) => {\n const localName = (element as HTMLElement).localName;\n return (\n allowedTypes.indexOf(element.nodeType) >= 0 &&\n localName === target.localName\n );\n });\n if (elements.length >= 1) {\n return elements.indexOf(target) + 1; // xpath starts from 1\n }\n // if there are no other similar child xpath doesn't need index\n return 0;\n}\n\n/**\n * get node value for xpath\n * @param target\n * @param optimised\n */\nfunction getNodeValue(target: HTMLElement, optimised?: boolean): string {\n const nodeType = target.nodeType;\n const index = getNodeIndex(target);\n let nodeValue: string;\n if (nodeType === Node.ELEMENT_NODE) {\n const id = target.getAttribute('id');\n if (optimised && id) {\n return `//*[@id=\"${id}\"]`;\n }\n nodeValue = target.localName;\n } else if (\n nodeType === Node.TEXT_NODE ||\n nodeType === Node.CDATA_SECTION_NODE\n ) {\n nodeValue = 'text()';\n } else if (nodeType === Node.COMMENT_NODE) {\n nodeValue = 'comment()';\n } else {\n return '';\n }\n // if index is 1 it can be omitted in xpath\n if (nodeValue && index > 1) {\n return `/${nodeValue}[${index}]`;\n }\n return `/${nodeValue}`;\n}\n\n/**\n * Checks if trace headers should be propagated\n * @param spanUrl\n * @private\n */\nexport function shouldPropagateTraceHeaders(\n spanUrl: string,\n propagateTraceHeaderCorsUrls?: PropagateTraceHeaderCorsUrls\n): boolean {\n let propagateTraceHeaderUrls = propagateTraceHeaderCorsUrls || [];\n if (\n typeof propagateTraceHeaderUrls === 'string' ||\n propagateTraceHeaderUrls instanceof RegExp\n ) {\n propagateTraceHeaderUrls = [propagateTraceHeaderUrls];\n }\n const parsedSpanUrl = parseUrl(spanUrl);\n\n if (parsedSpanUrl.origin === getOrigin()) {\n return true;\n } else {\n return propagateTraceHeaderUrls.some(propagateTraceHeaderUrl =>\n urlMatches(spanUrl, propagateTraceHeaderUrl)\n );\n }\n}\n"]}
@@ -1,2 +0,0 @@
1
- export declare const VERSION = "2.11.0-development.0";
2
- //# sourceMappingURL=version.d.ts.map
@@ -1,7 +0,0 @@
1
- /*
2
- * Copyright The OpenTelemetry Authors
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
- // this is autogenerated file, see scripts/version-update.js
6
- export const VERSION = '2.11.0-development.0';
7
- //# sourceMappingURL=version.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,sBAAsB,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '2.11.0-development.0';\n"]}
@@ -1,50 +0,0 @@
1
- import type { Context, ContextManager } from '@opentelemetry/api';
2
- /**
3
- * Stack Context Manager for managing the state in web
4
- * it doesn't fully support the async calls though
5
- */
6
- export declare class StackContextManager implements ContextManager {
7
- /**
8
- * whether the context manager is enabled or not
9
- */
10
- private _enabled;
11
- /**
12
- * Keeps the reference to current context
13
- */
14
- _currentContext: Context;
15
- /**
16
- *
17
- * @param context
18
- * @param target Function to be executed within the context
19
- */
20
- private _bindFunction;
21
- /**
22
- * Returns the active context
23
- */
24
- active(): Context;
25
- /**
26
- * Binds a the certain context or the active one to the target function and then returns the target
27
- * @param context A context (span) to be bind to target
28
- * @param target a function or event emitter. When target or one of its callbacks is called,
29
- * the provided context will be used as the active context for the duration of the call.
30
- */
31
- bind<T>(context: Context, target: T): T;
32
- /**
33
- * Disable the context manager (clears the current context)
34
- */
35
- disable(): this;
36
- /**
37
- * Enables the context manager and creates a default(root) context
38
- */
39
- enable(): this;
40
- /**
41
- * Calls the callback function [fn] with the provided [context]. If [context] is undefined then it will use the window.
42
- * The context will be set as active
43
- * @param context
44
- * @param fn Callback function
45
- * @param thisArg optional receiver to be used for calling fn
46
- * @param args optional arguments forwarded to fn
47
- */
48
- with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(context: Context | null, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
49
- }
50
- //# sourceMappingURL=StackContextManager.d.ts.map
@@ -1,98 +0,0 @@
1
- /*
2
- * Copyright The OpenTelemetry Authors
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
- import { ROOT_CONTEXT } from '@opentelemetry/api';
6
- /**
7
- * Stack Context Manager for managing the state in web
8
- * it doesn't fully support the async calls though
9
- */
10
- export class StackContextManager {
11
- /**
12
- * whether the context manager is enabled or not
13
- */
14
- _enabled = false;
15
- /**
16
- * Keeps the reference to current context
17
- */
18
- _currentContext = ROOT_CONTEXT;
19
- /**
20
- *
21
- * @param context
22
- * @param target Function to be executed within the context
23
- */
24
- // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
25
- _bindFunction(context = ROOT_CONTEXT, target) {
26
- const manager = this;
27
- const contextWrapper = function (...args) {
28
- return manager.with(context, () => target.apply(this, args));
29
- };
30
- Object.defineProperty(contextWrapper, 'length', {
31
- enumerable: false,
32
- configurable: true,
33
- writable: false,
34
- value: target.length,
35
- });
36
- return contextWrapper;
37
- }
38
- /**
39
- * Returns the active context
40
- */
41
- active() {
42
- return this._currentContext;
43
- }
44
- /**
45
- * Binds a the certain context or the active one to the target function and then returns the target
46
- * @param context A context (span) to be bind to target
47
- * @param target a function or event emitter. When target or one of its callbacks is called,
48
- * the provided context will be used as the active context for the duration of the call.
49
- */
50
- bind(context, target) {
51
- // if no specific context to propagate is given, we use the current one
52
- if (context === undefined) {
53
- context = this.active();
54
- }
55
- if (typeof target === 'function') {
56
- return this._bindFunction(context, target);
57
- }
58
- return target;
59
- }
60
- /**
61
- * Disable the context manager (clears the current context)
62
- */
63
- disable() {
64
- this._currentContext = ROOT_CONTEXT;
65
- this._enabled = false;
66
- return this;
67
- }
68
- /**
69
- * Enables the context manager and creates a default(root) context
70
- */
71
- enable() {
72
- if (this._enabled) {
73
- return this;
74
- }
75
- this._enabled = true;
76
- this._currentContext = ROOT_CONTEXT;
77
- return this;
78
- }
79
- /**
80
- * Calls the callback function [fn] with the provided [context]. If [context] is undefined then it will use the window.
81
- * The context will be set as active
82
- * @param context
83
- * @param fn Callback function
84
- * @param thisArg optional receiver to be used for calling fn
85
- * @param args optional arguments forwarded to fn
86
- */
87
- with(context, fn, thisArg, ...args) {
88
- const previousContext = this._currentContext;
89
- this._currentContext = context || ROOT_CONTEXT;
90
- try {
91
- return fn.call(thisArg, ...args);
92
- }
93
- finally {
94
- this._currentContext = previousContext;
95
- }
96
- }
97
- }
98
- //# sourceMappingURL=StackContextManager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StackContextManager.js","sourceRoot":"","sources":["../../src/StackContextManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IAC9B;;OAEG;IACK,QAAQ,GAAG,KAAK,CAAC;IAEzB;;OAEG;IACI,eAAe,GAAG,YAAY,CAAC;IAEtC;;;;OAIG;IACH,sEAAsE;IAC9D,aAAa,CACnB,OAAO,GAAG,YAAY,EACtB,MAAS;QAET,MAAM,OAAO,GAAG,IAAI,CAAC;QACrB,MAAM,cAAc,GAAG,UAAyB,GAAG,IAAe;YAChE,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;QAC/D,CAAC,CAAC;QACF,MAAM,CAAC,cAAc,CAAC,cAAc,EAAE,QAAQ,EAAE;YAC9C,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,IAAI;YAClB,QAAQ,EAAE,KAAK;YACf,KAAK,EAAE,MAAM,CAAC,MAAM;SACrB,CAAC,CAAC;QACH,OAAO,cAA8B,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED;;;;;OAKG;IACH,IAAI,CAAI,OAAgB,EAAE,MAAS;QACjC,uEAAuE;QACvE,IAAI,OAAO,KAAK,SAAS,EAAE;YACzB,OAAO,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;SACzB;QACD,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE;YAChC,OAAO,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;SAC5C;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,CAAC,eAAe,GAAG,YAAY,CAAC;QACpC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjB,OAAO,IAAI,CAAC;SACb;QACD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,eAAe,GAAG,YAAY,CAAC;QACpC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,CACF,OAAuB,EACvB,EAAK,EACL,OAA8B,EAC9B,GAAG,IAAO;QAEV,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAC7C,IAAI,CAAC,eAAe,GAAG,OAAO,IAAI,YAAY,CAAC;QAE/C,IAAI;YACF,OAAO,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;SAClC;gBAAS;YACR,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;SACxC;IACH,CAAC;CACF","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Context, ContextManager } from '@opentelemetry/api';\nimport { ROOT_CONTEXT } from '@opentelemetry/api';\n\n/**\n * Stack Context Manager for managing the state in web\n * it doesn't fully support the async calls though\n */\nexport class StackContextManager implements ContextManager {\n /**\n * whether the context manager is enabled or not\n */\n private _enabled = false;\n\n /**\n * Keeps the reference to current context\n */\n public _currentContext = ROOT_CONTEXT;\n\n /**\n *\n * @param context\n * @param target Function to be executed within the context\n */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n private _bindFunction<T extends Function>(\n context = ROOT_CONTEXT,\n target: T\n ): T {\n const manager = this;\n const contextWrapper = function (this: unknown, ...args: unknown[]) {\n return manager.with(context, () => target.apply(this, args));\n };\n Object.defineProperty(contextWrapper, 'length', {\n enumerable: false,\n configurable: true,\n writable: false,\n value: target.length,\n });\n return contextWrapper as unknown as T;\n }\n\n /**\n * Returns the active context\n */\n active(): Context {\n return this._currentContext;\n }\n\n /**\n * Binds a the certain context or the active one to the target function and then returns the target\n * @param context A context (span) to be bind to target\n * @param target a function or event emitter. When target or one of its callbacks is called,\n * the provided context will be used as the active context for the duration of the call.\n */\n bind<T>(context: Context, target: T): T {\n // if no specific context to propagate is given, we use the current one\n if (context === undefined) {\n context = this.active();\n }\n if (typeof target === 'function') {\n return this._bindFunction(context, target);\n }\n return target;\n }\n\n /**\n * Disable the context manager (clears the current context)\n */\n disable(): this {\n this._currentContext = ROOT_CONTEXT;\n this._enabled = false;\n return this;\n }\n\n /**\n * Enables the context manager and creates a default(root) context\n */\n enable(): this {\n if (this._enabled) {\n return this;\n }\n this._enabled = true;\n this._currentContext = ROOT_CONTEXT;\n return this;\n }\n\n /**\n * Calls the callback function [fn] with the provided [context]. If [context] is undefined then it will use the window.\n * The context will be set as active\n * @param context\n * @param fn Callback function\n * @param thisArg optional receiver to be used for calling fn\n * @param args optional arguments forwarded to fn\n */\n with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(\n context: Context | null,\n fn: F,\n thisArg?: ThisParameterType<F>,\n ...args: A\n ): ReturnType<F> {\n const previousContext = this._currentContext;\n this._currentContext = context || ROOT_CONTEXT;\n\n try {\n return fn.call(thisArg, ...args);\n } finally {\n this._currentContext = previousContext;\n }\n }\n}\n"]}
@@ -1,25 +0,0 @@
1
- import type { SDKRegistrationConfig, TracerConfig } from '@opentelemetry/sdk-trace-base';
2
- import { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';
3
- /**
4
- * WebTracerConfig provides an interface for configuring a Web Tracer.
5
- */
6
- export type WebTracerConfig = TracerConfig;
7
- /**
8
- * This class represents a web tracer with {@link StackContextManager}
9
- */
10
- export declare class WebTracerProvider extends BasicTracerProvider {
11
- /**
12
- * Constructs a new Tracer instance.
13
- * @param config Web Tracer config
14
- */
15
- constructor(config?: WebTracerConfig);
16
- /**
17
- * Register this TracerProvider for use with the OpenTelemetry API.
18
- * Undefined values may be replaced with defaults, and
19
- * null values will be skipped.
20
- *
21
- * @param config Configuration object for SDK registration
22
- */
23
- register(config?: SDKRegistrationConfig): void;
24
- }
25
- //# sourceMappingURL=WebTracerProvider.d.ts.map
@@ -1,65 +0,0 @@
1
- /*
2
- * Copyright The OpenTelemetry Authors
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
- import { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';
6
- import { StackContextManager } from './StackContextManager';
7
- import { trace, context, propagation } from '@opentelemetry/api';
8
- import { CompositePropagator, W3CBaggagePropagator, W3CTraceContextPropagator, } from '@opentelemetry/core';
9
- function setupContextManager(contextManager) {
10
- // null means 'do not register'
11
- if (contextManager === null) {
12
- return;
13
- }
14
- // undefined means 'register default'
15
- if (contextManager === undefined) {
16
- const defaultContextManager = new StackContextManager();
17
- defaultContextManager.enable();
18
- context.setGlobalContextManager(defaultContextManager);
19
- return;
20
- }
21
- contextManager.enable();
22
- context.setGlobalContextManager(contextManager);
23
- }
24
- function setupPropagator(propagator) {
25
- // null means 'do not register'
26
- if (propagator === null) {
27
- return;
28
- }
29
- // undefined means 'register default'
30
- if (propagator === undefined) {
31
- propagation.setGlobalPropagator(new CompositePropagator({
32
- propagators: [
33
- new W3CTraceContextPropagator(),
34
- new W3CBaggagePropagator(),
35
- ],
36
- }));
37
- return;
38
- }
39
- propagation.setGlobalPropagator(propagator);
40
- }
41
- /**
42
- * This class represents a web tracer with {@link StackContextManager}
43
- */
44
- export class WebTracerProvider extends BasicTracerProvider {
45
- /**
46
- * Constructs a new Tracer instance.
47
- * @param config Web Tracer config
48
- */
49
- constructor(config = {}) {
50
- super(config);
51
- }
52
- /**
53
- * Register this TracerProvider for use with the OpenTelemetry API.
54
- * Undefined values may be replaced with defaults, and
55
- * null values will be skipped.
56
- *
57
- * @param config Configuration object for SDK registration
58
- */
59
- register(config = {}) {
60
- trace.setGlobalTracerProvider(this);
61
- setupPropagator(config.propagator);
62
- setupContextManager(config.contextManager);
63
- }
64
- }
65
- //# sourceMappingURL=WebTracerProvider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WebTracerProvider.js","sourceRoot":"","sources":["../../src/WebTracerProvider.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAC;AAE7B,SAAS,mBAAmB,CAC1B,cAAiD;IAEjD,+BAA+B;IAC/B,IAAI,cAAc,KAAK,IAAI,EAAE;QAC3B,OAAO;KACR;IAED,qCAAqC;IACrC,IAAI,cAAc,KAAK,SAAS,EAAE;QAChC,MAAM,qBAAqB,GAAG,IAAI,mBAAmB,EAAE,CAAC;QACxD,qBAAqB,CAAC,MAAM,EAAE,CAAC;QAC/B,OAAO,CAAC,uBAAuB,CAAC,qBAAqB,CAAC,CAAC;QACvD,OAAO;KACR;IAED,cAAc,CAAC,MAAM,EAAE,CAAC;IACxB,OAAO,CAAC,uBAAuB,CAAC,cAAc,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,eAAe,CAAC,UAAgD;IACvE,+BAA+B;IAC/B,IAAI,UAAU,KAAK,IAAI,EAAE;QACvB,OAAO;KACR;IAED,qCAAqC;IACrC,IAAI,UAAU,KAAK,SAAS,EAAE;QAC5B,WAAW,CAAC,mBAAmB,CAC7B,IAAI,mBAAmB,CAAC;YACtB,WAAW,EAAE;gBACX,IAAI,yBAAyB,EAAE;gBAC/B,IAAI,oBAAoB,EAAE;aAC3B;SACF,CAAC,CACH,CAAC;QACF,OAAO;KACR;IAED,WAAW,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;AAC9C,CAAC;AAOD;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,mBAAmB;IACxD;;;OAGG;IACH,YAAY,SAA0B,EAAE;QACtC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,SAAgC,EAAE;QACzC,KAAK,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC;QACpC,eAAe,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACnC,mBAAmB,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAC7C,CAAC;CACF","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n SDKRegistrationConfig,\n TracerConfig,\n} from '@opentelemetry/sdk-trace-base';\nimport { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';\nimport { StackContextManager } from './StackContextManager';\nimport type { ContextManager, TextMapPropagator } from '@opentelemetry/api';\nimport { trace, context, propagation } from '@opentelemetry/api';\nimport {\n CompositePropagator,\n W3CBaggagePropagator,\n W3CTraceContextPropagator,\n} from '@opentelemetry/core';\n\nfunction setupContextManager(\n contextManager: ContextManager | null | undefined\n) {\n // null means 'do not register'\n if (contextManager === null) {\n return;\n }\n\n // undefined means 'register default'\n if (contextManager === undefined) {\n const defaultContextManager = new StackContextManager();\n defaultContextManager.enable();\n context.setGlobalContextManager(defaultContextManager);\n return;\n }\n\n contextManager.enable();\n context.setGlobalContextManager(contextManager);\n}\n\nfunction setupPropagator(propagator: TextMapPropagator | null | undefined) {\n // null means 'do not register'\n if (propagator === null) {\n return;\n }\n\n // undefined means 'register default'\n if (propagator === undefined) {\n propagation.setGlobalPropagator(\n new CompositePropagator({\n propagators: [\n new W3CTraceContextPropagator(),\n new W3CBaggagePropagator(),\n ],\n })\n );\n return;\n }\n\n propagation.setGlobalPropagator(propagator);\n}\n\n/**\n * WebTracerConfig provides an interface for configuring a Web Tracer.\n */\nexport type WebTracerConfig = TracerConfig;\n\n/**\n * This class represents a web tracer with {@link StackContextManager}\n */\nexport class WebTracerProvider extends BasicTracerProvider {\n /**\n * Constructs a new Tracer instance.\n * @param config Web Tracer config\n */\n constructor(config: WebTracerConfig = {}) {\n super(config);\n }\n\n /**\n * Register this TracerProvider for use with the OpenTelemetry API.\n * Undefined values may be replaced with defaults, and\n * null values will be skipped.\n *\n * @param config Configuration object for SDK registration\n */\n register(config: SDKRegistrationConfig = {}): void {\n trace.setGlobalTracerProvider(this);\n setupPropagator(config.propagator);\n setupContextManager(config.contextManager);\n }\n}\n"]}