@equinor/fusion-framework-vite-plugin-spa 5.1.0 → 5.2.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.
- package/README.md +27 -3
- package/dist/TelemetryAdapter-B6JH_RXA.js +91 -0
- package/dist/TelemetryAdapter-B6JH_RXA.js.map +1 -0
- package/dist/create-legacy-browser-delegate-4GII-R4B.js +2762 -0
- package/dist/create-legacy-browser-delegate-4GII-R4B.js.map +1 -0
- package/dist/enable-dev-server-tracing-GfRoCLxu.js +8227 -0
- package/dist/enable-dev-server-tracing-GfRoCLxu.js.map +1 -0
- package/dist/esm/html/bootstrap.js +17 -0
- package/dist/esm/html/bootstrap.js.map +1 -1
- package/dist/esm/html/enable-dev-server-tracing.js +94 -0
- package/dist/esm/html/enable-dev-server-tracing.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/html/bootstrap.js +247 -104
- package/dist/html/bootstrap.js.map +1 -1
- package/dist/index-CiqJ1Og1.js +1570 -0
- package/dist/index-CiqJ1Og1.js.map +1 -0
- package/dist/{index-Df9EZ6lh.js → index-glg6-DFO.js} +2 -2
- package/dist/index-glg6-DFO.js.map +1 -0
- package/dist/{module-DzjJ4gjy.js → module-BR47HvRl.js} +748 -319
- package/dist/module-BR47HvRl.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/html/enable-dev-server-tracing.d.ts +17 -0
- package/dist/types/html/html.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +17 -6
- package/dist/index-Df9EZ6lh.js.map +0 -1
- package/dist/module-DzjJ4gjy.js.map +0 -1
|
@@ -0,0 +1,2762 @@
|
|
|
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
|
+
const VERSION$2 = '1.9.1';
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Copyright The OpenTelemetry Authors
|
|
10
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
*/
|
|
12
|
+
const re = /^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;
|
|
13
|
+
/**
|
|
14
|
+
* Create a function to test an API version to see if it is compatible with the provided ownVersion.
|
|
15
|
+
*
|
|
16
|
+
* The returned function has the following semantics:
|
|
17
|
+
* - Exact match is always compatible
|
|
18
|
+
* - Major versions must match exactly
|
|
19
|
+
* - 1.x package cannot use global 2.x package
|
|
20
|
+
* - 2.x package cannot use global 1.x package
|
|
21
|
+
* - The minor version of the API module requesting access to the global API must be less than or equal to the minor version of this API
|
|
22
|
+
* - 1.3 package may use 1.4 global because the later global contains all functions 1.3 expects
|
|
23
|
+
* - 1.4 package may NOT use 1.3 global because it may try to call functions which don't exist on 1.3
|
|
24
|
+
* - If the major version is 0, the minor version is treated as the major and the patch is treated as the minor
|
|
25
|
+
* - Patch and build tag differences are not considered at this time
|
|
26
|
+
*
|
|
27
|
+
* @param ownVersion version which should be checked against
|
|
28
|
+
*/
|
|
29
|
+
function _makeCompatibilityCheck(ownVersion) {
|
|
30
|
+
const acceptedVersions = new Set([ownVersion]);
|
|
31
|
+
const rejectedVersions = new Set();
|
|
32
|
+
const myVersionMatch = ownVersion.match(re);
|
|
33
|
+
if (!myVersionMatch) {
|
|
34
|
+
// we cannot guarantee compatibility so we always return noop
|
|
35
|
+
return () => false;
|
|
36
|
+
}
|
|
37
|
+
const ownVersionParsed = {
|
|
38
|
+
major: +myVersionMatch[1],
|
|
39
|
+
minor: +myVersionMatch[2],
|
|
40
|
+
patch: +myVersionMatch[3],
|
|
41
|
+
prerelease: myVersionMatch[4],
|
|
42
|
+
};
|
|
43
|
+
// if ownVersion has a prerelease tag, versions must match exactly
|
|
44
|
+
if (ownVersionParsed.prerelease != null) {
|
|
45
|
+
return function isExactmatch(globalVersion) {
|
|
46
|
+
return globalVersion === ownVersion;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function _reject(v) {
|
|
50
|
+
rejectedVersions.add(v);
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
function _accept(v) {
|
|
54
|
+
acceptedVersions.add(v);
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
return function isCompatible(globalVersion) {
|
|
58
|
+
if (acceptedVersions.has(globalVersion)) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
if (rejectedVersions.has(globalVersion)) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
const globalVersionMatch = globalVersion.match(re);
|
|
65
|
+
if (!globalVersionMatch) {
|
|
66
|
+
// cannot parse other version
|
|
67
|
+
// we cannot guarantee compatibility so we always noop
|
|
68
|
+
return _reject(globalVersion);
|
|
69
|
+
}
|
|
70
|
+
const globalVersionParsed = {
|
|
71
|
+
major: +globalVersionMatch[1],
|
|
72
|
+
minor: +globalVersionMatch[2],
|
|
73
|
+
patch: +globalVersionMatch[3],
|
|
74
|
+
prerelease: globalVersionMatch[4],
|
|
75
|
+
};
|
|
76
|
+
// if globalVersion has a prerelease tag, versions must match exactly
|
|
77
|
+
if (globalVersionParsed.prerelease != null) {
|
|
78
|
+
return _reject(globalVersion);
|
|
79
|
+
}
|
|
80
|
+
// major versions must match
|
|
81
|
+
if (ownVersionParsed.major !== globalVersionParsed.major) {
|
|
82
|
+
return _reject(globalVersion);
|
|
83
|
+
}
|
|
84
|
+
if (ownVersionParsed.major === 0) {
|
|
85
|
+
if (ownVersionParsed.minor === globalVersionParsed.minor &&
|
|
86
|
+
ownVersionParsed.patch <= globalVersionParsed.patch) {
|
|
87
|
+
return _accept(globalVersion);
|
|
88
|
+
}
|
|
89
|
+
return _reject(globalVersion);
|
|
90
|
+
}
|
|
91
|
+
if (ownVersionParsed.minor <= globalVersionParsed.minor) {
|
|
92
|
+
return _accept(globalVersion);
|
|
93
|
+
}
|
|
94
|
+
return _reject(globalVersion);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Test an API version to see if it is compatible with this API.
|
|
99
|
+
*
|
|
100
|
+
* - Exact match is always compatible
|
|
101
|
+
* - Major versions must match exactly
|
|
102
|
+
* - 1.x package cannot use global 2.x package
|
|
103
|
+
* - 2.x package cannot use global 1.x package
|
|
104
|
+
* - The minor version of the API module requesting access to the global API must be less than or equal to the minor version of this API
|
|
105
|
+
* - 1.3 package may use 1.4 global because the later global contains all functions 1.3 expects
|
|
106
|
+
* - 1.4 package may NOT use 1.3 global because it may try to call functions which don't exist on 1.3
|
|
107
|
+
* - If the major version is 0, the minor version is treated as the major and the patch is treated as the minor
|
|
108
|
+
* - Patch and build tag differences are not considered at this time
|
|
109
|
+
*
|
|
110
|
+
* @param version version of the API requesting an instance of the global API
|
|
111
|
+
*/
|
|
112
|
+
const isCompatible = _makeCompatibilityCheck(VERSION$2);
|
|
113
|
+
|
|
114
|
+
/*
|
|
115
|
+
* Copyright The OpenTelemetry Authors
|
|
116
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
117
|
+
*/
|
|
118
|
+
const major = VERSION$2.split('.')[0];
|
|
119
|
+
const GLOBAL_OPENTELEMETRY_API_KEY = Symbol.for(`opentelemetry.js.api.${major}`);
|
|
120
|
+
const _global = (typeof globalThis === 'object'
|
|
121
|
+
? globalThis
|
|
122
|
+
: typeof self === 'object'
|
|
123
|
+
? self
|
|
124
|
+
: typeof window === 'object'
|
|
125
|
+
? window
|
|
126
|
+
: typeof global === 'object'
|
|
127
|
+
? global
|
|
128
|
+
: {});
|
|
129
|
+
function registerGlobal(type, instance, diag, allowOverride = false) {
|
|
130
|
+
var _a;
|
|
131
|
+
const api = (_global[GLOBAL_OPENTELEMETRY_API_KEY] = (_a = _global[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _a !== void 0 ? _a : {
|
|
132
|
+
version: VERSION$2,
|
|
133
|
+
});
|
|
134
|
+
if (!allowOverride && api[type]) {
|
|
135
|
+
// already registered an API of this type
|
|
136
|
+
const err = new Error(`@opentelemetry/api: Attempted duplicate registration of API: ${type}`);
|
|
137
|
+
diag.error(err.stack || err.message);
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
if (api.version !== VERSION$2) {
|
|
141
|
+
// All registered APIs must be of the same version exactly
|
|
142
|
+
const err = new Error(`@opentelemetry/api: Registration of version v${api.version} for ${type} does not match previously registered API v${VERSION$2}`);
|
|
143
|
+
diag.error(err.stack || err.message);
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
api[type] = instance;
|
|
147
|
+
diag.debug(`@opentelemetry/api: Registered a global for ${type} v${VERSION$2}.`);
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
function getGlobal(type) {
|
|
151
|
+
var _a, _b;
|
|
152
|
+
const globalVersion = (_a = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _a === void 0 ? void 0 : _a.version;
|
|
153
|
+
if (!globalVersion || !isCompatible(globalVersion)) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
return (_b = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _b === void 0 ? void 0 : _b[type];
|
|
157
|
+
}
|
|
158
|
+
function unregisterGlobal(type, diag) {
|
|
159
|
+
diag.debug(`@opentelemetry/api: Unregistering a global for ${type} v${VERSION$2}.`);
|
|
160
|
+
const api = _global[GLOBAL_OPENTELEMETRY_API_KEY];
|
|
161
|
+
if (api) {
|
|
162
|
+
delete api[type];
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/*
|
|
167
|
+
* Copyright The OpenTelemetry Authors
|
|
168
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
169
|
+
*/
|
|
170
|
+
/**
|
|
171
|
+
* Component Logger which is meant to be used as part of any component which
|
|
172
|
+
* will add automatically additional namespace in front of the log message.
|
|
173
|
+
* It will then forward all message to global diag logger
|
|
174
|
+
* @example
|
|
175
|
+
* const cLogger = diag.createComponentLogger({ namespace: '@opentelemetry/instrumentation-http' });
|
|
176
|
+
* cLogger.debug('test');
|
|
177
|
+
* // @opentelemetry/instrumentation-http test
|
|
178
|
+
*/
|
|
179
|
+
class DiagComponentLogger {
|
|
180
|
+
constructor(props) {
|
|
181
|
+
this._namespace = props.namespace || 'DiagComponentLogger';
|
|
182
|
+
}
|
|
183
|
+
debug(...args) {
|
|
184
|
+
return logProxy('debug', this._namespace, args);
|
|
185
|
+
}
|
|
186
|
+
error(...args) {
|
|
187
|
+
return logProxy('error', this._namespace, args);
|
|
188
|
+
}
|
|
189
|
+
info(...args) {
|
|
190
|
+
return logProxy('info', this._namespace, args);
|
|
191
|
+
}
|
|
192
|
+
warn(...args) {
|
|
193
|
+
return logProxy('warn', this._namespace, args);
|
|
194
|
+
}
|
|
195
|
+
verbose(...args) {
|
|
196
|
+
return logProxy('verbose', this._namespace, args);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function logProxy(funcName, namespace, args) {
|
|
200
|
+
const logger = getGlobal('diag');
|
|
201
|
+
// shortcut if logger not set
|
|
202
|
+
if (!logger) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
return logger[funcName](namespace, ...args);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/*
|
|
209
|
+
* Copyright The OpenTelemetry Authors
|
|
210
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
211
|
+
*/
|
|
212
|
+
/**
|
|
213
|
+
* Defines the available internal logging levels for the diagnostic logger, the numeric values
|
|
214
|
+
* of the levels are defined to match the original values from the initial LogLevel to avoid
|
|
215
|
+
* compatibility/migration issues for any implementation that assume the numeric ordering.
|
|
216
|
+
*/
|
|
217
|
+
var DiagLogLevel;
|
|
218
|
+
(function (DiagLogLevel) {
|
|
219
|
+
/** Diagnostic Logging level setting to disable all logging (except and forced logs) */
|
|
220
|
+
DiagLogLevel[DiagLogLevel["NONE"] = 0] = "NONE";
|
|
221
|
+
/** Identifies an error scenario */
|
|
222
|
+
DiagLogLevel[DiagLogLevel["ERROR"] = 30] = "ERROR";
|
|
223
|
+
/** Identifies a warning scenario */
|
|
224
|
+
DiagLogLevel[DiagLogLevel["WARN"] = 50] = "WARN";
|
|
225
|
+
/** General informational log message */
|
|
226
|
+
DiagLogLevel[DiagLogLevel["INFO"] = 60] = "INFO";
|
|
227
|
+
/** General debug log message */
|
|
228
|
+
DiagLogLevel[DiagLogLevel["DEBUG"] = 70] = "DEBUG";
|
|
229
|
+
/**
|
|
230
|
+
* Detailed trace level logging should only be used for development, should only be set
|
|
231
|
+
* in a development environment.
|
|
232
|
+
*/
|
|
233
|
+
DiagLogLevel[DiagLogLevel["VERBOSE"] = 80] = "VERBOSE";
|
|
234
|
+
/** Used to set the logging level to include all logging */
|
|
235
|
+
DiagLogLevel[DiagLogLevel["ALL"] = 9999] = "ALL";
|
|
236
|
+
})(DiagLogLevel || (DiagLogLevel = {}));
|
|
237
|
+
|
|
238
|
+
/*
|
|
239
|
+
* Copyright The OpenTelemetry Authors
|
|
240
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
241
|
+
*/
|
|
242
|
+
function createLogLevelDiagLogger(maxLevel, logger) {
|
|
243
|
+
if (maxLevel < DiagLogLevel.NONE) {
|
|
244
|
+
maxLevel = DiagLogLevel.NONE;
|
|
245
|
+
}
|
|
246
|
+
else if (maxLevel > DiagLogLevel.ALL) {
|
|
247
|
+
maxLevel = DiagLogLevel.ALL;
|
|
248
|
+
}
|
|
249
|
+
// In case the logger is null or undefined
|
|
250
|
+
logger = logger || {};
|
|
251
|
+
function _filterFunc(funcName, theLevel) {
|
|
252
|
+
const theFunc = logger[funcName];
|
|
253
|
+
if (typeof theFunc === 'function' && maxLevel >= theLevel) {
|
|
254
|
+
return theFunc.bind(logger);
|
|
255
|
+
}
|
|
256
|
+
return function () { };
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
error: _filterFunc('error', DiagLogLevel.ERROR),
|
|
260
|
+
warn: _filterFunc('warn', DiagLogLevel.WARN),
|
|
261
|
+
info: _filterFunc('info', DiagLogLevel.INFO),
|
|
262
|
+
debug: _filterFunc('debug', DiagLogLevel.DEBUG),
|
|
263
|
+
verbose: _filterFunc('verbose', DiagLogLevel.VERBOSE),
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/*
|
|
268
|
+
* Copyright The OpenTelemetry Authors
|
|
269
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
270
|
+
*/
|
|
271
|
+
const API_NAME$2 = 'diag';
|
|
272
|
+
/**
|
|
273
|
+
* Singleton object which represents the entry point to the OpenTelemetry internal
|
|
274
|
+
* diagnostic API
|
|
275
|
+
*
|
|
276
|
+
* @since 1.0.0
|
|
277
|
+
*/
|
|
278
|
+
class DiagAPI {
|
|
279
|
+
/** Get the singleton instance of the DiagAPI API */
|
|
280
|
+
static instance() {
|
|
281
|
+
if (!this._instance) {
|
|
282
|
+
this._instance = new DiagAPI();
|
|
283
|
+
}
|
|
284
|
+
return this._instance;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Private internal constructor
|
|
288
|
+
* @private
|
|
289
|
+
*/
|
|
290
|
+
constructor() {
|
|
291
|
+
function _logProxy(funcName) {
|
|
292
|
+
return function (...args) {
|
|
293
|
+
const logger = getGlobal('diag');
|
|
294
|
+
// shortcut if logger not set
|
|
295
|
+
if (!logger)
|
|
296
|
+
return;
|
|
297
|
+
return logger[funcName](...args);
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
// Using self local variable for minification purposes as 'this' cannot be minified
|
|
301
|
+
const self = this;
|
|
302
|
+
// DiagAPI specific functions
|
|
303
|
+
const setLogger = (logger, optionsOrLogLevel = { logLevel: DiagLogLevel.INFO }) => {
|
|
304
|
+
var _a, _b, _c;
|
|
305
|
+
if (logger === self) {
|
|
306
|
+
// There isn't much we can do here.
|
|
307
|
+
// Logging to the console might break the user application.
|
|
308
|
+
// Try to log to self. If a logger was previously registered it will receive the log.
|
|
309
|
+
const err = new Error('Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation');
|
|
310
|
+
self.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
if (typeof optionsOrLogLevel === 'number') {
|
|
314
|
+
optionsOrLogLevel = {
|
|
315
|
+
logLevel: optionsOrLogLevel,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
const oldLogger = getGlobal('diag');
|
|
319
|
+
const newLogger = createLogLevelDiagLogger((_b = optionsOrLogLevel.logLevel) !== null && _b !== void 0 ? _b : DiagLogLevel.INFO, logger);
|
|
320
|
+
// There already is an logger registered. We'll let it know before overwriting it.
|
|
321
|
+
if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) {
|
|
322
|
+
const stack = (_c = new Error().stack) !== null && _c !== void 0 ? _c : '<failed to generate stacktrace>';
|
|
323
|
+
oldLogger.warn(`Current logger will be overwritten from ${stack}`);
|
|
324
|
+
newLogger.warn(`Current logger will overwrite one already registered from ${stack}`);
|
|
325
|
+
}
|
|
326
|
+
return registerGlobal('diag', newLogger, self, true);
|
|
327
|
+
};
|
|
328
|
+
self.setLogger = setLogger;
|
|
329
|
+
self.disable = () => {
|
|
330
|
+
unregisterGlobal(API_NAME$2, self);
|
|
331
|
+
};
|
|
332
|
+
self.createComponentLogger = (options) => {
|
|
333
|
+
return new DiagComponentLogger(options);
|
|
334
|
+
};
|
|
335
|
+
self.verbose = _logProxy('verbose');
|
|
336
|
+
self.debug = _logProxy('debug');
|
|
337
|
+
self.info = _logProxy('info');
|
|
338
|
+
self.warn = _logProxy('warn');
|
|
339
|
+
self.error = _logProxy('error');
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/*
|
|
344
|
+
* Copyright The OpenTelemetry Authors
|
|
345
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
346
|
+
*/
|
|
347
|
+
/**
|
|
348
|
+
* Get a key to uniquely identify a context value
|
|
349
|
+
*
|
|
350
|
+
* @since 1.0.0
|
|
351
|
+
*/
|
|
352
|
+
function createContextKey(description) {
|
|
353
|
+
// The specification states that for the same input, multiple calls should
|
|
354
|
+
// return different keys. Due to the nature of the JS dependency management
|
|
355
|
+
// system, this creates problems where multiple versions of some package
|
|
356
|
+
// could hold different keys for the same property.
|
|
357
|
+
//
|
|
358
|
+
// Therefore, we use Symbol.for which returns the same key for the same input.
|
|
359
|
+
return Symbol.for(description);
|
|
360
|
+
}
|
|
361
|
+
class BaseContext {
|
|
362
|
+
/**
|
|
363
|
+
* Construct a new context which inherits values from an optional parent context.
|
|
364
|
+
*
|
|
365
|
+
* @param parentContext a context from which to inherit values
|
|
366
|
+
*/
|
|
367
|
+
constructor(parentContext) {
|
|
368
|
+
// for minification
|
|
369
|
+
const self = this;
|
|
370
|
+
self._currentContext = parentContext ? new Map(parentContext) : new Map();
|
|
371
|
+
self.getValue = (key) => self._currentContext.get(key);
|
|
372
|
+
self.setValue = (key, value) => {
|
|
373
|
+
const context = new BaseContext(self._currentContext);
|
|
374
|
+
context._currentContext.set(key, value);
|
|
375
|
+
return context;
|
|
376
|
+
};
|
|
377
|
+
self.deleteValue = (key) => {
|
|
378
|
+
const context = new BaseContext(self._currentContext);
|
|
379
|
+
context._currentContext.delete(key);
|
|
380
|
+
return context;
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* The root context is used as the default parent context when there is no active context
|
|
386
|
+
*
|
|
387
|
+
* @since 1.0.0
|
|
388
|
+
*/
|
|
389
|
+
const ROOT_CONTEXT = new BaseContext();
|
|
390
|
+
|
|
391
|
+
/*
|
|
392
|
+
* Copyright The OpenTelemetry Authors
|
|
393
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
394
|
+
*/
|
|
395
|
+
/**
|
|
396
|
+
* NoopMeter is a noop implementation of the {@link Meter} interface. It reuses
|
|
397
|
+
* constant NoopMetrics for all of its methods.
|
|
398
|
+
*/
|
|
399
|
+
class NoopMeter {
|
|
400
|
+
constructor() { }
|
|
401
|
+
/**
|
|
402
|
+
* @see {@link Meter.createGauge}
|
|
403
|
+
*/
|
|
404
|
+
createGauge(_name, _options) {
|
|
405
|
+
return NOOP_GAUGE_METRIC;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* @see {@link Meter.createHistogram}
|
|
409
|
+
*/
|
|
410
|
+
createHistogram(_name, _options) {
|
|
411
|
+
return NOOP_HISTOGRAM_METRIC;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* @see {@link Meter.createCounter}
|
|
415
|
+
*/
|
|
416
|
+
createCounter(_name, _options) {
|
|
417
|
+
return NOOP_COUNTER_METRIC;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* @see {@link Meter.createUpDownCounter}
|
|
421
|
+
*/
|
|
422
|
+
createUpDownCounter(_name, _options) {
|
|
423
|
+
return NOOP_UP_DOWN_COUNTER_METRIC;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* @see {@link Meter.createObservableGauge}
|
|
427
|
+
*/
|
|
428
|
+
createObservableGauge(_name, _options) {
|
|
429
|
+
return NOOP_OBSERVABLE_GAUGE_METRIC;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* @see {@link Meter.createObservableCounter}
|
|
433
|
+
*/
|
|
434
|
+
createObservableCounter(_name, _options) {
|
|
435
|
+
return NOOP_OBSERVABLE_COUNTER_METRIC;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* @see {@link Meter.createObservableUpDownCounter}
|
|
439
|
+
*/
|
|
440
|
+
createObservableUpDownCounter(_name, _options) {
|
|
441
|
+
return NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* @see {@link Meter.addBatchObservableCallback}
|
|
445
|
+
*/
|
|
446
|
+
addBatchObservableCallback(_callback, _observables) { }
|
|
447
|
+
/**
|
|
448
|
+
* @see {@link Meter.removeBatchObservableCallback}
|
|
449
|
+
*/
|
|
450
|
+
removeBatchObservableCallback(_callback) { }
|
|
451
|
+
}
|
|
452
|
+
class NoopMetric {
|
|
453
|
+
}
|
|
454
|
+
class NoopCounterMetric extends NoopMetric {
|
|
455
|
+
add(_value, _attributes) { }
|
|
456
|
+
}
|
|
457
|
+
class NoopUpDownCounterMetric extends NoopMetric {
|
|
458
|
+
add(_value, _attributes) { }
|
|
459
|
+
}
|
|
460
|
+
class NoopGaugeMetric extends NoopMetric {
|
|
461
|
+
record(_value, _attributes) { }
|
|
462
|
+
}
|
|
463
|
+
class NoopHistogramMetric extends NoopMetric {
|
|
464
|
+
record(_value, _attributes) { }
|
|
465
|
+
}
|
|
466
|
+
class NoopObservableMetric {
|
|
467
|
+
addCallback(_callback) { }
|
|
468
|
+
removeCallback(_callback) { }
|
|
469
|
+
}
|
|
470
|
+
class NoopObservableCounterMetric extends NoopObservableMetric {
|
|
471
|
+
}
|
|
472
|
+
class NoopObservableGaugeMetric extends NoopObservableMetric {
|
|
473
|
+
}
|
|
474
|
+
class NoopObservableUpDownCounterMetric extends NoopObservableMetric {
|
|
475
|
+
}
|
|
476
|
+
const NOOP_METER = new NoopMeter();
|
|
477
|
+
// Synchronous instruments
|
|
478
|
+
const NOOP_COUNTER_METRIC = new NoopCounterMetric();
|
|
479
|
+
const NOOP_GAUGE_METRIC = new NoopGaugeMetric();
|
|
480
|
+
const NOOP_HISTOGRAM_METRIC = new NoopHistogramMetric();
|
|
481
|
+
const NOOP_UP_DOWN_COUNTER_METRIC = new NoopUpDownCounterMetric();
|
|
482
|
+
// Asynchronous instruments
|
|
483
|
+
const NOOP_OBSERVABLE_COUNTER_METRIC = new NoopObservableCounterMetric();
|
|
484
|
+
const NOOP_OBSERVABLE_GAUGE_METRIC = new NoopObservableGaugeMetric();
|
|
485
|
+
const NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC = new NoopObservableUpDownCounterMetric();
|
|
486
|
+
/**
|
|
487
|
+
* Create a no-op Meter
|
|
488
|
+
*
|
|
489
|
+
* @since 1.3.0
|
|
490
|
+
*/
|
|
491
|
+
function createNoopMeter() {
|
|
492
|
+
return NOOP_METER;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/*
|
|
496
|
+
* Copyright The OpenTelemetry Authors
|
|
497
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
498
|
+
*/
|
|
499
|
+
class NoopContextManager {
|
|
500
|
+
active() {
|
|
501
|
+
return ROOT_CONTEXT;
|
|
502
|
+
}
|
|
503
|
+
with(_context, fn, thisArg, ...args) {
|
|
504
|
+
return fn.call(thisArg, ...args);
|
|
505
|
+
}
|
|
506
|
+
bind(_context, target) {
|
|
507
|
+
return target;
|
|
508
|
+
}
|
|
509
|
+
enable() {
|
|
510
|
+
return this;
|
|
511
|
+
}
|
|
512
|
+
disable() {
|
|
513
|
+
return this;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/*
|
|
518
|
+
* Copyright The OpenTelemetry Authors
|
|
519
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
520
|
+
*/
|
|
521
|
+
const API_NAME$1 = 'context';
|
|
522
|
+
const NOOP_CONTEXT_MANAGER = new NoopContextManager();
|
|
523
|
+
/**
|
|
524
|
+
* Singleton object which represents the entry point to the OpenTelemetry Context API
|
|
525
|
+
*
|
|
526
|
+
* @since 1.0.0
|
|
527
|
+
*/
|
|
528
|
+
class ContextAPI {
|
|
529
|
+
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
|
530
|
+
constructor() { }
|
|
531
|
+
/** Get the singleton instance of the Context API */
|
|
532
|
+
static getInstance() {
|
|
533
|
+
if (!this._instance) {
|
|
534
|
+
this._instance = new ContextAPI();
|
|
535
|
+
}
|
|
536
|
+
return this._instance;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Set the current context manager.
|
|
540
|
+
*
|
|
541
|
+
* @returns true if the context manager was successfully registered, else false
|
|
542
|
+
*/
|
|
543
|
+
setGlobalContextManager(contextManager) {
|
|
544
|
+
return registerGlobal(API_NAME$1, contextManager, DiagAPI.instance());
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Get the currently active context
|
|
548
|
+
*/
|
|
549
|
+
active() {
|
|
550
|
+
return this._getContextManager().active();
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Execute a function with an active context
|
|
554
|
+
*
|
|
555
|
+
* @param context context to be active during function execution
|
|
556
|
+
* @param fn function to execute in a context
|
|
557
|
+
* @param thisArg optional receiver to be used for calling fn
|
|
558
|
+
* @param args optional arguments forwarded to fn
|
|
559
|
+
*/
|
|
560
|
+
with(context, fn, thisArg, ...args) {
|
|
561
|
+
return this._getContextManager().with(context, fn, thisArg, ...args);
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Bind a context to a target function or event emitter
|
|
565
|
+
*
|
|
566
|
+
* @param context context to bind to the event emitter or function. Defaults to the currently active context
|
|
567
|
+
* @param target function or event emitter to bind
|
|
568
|
+
*/
|
|
569
|
+
bind(context, target) {
|
|
570
|
+
return this._getContextManager().bind(context, target);
|
|
571
|
+
}
|
|
572
|
+
_getContextManager() {
|
|
573
|
+
return getGlobal(API_NAME$1) || NOOP_CONTEXT_MANAGER;
|
|
574
|
+
}
|
|
575
|
+
/** Disable and remove the global context manager */
|
|
576
|
+
disable() {
|
|
577
|
+
this._getContextManager().disable();
|
|
578
|
+
unregisterGlobal(API_NAME$1, DiagAPI.instance());
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/*
|
|
583
|
+
* Copyright The OpenTelemetry Authors
|
|
584
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
585
|
+
*/
|
|
586
|
+
/**
|
|
587
|
+
* @since 1.0.0
|
|
588
|
+
*/
|
|
589
|
+
var TraceFlags;
|
|
590
|
+
(function (TraceFlags) {
|
|
591
|
+
/** Represents no flag set. */
|
|
592
|
+
TraceFlags[TraceFlags["NONE"] = 0] = "NONE";
|
|
593
|
+
/** Bit to represent whether trace is sampled in trace flags. */
|
|
594
|
+
TraceFlags[TraceFlags["SAMPLED"] = 1] = "SAMPLED";
|
|
595
|
+
})(TraceFlags || (TraceFlags = {}));
|
|
596
|
+
|
|
597
|
+
/*
|
|
598
|
+
* Copyright The OpenTelemetry Authors
|
|
599
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
600
|
+
*/
|
|
601
|
+
/**
|
|
602
|
+
* @since 1.0.0
|
|
603
|
+
*/
|
|
604
|
+
const INVALID_SPANID = '0000000000000000';
|
|
605
|
+
/**
|
|
606
|
+
* @since 1.0.0
|
|
607
|
+
*/
|
|
608
|
+
const INVALID_TRACEID = '00000000000000000000000000000000';
|
|
609
|
+
/**
|
|
610
|
+
* @since 1.0.0
|
|
611
|
+
*/
|
|
612
|
+
const INVALID_SPAN_CONTEXT = {
|
|
613
|
+
traceId: INVALID_TRACEID,
|
|
614
|
+
spanId: INVALID_SPANID,
|
|
615
|
+
traceFlags: TraceFlags.NONE,
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
/*
|
|
619
|
+
* Copyright The OpenTelemetry Authors
|
|
620
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
621
|
+
*/
|
|
622
|
+
/**
|
|
623
|
+
* The NonRecordingSpan is the default {@link Span} that is used when no Span
|
|
624
|
+
* implementation is available. All operations are no-op including context
|
|
625
|
+
* propagation.
|
|
626
|
+
*/
|
|
627
|
+
class NonRecordingSpan {
|
|
628
|
+
constructor(spanContext = INVALID_SPAN_CONTEXT) {
|
|
629
|
+
this._spanContext = spanContext;
|
|
630
|
+
}
|
|
631
|
+
// Returns a SpanContext.
|
|
632
|
+
spanContext() {
|
|
633
|
+
return this._spanContext;
|
|
634
|
+
}
|
|
635
|
+
// By default does nothing
|
|
636
|
+
setAttribute(_key, _value) {
|
|
637
|
+
return this;
|
|
638
|
+
}
|
|
639
|
+
// By default does nothing
|
|
640
|
+
setAttributes(_attributes) {
|
|
641
|
+
return this;
|
|
642
|
+
}
|
|
643
|
+
// By default does nothing
|
|
644
|
+
addEvent(_name, _attributes) {
|
|
645
|
+
return this;
|
|
646
|
+
}
|
|
647
|
+
addLink(_link) {
|
|
648
|
+
return this;
|
|
649
|
+
}
|
|
650
|
+
addLinks(_links) {
|
|
651
|
+
return this;
|
|
652
|
+
}
|
|
653
|
+
// By default does nothing
|
|
654
|
+
setStatus(_status) {
|
|
655
|
+
return this;
|
|
656
|
+
}
|
|
657
|
+
// By default does nothing
|
|
658
|
+
updateName(_name) {
|
|
659
|
+
return this;
|
|
660
|
+
}
|
|
661
|
+
// By default does nothing
|
|
662
|
+
end(_endTime) { }
|
|
663
|
+
// isRecording always returns false for NonRecordingSpan.
|
|
664
|
+
isRecording() {
|
|
665
|
+
return false;
|
|
666
|
+
}
|
|
667
|
+
// By default does nothing
|
|
668
|
+
recordException(_exception, _time) { }
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/*
|
|
672
|
+
* Copyright The OpenTelemetry Authors
|
|
673
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
674
|
+
*/
|
|
675
|
+
/**
|
|
676
|
+
* span key
|
|
677
|
+
*/
|
|
678
|
+
const SPAN_KEY = createContextKey('OpenTelemetry Context Key SPAN');
|
|
679
|
+
/**
|
|
680
|
+
* Return the span if one exists
|
|
681
|
+
*
|
|
682
|
+
* @param context context to get span from
|
|
683
|
+
*/
|
|
684
|
+
function getSpan(context) {
|
|
685
|
+
return context.getValue(SPAN_KEY) || undefined;
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Gets the span from the current context, if one exists.
|
|
689
|
+
*/
|
|
690
|
+
function getActiveSpan() {
|
|
691
|
+
return getSpan(ContextAPI.getInstance().active());
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Set the span on a context
|
|
695
|
+
*
|
|
696
|
+
* @param context context to use as parent
|
|
697
|
+
* @param span span to set active
|
|
698
|
+
*/
|
|
699
|
+
function setSpan(context, span) {
|
|
700
|
+
return context.setValue(SPAN_KEY, span);
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Remove current span stored in the context
|
|
704
|
+
*
|
|
705
|
+
* @param context context to delete span from
|
|
706
|
+
*/
|
|
707
|
+
function deleteSpan(context) {
|
|
708
|
+
return context.deleteValue(SPAN_KEY);
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Wrap span context in a NoopSpan and set as span in a new
|
|
712
|
+
* context
|
|
713
|
+
*
|
|
714
|
+
* @param context context to set active span on
|
|
715
|
+
* @param spanContext span context to be wrapped
|
|
716
|
+
*/
|
|
717
|
+
function setSpanContext(context, spanContext) {
|
|
718
|
+
return setSpan(context, new NonRecordingSpan(spanContext));
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Get the span context of the span if it exists.
|
|
722
|
+
*
|
|
723
|
+
* @param context context to get values from
|
|
724
|
+
*/
|
|
725
|
+
function getSpanContext(context) {
|
|
726
|
+
var _a;
|
|
727
|
+
return (_a = getSpan(context)) === null || _a === void 0 ? void 0 : _a.spanContext();
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
/*
|
|
731
|
+
* Copyright The OpenTelemetry Authors
|
|
732
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
733
|
+
*/
|
|
734
|
+
// Valid characters (0-9, a-f, A-F) are marked as 1.
|
|
735
|
+
const isHex = new Uint8Array([
|
|
736
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
737
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
|
|
738
|
+
1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
|
|
739
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
|
|
740
|
+
]);
|
|
741
|
+
function isValidHex(id, length) {
|
|
742
|
+
// As of 1.9.0 the id was allowed to be a non-string value,
|
|
743
|
+
// even though it was not possible in the types.
|
|
744
|
+
if (typeof id !== 'string' || id.length !== length)
|
|
745
|
+
return false;
|
|
746
|
+
let r = 0;
|
|
747
|
+
for (let i = 0; i < id.length; i += 4) {
|
|
748
|
+
r +=
|
|
749
|
+
(isHex[id.charCodeAt(i)] | 0) +
|
|
750
|
+
(isHex[id.charCodeAt(i + 1)] | 0) +
|
|
751
|
+
(isHex[id.charCodeAt(i + 2)] | 0) +
|
|
752
|
+
(isHex[id.charCodeAt(i + 3)] | 0);
|
|
753
|
+
}
|
|
754
|
+
return r === length;
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* @since 1.0.0
|
|
758
|
+
*/
|
|
759
|
+
function isValidTraceId(traceId) {
|
|
760
|
+
return isValidHex(traceId, 32) && traceId !== INVALID_TRACEID;
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* @since 1.0.0
|
|
764
|
+
*/
|
|
765
|
+
function isValidSpanId(spanId) {
|
|
766
|
+
return isValidHex(spanId, 16) && spanId !== INVALID_SPANID;
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Returns true if this {@link SpanContext} is valid.
|
|
770
|
+
* @return true if this {@link SpanContext} is valid.
|
|
771
|
+
*
|
|
772
|
+
* @since 1.0.0
|
|
773
|
+
*/
|
|
774
|
+
function isSpanContextValid(spanContext) {
|
|
775
|
+
return (isValidTraceId(spanContext.traceId) && isValidSpanId(spanContext.spanId));
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Wrap the given {@link SpanContext} in a new non-recording {@link Span}
|
|
779
|
+
*
|
|
780
|
+
* @param spanContext span context to be wrapped
|
|
781
|
+
* @returns a new non-recording {@link Span} with the provided context
|
|
782
|
+
*/
|
|
783
|
+
function wrapSpanContext(spanContext) {
|
|
784
|
+
return new NonRecordingSpan(spanContext);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/*
|
|
788
|
+
* Copyright The OpenTelemetry Authors
|
|
789
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
790
|
+
*/
|
|
791
|
+
const contextApi = ContextAPI.getInstance();
|
|
792
|
+
/**
|
|
793
|
+
* No-op implementations of {@link Tracer}.
|
|
794
|
+
*/
|
|
795
|
+
class NoopTracer {
|
|
796
|
+
// startSpan starts a noop span.
|
|
797
|
+
startSpan(name, options, context = contextApi.active()) {
|
|
798
|
+
const root = Boolean(options === null || options === void 0 ? void 0 : options.root);
|
|
799
|
+
if (root) {
|
|
800
|
+
return new NonRecordingSpan();
|
|
801
|
+
}
|
|
802
|
+
const parentFromContext = context && getSpanContext(context);
|
|
803
|
+
if (isSpanContext(parentFromContext) &&
|
|
804
|
+
isSpanContextValid(parentFromContext)) {
|
|
805
|
+
return new NonRecordingSpan(parentFromContext);
|
|
806
|
+
}
|
|
807
|
+
else {
|
|
808
|
+
return new NonRecordingSpan();
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
startActiveSpan(name, arg2, arg3, arg4) {
|
|
812
|
+
let opts;
|
|
813
|
+
let ctx;
|
|
814
|
+
let fn;
|
|
815
|
+
if (arguments.length < 2) {
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
else if (arguments.length === 2) {
|
|
819
|
+
fn = arg2;
|
|
820
|
+
}
|
|
821
|
+
else if (arguments.length === 3) {
|
|
822
|
+
opts = arg2;
|
|
823
|
+
fn = arg3;
|
|
824
|
+
}
|
|
825
|
+
else {
|
|
826
|
+
opts = arg2;
|
|
827
|
+
ctx = arg3;
|
|
828
|
+
fn = arg4;
|
|
829
|
+
}
|
|
830
|
+
const parentContext = ctx !== null && ctx !== void 0 ? ctx : contextApi.active();
|
|
831
|
+
const span = this.startSpan(name, opts, parentContext);
|
|
832
|
+
const contextWithSpanSet = setSpan(parentContext, span);
|
|
833
|
+
return contextApi.with(contextWithSpanSet, fn, undefined, span);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
function isSpanContext(spanContext) {
|
|
837
|
+
return (spanContext !== null &&
|
|
838
|
+
typeof spanContext === 'object' &&
|
|
839
|
+
'spanId' in spanContext &&
|
|
840
|
+
typeof spanContext['spanId'] === 'string' &&
|
|
841
|
+
'traceId' in spanContext &&
|
|
842
|
+
typeof spanContext['traceId'] === 'string' &&
|
|
843
|
+
'traceFlags' in spanContext &&
|
|
844
|
+
typeof spanContext['traceFlags'] === 'number');
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/*
|
|
848
|
+
* Copyright The OpenTelemetry Authors
|
|
849
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
850
|
+
*/
|
|
851
|
+
const NOOP_TRACER = new NoopTracer();
|
|
852
|
+
/**
|
|
853
|
+
* Proxy tracer provided by the proxy tracer provider
|
|
854
|
+
*
|
|
855
|
+
* @since 1.0.0
|
|
856
|
+
*/
|
|
857
|
+
class ProxyTracer {
|
|
858
|
+
constructor(provider, name, version, options) {
|
|
859
|
+
this._provider = provider;
|
|
860
|
+
this.name = name;
|
|
861
|
+
this.version = version;
|
|
862
|
+
this.options = options;
|
|
863
|
+
}
|
|
864
|
+
startSpan(name, options, context) {
|
|
865
|
+
return this._getTracer().startSpan(name, options, context);
|
|
866
|
+
}
|
|
867
|
+
startActiveSpan(_name, _options, _context, _fn) {
|
|
868
|
+
const tracer = this._getTracer();
|
|
869
|
+
return Reflect.apply(tracer.startActiveSpan, tracer, arguments);
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* Try to get a tracer from the proxy tracer provider.
|
|
873
|
+
* If the proxy tracer provider has no delegate, return a noop tracer.
|
|
874
|
+
*/
|
|
875
|
+
_getTracer() {
|
|
876
|
+
if (this._delegate) {
|
|
877
|
+
return this._delegate;
|
|
878
|
+
}
|
|
879
|
+
const tracer = this._provider.getDelegateTracer(this.name, this.version, this.options);
|
|
880
|
+
if (!tracer) {
|
|
881
|
+
return NOOP_TRACER;
|
|
882
|
+
}
|
|
883
|
+
this._delegate = tracer;
|
|
884
|
+
return this._delegate;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
/*
|
|
889
|
+
* Copyright The OpenTelemetry Authors
|
|
890
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
891
|
+
*/
|
|
892
|
+
/**
|
|
893
|
+
* An implementation of the {@link TracerProvider} which returns an impotent
|
|
894
|
+
* Tracer for all calls to `getTracer`.
|
|
895
|
+
*
|
|
896
|
+
* All operations are no-op.
|
|
897
|
+
*/
|
|
898
|
+
class NoopTracerProvider {
|
|
899
|
+
getTracer(_name, _version, _options) {
|
|
900
|
+
return new NoopTracer();
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
/*
|
|
905
|
+
* Copyright The OpenTelemetry Authors
|
|
906
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
907
|
+
*/
|
|
908
|
+
const NOOP_TRACER_PROVIDER = new NoopTracerProvider();
|
|
909
|
+
/**
|
|
910
|
+
* Tracer provider which provides {@link ProxyTracer}s.
|
|
911
|
+
*
|
|
912
|
+
* Before a delegate is set, tracers provided are NoOp.
|
|
913
|
+
* When a delegate is set, traces are provided from the delegate.
|
|
914
|
+
* When a delegate is set after tracers have already been provided,
|
|
915
|
+
* all tracers already provided will use the provided delegate implementation.
|
|
916
|
+
*
|
|
917
|
+
* @deprecated This will be removed in the next major version.
|
|
918
|
+
* @since 1.0.0
|
|
919
|
+
*/
|
|
920
|
+
class ProxyTracerProvider {
|
|
921
|
+
/**
|
|
922
|
+
* Get a {@link ProxyTracer}
|
|
923
|
+
*/
|
|
924
|
+
getTracer(name, version, options) {
|
|
925
|
+
var _a;
|
|
926
|
+
return ((_a = this.getDelegateTracer(name, version, options)) !== null && _a !== void 0 ? _a : new ProxyTracer(this, name, version, options));
|
|
927
|
+
}
|
|
928
|
+
getDelegate() {
|
|
929
|
+
var _a;
|
|
930
|
+
return (_a = this._delegate) !== null && _a !== void 0 ? _a : NOOP_TRACER_PROVIDER;
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Set the delegate tracer provider
|
|
934
|
+
*/
|
|
935
|
+
setDelegate(delegate) {
|
|
936
|
+
this._delegate = delegate;
|
|
937
|
+
}
|
|
938
|
+
getDelegateTracer(name, version, options) {
|
|
939
|
+
var _a;
|
|
940
|
+
return (_a = this._delegate) === null || _a === void 0 ? void 0 : _a.getTracer(name, version, options);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
/*
|
|
945
|
+
* Copyright The OpenTelemetry Authors
|
|
946
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
947
|
+
*/
|
|
948
|
+
// Split module-level variable definition into separate files to allow
|
|
949
|
+
// tree-shaking on each api instance.
|
|
950
|
+
/**
|
|
951
|
+
* Entrypoint for context API
|
|
952
|
+
* @since 1.0.0
|
|
953
|
+
*/
|
|
954
|
+
const context = ContextAPI.getInstance();
|
|
955
|
+
|
|
956
|
+
/*
|
|
957
|
+
* Copyright The OpenTelemetry Authors
|
|
958
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
959
|
+
*/
|
|
960
|
+
// Split module-level variable definition into separate files to allow
|
|
961
|
+
// tree-shaking on each api instance.
|
|
962
|
+
/**
|
|
963
|
+
* Entrypoint for Diag API.
|
|
964
|
+
* Defines Diagnostic handler used for internal diagnostic logging operations.
|
|
965
|
+
* The default provides a Noop DiagLogger implementation which may be changed via the
|
|
966
|
+
* diag.setLogger(logger: DiagLogger) function.
|
|
967
|
+
*
|
|
968
|
+
* @since 1.0.0
|
|
969
|
+
*/
|
|
970
|
+
const diag = DiagAPI.instance();
|
|
971
|
+
|
|
972
|
+
/*
|
|
973
|
+
* Copyright The OpenTelemetry Authors
|
|
974
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
975
|
+
*/
|
|
976
|
+
const API_NAME = 'trace';
|
|
977
|
+
/**
|
|
978
|
+
* Singleton object which represents the entry point to the OpenTelemetry Tracing API
|
|
979
|
+
*
|
|
980
|
+
* @since 1.0.0
|
|
981
|
+
*/
|
|
982
|
+
class TraceAPI {
|
|
983
|
+
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
|
984
|
+
constructor() {
|
|
985
|
+
this._proxyTracerProvider = new ProxyTracerProvider();
|
|
986
|
+
this.wrapSpanContext = wrapSpanContext;
|
|
987
|
+
this.isSpanContextValid = isSpanContextValid;
|
|
988
|
+
this.deleteSpan = deleteSpan;
|
|
989
|
+
this.getSpan = getSpan;
|
|
990
|
+
this.getActiveSpan = getActiveSpan;
|
|
991
|
+
this.getSpanContext = getSpanContext;
|
|
992
|
+
this.setSpan = setSpan;
|
|
993
|
+
this.setSpanContext = setSpanContext;
|
|
994
|
+
}
|
|
995
|
+
/** Get the singleton instance of the Trace API */
|
|
996
|
+
static getInstance() {
|
|
997
|
+
if (!this._instance) {
|
|
998
|
+
this._instance = new TraceAPI();
|
|
999
|
+
}
|
|
1000
|
+
return this._instance;
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* Set the current global tracer.
|
|
1004
|
+
*
|
|
1005
|
+
* @returns true if the tracer provider was successfully registered, else false
|
|
1006
|
+
*/
|
|
1007
|
+
setGlobalTracerProvider(provider) {
|
|
1008
|
+
const success = registerGlobal(API_NAME, this._proxyTracerProvider, DiagAPI.instance());
|
|
1009
|
+
if (success) {
|
|
1010
|
+
this._proxyTracerProvider.setDelegate(provider);
|
|
1011
|
+
}
|
|
1012
|
+
return success;
|
|
1013
|
+
}
|
|
1014
|
+
/**
|
|
1015
|
+
* Returns the global tracer provider.
|
|
1016
|
+
*/
|
|
1017
|
+
getTracerProvider() {
|
|
1018
|
+
return getGlobal(API_NAME) || this._proxyTracerProvider;
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Returns a tracer from the global tracer provider.
|
|
1022
|
+
*/
|
|
1023
|
+
getTracer(name, version) {
|
|
1024
|
+
return this.getTracerProvider().getTracer(name, version);
|
|
1025
|
+
}
|
|
1026
|
+
/** Remove the global tracer provider */
|
|
1027
|
+
disable() {
|
|
1028
|
+
unregisterGlobal(API_NAME, DiagAPI.instance());
|
|
1029
|
+
this._proxyTracerProvider = new ProxyTracerProvider();
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
/*
|
|
1034
|
+
* Copyright The OpenTelemetry Authors
|
|
1035
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1036
|
+
*/
|
|
1037
|
+
// Split module-level variable definition into separate files to allow
|
|
1038
|
+
// tree-shaking on each api instance.
|
|
1039
|
+
/**
|
|
1040
|
+
* Entrypoint for trace API
|
|
1041
|
+
*
|
|
1042
|
+
* @since 1.0.0
|
|
1043
|
+
*/
|
|
1044
|
+
const trace = TraceAPI.getInstance();
|
|
1045
|
+
|
|
1046
|
+
/*
|
|
1047
|
+
* Copyright The OpenTelemetry Authors
|
|
1048
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1049
|
+
*/
|
|
1050
|
+
const SUPPRESS_TRACING_KEY = createContextKey('OpenTelemetry SDK Context Key SUPPRESS_TRACING');
|
|
1051
|
+
function suppressTracing(context) {
|
|
1052
|
+
return context.setValue(SUPPRESS_TRACING_KEY, true);
|
|
1053
|
+
}
|
|
1054
|
+
function isTracingSuppressed(context) {
|
|
1055
|
+
return context.getValue(SUPPRESS_TRACING_KEY) === true;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
/*
|
|
1059
|
+
* Copyright The OpenTelemetry Authors
|
|
1060
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1061
|
+
*/
|
|
1062
|
+
/**
|
|
1063
|
+
* Returns a function that logs an error using the provided logger, or a
|
|
1064
|
+
* console logger if one was not provided.
|
|
1065
|
+
*/
|
|
1066
|
+
function loggingErrorHandler() {
|
|
1067
|
+
return (ex) => {
|
|
1068
|
+
diag.error(stringifyException(ex));
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Converts an exception into a string representation
|
|
1073
|
+
* @param {Exception} ex
|
|
1074
|
+
*/
|
|
1075
|
+
function stringifyException(ex) {
|
|
1076
|
+
if (typeof ex === 'string') {
|
|
1077
|
+
return ex;
|
|
1078
|
+
}
|
|
1079
|
+
else {
|
|
1080
|
+
return JSON.stringify(flattenException(ex));
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* Flattens an exception into key-value pairs by traversing the prototype chain
|
|
1085
|
+
* and coercing values to strings. Duplicate properties will not be overwritten;
|
|
1086
|
+
* the first insert wins.
|
|
1087
|
+
*/
|
|
1088
|
+
function flattenException(ex) {
|
|
1089
|
+
const result = {};
|
|
1090
|
+
let current = ex;
|
|
1091
|
+
while (current !== null) {
|
|
1092
|
+
Object.getOwnPropertyNames(current).forEach(propertyName => {
|
|
1093
|
+
if (result[propertyName])
|
|
1094
|
+
return;
|
|
1095
|
+
const value = current[propertyName];
|
|
1096
|
+
if (value) {
|
|
1097
|
+
result[propertyName] = String(value);
|
|
1098
|
+
}
|
|
1099
|
+
});
|
|
1100
|
+
current = Object.getPrototypeOf(current);
|
|
1101
|
+
}
|
|
1102
|
+
return result;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
/*
|
|
1106
|
+
* Copyright The OpenTelemetry Authors
|
|
1107
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1108
|
+
*/
|
|
1109
|
+
/** The global error handler delegate */
|
|
1110
|
+
let delegateHandler = loggingErrorHandler();
|
|
1111
|
+
/**
|
|
1112
|
+
* Return the global error handler
|
|
1113
|
+
* @param {Exception} ex
|
|
1114
|
+
*/
|
|
1115
|
+
function globalErrorHandler(ex) {
|
|
1116
|
+
try {
|
|
1117
|
+
delegateHandler(ex);
|
|
1118
|
+
}
|
|
1119
|
+
catch { } // eslint-disable-line no-empty
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
/*
|
|
1123
|
+
* Copyright The OpenTelemetry Authors
|
|
1124
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1125
|
+
*/
|
|
1126
|
+
// this is autogenerated file, see scripts/version-update.js
|
|
1127
|
+
const VERSION$1 = '2.12.0';
|
|
1128
|
+
|
|
1129
|
+
/*
|
|
1130
|
+
* Copyright The OpenTelemetry Authors
|
|
1131
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1132
|
+
*/
|
|
1133
|
+
//----------------------------------------------------------------------------------------------------------
|
|
1134
|
+
// DO NOT EDIT, this is an Auto-generated file from scripts/semconv/templates/registry/stable/attributes.ts.j2
|
|
1135
|
+
//----------------------------------------------------------------------------------------------------------
|
|
1136
|
+
/**
|
|
1137
|
+
* ASP.NET Core exception middleware handling result.
|
|
1138
|
+
*
|
|
1139
|
+
* @example handled
|
|
1140
|
+
* @example unhandled
|
|
1141
|
+
*/
|
|
1142
|
+
/**
|
|
1143
|
+
* Describes a class of error the operation ended with.
|
|
1144
|
+
*
|
|
1145
|
+
* @example timeout
|
|
1146
|
+
* @example java.net.UnknownHostException
|
|
1147
|
+
* @example server_certificate_invalid
|
|
1148
|
+
* @example 500
|
|
1149
|
+
*
|
|
1150
|
+
* @note The `error.type` **SHOULD** be predictable, and **SHOULD** have low cardinality.
|
|
1151
|
+
*
|
|
1152
|
+
* When `error.type` is set to a type (e.g., an exception type), its
|
|
1153
|
+
* canonical class name identifying the type within the artifact **SHOULD** be used.
|
|
1154
|
+
*
|
|
1155
|
+
* If the recorded error type is a wrapper that is not meaningful for
|
|
1156
|
+
* failure classification, instrumentation **MAY** use the type of the inner
|
|
1157
|
+
* error instead. For example, in Go, errors created with `fmt.Errorf`
|
|
1158
|
+
* using `%w` **MAY** be unwrapped when the wrapper type does not help
|
|
1159
|
+
* classify the failure.
|
|
1160
|
+
*
|
|
1161
|
+
* Instrumentations **SHOULD** document the list of errors they report.
|
|
1162
|
+
*
|
|
1163
|
+
* The cardinality of `error.type` within one instrumentation library **SHOULD** be low.
|
|
1164
|
+
* Telemetry consumers that aggregate data from multiple instrumentation libraries and applications
|
|
1165
|
+
* should be prepared for `error.type` to have high cardinality at query time when no
|
|
1166
|
+
* additional filters are applied.
|
|
1167
|
+
*
|
|
1168
|
+
* If the operation has completed successfully, instrumentations **SHOULD NOT** set `error.type`.
|
|
1169
|
+
*
|
|
1170
|
+
* If a specific domain defines its own set of error identifiers (such as HTTP or RPC status codes),
|
|
1171
|
+
* it's **RECOMMENDED** to:
|
|
1172
|
+
*
|
|
1173
|
+
* - Use a domain-specific attribute
|
|
1174
|
+
* - Set `error.type` to capture all errors, regardless of whether they are defined within the domain-specific set or not.
|
|
1175
|
+
*/
|
|
1176
|
+
const ATTR_ERROR_TYPE$1 = 'error.type';
|
|
1177
|
+
/**
|
|
1178
|
+
* The exception message.
|
|
1179
|
+
*
|
|
1180
|
+
* @example Division by zero
|
|
1181
|
+
* @example Can't convert 'int' object to str implicitly
|
|
1182
|
+
*
|
|
1183
|
+
* @note > [!WARNING]
|
|
1184
|
+
*
|
|
1185
|
+
* > This attribute may contain sensitive information.
|
|
1186
|
+
*/
|
|
1187
|
+
const ATTR_EXCEPTION_MESSAGE = 'exception.message';
|
|
1188
|
+
/**
|
|
1189
|
+
* A stacktrace as a string in the natural representation for the language runtime. The representation is to be determined and documented by each language SIG.
|
|
1190
|
+
*
|
|
1191
|
+
* @example "Exception in thread "main" java.lang.RuntimeException: Test exception\\n at com.example.GenerateTrace.methodB(GenerateTrace.java:13)\\n at com.example.GenerateTrace.methodA(GenerateTrace.java:9)\\n at com.example.GenerateTrace.main(GenerateTrace.java:5)\\n"
|
|
1192
|
+
*/
|
|
1193
|
+
const ATTR_EXCEPTION_STACKTRACE = 'exception.stacktrace';
|
|
1194
|
+
/**
|
|
1195
|
+
* The type of the exception (its fully-qualified class name, if applicable). The dynamic type of the exception should be preferred over the static type in languages that support it.
|
|
1196
|
+
*
|
|
1197
|
+
* @example java.net.ConnectException
|
|
1198
|
+
* @example OSError
|
|
1199
|
+
*
|
|
1200
|
+
* @note If the recorded exception type is a wrapper that is not meaningful for
|
|
1201
|
+
* failure classification, instrumentation **MAY** use the type of the inner
|
|
1202
|
+
* exception instead. For example, in Go, errors created with `fmt.Errorf`
|
|
1203
|
+
* using `%w` **MAY** be unwrapped when the wrapper type does not help
|
|
1204
|
+
* classify the failure.
|
|
1205
|
+
*/
|
|
1206
|
+
const ATTR_EXCEPTION_TYPE = 'exception.type';
|
|
1207
|
+
/**
|
|
1208
|
+
* HTTP request method.
|
|
1209
|
+
*
|
|
1210
|
+
* @example GET
|
|
1211
|
+
* @example POST
|
|
1212
|
+
* @example HEAD
|
|
1213
|
+
*
|
|
1214
|
+
* @note HTTP request method value **SHOULD** be "known" to the instrumentation.
|
|
1215
|
+
* By default, this convention defines "known" methods as the ones listed in [RFC9110](https://www.rfc-editor.org/rfc/rfc9110.html#name-methods),
|
|
1216
|
+
* the PATCH method defined in [RFC5789](https://www.rfc-editor.org/rfc/rfc5789.html)
|
|
1217
|
+
* and the QUERY method defined in [httpbis-safe-method-w-body](https://datatracker.ietf.org/doc/draft-ietf-httpbis-safe-method-w-body/?include_text=1).
|
|
1218
|
+
*
|
|
1219
|
+
* If the HTTP request method is not known to instrumentation, it **MUST** set the `http.request.method` attribute to `_OTHER`.
|
|
1220
|
+
*
|
|
1221
|
+
* If the HTTP instrumentation could end up converting valid HTTP request methods to `_OTHER`, then it **MUST** provide a way to override
|
|
1222
|
+
* the list of known HTTP methods. If this override is done via environment variable, then the environment variable **MUST** be named
|
|
1223
|
+
* OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS and support a comma-separated list of case-sensitive known HTTP methods.
|
|
1224
|
+
*
|
|
1225
|
+
*
|
|
1226
|
+
* If this override is done via declarative configuration, then the list **MUST** be configurable via the `known_methods` property
|
|
1227
|
+
* (an array of case-sensitive strings with minimum items 0) under `.instrumentation/development.general.http.client` and/or
|
|
1228
|
+
* `.instrumentation/development.general.http.server`.
|
|
1229
|
+
*
|
|
1230
|
+
* In either case, this list **MUST** be a full override of the default known methods,
|
|
1231
|
+
* it is not a list of known methods in addition to the defaults.
|
|
1232
|
+
*
|
|
1233
|
+
* HTTP method names are case-sensitive and `http.request.method` attribute value **MUST** match a known HTTP method name exactly.
|
|
1234
|
+
* Instrumentations for specific web frameworks that consider HTTP methods to be case insensitive, **SHOULD** populate a canonical equivalent.
|
|
1235
|
+
* Tracing instrumentations that do so, **MUST** also set `http.request.method_original` to the original value.
|
|
1236
|
+
*/
|
|
1237
|
+
const ATTR_HTTP_REQUEST_METHOD = 'http.request.method';
|
|
1238
|
+
/**
|
|
1239
|
+
* Original HTTP method sent by the client in the request line.
|
|
1240
|
+
*
|
|
1241
|
+
* @example GeT
|
|
1242
|
+
* @example ACL
|
|
1243
|
+
* @example foo
|
|
1244
|
+
*/
|
|
1245
|
+
const ATTR_HTTP_REQUEST_METHOD_ORIGINAL = 'http.request.method_original';
|
|
1246
|
+
/**
|
|
1247
|
+
* [HTTP response status code](https://tools.ietf.org/html/rfc7231#section-6).
|
|
1248
|
+
*
|
|
1249
|
+
* @example 200
|
|
1250
|
+
*/
|
|
1251
|
+
const ATTR_HTTP_RESPONSE_STATUS_CODE$1 = 'http.response.status_code';
|
|
1252
|
+
/**
|
|
1253
|
+
* Server domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name.
|
|
1254
|
+
*
|
|
1255
|
+
* @example example.com
|
|
1256
|
+
* @example 10.1.2.80
|
|
1257
|
+
* @example /tmp/my.sock
|
|
1258
|
+
*
|
|
1259
|
+
* @note When observed from the client side, and when communicating through an intermediary, `server.address` **SHOULD** represent the server address behind any intermediaries, for example proxies, if it's available.
|
|
1260
|
+
*/
|
|
1261
|
+
const ATTR_SERVER_ADDRESS$1 = 'server.address';
|
|
1262
|
+
/**
|
|
1263
|
+
* Server port number.
|
|
1264
|
+
*
|
|
1265
|
+
* @example 80
|
|
1266
|
+
* @example 8080
|
|
1267
|
+
* @example 443
|
|
1268
|
+
*
|
|
1269
|
+
* @note When observed from the client side, and when communicating through an intermediary, `server.port` **SHOULD** represent the server port behind any intermediaries, for example proxies, if it's available.
|
|
1270
|
+
*/
|
|
1271
|
+
const ATTR_SERVER_PORT$1 = 'server.port';
|
|
1272
|
+
/**
|
|
1273
|
+
* Logical name of the service.
|
|
1274
|
+
*
|
|
1275
|
+
* @example shoppingcart
|
|
1276
|
+
*
|
|
1277
|
+
* @note **MUST** be the same for all instances of horizontally scaled services. If the value was not specified, SDKs **MUST** fallback to `unknown_service:` concatenated with the process executable name, e.g. `unknown_service:bash`. If the process executable name is not available, the value **MUST** be set to `unknown_service`.
|
|
1278
|
+
* The process executable name is the name of the process executable, the same value as described by the [`process.executable.name`](process.md) resource attribute.
|
|
1279
|
+
*/
|
|
1280
|
+
const ATTR_SERVICE_NAME = 'service.name';
|
|
1281
|
+
/**
|
|
1282
|
+
* The language of the telemetry SDK.
|
|
1283
|
+
*/
|
|
1284
|
+
const ATTR_TELEMETRY_SDK_LANGUAGE = 'telemetry.sdk.language';
|
|
1285
|
+
/**
|
|
1286
|
+
* Enum value "webjs" for attribute {@link ATTR_TELEMETRY_SDK_LANGUAGE}.
|
|
1287
|
+
*/
|
|
1288
|
+
const TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS = "webjs";
|
|
1289
|
+
/**
|
|
1290
|
+
* The name of the telemetry SDK as defined above.
|
|
1291
|
+
*
|
|
1292
|
+
* @example opentelemetry
|
|
1293
|
+
*
|
|
1294
|
+
* @note The OpenTelemetry SDK **MUST** set the `telemetry.sdk.name` attribute to `opentelemetry`.
|
|
1295
|
+
* If another SDK, like a fork or a vendor-provided implementation, is used, this SDK **MUST** set the
|
|
1296
|
+
* `telemetry.sdk.name` attribute to the fully-qualified class or module name of this SDK's main entry point
|
|
1297
|
+
* or another suitable identifier depending on the language.
|
|
1298
|
+
* The identifier `opentelemetry` is reserved and **MUST NOT** be used in this case.
|
|
1299
|
+
* All custom identifiers **SHOULD** be stable across different versions of an implementation.
|
|
1300
|
+
*/
|
|
1301
|
+
const ATTR_TELEMETRY_SDK_NAME = 'telemetry.sdk.name';
|
|
1302
|
+
/**
|
|
1303
|
+
* The version string of the telemetry SDK.
|
|
1304
|
+
*
|
|
1305
|
+
* @example 1.2.3
|
|
1306
|
+
*/
|
|
1307
|
+
const ATTR_TELEMETRY_SDK_VERSION = 'telemetry.sdk.version';
|
|
1308
|
+
/**
|
|
1309
|
+
* Absolute URL describing a network resource according to [RFC3986](https://www.rfc-editor.org/rfc/rfc3986)
|
|
1310
|
+
*
|
|
1311
|
+
* @example https://www.foo.bar/search?q=OpenTelemetry#SemConv
|
|
1312
|
+
* @example //localhost
|
|
1313
|
+
*
|
|
1314
|
+
* @note For network calls, URL usually has `scheme://host[:port][path][?query][#fragment]` format, where the fragment
|
|
1315
|
+
* is not transmitted over HTTP, but if it is known, it **SHOULD** be included nevertheless.
|
|
1316
|
+
*
|
|
1317
|
+
* `url.full` **MUST NOT** contain credentials passed via URL in form of `https://username:password@www.example.com/`.
|
|
1318
|
+
* In such case username and password **SHOULD** be redacted and attribute's value **SHOULD** be `https://REDACTED:REDACTED@www.example.com/`.
|
|
1319
|
+
*
|
|
1320
|
+
* `url.full` **SHOULD** capture the absolute URL when it is available (or can be reconstructed).
|
|
1321
|
+
*
|
|
1322
|
+
* Sensitive content provided in `url.full` **SHOULD** be scrubbed when instrumentations can identify it.
|
|
1323
|
+
*
|
|
1324
|
+
*
|
|
1325
|
+
* Query string values for the following keys **SHOULD** be redacted by default and replaced by the
|
|
1326
|
+
* value `REDACTED`:
|
|
1327
|
+
*
|
|
1328
|
+
* - [`X-Amz-Signature`](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv-authentication-methods.html)
|
|
1329
|
+
* - [`X-Amz-Credential`](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv-authentication-methods.html)
|
|
1330
|
+
* - [`X-Amz-Security-Token`](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv-authentication-methods.html)
|
|
1331
|
+
* - [`sig`](https://learn.microsoft.com/azure/storage/common/storage-sas-overview#sas-token)
|
|
1332
|
+
* - [`X-Goog-Signature`](https://cloud.google.com/storage/docs/access-control/signed-urls)
|
|
1333
|
+
*
|
|
1334
|
+
* This list is subject to change over time.
|
|
1335
|
+
*
|
|
1336
|
+
* Matching of query parameter keys against the sensitive list **SHOULD** be case-sensitive.
|
|
1337
|
+
*
|
|
1338
|
+
*
|
|
1339
|
+
* Instrumentation **MAY** provide a way to override this list via declarative configuration.
|
|
1340
|
+
* If so, it **SHOULD** use the `sensitive_query_parameters` property
|
|
1341
|
+
* (an array of case-sensitive strings with minimum items 0) under
|
|
1342
|
+
* `.instrumentation/development.general.sanitization.url`.
|
|
1343
|
+
* This list is a full override of the default sensitive query parameter keys,
|
|
1344
|
+
* it is not a list of keys in addition to the defaults.
|
|
1345
|
+
*
|
|
1346
|
+
* When a query string value is redacted, the query string key **SHOULD** still be preserved, e.g.
|
|
1347
|
+
* `https://www.example.com/path?color=blue&sig=REDACTED`.
|
|
1348
|
+
*/
|
|
1349
|
+
const ATTR_URL_FULL = 'url.full';
|
|
1350
|
+
/**
|
|
1351
|
+
* Value of the [HTTP User-Agent](https://www.rfc-editor.org/rfc/rfc9110.html#field.user-agent) header sent by the client.
|
|
1352
|
+
*
|
|
1353
|
+
* @example CERN-LineMode/2.15 libwww/2.17b3
|
|
1354
|
+
* @example Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Mobile/15E148 Safari/604.1
|
|
1355
|
+
* @example YourApp/1.0.0 grpc-java-okhttp/1.27.2
|
|
1356
|
+
*/
|
|
1357
|
+
const ATTR_USER_AGENT_ORIGINAL = 'user_agent.original';
|
|
1358
|
+
|
|
1359
|
+
/*
|
|
1360
|
+
* Copyright The OpenTelemetry Authors
|
|
1361
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1362
|
+
*/
|
|
1363
|
+
/*
|
|
1364
|
+
* This file contains a copy of unstable semantic convention definitions
|
|
1365
|
+
* used by this package.
|
|
1366
|
+
* @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
|
|
1367
|
+
*/
|
|
1368
|
+
/**
|
|
1369
|
+
* The name of the runtime of this process.
|
|
1370
|
+
*
|
|
1371
|
+
* @example OpenJDK Runtime Environment
|
|
1372
|
+
*
|
|
1373
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
1374
|
+
*/
|
|
1375
|
+
const ATTR_PROCESS_RUNTIME_NAME = 'process.runtime.name';
|
|
1376
|
+
|
|
1377
|
+
/*
|
|
1378
|
+
* Copyright The OpenTelemetry Authors
|
|
1379
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1380
|
+
*/
|
|
1381
|
+
/** Constants describing the SDK in use */
|
|
1382
|
+
const SDK_INFO = {
|
|
1383
|
+
[ATTR_TELEMETRY_SDK_NAME]: 'opentelemetry',
|
|
1384
|
+
[ATTR_PROCESS_RUNTIME_NAME]: 'browser',
|
|
1385
|
+
[ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS,
|
|
1386
|
+
[ATTR_TELEMETRY_SDK_VERSION]: VERSION$1,
|
|
1387
|
+
};
|
|
1388
|
+
|
|
1389
|
+
/*
|
|
1390
|
+
* Copyright The OpenTelemetry Authors
|
|
1391
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1392
|
+
*/
|
|
1393
|
+
/**
|
|
1394
|
+
* @deprecated Use performance directly.
|
|
1395
|
+
*/
|
|
1396
|
+
const otperformance = performance;
|
|
1397
|
+
|
|
1398
|
+
/*
|
|
1399
|
+
* Copyright The OpenTelemetry Authors
|
|
1400
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1401
|
+
*/
|
|
1402
|
+
const NANOSECOND_DIGITS = 9;
|
|
1403
|
+
const NANOSECOND_DIGITS_IN_MILLIS = 6;
|
|
1404
|
+
const MILLISECONDS_TO_NANOSECONDS = Math.pow(10, NANOSECOND_DIGITS_IN_MILLIS);
|
|
1405
|
+
const SECOND_TO_NANOSECONDS = Math.pow(10, NANOSECOND_DIGITS);
|
|
1406
|
+
/**
|
|
1407
|
+
* Converts a number of milliseconds from epoch to HrTime([seconds, remainder in nanoseconds]).
|
|
1408
|
+
* @param epochMillis
|
|
1409
|
+
*/
|
|
1410
|
+
function millisToHrTime(epochMillis) {
|
|
1411
|
+
const epochSeconds = epochMillis / 1000;
|
|
1412
|
+
// Decimals only.
|
|
1413
|
+
const seconds = Math.trunc(epochSeconds);
|
|
1414
|
+
// Round sub-nanosecond accuracy to nanosecond.
|
|
1415
|
+
const nanos = Math.round((epochMillis % 1000) * MILLISECONDS_TO_NANOSECONDS);
|
|
1416
|
+
return [seconds, nanos];
|
|
1417
|
+
}
|
|
1418
|
+
/**
|
|
1419
|
+
* Returns an hrtime calculated via performance component.
|
|
1420
|
+
* @param performanceNow
|
|
1421
|
+
*/
|
|
1422
|
+
function hrTime(performanceNow) {
|
|
1423
|
+
const timeOrigin = millisToHrTime(otperformance.timeOrigin);
|
|
1424
|
+
const now = millisToHrTime(typeof performanceNow === 'number' ? performanceNow : otperformance.now());
|
|
1425
|
+
return addHrTimes(timeOrigin, now);
|
|
1426
|
+
}
|
|
1427
|
+
/**
|
|
1428
|
+
*
|
|
1429
|
+
* Converts a TimeInput to an HrTime, defaults to _hrtime().
|
|
1430
|
+
* @param time
|
|
1431
|
+
*/
|
|
1432
|
+
function timeInputToHrTime(time) {
|
|
1433
|
+
// process.hrtime
|
|
1434
|
+
if (isTimeInputHrTime(time)) {
|
|
1435
|
+
return time;
|
|
1436
|
+
}
|
|
1437
|
+
else if (typeof time === 'number') {
|
|
1438
|
+
// Distinguish between a relative performance.now() value and an absolute
|
|
1439
|
+
// epoch-millisecond timestamp.
|
|
1440
|
+
//
|
|
1441
|
+
// performance.timeOrigin uses a monotonic clock that may be slightly ahead
|
|
1442
|
+
// of Date.now() due to clock adjustments (see MDN docs). This means a
|
|
1443
|
+
// real epoch-ms value (e.g. Date.now()) can land just below
|
|
1444
|
+
// performance.timeOrigin, causing it to be misclassified as a relative
|
|
1445
|
+
// performance.now() reading and doubled when timeOrigin is added.
|
|
1446
|
+
//
|
|
1447
|
+
// A genuine performance.now() value represents elapsed time since the
|
|
1448
|
+
// document/process started, so it is bounded by system uptime. No real
|
|
1449
|
+
// system has been running long enough for performance.now() to reach half
|
|
1450
|
+
// the current epoch time (~1994 in ms terms). We therefore treat any value
|
|
1451
|
+
// below half of performance.timeOrigin as a relative performance.now()
|
|
1452
|
+
// reading, and everything else as an absolute epoch-millisecond timestamp.
|
|
1453
|
+
if (time < otperformance.timeOrigin / 2) {
|
|
1454
|
+
return hrTime(time);
|
|
1455
|
+
}
|
|
1456
|
+
else {
|
|
1457
|
+
// epoch milliseconds or performance.timeOrigin
|
|
1458
|
+
return millisToHrTime(time);
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
else if (time instanceof Date) {
|
|
1462
|
+
return millisToHrTime(time.getTime());
|
|
1463
|
+
}
|
|
1464
|
+
else {
|
|
1465
|
+
throw TypeError('Invalid input type');
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
/**
|
|
1469
|
+
* Returns a duration of two hrTime.
|
|
1470
|
+
* @param startTime
|
|
1471
|
+
* @param endTime
|
|
1472
|
+
*/
|
|
1473
|
+
function hrTimeDuration(startTime, endTime) {
|
|
1474
|
+
let seconds = endTime[0] - startTime[0];
|
|
1475
|
+
let nanos = endTime[1] - startTime[1];
|
|
1476
|
+
// overflow
|
|
1477
|
+
if (nanos < 0) {
|
|
1478
|
+
seconds -= 1;
|
|
1479
|
+
// negate
|
|
1480
|
+
nanos += SECOND_TO_NANOSECONDS;
|
|
1481
|
+
}
|
|
1482
|
+
return [seconds, nanos];
|
|
1483
|
+
}
|
|
1484
|
+
/**
|
|
1485
|
+
* Convert hrTime to nanoseconds.
|
|
1486
|
+
* @param time
|
|
1487
|
+
*/
|
|
1488
|
+
function hrTimeToNanoseconds(time) {
|
|
1489
|
+
return time[0] * SECOND_TO_NANOSECONDS + time[1];
|
|
1490
|
+
}
|
|
1491
|
+
/**
|
|
1492
|
+
* Convert hrTime to milliseconds.
|
|
1493
|
+
* @param time
|
|
1494
|
+
*/
|
|
1495
|
+
function hrTimeToMilliseconds(time) {
|
|
1496
|
+
return time[0] * 1e3 + time[1] / 1e6;
|
|
1497
|
+
}
|
|
1498
|
+
/**
|
|
1499
|
+
* check if time is HrTime
|
|
1500
|
+
* @param value
|
|
1501
|
+
*/
|
|
1502
|
+
function isTimeInputHrTime(value) {
|
|
1503
|
+
return (Array.isArray(value) &&
|
|
1504
|
+
value.length === 2 &&
|
|
1505
|
+
typeof value[0] === 'number' &&
|
|
1506
|
+
typeof value[1] === 'number');
|
|
1507
|
+
}
|
|
1508
|
+
/**
|
|
1509
|
+
* check if input value is a correct types.TimeInput
|
|
1510
|
+
* @param value
|
|
1511
|
+
*/
|
|
1512
|
+
function isTimeInput(value) {
|
|
1513
|
+
return (isTimeInputHrTime(value) ||
|
|
1514
|
+
typeof value === 'number' ||
|
|
1515
|
+
value instanceof Date);
|
|
1516
|
+
}
|
|
1517
|
+
/**
|
|
1518
|
+
* Given 2 HrTime formatted times, return their sum as an HrTime.
|
|
1519
|
+
*/
|
|
1520
|
+
function addHrTimes(time1, time2) {
|
|
1521
|
+
const out = [time1[0] + time2[0], time1[1] + time2[1]];
|
|
1522
|
+
// Nanoseconds
|
|
1523
|
+
if (out[1] >= SECOND_TO_NANOSECONDS) {
|
|
1524
|
+
out[1] -= SECOND_TO_NANOSECONDS;
|
|
1525
|
+
out[0] += 1;
|
|
1526
|
+
}
|
|
1527
|
+
return out;
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
/*
|
|
1531
|
+
* Copyright The OpenTelemetry Authors
|
|
1532
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1533
|
+
*/
|
|
1534
|
+
var ExportResultCode;
|
|
1535
|
+
(function (ExportResultCode) {
|
|
1536
|
+
ExportResultCode[ExportResultCode["SUCCESS"] = 0] = "SUCCESS";
|
|
1537
|
+
ExportResultCode[ExportResultCode["FAILED"] = 1] = "FAILED";
|
|
1538
|
+
})(ExportResultCode || (ExportResultCode = {}));
|
|
1539
|
+
|
|
1540
|
+
/*
|
|
1541
|
+
* Copyright The OpenTelemetry Authors
|
|
1542
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1543
|
+
*/
|
|
1544
|
+
class Deferred {
|
|
1545
|
+
_promise;
|
|
1546
|
+
_resolve;
|
|
1547
|
+
_reject;
|
|
1548
|
+
constructor() {
|
|
1549
|
+
this._promise = new Promise((resolve, reject) => {
|
|
1550
|
+
this._resolve = resolve;
|
|
1551
|
+
this._reject = reject;
|
|
1552
|
+
});
|
|
1553
|
+
}
|
|
1554
|
+
get promise() {
|
|
1555
|
+
return this._promise;
|
|
1556
|
+
}
|
|
1557
|
+
resolve(val) {
|
|
1558
|
+
this._resolve(val);
|
|
1559
|
+
}
|
|
1560
|
+
reject(err) {
|
|
1561
|
+
this._reject(err);
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
/*
|
|
1566
|
+
* Copyright The OpenTelemetry Authors
|
|
1567
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1568
|
+
*/
|
|
1569
|
+
/**
|
|
1570
|
+
* Bind the callback and only invoke the callback once regardless how many times `BindOnceFuture.call` is invoked.
|
|
1571
|
+
*/
|
|
1572
|
+
class BindOnceFuture {
|
|
1573
|
+
_isCalled = false;
|
|
1574
|
+
_deferred = new Deferred();
|
|
1575
|
+
_callback;
|
|
1576
|
+
_that;
|
|
1577
|
+
constructor(callback, that) {
|
|
1578
|
+
this._callback = callback;
|
|
1579
|
+
this._that = that;
|
|
1580
|
+
}
|
|
1581
|
+
get isCalled() {
|
|
1582
|
+
return this._isCalled;
|
|
1583
|
+
}
|
|
1584
|
+
get promise() {
|
|
1585
|
+
return this._deferred.promise;
|
|
1586
|
+
}
|
|
1587
|
+
call(...args) {
|
|
1588
|
+
if (!this._isCalled) {
|
|
1589
|
+
this._isCalled = true;
|
|
1590
|
+
try {
|
|
1591
|
+
Promise.resolve(this._callback.call(this._that, ...args)).then(val => this._deferred.resolve(val), err => this._deferred.reject(err));
|
|
1592
|
+
}
|
|
1593
|
+
catch (err) {
|
|
1594
|
+
this._deferred.reject(err);
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
return this._deferred.promise;
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
/*
|
|
1602
|
+
* Copyright The OpenTelemetry Authors
|
|
1603
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1604
|
+
*/
|
|
1605
|
+
class OTLPExporterBase {
|
|
1606
|
+
_delegate;
|
|
1607
|
+
constructor(delegate) {
|
|
1608
|
+
this._delegate = delegate;
|
|
1609
|
+
}
|
|
1610
|
+
/**
|
|
1611
|
+
* Export items.
|
|
1612
|
+
* @param items
|
|
1613
|
+
* @param resultCallback
|
|
1614
|
+
*/
|
|
1615
|
+
export(items, resultCallback) {
|
|
1616
|
+
this._delegate.export(items, resultCallback);
|
|
1617
|
+
}
|
|
1618
|
+
forceFlush() {
|
|
1619
|
+
return this._delegate.forceFlush();
|
|
1620
|
+
}
|
|
1621
|
+
shutdown() {
|
|
1622
|
+
return this._delegate.shutdown();
|
|
1623
|
+
}
|
|
1624
|
+
setMetrics(metrics) {
|
|
1625
|
+
this._delegate.setMetrics(metrics);
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
/*
|
|
1630
|
+
* Copyright The OpenTelemetry Authors
|
|
1631
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1632
|
+
*/
|
|
1633
|
+
/**
|
|
1634
|
+
* Interface for handling error
|
|
1635
|
+
*/
|
|
1636
|
+
class OTLPExporterError extends Error {
|
|
1637
|
+
code;
|
|
1638
|
+
name = 'OTLPExporterError';
|
|
1639
|
+
data;
|
|
1640
|
+
constructor(message, code, data) {
|
|
1641
|
+
super(message);
|
|
1642
|
+
this.data = data;
|
|
1643
|
+
this.code = code;
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
/*
|
|
1648
|
+
* Copyright The OpenTelemetry Authors
|
|
1649
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1650
|
+
*/
|
|
1651
|
+
function validateTimeoutMillis(timeoutMillis) {
|
|
1652
|
+
if (Number.isFinite(timeoutMillis) && timeoutMillis > 0) {
|
|
1653
|
+
return timeoutMillis;
|
|
1654
|
+
}
|
|
1655
|
+
throw new Error(`Configuration: timeoutMillis is invalid, expected number greater than 0 (actual: '${timeoutMillis}')`);
|
|
1656
|
+
}
|
|
1657
|
+
function wrapStaticHeadersInFunction(headers) {
|
|
1658
|
+
if (headers == null) {
|
|
1659
|
+
return undefined;
|
|
1660
|
+
}
|
|
1661
|
+
return async () => headers;
|
|
1662
|
+
}
|
|
1663
|
+
/**
|
|
1664
|
+
* @param userProvidedConfiguration Configuration options provided by the user in code.
|
|
1665
|
+
* @param fallbackConfiguration Fallback to use when the {@link userProvidedConfiguration} does not specify an option.
|
|
1666
|
+
* @param defaultConfiguration The defaults as defined by the exporter specification
|
|
1667
|
+
*/
|
|
1668
|
+
function mergeOtlpSharedConfigurationWithDefaults(userProvidedConfiguration, fallbackConfiguration, defaultConfiguration) {
|
|
1669
|
+
return {
|
|
1670
|
+
timeoutMillis: validateTimeoutMillis(userProvidedConfiguration.timeoutMillis ??
|
|
1671
|
+
fallbackConfiguration.timeoutMillis ??
|
|
1672
|
+
defaultConfiguration.timeoutMillis),
|
|
1673
|
+
concurrencyLimit: userProvidedConfiguration.concurrencyLimit ??
|
|
1674
|
+
fallbackConfiguration.concurrencyLimit ??
|
|
1675
|
+
defaultConfiguration.concurrencyLimit,
|
|
1676
|
+
compression: userProvidedConfiguration.compression ??
|
|
1677
|
+
fallbackConfiguration.compression ??
|
|
1678
|
+
defaultConfiguration.compression,
|
|
1679
|
+
};
|
|
1680
|
+
}
|
|
1681
|
+
function getSharedConfigurationDefaults() {
|
|
1682
|
+
return {
|
|
1683
|
+
timeoutMillis: 10000,
|
|
1684
|
+
concurrencyLimit: 30,
|
|
1685
|
+
compression: 'none',
|
|
1686
|
+
};
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
/*
|
|
1690
|
+
* Copyright The OpenTelemetry Authors
|
|
1691
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1692
|
+
*/
|
|
1693
|
+
class BoundedQueueExportPromiseHandler {
|
|
1694
|
+
_concurrencyLimit;
|
|
1695
|
+
_sendingPromises = [];
|
|
1696
|
+
/**
|
|
1697
|
+
* @param concurrencyLimit maximum promises allowed in a queue at the same time.
|
|
1698
|
+
*/
|
|
1699
|
+
constructor(concurrencyLimit) {
|
|
1700
|
+
this._concurrencyLimit = concurrencyLimit;
|
|
1701
|
+
}
|
|
1702
|
+
pushPromise(promise) {
|
|
1703
|
+
if (this.hasReachedLimit()) {
|
|
1704
|
+
throw new Error('Concurrency Limit reached');
|
|
1705
|
+
}
|
|
1706
|
+
this._sendingPromises.push(promise);
|
|
1707
|
+
const popPromise = () => {
|
|
1708
|
+
const index = this._sendingPromises.indexOf(promise);
|
|
1709
|
+
void this._sendingPromises.splice(index, 1);
|
|
1710
|
+
};
|
|
1711
|
+
promise.then(popPromise, popPromise);
|
|
1712
|
+
}
|
|
1713
|
+
hasReachedLimit() {
|
|
1714
|
+
return this._sendingPromises.length >= this._concurrencyLimit;
|
|
1715
|
+
}
|
|
1716
|
+
async awaitAll() {
|
|
1717
|
+
await Promise.all(this._sendingPromises);
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
/**
|
|
1721
|
+
* Promise queue for keeping track of export promises. Finished promises will be auto-dequeued.
|
|
1722
|
+
* Allows for awaiting all promises in the queue.
|
|
1723
|
+
*/
|
|
1724
|
+
function createBoundedQueueExportPromiseHandler(options) {
|
|
1725
|
+
return new BoundedQueueExportPromiseHandler(options.concurrencyLimit);
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
/*
|
|
1729
|
+
* Copyright The OpenTelemetry Authors
|
|
1730
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1731
|
+
*/
|
|
1732
|
+
function isPartialSuccessResponse(response) {
|
|
1733
|
+
return Object.prototype.hasOwnProperty.call(response, 'partialSuccess');
|
|
1734
|
+
}
|
|
1735
|
+
/**
|
|
1736
|
+
* Default response handler that logs a partial success to the console.
|
|
1737
|
+
*/
|
|
1738
|
+
function createLoggingPartialSuccessResponseHandler() {
|
|
1739
|
+
return {
|
|
1740
|
+
handleResponse(response) {
|
|
1741
|
+
// Partial success MUST never be an empty object according the specification
|
|
1742
|
+
// see https://opentelemetry.io/docs/specs/otlp/#partial-success
|
|
1743
|
+
if (response == null ||
|
|
1744
|
+
!isPartialSuccessResponse(response) ||
|
|
1745
|
+
response.partialSuccess == null ||
|
|
1746
|
+
Object.keys(response.partialSuccess).length === 0) {
|
|
1747
|
+
return;
|
|
1748
|
+
}
|
|
1749
|
+
diag.warn('Received Partial Success response:', JSON.stringify(response.partialSuccess));
|
|
1750
|
+
},
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
/*
|
|
1755
|
+
* Copyright The OpenTelemetry Authors
|
|
1756
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1757
|
+
*/
|
|
1758
|
+
class OTLPExportDelegate {
|
|
1759
|
+
_metrics;
|
|
1760
|
+
_diagLogger;
|
|
1761
|
+
_transport;
|
|
1762
|
+
_serializer;
|
|
1763
|
+
_responseHandler;
|
|
1764
|
+
_promiseQueue;
|
|
1765
|
+
_timeout;
|
|
1766
|
+
constructor(transport, serializer, responseHandler, promiseQueue, metrics, timeout) {
|
|
1767
|
+
this._transport = transport;
|
|
1768
|
+
this._serializer = serializer;
|
|
1769
|
+
this._responseHandler = responseHandler;
|
|
1770
|
+
this._promiseQueue = promiseQueue;
|
|
1771
|
+
this._timeout = timeout;
|
|
1772
|
+
this._diagLogger = diag.createComponentLogger({
|
|
1773
|
+
namespace: 'OTLPExportDelegate',
|
|
1774
|
+
});
|
|
1775
|
+
this._metrics = metrics;
|
|
1776
|
+
}
|
|
1777
|
+
export(internalRepresentation, resultCallback) {
|
|
1778
|
+
this._diagLogger.debug('items to be sent', internalRepresentation);
|
|
1779
|
+
// don't do any work if too many exports are in progress.
|
|
1780
|
+
if (this._promiseQueue.hasReachedLimit()) {
|
|
1781
|
+
resultCallback({
|
|
1782
|
+
code: ExportResultCode.FAILED,
|
|
1783
|
+
error: new Error('Concurrent export limit reached'),
|
|
1784
|
+
});
|
|
1785
|
+
return;
|
|
1786
|
+
}
|
|
1787
|
+
const serializedRequest = this._serializer.serializeRequest(internalRepresentation);
|
|
1788
|
+
if (serializedRequest == null) {
|
|
1789
|
+
resultCallback({
|
|
1790
|
+
code: ExportResultCode.FAILED,
|
|
1791
|
+
error: new Error('Nothing to send'),
|
|
1792
|
+
});
|
|
1793
|
+
return;
|
|
1794
|
+
}
|
|
1795
|
+
const finishExport = this._metrics.startExport(internalRepresentation);
|
|
1796
|
+
this._promiseQueue.pushPromise(this._transport.send(serializedRequest, this._timeout).then(response => {
|
|
1797
|
+
if (response.status === 'success') {
|
|
1798
|
+
finishExport(undefined);
|
|
1799
|
+
if (response.data != null) {
|
|
1800
|
+
try {
|
|
1801
|
+
this._responseHandler.handleResponse(this._serializer.deserializeResponse(response.data));
|
|
1802
|
+
}
|
|
1803
|
+
catch (e) {
|
|
1804
|
+
this._diagLogger.warn('Export succeeded but could not deserialize response - is the response specification compliant?', e, response.data);
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
// No matter the response, we can consider the export still successful.
|
|
1808
|
+
resultCallback({
|
|
1809
|
+
code: ExportResultCode.SUCCESS,
|
|
1810
|
+
});
|
|
1811
|
+
return;
|
|
1812
|
+
}
|
|
1813
|
+
else if (response.status === 'failure' && response.error) {
|
|
1814
|
+
finishExport(response.error);
|
|
1815
|
+
resultCallback({
|
|
1816
|
+
code: ExportResultCode.FAILED,
|
|
1817
|
+
error: response.error,
|
|
1818
|
+
});
|
|
1819
|
+
return;
|
|
1820
|
+
}
|
|
1821
|
+
else if (response.status === 'retryable') {
|
|
1822
|
+
finishExport('export_max_retries');
|
|
1823
|
+
resultCallback({
|
|
1824
|
+
code: ExportResultCode.FAILED,
|
|
1825
|
+
error: response.error ??
|
|
1826
|
+
new OTLPExporterError('Export failed with retryable status'),
|
|
1827
|
+
});
|
|
1828
|
+
}
|
|
1829
|
+
else {
|
|
1830
|
+
finishExport('export_failed');
|
|
1831
|
+
resultCallback({
|
|
1832
|
+
code: ExportResultCode.FAILED,
|
|
1833
|
+
error: new OTLPExporterError('Export failed with unknown error'),
|
|
1834
|
+
});
|
|
1835
|
+
}
|
|
1836
|
+
}, reason => {
|
|
1837
|
+
finishExport(reason);
|
|
1838
|
+
resultCallback({
|
|
1839
|
+
code: ExportResultCode.FAILED,
|
|
1840
|
+
error: reason,
|
|
1841
|
+
});
|
|
1842
|
+
}));
|
|
1843
|
+
}
|
|
1844
|
+
forceFlush() {
|
|
1845
|
+
return this._promiseQueue.awaitAll();
|
|
1846
|
+
}
|
|
1847
|
+
setMetrics(metrics) {
|
|
1848
|
+
this._metrics = metrics;
|
|
1849
|
+
}
|
|
1850
|
+
async shutdown() {
|
|
1851
|
+
this._diagLogger.debug('shutdown started');
|
|
1852
|
+
await this.forceFlush();
|
|
1853
|
+
this._transport.shutdown();
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
/**
|
|
1857
|
+
* Creates a generic delegate for OTLP exports which only contains parts of the OTLP export that are shared across all
|
|
1858
|
+
* signals.
|
|
1859
|
+
*/
|
|
1860
|
+
function createOtlpExportDelegate(components, settings) {
|
|
1861
|
+
return new OTLPExportDelegate(components.transport, components.serializer, createLoggingPartialSuccessResponseHandler(), components.promiseHandler, components.metrics, settings.timeout);
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
/*
|
|
1865
|
+
* Copyright The OpenTelemetry Authors
|
|
1866
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1867
|
+
*/
|
|
1868
|
+
function createOtlpNetworkExportDelegate(options, serializer, metrics, transport) {
|
|
1869
|
+
return createOtlpExportDelegate({
|
|
1870
|
+
transport: transport,
|
|
1871
|
+
serializer,
|
|
1872
|
+
promiseHandler: createBoundedQueueExportPromiseHandler(options),
|
|
1873
|
+
metrics,
|
|
1874
|
+
}, { timeout: options.timeoutMillis });
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
/*
|
|
1878
|
+
* Copyright The OpenTelemetry Authors
|
|
1879
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1880
|
+
*/
|
|
1881
|
+
/*
|
|
1882
|
+
* This file contains a copy of unstable semantic convention definitions
|
|
1883
|
+
* used by this package.
|
|
1884
|
+
* @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
|
|
1885
|
+
*/
|
|
1886
|
+
/**
|
|
1887
|
+
* [HTTP response status code](https://tools.ietf.org/html/rfc7231#section-6).
|
|
1888
|
+
*
|
|
1889
|
+
* @example 200
|
|
1890
|
+
*/
|
|
1891
|
+
const ATTR_HTTP_RESPONSE_STATUS_CODE = 'http.response.status_code';
|
|
1892
|
+
/**
|
|
1893
|
+
* A name uniquely identifying the instance of the OpenTelemetry component within its containing SDK instance.
|
|
1894
|
+
*
|
|
1895
|
+
* @example otlp_grpc_span_exporter/0
|
|
1896
|
+
* @example custom-name
|
|
1897
|
+
*
|
|
1898
|
+
* @note Implementations **SHOULD** ensure a low cardinality for this attribute, even across application or SDK restarts.
|
|
1899
|
+
* E.g. implementations **MUST NOT** use UUIDs as values for this attribute.
|
|
1900
|
+
*
|
|
1901
|
+
* Implementations **MAY** achieve these goals by following a `<otel.component.type>/<instance-counter>` pattern, e.g. `batching_span_processor/0`.
|
|
1902
|
+
* Hereby `otel.component.type` refers to the corresponding attribute value of the component.
|
|
1903
|
+
*
|
|
1904
|
+
* The value of `instance-counter` **MAY** be automatically assigned by the component and uniqueness within the enclosing SDK instance **MUST** be guaranteed.
|
|
1905
|
+
* For example, `<instance-counter>` **MAY** be implemented by using a monotonically increasing counter (starting with `0`), which is incremented every time an
|
|
1906
|
+
* instance of the given component type is started.
|
|
1907
|
+
*
|
|
1908
|
+
* With this implementation, for example the first Batching Span Processor would have `batching_span_processor/0`
|
|
1909
|
+
* as `otel.component.name`, the second one `batching_span_processor/1` and so on.
|
|
1910
|
+
* These values will therefore be reused in the case of an application restart.
|
|
1911
|
+
*
|
|
1912
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
1913
|
+
*/
|
|
1914
|
+
const ATTR_OTEL_COMPONENT_NAME = 'otel.component.name';
|
|
1915
|
+
/**
|
|
1916
|
+
* A name identifying the type of the OpenTelemetry component.
|
|
1917
|
+
*
|
|
1918
|
+
* @example batching_span_processor
|
|
1919
|
+
* @example com.example.MySpanExporter
|
|
1920
|
+
*
|
|
1921
|
+
* @note If none of the standardized values apply, implementations **SHOULD** use the language-defined name of the type.
|
|
1922
|
+
* E.g. for Java the fully qualified classname **SHOULD** be used in this case.
|
|
1923
|
+
*
|
|
1924
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
1925
|
+
*/
|
|
1926
|
+
const ATTR_OTEL_COMPONENT_TYPE = 'otel.component.type';
|
|
1927
|
+
/**
|
|
1928
|
+
* Server domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name.
|
|
1929
|
+
*
|
|
1930
|
+
* @example example.com
|
|
1931
|
+
* @example 10.1.2.80
|
|
1932
|
+
* @example /tmp/my.sock
|
|
1933
|
+
*
|
|
1934
|
+
* @note When observed from the client side, and when communicating through an intermediary, `server.address` **SHOULD** represent the server address behind any intermediaries, for example proxies, if it's available.
|
|
1935
|
+
*/
|
|
1936
|
+
const ATTR_SERVER_ADDRESS = 'server.address';
|
|
1937
|
+
/**
|
|
1938
|
+
* Server port number.
|
|
1939
|
+
*
|
|
1940
|
+
* @example 80
|
|
1941
|
+
* @example 8080
|
|
1942
|
+
* @example 443
|
|
1943
|
+
*
|
|
1944
|
+
* @note When observed from the client side, and when communicating through an intermediary, `server.port` **SHOULD** represent the server port behind any intermediaries, for example proxies, if it's available.
|
|
1945
|
+
*/
|
|
1946
|
+
const ATTR_SERVER_PORT = 'server.port';
|
|
1947
|
+
/**
|
|
1948
|
+
* Describes a class of error the operation ended with.
|
|
1949
|
+
*
|
|
1950
|
+
* @example timeout
|
|
1951
|
+
* @example java.net.UnknownHostException
|
|
1952
|
+
* @example server_certificate_invalid
|
|
1953
|
+
* @example 500
|
|
1954
|
+
*
|
|
1955
|
+
* @note The `error.type` **SHOULD** be predictable, and **SHOULD** have low cardinality.
|
|
1956
|
+
*
|
|
1957
|
+
* When `error.type` is set to a type (e.g., an exception type), its
|
|
1958
|
+
* canonical class name identifying the type within the artifact **SHOULD** be used.
|
|
1959
|
+
*
|
|
1960
|
+
* Instrumentations **SHOULD** document the list of errors they report.
|
|
1961
|
+
*
|
|
1962
|
+
* The cardinality of `error.type` within one instrumentation library **SHOULD** be low.
|
|
1963
|
+
* Telemetry consumers that aggregate data from multiple instrumentation libraries and applications
|
|
1964
|
+
* should be prepared for `error.type` to have high cardinality at query time when no
|
|
1965
|
+
* additional filters are applied.
|
|
1966
|
+
*
|
|
1967
|
+
* If the operation has completed successfully, instrumentations **SHOULD NOT** set `error.type`.
|
|
1968
|
+
*
|
|
1969
|
+
* If a specific domain defines its own set of error identifiers (such as HTTP or RPC status codes),
|
|
1970
|
+
* it's **RECOMMENDED** to:
|
|
1971
|
+
*
|
|
1972
|
+
* - Use a domain-specific attribute
|
|
1973
|
+
* - Set `error.type` to capture all errors, regardless of whether they are defined within the domain-specific set or not.
|
|
1974
|
+
*/
|
|
1975
|
+
const ATTR_ERROR_TYPE = 'error.type';
|
|
1976
|
+
|
|
1977
|
+
/*
|
|
1978
|
+
* Copyright The OpenTelemetry Authors
|
|
1979
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1980
|
+
*/
|
|
1981
|
+
// this is autogenerated file, see scripts/version-update.js
|
|
1982
|
+
const VERSION = '0.223.0';
|
|
1983
|
+
|
|
1984
|
+
/*
|
|
1985
|
+
* Copyright The OpenTelemetry Authors
|
|
1986
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1987
|
+
*/
|
|
1988
|
+
const componentCounter = new Map();
|
|
1989
|
+
/**
|
|
1990
|
+
* Generates `otel.sdk.exporter.*` metrics.
|
|
1991
|
+
* https://opentelemetry.io/docs/specs/semconv/otel/sdk-metrics
|
|
1992
|
+
*/
|
|
1993
|
+
class ExporterMetrics {
|
|
1994
|
+
inflight;
|
|
1995
|
+
exported;
|
|
1996
|
+
duration;
|
|
1997
|
+
standardAttrs;
|
|
1998
|
+
responseAttributesFromError;
|
|
1999
|
+
helper;
|
|
2000
|
+
constructor(options) {
|
|
2001
|
+
const { componentType, metricsHelper, meterProvider, url, responseAttributesFromError, } = options;
|
|
2002
|
+
this.responseAttributesFromError = responseAttributesFromError;
|
|
2003
|
+
const meter = meterProvider
|
|
2004
|
+
? meterProvider.getMeter('@opentelemetry/otlp-exporter', VERSION)
|
|
2005
|
+
: createNoopMeter();
|
|
2006
|
+
const counter = componentCounter.get(componentType) ?? 0;
|
|
2007
|
+
componentCounter.set(componentType, counter + 1);
|
|
2008
|
+
this.standardAttrs = {
|
|
2009
|
+
[ATTR_OTEL_COMPONENT_TYPE]: componentType,
|
|
2010
|
+
[ATTR_OTEL_COMPONENT_NAME]: `${componentType}/${counter}`,
|
|
2011
|
+
};
|
|
2012
|
+
if (url) {
|
|
2013
|
+
// URLs may exclude scheme for gRPC endpoints, but in this case they always
|
|
2014
|
+
// have a port number. Because the URL constructor requires a scheme, we
|
|
2015
|
+
// can still handle gRPC endpoints by prepending an arbitrary scheme.
|
|
2016
|
+
let urlToParse = url;
|
|
2017
|
+
if (!url.includes('://')) {
|
|
2018
|
+
urlToParse = `http://${url}`;
|
|
2019
|
+
}
|
|
2020
|
+
try {
|
|
2021
|
+
const parsedUrl = new URL(urlToParse);
|
|
2022
|
+
this.standardAttrs[ATTR_SERVER_ADDRESS] = parsedUrl.hostname;
|
|
2023
|
+
let port = undefined;
|
|
2024
|
+
if (parsedUrl.port) {
|
|
2025
|
+
port = Number(parsedUrl.port);
|
|
2026
|
+
}
|
|
2027
|
+
else if (parsedUrl.protocol === 'http:') {
|
|
2028
|
+
port = 80;
|
|
2029
|
+
}
|
|
2030
|
+
else if (parsedUrl.protocol === 'https:') {
|
|
2031
|
+
port = 443;
|
|
2032
|
+
}
|
|
2033
|
+
if (typeof port === 'number') {
|
|
2034
|
+
this.standardAttrs[ATTR_SERVER_PORT] = port;
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
catch {
|
|
2038
|
+
// In practice, URLs will be valid or something else will break. Better to let that
|
|
2039
|
+
// inform the user than an exception in this internal code and proceed best-effort
|
|
2040
|
+
// here.
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
this.helper = metricsHelper;
|
|
2044
|
+
this.inflight = meter.createUpDownCounter(`otel.sdk.exporter.${this.helper.name}.inflight`, {
|
|
2045
|
+
unit: `{${this.helper.name}}`,
|
|
2046
|
+
description: `The number of ${this.helper.name}s which were passed to the exporter, but that have not been exported yet (neither successful, nor failed).`,
|
|
2047
|
+
});
|
|
2048
|
+
this.exported = meter.createCounter(`otel.sdk.exporter.${this.helper.name}.exported`, {
|
|
2049
|
+
unit: `{${this.helper.name}}`,
|
|
2050
|
+
description: `The number of ${this.helper.name}s for which the export has finished, either successful or failed.`,
|
|
2051
|
+
});
|
|
2052
|
+
this.duration = meter.createHistogram('otel.sdk.exporter.operation.duration', {
|
|
2053
|
+
unit: 's',
|
|
2054
|
+
description: 'The duration of exporting a batch of telemetry records.',
|
|
2055
|
+
advice: {
|
|
2056
|
+
explicitBucketBoundaries: [],
|
|
2057
|
+
},
|
|
2058
|
+
});
|
|
2059
|
+
}
|
|
2060
|
+
startExport(request) {
|
|
2061
|
+
const numItems = this.helper.countItems(request);
|
|
2062
|
+
const startTime = hrTime();
|
|
2063
|
+
this.inflight.add(numItems, this.standardAttrs);
|
|
2064
|
+
return (error) => {
|
|
2065
|
+
const endTime = hrTime();
|
|
2066
|
+
this.inflight.add(-numItems, this.standardAttrs);
|
|
2067
|
+
const exportedAttrs = error
|
|
2068
|
+
? {
|
|
2069
|
+
...this.standardAttrs,
|
|
2070
|
+
[ATTR_ERROR_TYPE]: error instanceof Error ? error.name : 'export_failed',
|
|
2071
|
+
}
|
|
2072
|
+
: this.standardAttrs;
|
|
2073
|
+
this.exported.add(numItems, exportedAttrs);
|
|
2074
|
+
const durationAttrs = {
|
|
2075
|
+
...exportedAttrs,
|
|
2076
|
+
...this.responseAttributesFromError(error),
|
|
2077
|
+
};
|
|
2078
|
+
const duration = hrTimeToMilliseconds(hrTimeDuration(startTime, endTime)) / 1000;
|
|
2079
|
+
this.duration.record(duration, durationAttrs);
|
|
2080
|
+
};
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2084
|
+
/*
|
|
2085
|
+
* Copyright The OpenTelemetry Authors
|
|
2086
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2087
|
+
*/
|
|
2088
|
+
class NoopLogger {
|
|
2089
|
+
emit(_logRecord) { }
|
|
2090
|
+
enabled() {
|
|
2091
|
+
return false;
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
const NOOP_LOGGER = new NoopLogger();
|
|
2095
|
+
/**
|
|
2096
|
+
* Create a no-op Logger
|
|
2097
|
+
*/
|
|
2098
|
+
function createNoopLogger() {
|
|
2099
|
+
return NOOP_LOGGER;
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2102
|
+
/*
|
|
2103
|
+
* Copyright The OpenTelemetry Authors
|
|
2104
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2105
|
+
*/
|
|
2106
|
+
let serviceName;
|
|
2107
|
+
/**
|
|
2108
|
+
* Returns the default service name for OpenTelemetry resources.
|
|
2109
|
+
* In Node.js environments, returns "unknown_service:<process.argv0>".
|
|
2110
|
+
* In browser/edge environments, returns "unknown_service".
|
|
2111
|
+
*/
|
|
2112
|
+
function defaultServiceName() {
|
|
2113
|
+
if (serviceName === undefined) {
|
|
2114
|
+
try {
|
|
2115
|
+
const argv0 = globalThis.process.argv0;
|
|
2116
|
+
serviceName = argv0 ? `unknown_service:${argv0}` : 'unknown_service';
|
|
2117
|
+
}
|
|
2118
|
+
catch {
|
|
2119
|
+
serviceName = 'unknown_service';
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
return serviceName;
|
|
2123
|
+
}
|
|
2124
|
+
|
|
2125
|
+
/*
|
|
2126
|
+
* Copyright The OpenTelemetry Authors
|
|
2127
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2128
|
+
*/
|
|
2129
|
+
const isPromiseLike = (val) => {
|
|
2130
|
+
return (val !== null &&
|
|
2131
|
+
typeof val === 'object' &&
|
|
2132
|
+
typeof val.then === 'function');
|
|
2133
|
+
};
|
|
2134
|
+
|
|
2135
|
+
/*
|
|
2136
|
+
* Copyright The OpenTelemetry Authors
|
|
2137
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2138
|
+
*/
|
|
2139
|
+
class ResourceImpl {
|
|
2140
|
+
_rawAttributes;
|
|
2141
|
+
_asyncAttributesPending = false;
|
|
2142
|
+
_schemaUrl;
|
|
2143
|
+
_memoizedAttributes;
|
|
2144
|
+
static FromAttributeList(attributes, options) {
|
|
2145
|
+
const res = new ResourceImpl({}, options);
|
|
2146
|
+
res._rawAttributes = guardedRawAttributes(attributes);
|
|
2147
|
+
res._asyncAttributesPending =
|
|
2148
|
+
attributes.filter(([_, val]) => isPromiseLike(val)).length > 0;
|
|
2149
|
+
return res;
|
|
2150
|
+
}
|
|
2151
|
+
constructor(
|
|
2152
|
+
/**
|
|
2153
|
+
* A dictionary of attributes with string keys and values that provide
|
|
2154
|
+
* information about the entity as numbers, strings or booleans
|
|
2155
|
+
* TODO: Consider to add check/validation on attributes.
|
|
2156
|
+
*/
|
|
2157
|
+
resource, options) {
|
|
2158
|
+
const attributes = resource.attributes ?? {};
|
|
2159
|
+
this._rawAttributes = Object.entries(attributes).map(([k, v]) => {
|
|
2160
|
+
if (isPromiseLike(v)) {
|
|
2161
|
+
// side-effect
|
|
2162
|
+
this._asyncAttributesPending = true;
|
|
2163
|
+
}
|
|
2164
|
+
return [k, v];
|
|
2165
|
+
});
|
|
2166
|
+
this._rawAttributes = guardedRawAttributes(this._rawAttributes);
|
|
2167
|
+
this._schemaUrl = validateSchemaUrl(options?.schemaUrl);
|
|
2168
|
+
}
|
|
2169
|
+
get asyncAttributesPending() {
|
|
2170
|
+
return this._asyncAttributesPending;
|
|
2171
|
+
}
|
|
2172
|
+
async waitForAsyncAttributes() {
|
|
2173
|
+
if (!this.asyncAttributesPending) {
|
|
2174
|
+
return;
|
|
2175
|
+
}
|
|
2176
|
+
for (let i = 0; i < this._rawAttributes.length; i++) {
|
|
2177
|
+
const [k, v] = this._rawAttributes[i];
|
|
2178
|
+
this._rawAttributes[i] = [k, isPromiseLike(v) ? await v : v];
|
|
2179
|
+
}
|
|
2180
|
+
this._asyncAttributesPending = false;
|
|
2181
|
+
}
|
|
2182
|
+
get attributes() {
|
|
2183
|
+
if (this.asyncAttributesPending) {
|
|
2184
|
+
diag.error('Accessing resource attributes before async attributes settled');
|
|
2185
|
+
}
|
|
2186
|
+
if (this._memoizedAttributes) {
|
|
2187
|
+
return this._memoizedAttributes;
|
|
2188
|
+
}
|
|
2189
|
+
const attrs = {};
|
|
2190
|
+
for (const [k, v] of this._rawAttributes) {
|
|
2191
|
+
if (isPromiseLike(v)) {
|
|
2192
|
+
diag.debug(`Unsettled resource attribute ${k} skipped`);
|
|
2193
|
+
continue;
|
|
2194
|
+
}
|
|
2195
|
+
if (v != null) {
|
|
2196
|
+
attrs[k] ??= v;
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
// only memoize output if all attributes are settled
|
|
2200
|
+
if (!this._asyncAttributesPending) {
|
|
2201
|
+
this._memoizedAttributes = attrs;
|
|
2202
|
+
}
|
|
2203
|
+
return attrs;
|
|
2204
|
+
}
|
|
2205
|
+
getRawAttributes() {
|
|
2206
|
+
return this._rawAttributes;
|
|
2207
|
+
}
|
|
2208
|
+
get schemaUrl() {
|
|
2209
|
+
return this._schemaUrl;
|
|
2210
|
+
}
|
|
2211
|
+
merge(resource) {
|
|
2212
|
+
if (resource == null)
|
|
2213
|
+
return this;
|
|
2214
|
+
// Order is important
|
|
2215
|
+
// Spec states incoming attributes override existing attributes
|
|
2216
|
+
const mergedSchemaUrl = mergeSchemaUrl(this, resource);
|
|
2217
|
+
const mergedOptions = mergedSchemaUrl
|
|
2218
|
+
? { schemaUrl: mergedSchemaUrl }
|
|
2219
|
+
: undefined;
|
|
2220
|
+
return ResourceImpl.FromAttributeList([...resource.getRawAttributes(), ...this.getRawAttributes()], mergedOptions);
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
function resourceFromAttributes(attributes, options) {
|
|
2224
|
+
return ResourceImpl.FromAttributeList(Object.entries(attributes), options);
|
|
2225
|
+
}
|
|
2226
|
+
function defaultResource() {
|
|
2227
|
+
return resourceFromAttributes({
|
|
2228
|
+
[ATTR_SERVICE_NAME]: defaultServiceName(),
|
|
2229
|
+
[ATTR_TELEMETRY_SDK_LANGUAGE]: SDK_INFO[ATTR_TELEMETRY_SDK_LANGUAGE],
|
|
2230
|
+
[ATTR_TELEMETRY_SDK_NAME]: SDK_INFO[ATTR_TELEMETRY_SDK_NAME],
|
|
2231
|
+
[ATTR_TELEMETRY_SDK_VERSION]: SDK_INFO[ATTR_TELEMETRY_SDK_VERSION],
|
|
2232
|
+
});
|
|
2233
|
+
}
|
|
2234
|
+
function guardedRawAttributes(attributes) {
|
|
2235
|
+
return attributes.map(([k, v]) => {
|
|
2236
|
+
if (isPromiseLike(v)) {
|
|
2237
|
+
return [
|
|
2238
|
+
k,
|
|
2239
|
+
v.catch(err => {
|
|
2240
|
+
diag.debug('promise rejection for resource attribute: %s - %s', k, err);
|
|
2241
|
+
return undefined;
|
|
2242
|
+
}),
|
|
2243
|
+
];
|
|
2244
|
+
}
|
|
2245
|
+
return [k, v];
|
|
2246
|
+
});
|
|
2247
|
+
}
|
|
2248
|
+
function validateSchemaUrl(schemaUrl) {
|
|
2249
|
+
if (typeof schemaUrl === 'string' || schemaUrl === undefined) {
|
|
2250
|
+
return schemaUrl;
|
|
2251
|
+
}
|
|
2252
|
+
diag.warn('Schema URL must be string or undefined, got %s. Schema URL will be ignored.', schemaUrl);
|
|
2253
|
+
return undefined;
|
|
2254
|
+
}
|
|
2255
|
+
function mergeSchemaUrl(old, updating) {
|
|
2256
|
+
const oldSchemaUrl = old?.schemaUrl;
|
|
2257
|
+
const updatingSchemaUrl = updating?.schemaUrl;
|
|
2258
|
+
const isOldEmpty = oldSchemaUrl === undefined || oldSchemaUrl === '';
|
|
2259
|
+
const isUpdatingEmpty = updatingSchemaUrl === undefined || updatingSchemaUrl === '';
|
|
2260
|
+
if (isOldEmpty) {
|
|
2261
|
+
return updatingSchemaUrl;
|
|
2262
|
+
}
|
|
2263
|
+
if (isUpdatingEmpty) {
|
|
2264
|
+
return oldSchemaUrl;
|
|
2265
|
+
}
|
|
2266
|
+
if (oldSchemaUrl === updatingSchemaUrl) {
|
|
2267
|
+
return oldSchemaUrl;
|
|
2268
|
+
}
|
|
2269
|
+
diag.warn('Schema URL merge conflict: old resource has "%s", updating resource has "%s". Resulting resource will have undefined Schema URL.', oldSchemaUrl, updatingSchemaUrl);
|
|
2270
|
+
return undefined;
|
|
2271
|
+
}
|
|
2272
|
+
|
|
2273
|
+
function createResource(resource, encoder) {
|
|
2274
|
+
const result = {
|
|
2275
|
+
attributes: toAttributes(resource.attributes, encoder),
|
|
2276
|
+
droppedAttributesCount: 0,
|
|
2277
|
+
};
|
|
2278
|
+
const schemaUrl = resource.schemaUrl;
|
|
2279
|
+
if (schemaUrl && schemaUrl !== '')
|
|
2280
|
+
result.schemaUrl = schemaUrl;
|
|
2281
|
+
return result;
|
|
2282
|
+
}
|
|
2283
|
+
function createInstrumentationScope(scope, encoder) {
|
|
2284
|
+
const result = {
|
|
2285
|
+
name: scope.name,
|
|
2286
|
+
version: scope.version,
|
|
2287
|
+
};
|
|
2288
|
+
if (scope.attributes && Object.keys(scope.attributes).length > 0) {
|
|
2289
|
+
result.attributes = toAttributes(scope.attributes, encoder);
|
|
2290
|
+
result.droppedAttributesCount = scope.droppedAttributesCount ?? 0;
|
|
2291
|
+
}
|
|
2292
|
+
return result;
|
|
2293
|
+
}
|
|
2294
|
+
function toAttributes(attributes, encoder) {
|
|
2295
|
+
return Object.keys(attributes).map(key => toKeyValue(key, attributes[key], encoder));
|
|
2296
|
+
}
|
|
2297
|
+
function toKeyValue(key, value, encoder) {
|
|
2298
|
+
return {
|
|
2299
|
+
key: key,
|
|
2300
|
+
value: toAnyValue(value, encoder),
|
|
2301
|
+
};
|
|
2302
|
+
}
|
|
2303
|
+
function toAnyValue(value, encoder) {
|
|
2304
|
+
const t = typeof value;
|
|
2305
|
+
if (t === 'string')
|
|
2306
|
+
return { stringValue: value };
|
|
2307
|
+
if (t === 'number') {
|
|
2308
|
+
if (!Number.isInteger(value))
|
|
2309
|
+
return { doubleValue: value };
|
|
2310
|
+
return { intValue: value };
|
|
2311
|
+
}
|
|
2312
|
+
if (t === 'boolean')
|
|
2313
|
+
return { boolValue: value };
|
|
2314
|
+
if (value instanceof Uint8Array)
|
|
2315
|
+
return { bytesValue: encoder.encodeUint8Array(value) };
|
|
2316
|
+
if (Array.isArray(value)) {
|
|
2317
|
+
const values = new Array(value.length);
|
|
2318
|
+
for (let i = 0; i < value.length; i++) {
|
|
2319
|
+
values[i] = toAnyValue(value[i], encoder);
|
|
2320
|
+
}
|
|
2321
|
+
return { arrayValue: { values } };
|
|
2322
|
+
}
|
|
2323
|
+
if (t === 'object' && value != null) {
|
|
2324
|
+
const keys = Object.keys(value);
|
|
2325
|
+
const values = new Array(keys.length);
|
|
2326
|
+
for (let i = 0; i < keys.length; i++) {
|
|
2327
|
+
values[i] = {
|
|
2328
|
+
key: keys[i],
|
|
2329
|
+
value: toAnyValue(value[keys[i]], encoder),
|
|
2330
|
+
};
|
|
2331
|
+
}
|
|
2332
|
+
return { kvlistValue: { values } };
|
|
2333
|
+
}
|
|
2334
|
+
return {};
|
|
2335
|
+
}
|
|
2336
|
+
|
|
2337
|
+
/*
|
|
2338
|
+
* Copyright The OpenTelemetry Authors
|
|
2339
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2340
|
+
*/
|
|
2341
|
+
function hrTimeToNanos(hrTime) {
|
|
2342
|
+
const NANOSECONDS = BigInt(1000000000);
|
|
2343
|
+
return (BigInt(Math.trunc(hrTime[0])) * NANOSECONDS + BigInt(Math.trunc(hrTime[1])));
|
|
2344
|
+
}
|
|
2345
|
+
function encodeAsString(hrTime) {
|
|
2346
|
+
const nanos = hrTimeToNanos(hrTime);
|
|
2347
|
+
return nanos.toString();
|
|
2348
|
+
}
|
|
2349
|
+
const encodeTimestamp = typeof BigInt !== 'undefined' ? encodeAsString : hrTimeToNanoseconds;
|
|
2350
|
+
function identity(value) {
|
|
2351
|
+
return value;
|
|
2352
|
+
}
|
|
2353
|
+
/**
|
|
2354
|
+
* Encoder for JSON format.
|
|
2355
|
+
* Uses string timestamps, hex for span/trace IDs, and base64 for Uint8Array.
|
|
2356
|
+
*/
|
|
2357
|
+
const JSON_ENCODER = {
|
|
2358
|
+
encodeHrTime: encodeTimestamp,
|
|
2359
|
+
encodeSpanContext: identity,
|
|
2360
|
+
encodeOptionalSpanContext: identity,
|
|
2361
|
+
encodeUint8Array: (bytes) => {
|
|
2362
|
+
if (typeof Buffer !== 'undefined') {
|
|
2363
|
+
return Buffer.from(bytes).toString('base64');
|
|
2364
|
+
}
|
|
2365
|
+
// implementation note: not using spread operator and passing to
|
|
2366
|
+
// btoa to avoid stack overflow on large Uint8Arrays
|
|
2367
|
+
const chars = new Array(bytes.length);
|
|
2368
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
2369
|
+
chars[i] = String.fromCharCode(bytes[i]);
|
|
2370
|
+
}
|
|
2371
|
+
return btoa(chars.join(''));
|
|
2372
|
+
},
|
|
2373
|
+
};
|
|
2374
|
+
|
|
2375
|
+
/*
|
|
2376
|
+
* Copyright The OpenTelemetry Authors
|
|
2377
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2378
|
+
*/
|
|
2379
|
+
const MAX_ATTEMPTS = 5;
|
|
2380
|
+
const INITIAL_BACKOFF = 1000;
|
|
2381
|
+
const MAX_BACKOFF = 5000;
|
|
2382
|
+
const BACKOFF_MULTIPLIER = 1.5;
|
|
2383
|
+
const JITTER = 0.2;
|
|
2384
|
+
/**
|
|
2385
|
+
* Get a pseudo-random jitter that falls in the range of [-JITTER, +JITTER]
|
|
2386
|
+
*/
|
|
2387
|
+
function getJitter() {
|
|
2388
|
+
return Math.random() * (2 * JITTER) - JITTER;
|
|
2389
|
+
}
|
|
2390
|
+
class RetryingTransport {
|
|
2391
|
+
_transport;
|
|
2392
|
+
constructor(transport) {
|
|
2393
|
+
this._transport = transport;
|
|
2394
|
+
}
|
|
2395
|
+
retry(data, timeoutMillis, inMillis) {
|
|
2396
|
+
return new Promise((resolve, reject) => {
|
|
2397
|
+
setTimeout(() => {
|
|
2398
|
+
this._transport.send(data, timeoutMillis).then(resolve, reject);
|
|
2399
|
+
}, inMillis);
|
|
2400
|
+
});
|
|
2401
|
+
}
|
|
2402
|
+
async send(data, timeoutMillis) {
|
|
2403
|
+
let attempts = MAX_ATTEMPTS;
|
|
2404
|
+
let nextBackoff = INITIAL_BACKOFF;
|
|
2405
|
+
const deadline = Date.now() + timeoutMillis;
|
|
2406
|
+
let result = await this._transport.send(data, timeoutMillis);
|
|
2407
|
+
while (result.status === 'retryable' && attempts > 0) {
|
|
2408
|
+
attempts--;
|
|
2409
|
+
// use maximum of computed backoff and 0 to avoid negative timeouts
|
|
2410
|
+
const backoff = Math.max(Math.min(nextBackoff * (1 + getJitter()), MAX_BACKOFF), 0);
|
|
2411
|
+
nextBackoff = nextBackoff * BACKOFF_MULTIPLIER;
|
|
2412
|
+
const retryInMillis = result.retryInMillis ?? backoff;
|
|
2413
|
+
// return when expected retry time is after the export deadline.
|
|
2414
|
+
const remainingTimeoutMillis = deadline - Date.now();
|
|
2415
|
+
if (retryInMillis > remainingTimeoutMillis) {
|
|
2416
|
+
diag.info(`Export retry time ${Math.round(retryInMillis)}ms exceeds remaining timeout ${Math.round(remainingTimeoutMillis)}ms, not retrying further.`);
|
|
2417
|
+
return result;
|
|
2418
|
+
}
|
|
2419
|
+
diag.verbose(`Scheduling export retry in ${Math.round(retryInMillis)}ms`);
|
|
2420
|
+
result = await this.retry(data, remainingTimeoutMillis, retryInMillis);
|
|
2421
|
+
}
|
|
2422
|
+
if (result.status === 'success') {
|
|
2423
|
+
diag.verbose(`Export succeeded after ${MAX_ATTEMPTS - attempts} retry attempts.`);
|
|
2424
|
+
}
|
|
2425
|
+
else if (result.status === 'retryable') {
|
|
2426
|
+
diag.info(`Export failed after maximum retry attempts (${MAX_ATTEMPTS}).`);
|
|
2427
|
+
}
|
|
2428
|
+
else {
|
|
2429
|
+
diag.info(`Export failed with non-retryable error: ${result.error}`);
|
|
2430
|
+
}
|
|
2431
|
+
return result;
|
|
2432
|
+
}
|
|
2433
|
+
shutdown() {
|
|
2434
|
+
return this._transport.shutdown();
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
/**
|
|
2438
|
+
* Creates an Exporter Transport that retries on 'retryable' response.
|
|
2439
|
+
*/
|
|
2440
|
+
function createRetryingTransport(options) {
|
|
2441
|
+
return new RetryingTransport(options.transport);
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2444
|
+
/*
|
|
2445
|
+
* Copyright The OpenTelemetry Authors
|
|
2446
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2447
|
+
*/
|
|
2448
|
+
function isExportHTTPErrorRetryable(statusCode) {
|
|
2449
|
+
return (statusCode === 429 ||
|
|
2450
|
+
statusCode === 502 ||
|
|
2451
|
+
statusCode === 503 ||
|
|
2452
|
+
statusCode === 504);
|
|
2453
|
+
}
|
|
2454
|
+
function parseRetryAfterToMills(retryAfter) {
|
|
2455
|
+
if (retryAfter == null) {
|
|
2456
|
+
return undefined;
|
|
2457
|
+
}
|
|
2458
|
+
const seconds = Number.parseInt(retryAfter, 10);
|
|
2459
|
+
if (Number.isInteger(seconds)) {
|
|
2460
|
+
return seconds > 0 ? seconds * 1000 : -1;
|
|
2461
|
+
}
|
|
2462
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After#directives
|
|
2463
|
+
const delay = new Date(retryAfter).getTime() - Date.now();
|
|
2464
|
+
if (delay >= 0) {
|
|
2465
|
+
return delay;
|
|
2466
|
+
}
|
|
2467
|
+
return 0;
|
|
2468
|
+
}
|
|
2469
|
+
|
|
2470
|
+
/*
|
|
2471
|
+
* Copyright The OpenTelemetry Authors
|
|
2472
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2473
|
+
*/
|
|
2474
|
+
/**
|
|
2475
|
+
* Maximum total body size for concurrent keepalive requests.
|
|
2476
|
+
* Browsers enforce a 64KiB cumulative limit across all pending keepalive requests.
|
|
2477
|
+
* We use 60KB to leave headroom for headers.
|
|
2478
|
+
* @see https://github.com/whatwg/fetch/issues/679
|
|
2479
|
+
* @see https://blog.huli.tw/2025/01/06/en/navigator-sendbeacon-64kib-and-source-code/
|
|
2480
|
+
*/
|
|
2481
|
+
const MAX_KEEPALIVE_BODY_SIZE = 60 * 1024;
|
|
2482
|
+
/**
|
|
2483
|
+
* Maximum concurrent keepalive requests.
|
|
2484
|
+
* Chrome enforces 9 concurrent keepalive fetch requests per renderer process.
|
|
2485
|
+
* @see https://github.com/whatwg/fetch/issues/679
|
|
2486
|
+
* Quote: "If the renderer process is processing more than 9 requests with keepalive set, we reject a new request"
|
|
2487
|
+
*/
|
|
2488
|
+
const MAX_KEEPALIVE_REQUESTS = 9;
|
|
2489
|
+
/**
|
|
2490
|
+
* Track cumulative pending body size across all in-flight keepalive requests.
|
|
2491
|
+
* This is necessary because the 64KiB limit is cumulative, not per-request.
|
|
2492
|
+
*/
|
|
2493
|
+
let pendingBodySize = 0;
|
|
2494
|
+
/**
|
|
2495
|
+
* Track number of pending keepalive requests.
|
|
2496
|
+
*/
|
|
2497
|
+
let pendingKeepaliveCount = 0;
|
|
2498
|
+
class FetchTransport {
|
|
2499
|
+
_parameters;
|
|
2500
|
+
constructor(parameters) {
|
|
2501
|
+
this._parameters = parameters;
|
|
2502
|
+
}
|
|
2503
|
+
async send(data, timeoutMillis) {
|
|
2504
|
+
const abortController = new AbortController();
|
|
2505
|
+
const timeout = setTimeout(() => abortController.abort(), timeoutMillis);
|
|
2506
|
+
// Fetch API may be wrapped by an instrumentation like `@opentelemetry/instrumentation-fetch`.
|
|
2507
|
+
// In that case the instrumentation would create a new Span for this request
|
|
2508
|
+
// because the context manager cannot keep the context after `await` calls.
|
|
2509
|
+
// This creates an indirect endless loop Export -> Span -> Export
|
|
2510
|
+
// By using the `__original` function the instrumentation can't intercept the call
|
|
2511
|
+
// and no Span will be created breaking the vicious cycle
|
|
2512
|
+
let fetchApi = globalThis.fetch;
|
|
2513
|
+
// @ts-expect-error -- fetch could be wrapped
|
|
2514
|
+
if (typeof fetchApi.__original === 'function') {
|
|
2515
|
+
// @ts-expect-error -- fetch could be wrapped
|
|
2516
|
+
fetchApi = fetchApi.__original;
|
|
2517
|
+
}
|
|
2518
|
+
const requestSize = data.byteLength;
|
|
2519
|
+
// Determine if we can use keepalive based on cumulative browser limits.
|
|
2520
|
+
// We must check BEFORE adding to pending totals to avoid exceeding limits.
|
|
2521
|
+
const wouldExceedSize = pendingBodySize + requestSize > MAX_KEEPALIVE_BODY_SIZE;
|
|
2522
|
+
const wouldExceedCount = pendingKeepaliveCount >= MAX_KEEPALIVE_REQUESTS;
|
|
2523
|
+
const useKeepalive = !wouldExceedSize && !wouldExceedCount;
|
|
2524
|
+
if (useKeepalive) {
|
|
2525
|
+
pendingBodySize += requestSize;
|
|
2526
|
+
pendingKeepaliveCount++;
|
|
2527
|
+
}
|
|
2528
|
+
else {
|
|
2529
|
+
const reason = wouldExceedSize ? 'size limit' : 'count limit';
|
|
2530
|
+
diag.debug(`keepalive disabled: ${(requestSize / 1024).toFixed(1)}KB payload, ${pendingKeepaliveCount} pending (${reason})`);
|
|
2531
|
+
}
|
|
2532
|
+
try {
|
|
2533
|
+
const url = new URL(this._parameters.url);
|
|
2534
|
+
const response = await fetchApi(url.href, {
|
|
2535
|
+
method: 'POST',
|
|
2536
|
+
headers: await this._parameters.headers(),
|
|
2537
|
+
body: data,
|
|
2538
|
+
signal: abortController.signal,
|
|
2539
|
+
keepalive: useKeepalive,
|
|
2540
|
+
mode: globalThis.location
|
|
2541
|
+
? globalThis.location.origin === url.origin
|
|
2542
|
+
? 'same-origin'
|
|
2543
|
+
: 'cors'
|
|
2544
|
+
: 'no-cors',
|
|
2545
|
+
});
|
|
2546
|
+
if (response.status >= 200 && response.status <= 299) {
|
|
2547
|
+
diag.debug(`export response success (status: ${response.status})`);
|
|
2548
|
+
return { status: 'success' };
|
|
2549
|
+
}
|
|
2550
|
+
else if (isExportHTTPErrorRetryable(response.status)) {
|
|
2551
|
+
diag.warn(`export response retryable (status: ${response.status})`);
|
|
2552
|
+
const retryAfter = response.headers.get('Retry-After');
|
|
2553
|
+
const retryInMillis = parseRetryAfterToMills(retryAfter);
|
|
2554
|
+
return { status: 'retryable', retryInMillis };
|
|
2555
|
+
}
|
|
2556
|
+
diag.error(`export response failure (status: ${response.status})`);
|
|
2557
|
+
return {
|
|
2558
|
+
status: 'failure',
|
|
2559
|
+
error: new Error(`Fetch request failed with non-retryable status ${response.status}`),
|
|
2560
|
+
};
|
|
2561
|
+
}
|
|
2562
|
+
catch (error) {
|
|
2563
|
+
if (isFetchNetworkErrorRetryable(error)) {
|
|
2564
|
+
diag.warn(`export request retryable (network error: ${error})`);
|
|
2565
|
+
return {
|
|
2566
|
+
status: 'retryable',
|
|
2567
|
+
error: new Error('Fetch request encountered a network error', {
|
|
2568
|
+
cause: error,
|
|
2569
|
+
}),
|
|
2570
|
+
};
|
|
2571
|
+
}
|
|
2572
|
+
diag.error(`export request failure (error: ${error})`);
|
|
2573
|
+
return {
|
|
2574
|
+
status: 'failure',
|
|
2575
|
+
error: new Error('Fetch request errored', { cause: error }),
|
|
2576
|
+
};
|
|
2577
|
+
}
|
|
2578
|
+
finally {
|
|
2579
|
+
clearTimeout(timeout);
|
|
2580
|
+
if (useKeepalive) {
|
|
2581
|
+
pendingBodySize -= requestSize;
|
|
2582
|
+
pendingKeepaliveCount--;
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
shutdown() {
|
|
2587
|
+
// Intentionally left empty, nothing to do.
|
|
2588
|
+
}
|
|
2589
|
+
}
|
|
2590
|
+
/**
|
|
2591
|
+
* Creates an exporter transport that uses `fetch` to send the data
|
|
2592
|
+
* @param parameters applied to each request made by transport
|
|
2593
|
+
*/
|
|
2594
|
+
function createFetchTransport(parameters) {
|
|
2595
|
+
return new FetchTransport(parameters);
|
|
2596
|
+
}
|
|
2597
|
+
function isFetchNetworkErrorRetryable(error) {
|
|
2598
|
+
return error instanceof TypeError && !error.cause;
|
|
2599
|
+
}
|
|
2600
|
+
|
|
2601
|
+
/*
|
|
2602
|
+
* Copyright The OpenTelemetry Authors
|
|
2603
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2604
|
+
*/
|
|
2605
|
+
function createOtlpFetchExportDelegate(options, serializer, metrics) {
|
|
2606
|
+
return createOtlpNetworkExportDelegate(options, serializer, metrics, createRetryingTransport({
|
|
2607
|
+
transport: createFetchTransport(options),
|
|
2608
|
+
}));
|
|
2609
|
+
}
|
|
2610
|
+
|
|
2611
|
+
/*
|
|
2612
|
+
* Copyright The OpenTelemetry Authors
|
|
2613
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2614
|
+
*/
|
|
2615
|
+
/**
|
|
2616
|
+
* Parses headers from config leaving only those that have defined values
|
|
2617
|
+
* @param partialHeaders
|
|
2618
|
+
*/
|
|
2619
|
+
function validateAndNormalizeHeaders(partialHeaders) {
|
|
2620
|
+
const headers = {};
|
|
2621
|
+
Object.entries(partialHeaders ?? {}).forEach(([key, value]) => {
|
|
2622
|
+
if (typeof value !== 'undefined') {
|
|
2623
|
+
headers[key] = String(value);
|
|
2624
|
+
}
|
|
2625
|
+
else {
|
|
2626
|
+
diag.warn(`Header "${key}" has invalid value (${value}) and will be ignored`);
|
|
2627
|
+
}
|
|
2628
|
+
});
|
|
2629
|
+
return headers;
|
|
2630
|
+
}
|
|
2631
|
+
|
|
2632
|
+
/*
|
|
2633
|
+
* Copyright The OpenTelemetry Authors
|
|
2634
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2635
|
+
*/
|
|
2636
|
+
function mergeHeaders(userProvidedHeaders, fallbackHeaders, defaultHeaders) {
|
|
2637
|
+
return async () => {
|
|
2638
|
+
const requiredHeaders = {
|
|
2639
|
+
...(await defaultHeaders()),
|
|
2640
|
+
};
|
|
2641
|
+
const headers = {};
|
|
2642
|
+
// add fallback ones first
|
|
2643
|
+
if (fallbackHeaders != null) {
|
|
2644
|
+
Object.assign(headers, await fallbackHeaders());
|
|
2645
|
+
}
|
|
2646
|
+
// override with user-provided ones
|
|
2647
|
+
if (userProvidedHeaders != null) {
|
|
2648
|
+
Object.assign(headers, validateAndNormalizeHeaders(await userProvidedHeaders()));
|
|
2649
|
+
}
|
|
2650
|
+
// override required ones.
|
|
2651
|
+
return Object.assign(headers, requiredHeaders);
|
|
2652
|
+
};
|
|
2653
|
+
}
|
|
2654
|
+
function validateUserProvidedUrl(url) {
|
|
2655
|
+
if (url == null) {
|
|
2656
|
+
return undefined;
|
|
2657
|
+
}
|
|
2658
|
+
try {
|
|
2659
|
+
// NOTE: In non-browser environments, `globalThis.location` will be `undefined`.
|
|
2660
|
+
const base = globalThis.location?.href;
|
|
2661
|
+
return new URL(url, base).href;
|
|
2662
|
+
}
|
|
2663
|
+
catch {
|
|
2664
|
+
throw new Error(`Configuration: Could not parse user-provided export URL: '${url}'`);
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
/**
|
|
2668
|
+
* @param userProvidedConfiguration Configuration options provided by the user in code.
|
|
2669
|
+
* @param fallbackConfiguration Fallback to use when the {@link userProvidedConfiguration} does not specify an option.
|
|
2670
|
+
* @param defaultConfiguration The defaults as defined by the exporter specification
|
|
2671
|
+
*/
|
|
2672
|
+
function mergeOtlpHttpConfigurationWithDefaults(userProvidedConfiguration, fallbackConfiguration, defaultConfiguration) {
|
|
2673
|
+
return {
|
|
2674
|
+
...mergeOtlpSharedConfigurationWithDefaults(userProvidedConfiguration, fallbackConfiguration, defaultConfiguration),
|
|
2675
|
+
headers: mergeHeaders(userProvidedConfiguration.headers, fallbackConfiguration.headers, defaultConfiguration.headers),
|
|
2676
|
+
url: validateUserProvidedUrl(userProvidedConfiguration.url) ??
|
|
2677
|
+
fallbackConfiguration.url ??
|
|
2678
|
+
defaultConfiguration.url,
|
|
2679
|
+
};
|
|
2680
|
+
}
|
|
2681
|
+
function getHttpConfigurationDefaults(requiredHeaders, signalResourcePath) {
|
|
2682
|
+
return {
|
|
2683
|
+
...getSharedConfigurationDefaults(),
|
|
2684
|
+
headers: async () => requiredHeaders,
|
|
2685
|
+
url: 'http://localhost:4318/' + signalResourcePath,
|
|
2686
|
+
};
|
|
2687
|
+
}
|
|
2688
|
+
|
|
2689
|
+
/*
|
|
2690
|
+
* Copyright The OpenTelemetry Authors
|
|
2691
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2692
|
+
*/
|
|
2693
|
+
function convertLegacyHeaders(config) {
|
|
2694
|
+
if (typeof config.headers === 'function') {
|
|
2695
|
+
return config.headers;
|
|
2696
|
+
}
|
|
2697
|
+
return wrapStaticHeadersInFunction(config.headers);
|
|
2698
|
+
}
|
|
2699
|
+
|
|
2700
|
+
/**
|
|
2701
|
+
* @deprecated this will be removed in 2.0
|
|
2702
|
+
*
|
|
2703
|
+
* @param config
|
|
2704
|
+
* @param signalResourcePath
|
|
2705
|
+
* @param requiredHeaders
|
|
2706
|
+
*/
|
|
2707
|
+
function convertLegacyBrowserHttpOptions(config, signalResourcePath, requiredHeaders) {
|
|
2708
|
+
return mergeOtlpHttpConfigurationWithDefaults({
|
|
2709
|
+
url: config.url,
|
|
2710
|
+
timeoutMillis: config.timeoutMillis,
|
|
2711
|
+
headers: convertLegacyHeaders(config),
|
|
2712
|
+
concurrencyLimit: config.concurrencyLimit,
|
|
2713
|
+
}, {}, // no fallback for browser case
|
|
2714
|
+
getHttpConfigurationDefaults(requiredHeaders, signalResourcePath));
|
|
2715
|
+
}
|
|
2716
|
+
|
|
2717
|
+
/*
|
|
2718
|
+
* Copyright The OpenTelemetry Authors
|
|
2719
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2720
|
+
*/
|
|
2721
|
+
/**
|
|
2722
|
+
* @deprecated
|
|
2723
|
+
*/
|
|
2724
|
+
function createLegacyOtlpBrowserExporterMetrics(metricsComponentType, exporterMetricsHelper, url, meterProvider) {
|
|
2725
|
+
return new ExporterMetrics({
|
|
2726
|
+
componentType: metricsComponentType,
|
|
2727
|
+
metricsHelper: exporterMetricsHelper,
|
|
2728
|
+
url,
|
|
2729
|
+
meterProvider,
|
|
2730
|
+
responseAttributesFromError: (error) => {
|
|
2731
|
+
if (!error) {
|
|
2732
|
+
return {
|
|
2733
|
+
[ATTR_HTTP_RESPONSE_STATUS_CODE]: 200,
|
|
2734
|
+
};
|
|
2735
|
+
}
|
|
2736
|
+
if (!(error instanceof Error)) {
|
|
2737
|
+
return {};
|
|
2738
|
+
}
|
|
2739
|
+
if (error.message.startsWith('Fetch request failed with non-retryable status ')) {
|
|
2740
|
+
const statusStr = error.message.substring('Fetch request failed with non-retryable status '.length);
|
|
2741
|
+
return {
|
|
2742
|
+
[ATTR_HTTP_RESPONSE_STATUS_CODE]: Number(statusStr),
|
|
2743
|
+
};
|
|
2744
|
+
}
|
|
2745
|
+
return {};
|
|
2746
|
+
},
|
|
2747
|
+
});
|
|
2748
|
+
}
|
|
2749
|
+
/**
|
|
2750
|
+
* @deprecated
|
|
2751
|
+
* @param config
|
|
2752
|
+
* @param serializer
|
|
2753
|
+
* @param signalResourcePath
|
|
2754
|
+
* @param requiredHeaders
|
|
2755
|
+
*/
|
|
2756
|
+
function createLegacyOtlpBrowserExportDelegate(config, serializer, metricsComponentType, exporterMetricsHelper, meterProvider, signalResourcePath, requiredHeaders) {
|
|
2757
|
+
const options = convertLegacyBrowserHttpOptions(config, signalResourcePath, requiredHeaders);
|
|
2758
|
+
return createOtlpFetchExportDelegate(options, serializer, createLegacyOtlpBrowserExporterMetrics(metricsComponentType, exporterMetricsHelper, options.url, config.selfObsMeterProvider));
|
|
2759
|
+
}
|
|
2760
|
+
|
|
2761
|
+
export { createNoopLogger as $, ATTR_EXCEPTION_TYPE as A, BindOnceFuture as B, ContextAPI as C, DiagAPI as D, createNoopMeter as E, suppressTracing as F, ExportResultCode as G, defaultResource as H, INVALID_SPAN_CONTEXT as I, JSON_ENCODER as J, isValidTraceId as K, ATTR_URL_FULL as L, ATTR_USER_AGENT_ORIGINAL as M, NOOP_METER as N, OTLPExporterBase as O, hrTimeToNanoseconds as P, timeInputToHrTime as Q, ROOT_CONTEXT as R, ATTR_HTTP_RESPONSE_STATUS_CODE$1 as S, TraceFlags as T, ATTR_SERVER_ADDRESS$1 as U, ATTR_SERVER_PORT$1 as V, ATTR_HTTP_REQUEST_METHOD as W, ATTR_HTTP_REQUEST_METHOD_ORIGINAL as X, ProxyTracerProvider as Y, resourceFromAttributes as Z, toAnyValue as _, isSpanContextValid as a, NoopLogger as b, createContextKey as c, diag as d, NOOP_LOGGER as e, createInstrumentationScope as f, getGlobal as g, createResource as h, isTracingSuppressed as i, toAttributes as j, createLegacyOtlpBrowserExportDelegate as k, isTimeInput as l, hrTimeDuration as m, hrTime as n, otperformance as o, millisToHrTime as p, isTimeInputHrTime as q, registerGlobal as r, addHrTimes as s, trace as t, unregisterGlobal as u, ATTR_EXCEPTION_MESSAGE as v, ATTR_EXCEPTION_STACKTRACE as w, context as x, globalErrorHandler as y, ATTR_ERROR_TYPE$1 as z };
|
|
2762
|
+
//# sourceMappingURL=create-legacy-browser-delegate-4GII-R4B.js.map
|