UNPKG

@echoteam/signoz-react

Version:

SignOz React JS - Library untuk monitoring dan tracing aplikasi React menggunakan OpenTelemetry dan SignOz

1,331 lines (1,307 loc) 694 kB
'use strict'; var jsxRuntime = require('react/jsx-runtime'); var React2 = require('react'); function _interopNamespaceDefault(e) { var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n.default = e; return Object.freeze(n); } var React2__namespace = /*#__PURE__*/_interopNamespaceDefault(React2); // Polyfill untuk modul Node.js yang tidak tersedia di browser // File ini hanya berisi side effects, tidak ada export // Polyfill untuk perf_hooks if (typeof window !== 'undefined' && !window.performance) { // Fallback sederhana jika performance API tidak tersedia window.performance = { now: () => Date.now(), mark: () => { }, measure: () => { }, getEntriesByType: () => [], getEntriesByName: () => [], clearMarks: () => { }, clearMeasures: () => { }, clearResourceTimings: () => { }, }; } // Polyfill untuk process if (typeof window !== 'undefined' && !window.process) { window.process = { env: {}, version: '', versions: {}, platform: 'browser', arch: 'x64', cwd: () => '/', nextTick: (fn) => setTimeout(fn, 0), }; } // Polyfill untuk Buffer if (typeof window !== 'undefined' && !window.Buffer) { window.Buffer = { from: (data) => new Uint8Array(data), alloc: (size) => new Uint8Array(size), allocUnsafe: (size) => new Uint8Array(size), isBuffer: (obj) => obj instanceof Uint8Array, }; } // Polyfill untuk util if (typeof window !== 'undefined' && !window.util) { window.util = { inspect: (obj) => JSON.stringify(obj), format: (...args) => args.join(' '), inherits: () => { }, }; } // Polyfill untuk events if (typeof window !== 'undefined' && !window.EventEmitter) { class EventEmitter { constructor() { this.events = {}; } on(event, listener) { if (!this.events[event]) { this.events[event] = []; } this.events[event].push(listener); } emit(event, ...args) { if (this.events[event]) { this.events[event].forEach(listener => listener(...args)); } } removeListener(event, listener) { if (this.events[event]) { this.events[event] = this.events[event].filter(l => l !== listener); } } } window.EventEmitter = EventEmitter; } /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ // Updates to this file should also be replicated to @opentelemetry/core too. /** * - globalThis (New standard) * - self (Will return the current window instance for supported browsers) * - window (fallback for older browser implementations) * - global (NodeJS implementation) * - <object> (When all else fails) */ /** only globals that common to node and browsers are allowed */ // eslint-disable-next-line node/no-unsupported-features/es-builtins, no-undef var _globalThis$6 = typeof globalThis === 'object' ? globalThis : typeof self === 'object' ? self : typeof window === 'object' ? window : typeof global === 'object' ? global : {}; /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ // this is autogenerated file, see scripts/version-update.js var VERSION$4 = '1.7.0'; /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var re = /^(\d+)\.(\d+)\.(\d+)(-(.+))?$/; /** * Create a function to test an API version to see if it is compatible with the provided ownVersion. * * The returned function has the following semantics: * - Exact match is always compatible * - Major versions must match exactly * - 1.x package cannot use global 2.x package * - 2.x package cannot use global 1.x package * - 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 * - 1.3 package may use 1.4 global because the later global contains all functions 1.3 expects * - 1.4 package may NOT use 1.3 global because it may try to call functions which don't exist on 1.3 * - If the major version is 0, the minor version is treated as the major and the patch is treated as the minor * - Patch and build tag differences are not considered at this time * * @param ownVersion version which should be checked against */ function _makeCompatibilityCheck(ownVersion) { var acceptedVersions = new Set([ownVersion]); var rejectedVersions = new Set(); var myVersionMatch = ownVersion.match(re); if (!myVersionMatch) { // we cannot guarantee compatibility so we always return noop return function () { return false; }; } var ownVersionParsed = { major: +myVersionMatch[1], minor: +myVersionMatch[2], patch: +myVersionMatch[3], prerelease: myVersionMatch[4], }; // if ownVersion has a prerelease tag, versions must match exactly if (ownVersionParsed.prerelease != null) { return function isExactmatch(globalVersion) { return globalVersion === ownVersion; }; } function _reject(v) { rejectedVersions.add(v); return false; } function _accept(v) { acceptedVersions.add(v); return true; } return function isCompatible(globalVersion) { if (acceptedVersions.has(globalVersion)) { return true; } if (rejectedVersions.has(globalVersion)) { return false; } var globalVersionMatch = globalVersion.match(re); if (!globalVersionMatch) { // cannot parse other version // we cannot guarantee compatibility so we always noop return _reject(globalVersion); } var globalVersionParsed = { major: +globalVersionMatch[1], minor: +globalVersionMatch[2], patch: +globalVersionMatch[3], prerelease: globalVersionMatch[4], }; // if globalVersion has a prerelease tag, versions must match exactly if (globalVersionParsed.prerelease != null) { return _reject(globalVersion); } // major versions must match if (ownVersionParsed.major !== globalVersionParsed.major) { return _reject(globalVersion); } if (ownVersionParsed.major === 0) { if (ownVersionParsed.minor === globalVersionParsed.minor && ownVersionParsed.patch <= globalVersionParsed.patch) { return _accept(globalVersion); } return _reject(globalVersion); } if (ownVersionParsed.minor <= globalVersionParsed.minor) { return _accept(globalVersion); } return _reject(globalVersion); }; } /** * Test an API version to see if it is compatible with this API. * * - Exact match is always compatible * - Major versions must match exactly * - 1.x package cannot use global 2.x package * - 2.x package cannot use global 1.x package * - 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 * - 1.3 package may use 1.4 global because the later global contains all functions 1.3 expects * - 1.4 package may NOT use 1.3 global because it may try to call functions which don't exist on 1.3 * - If the major version is 0, the minor version is treated as the major and the patch is treated as the minor * - Patch and build tag differences are not considered at this time * * @param version version of the API requesting an instance of the global API */ var isCompatible = _makeCompatibilityCheck(VERSION$4); /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var major = VERSION$4.split('.')[0]; var GLOBAL_OPENTELEMETRY_API_KEY = Symbol.for("opentelemetry.js.api." + major); var _global$5 = _globalThis$6; function registerGlobal(type, instance, diag, allowOverride) { var _a; if (allowOverride === void 0) { allowOverride = false; } var api = (_global$5[GLOBAL_OPENTELEMETRY_API_KEY] = (_a = _global$5[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _a !== void 0 ? _a : { version: VERSION$4, }); if (!allowOverride && api[type]) { // already registered an API of this type var err = new Error("@opentelemetry/api: Attempted duplicate registration of API: " + type); diag.error(err.stack || err.message); return false; } if (api.version !== VERSION$4) { // All registered APIs must be of the same version exactly var err = new Error("@opentelemetry/api: Registration of version v" + api.version + " for " + type + " does not match previously registered API v" + VERSION$4); diag.error(err.stack || err.message); return false; } api[type] = instance; diag.debug("@opentelemetry/api: Registered a global for " + type + " v" + VERSION$4 + "."); return true; } function getGlobal(type) { var _a, _b; var globalVersion = (_a = _global$5[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _a === void 0 ? void 0 : _a.version; if (!globalVersion || !isCompatible(globalVersion)) { return; } return (_b = _global$5[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _b === void 0 ? void 0 : _b[type]; } function unregisterGlobal(type, diag) { diag.debug("@opentelemetry/api: Unregistering a global for " + type + " v" + VERSION$4 + "."); var api = _global$5[GLOBAL_OPENTELEMETRY_API_KEY]; if (api) { delete api[type]; } } /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var __read$e = (undefined && undefined.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spreadArray$5 = (undefined && undefined.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; /** * Component Logger which is meant to be used as part of any component which * will add automatically additional namespace in front of the log message. * It will then forward all message to global diag logger * @example * const cLogger = diag.createComponentLogger({ namespace: '@opentelemetry/instrumentation-http' }); * cLogger.debug('test'); * // @opentelemetry/instrumentation-http test */ var DiagComponentLogger = /** @class */ (function () { function DiagComponentLogger(props) { this._namespace = props.namespace || 'DiagComponentLogger'; } DiagComponentLogger.prototype.debug = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return logProxy('debug', this._namespace, args); }; DiagComponentLogger.prototype.error = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return logProxy('error', this._namespace, args); }; DiagComponentLogger.prototype.info = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return logProxy('info', this._namespace, args); }; DiagComponentLogger.prototype.warn = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return logProxy('warn', this._namespace, args); }; DiagComponentLogger.prototype.verbose = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return logProxy('verbose', this._namespace, args); }; return DiagComponentLogger; }()); function logProxy(funcName, namespace, args) { var logger = getGlobal('diag'); // shortcut if logger not set if (!logger) { return; } args.unshift(namespace); return logger[funcName].apply(logger, __spreadArray$5([], __read$e(args), false)); } /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Defines the available internal logging levels for the diagnostic logger, the numeric values * of the levels are defined to match the original values from the initial LogLevel to avoid * compatibility/migration issues for any implementation that assume the numeric ordering. */ var DiagLogLevel; (function (DiagLogLevel) { /** Diagnostic Logging level setting to disable all logging (except and forced logs) */ DiagLogLevel[DiagLogLevel["NONE"] = 0] = "NONE"; /** Identifies an error scenario */ DiagLogLevel[DiagLogLevel["ERROR"] = 30] = "ERROR"; /** Identifies a warning scenario */ DiagLogLevel[DiagLogLevel["WARN"] = 50] = "WARN"; /** General informational log message */ DiagLogLevel[DiagLogLevel["INFO"] = 60] = "INFO"; /** General debug log message */ DiagLogLevel[DiagLogLevel["DEBUG"] = 70] = "DEBUG"; /** * Detailed trace level logging should only be used for development, should only be set * in a development environment. */ DiagLogLevel[DiagLogLevel["VERBOSE"] = 80] = "VERBOSE"; /** Used to set the logging level to include all logging */ DiagLogLevel[DiagLogLevel["ALL"] = 9999] = "ALL"; })(DiagLogLevel || (DiagLogLevel = {})); /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function createLogLevelDiagLogger(maxLevel, logger) { if (maxLevel < DiagLogLevel.NONE) { maxLevel = DiagLogLevel.NONE; } else if (maxLevel > DiagLogLevel.ALL) { maxLevel = DiagLogLevel.ALL; } // In case the logger is null or undefined logger = logger || {}; function _filterFunc(funcName, theLevel) { var theFunc = logger[funcName]; if (typeof theFunc === 'function' && maxLevel >= theLevel) { return theFunc.bind(logger); } return function () { }; } return { error: _filterFunc('error', DiagLogLevel.ERROR), warn: _filterFunc('warn', DiagLogLevel.WARN), info: _filterFunc('info', DiagLogLevel.INFO), debug: _filterFunc('debug', DiagLogLevel.DEBUG), verbose: _filterFunc('verbose', DiagLogLevel.VERBOSE), }; } /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var __read$d = (undefined && undefined.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spreadArray$4 = (undefined && undefined.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; var API_NAME$4 = 'diag'; /** * Singleton object which represents the entry point to the OpenTelemetry internal * diagnostic API */ var DiagAPI = /** @class */ (function () { /** * Private internal constructor * @private */ function DiagAPI() { function _logProxy(funcName) { return function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var logger = getGlobal('diag'); // shortcut if logger not set if (!logger) return; return logger[funcName].apply(logger, __spreadArray$4([], __read$d(args), false)); }; } // Using self local variable for minification purposes as 'this' cannot be minified var self = this; // DiagAPI specific functions var setLogger = function (logger, optionsOrLogLevel) { var _a, _b, _c; if (optionsOrLogLevel === void 0) { optionsOrLogLevel = { logLevel: DiagLogLevel.INFO }; } if (logger === self) { // There isn't much we can do here. // Logging to the console might break the user application. // Try to log to self. If a logger was previously registered it will receive the log. var err = new Error('Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation'); self.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message); return false; } if (typeof optionsOrLogLevel === 'number') { optionsOrLogLevel = { logLevel: optionsOrLogLevel, }; } var oldLogger = getGlobal('diag'); var newLogger = createLogLevelDiagLogger((_b = optionsOrLogLevel.logLevel) !== null && _b !== void 0 ? _b : DiagLogLevel.INFO, logger); // There already is an logger registered. We'll let it know before overwriting it. if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) { var stack = (_c = new Error().stack) !== null && _c !== void 0 ? _c : '<failed to generate stacktrace>'; oldLogger.warn("Current logger will be overwritten from " + stack); newLogger.warn("Current logger will overwrite one already registered from " + stack); } return registerGlobal('diag', newLogger, self, true); }; self.setLogger = setLogger; self.disable = function () { unregisterGlobal(API_NAME$4, self); }; self.createComponentLogger = function (options) { return new DiagComponentLogger(options); }; self.verbose = _logProxy('verbose'); self.debug = _logProxy('debug'); self.info = _logProxy('info'); self.warn = _logProxy('warn'); self.error = _logProxy('error'); } /** Get the singleton instance of the DiagAPI API */ DiagAPI.instance = function () { if (!this._instance) { this._instance = new DiagAPI(); } return this._instance; }; return DiagAPI; }()); /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var __read$c = (undefined && undefined.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __values$7 = (undefined && undefined.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; var BaggageImpl = /** @class */ (function () { function BaggageImpl(entries) { this._entries = entries ? new Map(entries) : new Map(); } BaggageImpl.prototype.getEntry = function (key) { var entry = this._entries.get(key); if (!entry) { return undefined; } return Object.assign({}, entry); }; BaggageImpl.prototype.getAllEntries = function () { return Array.from(this._entries.entries()).map(function (_a) { var _b = __read$c(_a, 2), k = _b[0], v = _b[1]; return [k, v]; }); }; BaggageImpl.prototype.setEntry = function (key, entry) { var newBaggage = new BaggageImpl(this._entries); newBaggage._entries.set(key, entry); return newBaggage; }; BaggageImpl.prototype.removeEntry = function (key) { var newBaggage = new BaggageImpl(this._entries); newBaggage._entries.delete(key); return newBaggage; }; BaggageImpl.prototype.removeEntries = function () { var e_1, _a; var keys = []; for (var _i = 0; _i < arguments.length; _i++) { keys[_i] = arguments[_i]; } var newBaggage = new BaggageImpl(this._entries); try { for (var keys_1 = __values$7(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) { var key = keys_1_1.value; newBaggage._entries.delete(key); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (keys_1_1 && !keys_1_1.done && (_a = keys_1.return)) _a.call(keys_1); } finally { if (e_1) throw e_1.error; } } return newBaggage; }; BaggageImpl.prototype.clear = function () { return new BaggageImpl(); }; return BaggageImpl; }()); /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Symbol used to make BaggageEntryMetadata an opaque type */ var baggageEntryMetadataSymbol = Symbol('BaggageEntryMetadata'); /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var diag$1 = DiagAPI.instance(); /** * Create a new Baggage with optional entries * * @param entries An array of baggage entries the new baggage should contain */ function createBaggage(entries) { if (entries === void 0) { entries = {}; } return new BaggageImpl(new Map(Object.entries(entries))); } /** * Create a serializable BaggageEntryMetadata object from a string. * * @param str string metadata. Format is currently not defined by the spec and has no special meaning. * */ function baggageEntryMetadataFromString(str) { if (typeof str !== 'string') { diag$1.error("Cannot create baggage metadata from unknown type: " + typeof str); str = ''; } return { __TYPE__: baggageEntryMetadataSymbol, toString: function () { return str; }, }; } /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** Get a key to uniquely identify a context value */ function createContextKey(description) { // The specification states that for the same input, multiple calls should // return different keys. Due to the nature of the JS dependency management // system, this creates problems where multiple versions of some package // could hold different keys for the same property. // // Therefore, we use Symbol.for which returns the same key for the same input. return Symbol.for(description); } var BaseContext = /** @class */ (function () { /** * Construct a new context which inherits values from an optional parent context. * * @param parentContext a context from which to inherit values */ function BaseContext(parentContext) { // for minification var self = this; self._currentContext = parentContext ? new Map(parentContext) : new Map(); self.getValue = function (key) { return self._currentContext.get(key); }; self.setValue = function (key, value) { var context = new BaseContext(self._currentContext); context._currentContext.set(key, value); return context; }; self.deleteValue = function (key) { var context = new BaseContext(self._currentContext); context._currentContext.delete(key); return context; }; } return BaseContext; }()); /** The root context is used as the default parent context when there is no active context */ var ROOT_CONTEXT = new BaseContext(); /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var __extends$d = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * NoopMeter is a noop implementation of the {@link Meter} interface. It reuses * constant NoopMetrics for all of its methods. */ var NoopMeter = /** @class */ (function () { function NoopMeter() { } /** * @see {@link Meter.createHistogram} */ NoopMeter.prototype.createHistogram = function (_name, _options) { return NOOP_HISTOGRAM_METRIC; }; /** * @see {@link Meter.createCounter} */ NoopMeter.prototype.createCounter = function (_name, _options) { return NOOP_COUNTER_METRIC; }; /** * @see {@link Meter.createUpDownCounter} */ NoopMeter.prototype.createUpDownCounter = function (_name, _options) { return NOOP_UP_DOWN_COUNTER_METRIC; }; /** * @see {@link Meter.createObservableGauge} */ NoopMeter.prototype.createObservableGauge = function (_name, _options) { return NOOP_OBSERVABLE_GAUGE_METRIC; }; /** * @see {@link Meter.createObservableCounter} */ NoopMeter.prototype.createObservableCounter = function (_name, _options) { return NOOP_OBSERVABLE_COUNTER_METRIC; }; /** * @see {@link Meter.createObservableUpDownCounter} */ NoopMeter.prototype.createObservableUpDownCounter = function (_name, _options) { return NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC; }; /** * @see {@link Meter.addBatchObservableCallback} */ NoopMeter.prototype.addBatchObservableCallback = function (_callback, _observables) { }; /** * @see {@link Meter.removeBatchObservableCallback} */ NoopMeter.prototype.removeBatchObservableCallback = function (_callback) { }; return NoopMeter; }()); var NoopMetric = /** @class */ (function () { function NoopMetric() { } return NoopMetric; }()); var NoopCounterMetric = /** @class */ (function (_super) { __extends$d(NoopCounterMetric, _super); function NoopCounterMetric() { return _super !== null && _super.apply(this, arguments) || this; } NoopCounterMetric.prototype.add = function (_value, _attributes) { }; return NoopCounterMetric; }(NoopMetric)); var NoopUpDownCounterMetric = /** @class */ (function (_super) { __extends$d(NoopUpDownCounterMetric, _super); function NoopUpDownCounterMetric() { return _super !== null && _super.apply(this, arguments) || this; } NoopUpDownCounterMetric.prototype.add = function (_value, _attributes) { }; return NoopUpDownCounterMetric; }(NoopMetric)); var NoopHistogramMetric = /** @class */ (function (_super) { __extends$d(NoopHistogramMetric, _super); function NoopHistogramMetric() { return _super !== null && _super.apply(this, arguments) || this; } NoopHistogramMetric.prototype.record = function (_value, _attributes) { }; return NoopHistogramMetric; }(NoopMetric)); var NoopObservableMetric = /** @class */ (function () { function NoopObservableMetric() { } NoopObservableMetric.prototype.addCallback = function (_callback) { }; NoopObservableMetric.prototype.removeCallback = function (_callback) { }; return NoopObservableMetric; }()); var NoopObservableCounterMetric = /** @class */ (function (_super) { __extends$d(NoopObservableCounterMetric, _super); function NoopObservableCounterMetric() { return _super !== null && _super.apply(this, arguments) || this; } return NoopObservableCounterMetric; }(NoopObservableMetric)); var NoopObservableGaugeMetric = /** @class */ (function (_super) { __extends$d(NoopObservableGaugeMetric, _super); function NoopObservableGaugeMetric() { return _super !== null && _super.apply(this, arguments) || this; } return NoopObservableGaugeMetric; }(NoopObservableMetric)); var NoopObservableUpDownCounterMetric = /** @class */ (function (_super) { __extends$d(NoopObservableUpDownCounterMetric, _super); function NoopObservableUpDownCounterMetric() { return _super !== null && _super.apply(this, arguments) || this; } return NoopObservableUpDownCounterMetric; }(NoopObservableMetric)); var NOOP_METER = new NoopMeter(); // Synchronous instruments var NOOP_COUNTER_METRIC = new NoopCounterMetric(); var NOOP_HISTOGRAM_METRIC = new NoopHistogramMetric(); var NOOP_UP_DOWN_COUNTER_METRIC = new NoopUpDownCounterMetric(); // Asynchronous instruments var NOOP_OBSERVABLE_COUNTER_METRIC = new NoopObservableCounterMetric(); var NOOP_OBSERVABLE_GAUGE_METRIC = new NoopObservableGaugeMetric(); var NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC = new NoopObservableUpDownCounterMetric(); /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var defaultTextMapGetter = { get: function (carrier, key) { if (carrier == null) { return undefined; } return carrier[key]; }, keys: function (carrier) { if (carrier == null) { return []; } return Object.keys(carrier); }, }; var defaultTextMapSetter = { set: function (carrier, key, value) { if (carrier == null) { return; } carrier[key] = value; }, }; /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var __read$b = (undefined && undefined.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spreadArray$3 = (undefined && undefined.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; var NoopContextManager = /** @class */ (function () { function NoopContextManager() { } NoopContextManager.prototype.active = function () { return ROOT_CONTEXT; }; NoopContextManager.prototype.with = function (_context, fn, thisArg) { var args = []; for (var _i = 3; _i < arguments.length; _i++) { args[_i - 3] = arguments[_i]; } return fn.call.apply(fn, __spreadArray$3([thisArg], __read$b(args), false)); }; NoopContextManager.prototype.bind = function (_context, target) { return target; }; NoopContextManager.prototype.enable = function () { return this; }; NoopContextManager.prototype.disable = function () { return this; }; return NoopContextManager; }()); /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var __read$a = (undefined && undefined.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spreadArray$2 = (undefined && undefined.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; var API_NAME$3 = 'context'; var NOOP_CONTEXT_MANAGER = new NoopContextManager(); /** * Singleton object which represents the entry point to the OpenTelemetry Context API */ var ContextAPI = /** @class */ (function () { /** Empty private constructor prevents end users from constructing a new instance of the API */ function ContextAPI() { } /** Get the singleton instance of the Context API */ ContextAPI.getInstance = function () { if (!this._instance) { this._instance = new ContextAPI(); } return this._instance; }; /** * Set the current context manager. * * @returns true if the context manager was successfully registered, else false */ ContextAPI.prototype.setGlobalContextManager = function (contextManager) { return registerGlobal(API_NAME$3, contextManager, DiagAPI.instance()); }; /** * Get the currently active context */ ContextAPI.prototype.active = function () { return this._getContextManager().active(); }; /** * Execute a function with an active context * * @param context context to be active during function execution * @param fn function to execute in a context * @param thisArg optional receiver to be used for calling fn * @param args optional arguments forwarded to fn */ ContextAPI.prototype.with = function (context, fn, thisArg) { var _a; var args = []; for (var _i = 3; _i < arguments.length; _i++) { args[_i - 3] = arguments[_i]; } return (_a = this._getContextManager()).with.apply(_a, __spreadArray$2([context, fn, thisArg], __read$a(args), false)); }; /** * Bind a context to a target function or event emitter * * @param context context to bind to the event emitter or function. Defaults to the currently active context * @param target function or event emitter to bind */ ContextAPI.prototype.bind = function (context, target) { return this._getContextManager().bind(context, target); }; ContextAPI.prototype._getContextManager = function () { return getGlobal(API_NAME$3) || NOOP_CONTEXT_MANAGER; }; /** Disable and remove the global context manager */ ContextAPI.prototype.disable = function () { this._getContextManager().disable(); unregisterGlobal(API_NAME$3, DiagAPI.instance()); }; return ContextAPI; }()); /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var TraceFlags; (function (TraceFlags) { /** Represents no flag set. */ TraceFlags[TraceFlags["NONE"] = 0] = "NONE"; /** Bit to represent whether trace is sampled in trace flags. */ TraceFlags[TraceFlags["SAMPLED"] = 1] = "SAMPLED"; })(TraceFlags || (TraceFlags = {})); /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var INVALID_SPANID = '0000000000000000'; var INVALID_TRACEID = '00000000000000000000000000000000'; var INVALID_SPAN_CONTEXT = { traceId: INVALID_TRACEID, spanId: INVALID_SPANID, traceFlags: TraceFlags.NONE, }; /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * The NonRecordingSpan is the default {@link Span} that is used when no Span * implementation is available. All operations are no-op including context * propagation. */ var NonRecordingSpan = /** @class */ (function () { function NonRecordingSpan(_spanContext) { if (_spanContext === void 0) { _spanContext = INVALID_SPAN_CONTEXT; } this._spanContext = _spanContext; } // Returns a SpanContext. NonRecordingSpan.prototype.spanContext = function () { return this._spanContext; }; // By default does nothing NonRecordingSpan.prototype.setAttribute = function (_key, _value) { return this; }; // By default does nothing NonRecordingSpan.prototype.setAttributes = function (_attributes) { return this; }; // By default does nothing NonRecordingSpan.prototype.addEvent = function (_name, _attributes) { return this; }; // By default does nothing NonRecordingSpan.prototype.setStatus = function (_status) { return this; }; // By default does nothing NonRecordingSpan.prototype.updateName = function (_name) { return this; }; // By default does nothing NonRecordingSpan.prototype.end = function (_endTime) { }; // isRecording always returns false for NonRecordingSpan. NonRecordingSpan.prototype.isRecording = function () { return false; }; // By default does nothing NonRecordingSpan.prototype.recordException = function (_exception, _time) { }; return NonRecordingSpan; }()); /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * span key */ var SPAN_KEY = createContextKey('OpenTelemetry Context Key SPAN'); /** * Return the span if one exists * * @param context context to get span from */ function getSpan(context) { return context.getValue(SPAN_KEY) || undefined; } /** * Gets the span from the current context, if one exists. */ function getActiveSpan() { return getSpan(ContextAPI.getInstance().active()); } /** * Set