@opentelemetry/sdk-trace-web 1.1.0 → 1.1.1

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 (46) hide show
  1. package/build/esm/StackContextManager.d.ts +50 -0
  2. package/build/esm/StackContextManager.js +148 -0
  3. package/build/esm/StackContextManager.js.map +1 -0
  4. package/build/esm/WebTracerProvider.d.ts +24 -0
  5. package/build/esm/WebTracerProvider.js +74 -0
  6. package/build/esm/WebTracerProvider.js.map +1 -0
  7. package/build/esm/enums/PerformanceTimingNames.d.ts +25 -0
  8. package/build/esm/enums/PerformanceTimingNames.js +41 -0
  9. package/build/esm/enums/PerformanceTimingNames.js.map +1 -0
  10. package/build/esm/index.d.ts +6 -0
  11. package/build/esm/index.js +21 -0
  12. package/build/esm/index.js.map +1 -0
  13. package/build/esm/types.d.ts +46 -0
  14. package/build/esm/types.js +17 -0
  15. package/build/esm/types.js.map +1 -0
  16. package/build/esm/utils.d.ts +81 -0
  17. package/build/esm/utils.js +315 -0
  18. package/build/esm/utils.js.map +1 -0
  19. package/build/esm/version.d.ts +2 -0
  20. package/build/esm/version.js +18 -0
  21. package/build/esm/version.js.map +1 -0
  22. package/build/esnext/StackContextManager.d.ts +50 -0
  23. package/build/esnext/StackContextManager.js +111 -0
  24. package/build/esnext/StackContextManager.js.map +1 -0
  25. package/build/esnext/WebTracerProvider.d.ts +24 -0
  26. package/build/esnext/WebTracerProvider.js +53 -0
  27. package/build/esnext/WebTracerProvider.js.map +1 -0
  28. package/build/esnext/enums/PerformanceTimingNames.d.ts +25 -0
  29. package/build/esnext/enums/PerformanceTimingNames.js +41 -0
  30. package/build/esnext/enums/PerformanceTimingNames.js.map +1 -0
  31. package/build/esnext/index.d.ts +6 -0
  32. package/build/esnext/index.js +21 -0
  33. package/build/esnext/index.js.map +1 -0
  34. package/build/esnext/types.d.ts +46 -0
  35. package/build/esnext/types.js +17 -0
  36. package/build/esnext/types.js.map +1 -0
  37. package/build/esnext/utils.d.ts +81 -0
  38. package/build/esnext/utils.js +312 -0
  39. package/build/esnext/utils.js.map +1 -0
  40. package/build/esnext/version.d.ts +2 -0
  41. package/build/esnext/version.js +18 -0
  42. package/build/esnext/version.js.map +1 -0
  43. package/build/src/version.d.ts +1 -1
  44. package/build/src/version.js +1 -1
  45. package/build/src/version.js.map +1 -1
  46. package/package.json +9 -8
@@ -0,0 +1,50 @@
1
+ import { 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
@@ -0,0 +1,148 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ var __read = (this && this.__read) || function (o, n) {
17
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
18
+ if (!m) return o;
19
+ var i = m.call(o), r, ar = [], e;
20
+ try {
21
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
22
+ }
23
+ catch (error) { e = { error: error }; }
24
+ finally {
25
+ try {
26
+ if (r && !r.done && (m = i["return"])) m.call(i);
27
+ }
28
+ finally { if (e) throw e.error; }
29
+ }
30
+ return ar;
31
+ };
32
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
33
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
34
+ if (ar || !(i in from)) {
35
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
36
+ ar[i] = from[i];
37
+ }
38
+ }
39
+ return to.concat(ar || Array.prototype.slice.call(from));
40
+ };
41
+ import { ROOT_CONTEXT } from '@opentelemetry/api';
42
+ /**
43
+ * Stack Context Manager for managing the state in web
44
+ * it doesn't fully support the async calls though
45
+ */
46
+ var StackContextManager = /** @class */ (function () {
47
+ function StackContextManager() {
48
+ /**
49
+ * whether the context manager is enabled or not
50
+ */
51
+ this._enabled = false;
52
+ /**
53
+ * Keeps the reference to current context
54
+ */
55
+ this._currentContext = ROOT_CONTEXT;
56
+ }
57
+ /**
58
+ *
59
+ * @param context
60
+ * @param target Function to be executed within the context
61
+ */
62
+ // eslint-disable-next-line @typescript-eslint/ban-types
63
+ StackContextManager.prototype._bindFunction = function (context, target) {
64
+ if (context === void 0) { context = ROOT_CONTEXT; }
65
+ var manager = this;
66
+ var contextWrapper = function () {
67
+ var _this = this;
68
+ var args = [];
69
+ for (var _i = 0; _i < arguments.length; _i++) {
70
+ args[_i] = arguments[_i];
71
+ }
72
+ return manager.with(context, function () { return target.apply(_this, args); });
73
+ };
74
+ Object.defineProperty(contextWrapper, 'length', {
75
+ enumerable: false,
76
+ configurable: true,
77
+ writable: false,
78
+ value: target.length,
79
+ });
80
+ return contextWrapper;
81
+ };
82
+ /**
83
+ * Returns the active context
84
+ */
85
+ StackContextManager.prototype.active = function () {
86
+ return this._currentContext;
87
+ };
88
+ /**
89
+ * Binds a the certain context or the active one to the target function and then returns the target
90
+ * @param context A context (span) to be bind to target
91
+ * @param target a function or event emitter. When target or one of its callbacks is called,
92
+ * the provided context will be used as the active context for the duration of the call.
93
+ */
94
+ StackContextManager.prototype.bind = function (context, target) {
95
+ // if no specific context to propagate is given, we use the current one
96
+ if (context === undefined) {
97
+ context = this.active();
98
+ }
99
+ if (typeof target === 'function') {
100
+ return this._bindFunction(context, target);
101
+ }
102
+ return target;
103
+ };
104
+ /**
105
+ * Disable the context manager (clears the current context)
106
+ */
107
+ StackContextManager.prototype.disable = function () {
108
+ this._currentContext = ROOT_CONTEXT;
109
+ this._enabled = false;
110
+ return this;
111
+ };
112
+ /**
113
+ * Enables the context manager and creates a default(root) context
114
+ */
115
+ StackContextManager.prototype.enable = function () {
116
+ if (this._enabled) {
117
+ return this;
118
+ }
119
+ this._enabled = true;
120
+ this._currentContext = ROOT_CONTEXT;
121
+ return this;
122
+ };
123
+ /**
124
+ * Calls the callback function [fn] with the provided [context]. If [context] is undefined then it will use the window.
125
+ * The context will be set as active
126
+ * @param context
127
+ * @param fn Callback function
128
+ * @param thisArg optional receiver to be used for calling fn
129
+ * @param args optional arguments forwarded to fn
130
+ */
131
+ StackContextManager.prototype.with = function (context, fn, thisArg) {
132
+ var args = [];
133
+ for (var _i = 3; _i < arguments.length; _i++) {
134
+ args[_i - 3] = arguments[_i];
135
+ }
136
+ var previousContext = this._currentContext;
137
+ this._currentContext = context || ROOT_CONTEXT;
138
+ try {
139
+ return fn.call.apply(fn, __spreadArray([thisArg], __read(args), false));
140
+ }
141
+ finally {
142
+ this._currentContext = previousContext;
143
+ }
144
+ };
145
+ return StackContextManager;
146
+ }());
147
+ export { StackContextManager };
148
+ //# sourceMappingURL=StackContextManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StackContextManager.js","sourceRoot":"","sources":["../../src/StackContextManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,OAAO,EAA2B,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAE3E;;;GAGG;AACH;IAAA;QACE;;WAEG;QACK,aAAQ,GAAG,KAAK,CAAC;QAEzB;;WAEG;QACI,oBAAe,GAAG,YAAY,CAAC;IA6FxC,CAAC;IA3FC;;;;OAIG;IACH,wDAAwD;IAChD,2CAAa,GAArB,UACE,OAAsB,EACtB,MAAS;QADT,wBAAA,EAAA,sBAAsB;QAGtB,IAAM,OAAO,GAAG,IAAI,CAAC;QACrB,IAAM,cAAc,GAAG;YAAA,iBAEtB;YAF+C,cAAkB;iBAAlB,UAAkB,EAAlB,qBAAkB,EAAlB,IAAkB;gBAAlB,yBAAkB;;YAChE,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,cAAM,OAAA,MAAM,CAAC,KAAK,CAAC,KAAI,EAAE,IAAI,CAAC,EAAxB,CAAwB,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,OAAQ,cAA+B,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,oCAAM,GAAN;QACE,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED;;;;;OAKG;IACH,kCAAI,GAAJ,UAAQ,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,qCAAO,GAAP;QACE,IAAI,CAAC,eAAe,GAAG,YAAY,CAAC;QACpC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,oCAAM,GAAN;QACE,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,kCAAI,GAAJ,UACE,OAAuB,EACvB,EAAK,EACL,OAA8B;QAC9B,cAAU;aAAV,UAAU,EAAV,qBAAU,EAAV,IAAU;YAAV,6BAAU;;QAEV,IAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAC7C,IAAI,CAAC,eAAe,GAAG,OAAO,IAAI,YAAY,CAAC;QAE/C,IAAI;YACF,OAAO,EAAE,CAAC,IAAI,OAAP,EAAE,iBAAM,OAAO,UAAK,IAAI,WAAE;SAClC;gBAAS;YACR,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;SACxC;IACH,CAAC;IACH,0BAAC;AAAD,CAAC,AAtGD,IAsGC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Context, ContextManager, 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/ban-types\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"]}
@@ -0,0 +1,24 @@
1
+ import { BasicTracerProvider, SDKRegistrationConfig, TracerConfig } from '@opentelemetry/sdk-trace-base';
2
+ /**
3
+ * WebTracerConfig provides an interface for configuring a Web Tracer.
4
+ */
5
+ export declare type WebTracerConfig = TracerConfig;
6
+ /**
7
+ * This class represents a web tracer with {@link StackContextManager}
8
+ */
9
+ export declare class WebTracerProvider extends BasicTracerProvider {
10
+ /**
11
+ * Constructs a new Tracer instance.
12
+ * @param config Web Tracer config
13
+ */
14
+ constructor(config?: WebTracerConfig);
15
+ /**
16
+ * Register this TracerProvider for use with the OpenTelemetry API.
17
+ * Undefined values may be replaced with defaults, and
18
+ * null values will be skipped.
19
+ *
20
+ * @param config Configuration object for SDK registration
21
+ */
22
+ register(config?: SDKRegistrationConfig): void;
23
+ }
24
+ //# sourceMappingURL=WebTracerProvider.d.ts.map
@@ -0,0 +1,74 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ var __extends = (this && this.__extends) || (function () {
17
+ var extendStatics = function (d, b) {
18
+ extendStatics = Object.setPrototypeOf ||
19
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
20
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
21
+ return extendStatics(d, b);
22
+ };
23
+ return function (d, b) {
24
+ if (typeof b !== "function" && b !== null)
25
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
26
+ extendStatics(d, b);
27
+ function __() { this.constructor = d; }
28
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29
+ };
30
+ })();
31
+ import { BasicTracerProvider, } from '@opentelemetry/sdk-trace-base';
32
+ import { StackContextManager } from './StackContextManager';
33
+ /**
34
+ * This class represents a web tracer with {@link StackContextManager}
35
+ */
36
+ var WebTracerProvider = /** @class */ (function (_super) {
37
+ __extends(WebTracerProvider, _super);
38
+ /**
39
+ * Constructs a new Tracer instance.
40
+ * @param config Web Tracer config
41
+ */
42
+ function WebTracerProvider(config) {
43
+ if (config === void 0) { config = {}; }
44
+ var _this = _super.call(this, config) || this;
45
+ if (config.contextManager) {
46
+ throw ('contextManager should be defined in register method not in' +
47
+ ' constructor');
48
+ }
49
+ if (config.propagator) {
50
+ throw 'propagator should be defined in register method not in constructor';
51
+ }
52
+ return _this;
53
+ }
54
+ /**
55
+ * Register this TracerProvider for use with the OpenTelemetry API.
56
+ * Undefined values may be replaced with defaults, and
57
+ * null values will be skipped.
58
+ *
59
+ * @param config Configuration object for SDK registration
60
+ */
61
+ WebTracerProvider.prototype.register = function (config) {
62
+ if (config === void 0) { config = {}; }
63
+ if (config.contextManager === undefined) {
64
+ config.contextManager = new StackContextManager();
65
+ }
66
+ if (config.contextManager) {
67
+ config.contextManager.enable();
68
+ }
69
+ _super.prototype.register.call(this, config);
70
+ };
71
+ return WebTracerProvider;
72
+ }(BasicTracerProvider));
73
+ export { WebTracerProvider };
74
+ //# sourceMappingURL=WebTracerProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebTracerProvider.js","sourceRoot":"","sources":["../../src/WebTracerProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;AAEH,OAAO,EACL,mBAAmB,GAGpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAO5D;;GAEG;AACH;IAAuC,qCAAmB;IACxD;;;OAGG;IACH,2BAAY,MAA4B;QAA5B,uBAAA,EAAA,WAA4B;QAAxC,YACE,kBAAM,MAAM,CAAC,SAWd;QATC,IAAK,MAAgC,CAAC,cAAc,EAAE;YACpD,MAAM,CACJ,4DAA4D;gBAC5D,cAAc,CACf,CAAC;SACH;QACD,IAAK,MAAgC,CAAC,UAAU,EAAE;YAChD,MAAM,oEAAoE,CAAC;SAC5E;;IACH,CAAC;IAED;;;;;;OAMG;IACM,oCAAQ,GAAjB,UAAkB,MAAkC;QAAlC,uBAAA,EAAA,WAAkC;QAClD,IAAI,MAAM,CAAC,cAAc,KAAK,SAAS,EAAE;YACvC,MAAM,CAAC,cAAc,GAAG,IAAI,mBAAmB,EAAE,CAAC;SACnD;QACD,IAAI,MAAM,CAAC,cAAc,EAAE;YACzB,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC;SAChC;QAED,iBAAM,QAAQ,YAAC,MAAM,CAAC,CAAC;IACzB,CAAC;IACH,wBAAC;AAAD,CAAC,AApCD,CAAuC,mBAAmB,GAoCzD","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n BasicTracerProvider,\n SDKRegistrationConfig,\n TracerConfig,\n} from '@opentelemetry/sdk-trace-base';\nimport { StackContextManager } from './StackContextManager';\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 if ((config as SDKRegistrationConfig).contextManager) {\n throw (\n 'contextManager should be defined in register method not in' +\n ' constructor'\n );\n }\n if ((config as SDKRegistrationConfig).propagator) {\n throw 'propagator should be defined in register method not in constructor';\n }\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 override register(config: SDKRegistrationConfig = {}): void {\n if (config.contextManager === undefined) {\n config.contextManager = new StackContextManager();\n }\n if (config.contextManager) {\n config.contextManager.enable();\n }\n\n super.register(config);\n }\n}\n"]}
@@ -0,0 +1,25 @@
1
+ export declare enum PerformanceTimingNames {
2
+ CONNECT_END = "connectEnd",
3
+ CONNECT_START = "connectStart",
4
+ DECODED_BODY_SIZE = "decodedBodySize",
5
+ DOM_COMPLETE = "domComplete",
6
+ DOM_CONTENT_LOADED_EVENT_END = "domContentLoadedEventEnd",
7
+ DOM_CONTENT_LOADED_EVENT_START = "domContentLoadedEventStart",
8
+ DOM_INTERACTIVE = "domInteractive",
9
+ DOMAIN_LOOKUP_END = "domainLookupEnd",
10
+ DOMAIN_LOOKUP_START = "domainLookupStart",
11
+ ENCODED_BODY_SIZE = "encodedBodySize",
12
+ FETCH_START = "fetchStart",
13
+ LOAD_EVENT_END = "loadEventEnd",
14
+ LOAD_EVENT_START = "loadEventStart",
15
+ NAVIGATION_START = "navigationStart",
16
+ REDIRECT_END = "redirectEnd",
17
+ REDIRECT_START = "redirectStart",
18
+ REQUEST_START = "requestStart",
19
+ RESPONSE_END = "responseEnd",
20
+ RESPONSE_START = "responseStart",
21
+ SECURE_CONNECTION_START = "secureConnectionStart",
22
+ UNLOAD_EVENT_END = "unloadEventEnd",
23
+ UNLOAD_EVENT_START = "unloadEventStart"
24
+ }
25
+ //# sourceMappingURL=PerformanceTimingNames.d.ts.map
@@ -0,0 +1,41 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export var PerformanceTimingNames;
17
+ (function (PerformanceTimingNames) {
18
+ PerformanceTimingNames["CONNECT_END"] = "connectEnd";
19
+ PerformanceTimingNames["CONNECT_START"] = "connectStart";
20
+ PerformanceTimingNames["DECODED_BODY_SIZE"] = "decodedBodySize";
21
+ PerformanceTimingNames["DOM_COMPLETE"] = "domComplete";
22
+ PerformanceTimingNames["DOM_CONTENT_LOADED_EVENT_END"] = "domContentLoadedEventEnd";
23
+ PerformanceTimingNames["DOM_CONTENT_LOADED_EVENT_START"] = "domContentLoadedEventStart";
24
+ PerformanceTimingNames["DOM_INTERACTIVE"] = "domInteractive";
25
+ PerformanceTimingNames["DOMAIN_LOOKUP_END"] = "domainLookupEnd";
26
+ PerformanceTimingNames["DOMAIN_LOOKUP_START"] = "domainLookupStart";
27
+ PerformanceTimingNames["ENCODED_BODY_SIZE"] = "encodedBodySize";
28
+ PerformanceTimingNames["FETCH_START"] = "fetchStart";
29
+ PerformanceTimingNames["LOAD_EVENT_END"] = "loadEventEnd";
30
+ PerformanceTimingNames["LOAD_EVENT_START"] = "loadEventStart";
31
+ PerformanceTimingNames["NAVIGATION_START"] = "navigationStart";
32
+ PerformanceTimingNames["REDIRECT_END"] = "redirectEnd";
33
+ PerformanceTimingNames["REDIRECT_START"] = "redirectStart";
34
+ PerformanceTimingNames["REQUEST_START"] = "requestStart";
35
+ PerformanceTimingNames["RESPONSE_END"] = "responseEnd";
36
+ PerformanceTimingNames["RESPONSE_START"] = "responseStart";
37
+ PerformanceTimingNames["SECURE_CONNECTION_START"] = "secureConnectionStart";
38
+ PerformanceTimingNames["UNLOAD_EVENT_END"] = "unloadEventEnd";
39
+ PerformanceTimingNames["UNLOAD_EVENT_START"] = "unloadEventStart";
40
+ })(PerformanceTimingNames || (PerformanceTimingNames = {}));
41
+ //# sourceMappingURL=PerformanceTimingNames.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PerformanceTimingNames.js","sourceRoot":"","sources":["../../../src/enums/PerformanceTimingNames.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,CAAN,IAAY,sBAuBX;AAvBD,WAAY,sBAAsB;IAChC,oDAA0B,CAAA;IAC1B,wDAA8B,CAAA;IAC9B,+DAAqC,CAAA;IACrC,sDAA4B,CAAA;IAC5B,mFAAyD,CAAA;IACzD,uFAA6D,CAAA;IAC7D,4DAAkC,CAAA;IAClC,+DAAqC,CAAA;IACrC,mEAAyC,CAAA;IACzC,+DAAqC,CAAA;IACrC,oDAA0B,CAAA;IAC1B,yDAA+B,CAAA;IAC/B,6DAAmC,CAAA;IACnC,8DAAoC,CAAA;IACpC,sDAA4B,CAAA;IAC5B,0DAAgC,CAAA;IAChC,wDAA8B,CAAA;IAC9B,sDAA4B,CAAA;IAC5B,0DAAgC,CAAA;IAChC,2EAAiD,CAAA;IACjD,6DAAmC,CAAA;IACnC,iEAAuC,CAAA;AACzC,CAAC,EAvBW,sBAAsB,KAAtB,sBAAsB,QAuBjC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport enum PerformanceTimingNames {\n CONNECT_END = 'connectEnd',\n CONNECT_START = 'connectStart',\n DECODED_BODY_SIZE = 'decodedBodySize',\n DOM_COMPLETE = 'domComplete',\n DOM_CONTENT_LOADED_EVENT_END = 'domContentLoadedEventEnd',\n DOM_CONTENT_LOADED_EVENT_START = 'domContentLoadedEventStart',\n DOM_INTERACTIVE = 'domInteractive',\n DOMAIN_LOOKUP_END = 'domainLookupEnd',\n DOMAIN_LOOKUP_START = 'domainLookupStart',\n ENCODED_BODY_SIZE = 'encodedBodySize',\n FETCH_START = 'fetchStart',\n LOAD_EVENT_END = 'loadEventEnd',\n LOAD_EVENT_START = 'loadEventStart',\n NAVIGATION_START = 'navigationStart',\n REDIRECT_END = 'redirectEnd',\n REDIRECT_START = 'redirectStart',\n REQUEST_START = 'requestStart',\n RESPONSE_END = 'responseEnd',\n RESPONSE_START = 'responseStart',\n SECURE_CONNECTION_START = 'secureConnectionStart',\n UNLOAD_EVENT_END = 'unloadEventEnd',\n UNLOAD_EVENT_START = 'unloadEventStart',\n}\n"]}
@@ -0,0 +1,6 @@
1
+ export * from './WebTracerProvider';
2
+ export * from './StackContextManager';
3
+ export * from './enums/PerformanceTimingNames';
4
+ export * from './types';
5
+ export * from './utils';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,21 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export * from './WebTracerProvider';
17
+ export * from './StackContextManager';
18
+ export * from './enums/PerformanceTimingNames';
19
+ export * from './types';
20
+ export * from './utils';
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * from './WebTracerProvider';\nexport * from './StackContextManager';\nexport * from './enums/PerformanceTimingNames';\nexport * from './types';\nexport * from './utils';\n"]}
@@ -0,0 +1,46 @@
1
+ import { PerformanceTimingNames } from './enums/PerformanceTimingNames';
2
+ export declare type PerformanceEntries = {
3
+ [PerformanceTimingNames.CONNECT_END]?: number;
4
+ [PerformanceTimingNames.CONNECT_START]?: number;
5
+ [PerformanceTimingNames.DECODED_BODY_SIZE]?: number;
6
+ [PerformanceTimingNames.DOM_COMPLETE]?: number;
7
+ [PerformanceTimingNames.DOM_CONTENT_LOADED_EVENT_END]?: number;
8
+ [PerformanceTimingNames.DOM_CONTENT_LOADED_EVENT_START]?: number;
9
+ [PerformanceTimingNames.DOM_INTERACTIVE]?: number;
10
+ [PerformanceTimingNames.DOMAIN_LOOKUP_END]?: number;
11
+ [PerformanceTimingNames.DOMAIN_LOOKUP_START]?: number;
12
+ [PerformanceTimingNames.ENCODED_BODY_SIZE]?: number;
13
+ [PerformanceTimingNames.FETCH_START]?: number;
14
+ [PerformanceTimingNames.LOAD_EVENT_END]?: number;
15
+ [PerformanceTimingNames.LOAD_EVENT_START]?: number;
16
+ [PerformanceTimingNames.REDIRECT_END]?: number;
17
+ [PerformanceTimingNames.REDIRECT_START]?: number;
18
+ [PerformanceTimingNames.REQUEST_START]?: number;
19
+ [PerformanceTimingNames.RESPONSE_END]?: number;
20
+ [PerformanceTimingNames.RESPONSE_START]?: number;
21
+ [PerformanceTimingNames.SECURE_CONNECTION_START]?: number;
22
+ [PerformanceTimingNames.UNLOAD_EVENT_END]?: number;
23
+ [PerformanceTimingNames.UNLOAD_EVENT_START]?: number;
24
+ };
25
+ /**
26
+ * This interface defines a fallback to read performance metrics,
27
+ * this happens for example on Safari Mac
28
+ */
29
+ export interface PerformanceLegacy {
30
+ timing?: PerformanceEntries;
31
+ }
32
+ /**
33
+ * This interface is used in {@link getResource} function to return
34
+ * main request and it's corresponding PreFlight request
35
+ */
36
+ export interface PerformanceResourceTimingInfo {
37
+ corsPreFlightRequest?: PerformanceResourceTiming;
38
+ mainRequest?: PerformanceResourceTiming;
39
+ }
40
+ declare type PropagateTraceHeaderCorsUrl = string | RegExp;
41
+ /**
42
+ * urls which should include trace headers when origin doesn't match
43
+ */
44
+ export declare type PropagateTraceHeaderCorsUrls = PropagateTraceHeaderCorsUrl | PropagateTraceHeaderCorsUrl[];
45
+ export {};
46
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { PerformanceTimingNames } from './enums/PerformanceTimingNames';
17
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { PerformanceTimingNames } from './enums/PerformanceTimingNames';\n\nexport type PerformanceEntries = {\n [PerformanceTimingNames.CONNECT_END]?: number;\n [PerformanceTimingNames.CONNECT_START]?: number;\n [PerformanceTimingNames.DECODED_BODY_SIZE]?: number;\n [PerformanceTimingNames.DOM_COMPLETE]?: number;\n [PerformanceTimingNames.DOM_CONTENT_LOADED_EVENT_END]?: number;\n [PerformanceTimingNames.DOM_CONTENT_LOADED_EVENT_START]?: number;\n [PerformanceTimingNames.DOM_INTERACTIVE]?: number;\n [PerformanceTimingNames.DOMAIN_LOOKUP_END]?: number;\n [PerformanceTimingNames.DOMAIN_LOOKUP_START]?: number;\n [PerformanceTimingNames.ENCODED_BODY_SIZE]?: number;\n [PerformanceTimingNames.FETCH_START]?: number;\n [PerformanceTimingNames.LOAD_EVENT_END]?: number;\n [PerformanceTimingNames.LOAD_EVENT_START]?: number;\n [PerformanceTimingNames.REDIRECT_END]?: number;\n [PerformanceTimingNames.REDIRECT_START]?: number;\n [PerformanceTimingNames.REQUEST_START]?: number;\n [PerformanceTimingNames.RESPONSE_END]?: number;\n [PerformanceTimingNames.RESPONSE_START]?: number;\n [PerformanceTimingNames.SECURE_CONNECTION_START]?: number;\n [PerformanceTimingNames.UNLOAD_EVENT_END]?: number;\n [PerformanceTimingNames.UNLOAD_EVENT_START]?: number;\n};\n\n/**\n * This interface defines a fallback to read performance metrics,\n * this happens for example on Safari Mac\n */\nexport interface PerformanceLegacy {\n timing?: PerformanceEntries;\n}\n\n/**\n * This interface is used in {@link getResource} function to return\n * main request and it's corresponding PreFlight request\n */\nexport interface PerformanceResourceTimingInfo {\n corsPreFlightRequest?: PerformanceResourceTiming;\n mainRequest?: PerformanceResourceTiming;\n}\n\ntype PropagateTraceHeaderCorsUrl = string | RegExp;\n\n/**\n * urls which should include trace headers when origin doesn't match\n */\nexport type PropagateTraceHeaderCorsUrls =\n | PropagateTraceHeaderCorsUrl\n | PropagateTraceHeaderCorsUrl[];\n"]}
@@ -0,0 +1,81 @@
1
+ import { PerformanceEntries, PerformanceResourceTimingInfo, PropagateTraceHeaderCorsUrls } from './types';
2
+ import * as api from '@opentelemetry/api';
3
+ /**
4
+ * Helper function to be able to use enum as typed key in type and in interface when using forEach
5
+ * @param obj
6
+ * @param key
7
+ */
8
+ export declare function hasKey<O>(obj: O, key: keyof any): key is keyof O;
9
+ /**
10
+ * Helper function for starting an event on span based on {@link PerformanceEntries}
11
+ * @param span
12
+ * @param performanceName name of performance entry for time start
13
+ * @param entries
14
+ */
15
+ export declare function addSpanNetworkEvent(span: api.Span, performanceName: string, entries: PerformanceEntries): api.Span | undefined;
16
+ /**
17
+ * Helper function for adding network events
18
+ * @param span
19
+ * @param resource
20
+ */
21
+ export declare function addSpanNetworkEvents(span: api.Span, resource: PerformanceEntries): void;
22
+ /**
23
+ * sort resources by startTime
24
+ * @param filteredResources
25
+ */
26
+ export declare function sortResources(filteredResources: PerformanceResourceTiming[]): PerformanceResourceTiming[];
27
+ /**
28
+ * Get closest performance resource ignoring the resources that have been
29
+ * already used.
30
+ * @param spanUrl
31
+ * @param startTimeHR
32
+ * @param endTimeHR
33
+ * @param resources
34
+ * @param ignoredResources
35
+ * @param initiatorType
36
+ */
37
+ export declare function getResource(spanUrl: string, startTimeHR: api.HrTime, endTimeHR: api.HrTime, resources: PerformanceResourceTiming[], ignoredResources?: WeakSet<PerformanceResourceTiming>, initiatorType?: string): PerformanceResourceTimingInfo;
38
+ /**
39
+ * The URLLike interface represents an URL and HTMLAnchorElement compatible fields.
40
+ */
41
+ export interface URLLike {
42
+ hash: string;
43
+ host: string;
44
+ hostname: string;
45
+ href: string;
46
+ readonly origin: string;
47
+ password: string;
48
+ pathname: string;
49
+ port: string;
50
+ protocol: string;
51
+ search: string;
52
+ username: string;
53
+ }
54
+ /**
55
+ * Parses url using URL constructor or fallback to anchor element.
56
+ * @param url
57
+ */
58
+ export declare function parseUrl(url: string): URLLike;
59
+ /**
60
+ * Parses url using URL constructor or fallback to anchor element and serialize
61
+ * it to a string.
62
+ *
63
+ * Performs the steps described in https://html.spec.whatwg.org/multipage/urls-and-fetching.html#parse-a-url
64
+ *
65
+ * @param url
66
+ */
67
+ export declare function normalizeUrl(url: string): string;
68
+ /**
69
+ * Get element XPath
70
+ * @param target - target element
71
+ * @param optimised - when id attribute of element is present the xpath can be
72
+ * simplified to contain id
73
+ */
74
+ export declare function getElementXPath(target: any, optimised?: boolean): string;
75
+ /**
76
+ * Checks if trace headers should be propagated
77
+ * @param spanUrl
78
+ * @private
79
+ */
80
+ export declare function shouldPropagateTraceHeaders(spanUrl: string, propagateTraceHeaderCorsUrls?: PropagateTraceHeaderCorsUrls): boolean;
81
+ //# sourceMappingURL=utils.d.ts.map