UNPKG

lightstep-tracer

Version:

> ❗ **This instrumentation is no longer recommended**. Please review [documentation on setting up and configuring the OpenTelemetry Node.js Launcher](https://github.com/lightstep/otel-launcher-node) or [OpenTelemetry JS (Browser)](https://github.com/open-

1,628 lines (1,269 loc) 262 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define([], factory); else if(typeof exports === 'object') exports["lightstep"] = factory(); else root["lightstep"] = factory(); })(self, () => { return /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ "./src/_each.js": /*!**********************!*\ !*** ./src/_each.js ***! \**********************/ /***/ ((module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports["default"] = _each; // Underscore.js-like wrapper to iterate object key-values. Note that even for completely // internal objects, packages may modify default Object prototypes and properties // (e.g. Ember.js) so it's almost never safe to assume a particular object can // iterated with for-in. // TODO: remove this function and replace with Object.keys, Object.values, ... (spread) or other. function _each(obj, cb) { if (!obj) { return; } // eslint-disable-next-line no-restricted-syntax for (var key in obj) { if (hasOwnProperty.call(obj, key)) { cb(obj[key], key); } } } module.exports = exports.default; /***/ }), /***/ "./src/constants.js": /*!**************************!*\ !*** ./src/constants.js ***! \**************************/ /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.LS_META_TRACE_KEY = exports.LS_META_TRACER_GUID_KEY = exports.LS_META_TRACER_CREATE = exports.LS_META_SP_START = exports.LS_META_SP_FINISH = exports.LS_META_SPAN_KEY = exports.LS_META_PROPAGATION_KEY = exports.LS_META_INJECT = exports.LS_META_EXTRACT = exports.LS_META_EVENT_KEY = exports.LOG_WARN = exports.LOG_STRING_TO_LEVEL = exports.LOG_LEVEL_TO_STRING = exports.LOG_INFO = exports.LOG_FATAL = exports.LOG_ERROR = exports.LIGHTSTEP_APP_URL_PREFIX = exports.JOIN_ID_PREFIX = exports.FORMAT_B3 = exports.CLOCK_STATE_REFRESH_INTERVAL_MS = void 0; var LOG_INFO = 0; exports.LOG_INFO = LOG_INFO; var LOG_WARN = 1; exports.LOG_WARN = LOG_WARN; var LOG_ERROR = 2; exports.LOG_ERROR = LOG_ERROR; var LOG_FATAL = 3; exports.LOG_FATAL = LOG_FATAL; var LOG_LEVEL_TO_STRING = { LOG_INFO: 'I', LOG_WARN: 'W', LOG_ERROR: 'E', LOG_FATAL: 'F' }; exports.LOG_LEVEL_TO_STRING = LOG_LEVEL_TO_STRING; var LOG_STRING_TO_LEVEL = { I: LOG_INFO, W: LOG_WARN, E: LOG_ERROR, F: LOG_FATAL }; // The report interval for empty reports used to sample the clock skew exports.LOG_STRING_TO_LEVEL = LOG_STRING_TO_LEVEL; var CLOCK_STATE_REFRESH_INTERVAL_MS = 350; exports.CLOCK_STATE_REFRESH_INTERVAL_MS = CLOCK_STATE_REFRESH_INTERVAL_MS; var LIGHTSTEP_APP_URL_PREFIX = 'https://app.lightstep.com'; exports.LIGHTSTEP_APP_URL_PREFIX = LIGHTSTEP_APP_URL_PREFIX; var JOIN_ID_PREFIX = 'join:'; exports.JOIN_ID_PREFIX = JOIN_ID_PREFIX; var LS_META_EVENT_KEY = 'lightstep.meta_event'; exports.LS_META_EVENT_KEY = LS_META_EVENT_KEY; var LS_META_PROPAGATION_KEY = 'lightstep.propagation_format'; exports.LS_META_PROPAGATION_KEY = LS_META_PROPAGATION_KEY; var LS_META_TRACE_KEY = 'lightstep.trace_id'; exports.LS_META_TRACE_KEY = LS_META_TRACE_KEY; var LS_META_SPAN_KEY = 'lightstep.span_id'; exports.LS_META_SPAN_KEY = LS_META_SPAN_KEY; var LS_META_TRACER_GUID_KEY = 'lightstep.tracer_guid'; exports.LS_META_TRACER_GUID_KEY = LS_META_TRACER_GUID_KEY; var LS_META_EXTRACT = 'lightstep.extract_span'; exports.LS_META_EXTRACT = LS_META_EXTRACT; var LS_META_INJECT = 'lightstep.inject_span'; exports.LS_META_INJECT = LS_META_INJECT; var LS_META_SP_START = 'lightstep.span_start'; exports.LS_META_SP_START = LS_META_SP_START; var LS_META_SP_FINISH = 'lightstep.span_finish'; exports.LS_META_SP_FINISH = LS_META_SP_FINISH; var LS_META_TRACER_CREATE = 'lightstep.tracer_create'; exports.LS_META_TRACER_CREATE = LS_META_TRACER_CREATE; var FORMAT_B3 = 'format.b3'; exports.FORMAT_B3 = FORMAT_B3; /***/ }), /***/ "./src/imp/auth_imp.js": /*!*****************************!*\ !*** ./src/imp/auth_imp.js ***! \*****************************/ /***/ ((module, exports, __webpack_require__) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports["default"] = void 0; var _platform_abstraction_layer = __webpack_require__(/*! ../platform_abstraction_layer */ "./src/platform_abstraction_layer.js"); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } var AuthImp = /*#__PURE__*/function () { function AuthImp(accessToken) { _classCallCheck(this, AuthImp); this._accessToken = accessToken; } _createClass(AuthImp, [{ key: "getAccessToken", value: function getAccessToken() { if (typeof this._accessToken === 'undefined' || this._accessToken === null || this._accessToken.length === 0) { return 'empty'; } return this._accessToken; } }, { key: "toThrift", value: function toThrift() { // eslint-disable-next-line camelcase return new _platform_abstraction_layer.crouton_thrift.Auth({ access_token: this._accessToken }); } }]); return AuthImp; }(); exports["default"] = AuthImp; module.exports = exports.default; /***/ }), /***/ "./src/imp/coerce.js": /*!***************************!*\ !*** ./src/imp/coerce.js ***! \***************************/ /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.toBoolean = toBoolean; exports.toNumber = toNumber; exports.toString = toString; function toString(value) { return '' + value; // eslint-disable-line prefer-template } function toNumber(value) { return Number(value); } function toBoolean(value) { return !!value; } /***/ }), /***/ "./src/imp/globals.js": /*!****************************!*\ !*** ./src/imp/globals.js ***! \****************************/ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; var _each2 = _interopRequireDefault(__webpack_require__(/*! ../_each */ "./src/_each.js")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } var PackageGlobals = /*#__PURE__*/function () { function PackageGlobals() { _classCallCheck(this, PackageGlobals); this.options = {}; } _createClass(PackageGlobals, [{ key: "setOptions", value: function setOptions(opts) { var _this = this; (0, _each2.default)(opts, function (val, key) { _this.options[key] = val; }); } }]); return PackageGlobals; }(); module.exports = new PackageGlobals(); /***/ }), /***/ "./src/imp/log_builder.js": /*!********************************!*\ !*** ./src/imp/log_builder.js ***! \********************************/ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; var _platform_abstraction_layer = __webpack_require__(/*! ../platform_abstraction_layer */ "./src/platform_abstraction_layer.js"); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } var constants = __webpack_require__(/*! ../constants */ "./src/constants.js"); var coerce = __webpack_require__(/*! ./coerce */ "./src/imp/coerce.js"); // Facade on the thrift log data structure to make constructing log records more // convenient. var LogBuilder = /*#__PURE__*/function () { function LogBuilder(runtime) { _classCallCheck(this, LogBuilder); this._runtime = runtime; // eslint-disable-next-line camelcase this._record = new _platform_abstraction_layer.crouton_thrift.LogRecord({ timestamp_micros: runtime._platform.nowMicros(), runtime_guid: null, span_guid: null, stable_name: null, message: null, level: null, thread_id: null, filename: null, line_number: null, stack_frames: null, payload_json: null, error_flag: null }); } _createClass(LogBuilder, [{ key: "record", value: function record() { return this._record; } }, { key: "end", value: function end() { this._runtime._addLogRecord(this._record); } }, { key: "timestamp", value: function timestamp(micros) { this._record.timestamp_micros = coerce.toNumber(micros); return this; } }, { key: "message", value: function message(msg) { this._record.message = coerce.toString(msg); return this; } }, { key: "level", value: function level(num) { this._record.level = constants.LOG_LEVEL_TO_STRING[num] || null; if (num >= constants.LOG_ERROR) { this.error(true); } return this; } }, { key: "span", value: function span(guid) { if (guid !== undefined) { this._record.span_guid = coerce.toString(guid); } return this; } }, { key: "name", value: function name(stableName) { this._record.stable_name = coerce.toString(stableName); return this; } }, { key: "error", value: function error(flag) { this._record.error_flag = coerce.toBoolean(flag); return this; } }, { key: "payload", value: function payload(data) { if (data !== undefined) { this._record.payload_json = this._encodePayload(data); } return this; } }, { key: "_encodePayload", value: function _encodePayload(data) { var payloadJSON = null; try { payloadJSON = JSON.stringify(data); } catch (_ignored) { // TODO: this should log an internal warning that a payload could // not be encoded as JSON. return undefined; } return payloadJSON; } }]); return LogBuilder; }(); module.exports = LogBuilder; /***/ }), /***/ "./src/imp/log_record_imp.js": /*!***********************************!*\ !*** ./src/imp/log_record_imp.js ***! \***********************************/ /***/ ((module, exports, __webpack_require__) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports["default"] = void 0; var _platform_abstraction_layer = __webpack_require__(/*! ../platform_abstraction_layer */ "./src/platform_abstraction_layer.js"); var _each2 = _interopRequireDefault(__webpack_require__(/*! ../_each */ "./src/_each.js")); var coerce = _interopRequireWildcard(__webpack_require__(/*! ./coerce */ "./src/imp/coerce.js")); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } // eslint-disable-line camelcase var LogRecordImp = /*#__PURE__*/function () { function LogRecordImp(logFieldKeyHardLimit, logFieldValueHardLimit, timestampMicros, fields) { _classCallCheck(this, LogRecordImp); if (fields instanceof Error) { fields = { stack: fields.stack, message: fields.message }; } this._logFieldKeyHardLimit = logFieldKeyHardLimit; this._logFieldValueHardLimit = logFieldValueHardLimit; this._timestampMicros = timestampMicros; this._fields = fields; this._keysOverLimit = 0; this._valuesOverLimit = 0; } _createClass(LogRecordImp, [{ key: "_clearOverLimits", value: function _clearOverLimits() { this._keysOverLimit = 0; this._valuesOverLimit = 0; } }, { key: "getNumKeysOverLimit", value: function getNumKeysOverLimit() { return this._keysOverLimit; } }, { key: "getNumValuesOverLimit", value: function getNumValuesOverLimit() { return this._valuesOverLimit; } }, { key: "toThrift", value: function toThrift() { var _this = this; this._clearOverLimits(); var thriftFields = []; (0, _each2.default)(this._fields, function (value, key) { if (!key || !value) { return; } var keyStr = _this.getFieldKey(key); var valStr = _this.getFieldValue(value); // eslint-disable-next-line camelcase thriftFields.push(new _platform_abstraction_layer.crouton_thrift.KeyValue({ Key: keyStr, Value: valStr })); }); // eslint-disable-next-line camelcase return new _platform_abstraction_layer.crouton_thrift.LogRecord({ timestamp_micros: this._timestampMicros, fields: thriftFields }); } }, { key: "getFieldKey", value: function getFieldKey(key) { var keyStr = coerce.toString(key); if (keyStr.length > this._logFieldKeyHardLimit) { this._keysOverLimit += 1; keyStr = "".concat(keyStr.substr(0, this._logFieldKeyHardLimit), "..."); } return keyStr; } }, { key: "getFieldValue", value: function getFieldValue(value) { var valStr = null; if (value instanceof Error) { try { // https://stackoverflow.com/a/26199752/9778850 valStr = JSON.stringify(value, Object.getOwnPropertyNames(value)); } catch (e) { valStr = "Could not encode value. Exception: ".concat(e); } } else if (value instanceof Object) { try { valStr = JSON.stringify(value, null, ' '); } catch (e) { valStr = "Could not encode value. Exception: ".concat(e); } } else { valStr = coerce.toString(value); } if (valStr.length > this._logFieldValueHardLimit) { this._valuesOverLimit += 1; valStr = "".concat(valStr.substr(0, this._logFieldValueHardLimit), "..."); } return valStr; } }]); return LogRecordImp; }(); exports["default"] = LogRecordImp; module.exports = exports.default; /***/ }), /***/ "./src/imp/platform/browser/crouton_thrift.js": /*!****************************************************!*\ !*** ./src/imp/platform/browser/crouton_thrift.js ***! \****************************************************/ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; // eslint-disable-next-line import/extensions module.exports = __webpack_require__(/*! ./generated/thrift_all.js */ "./src/imp/platform/browser/generated/thrift_all.js").crouton_thrift; /***/ }), /***/ "./src/imp/platform/browser/generated/thrift_all.js": /*!**********************************************************!*\ !*** ./src/imp/platform/browser/generated/thrift_all.js ***! \**********************************************************/ /***/ ((module) => { "use strict"; // // GENERATED FILE - DO NOT EDIT DIRECTLY // // See scripts/build_browser_thrift_lib.js // // (function () { var Thrift = {}; var crouton_thrift = {}; // // Autogenerated by Thrift Compiler (0.9.2) // // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING // if (typeof crouton_thrift === 'undefined') { crouton_thrift = {}; } crouton_thrift.KeyValue = function (args) { this.Key = null; this.Value = null; if (args) { if (args.Key !== undefined) { this.Key = args.Key; } else { throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Key is unset!'); } if (args.Value !== undefined) { this.Value = args.Value; } else { throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Value is unset!'); } } }; crouton_thrift.KeyValue.prototype = {}; crouton_thrift.KeyValue.prototype.read = false && 0; crouton_thrift.KeyValue.prototype.write = false && 0; crouton_thrift.NamedCounter = function (args) { this.Name = null; this.Value = null; if (args) { if (args.Name !== undefined) { this.Name = args.Name; } else { throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Name is unset!'); } if (args.Value !== undefined) { this.Value = args.Value; } else { throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Value is unset!'); } } }; crouton_thrift.NamedCounter.prototype = {}; crouton_thrift.NamedCounter.prototype.read = false && 0; crouton_thrift.NamedCounter.prototype.write = false && 0; crouton_thrift.Runtime = function (args) { this.guid = null; this.start_micros = null; this.group_name = null; this.attrs = null; if (args) { if (args.guid !== undefined) { this.guid = args.guid; } if (args.start_micros !== undefined) { this.start_micros = args.start_micros; } if (args.group_name !== undefined) { this.group_name = args.group_name; } if (args.attrs !== undefined) { this.attrs = args.attrs; } } }; crouton_thrift.Runtime.prototype = {}; crouton_thrift.Runtime.prototype.read = false && 0; crouton_thrift.Runtime.prototype.write = false && 0; crouton_thrift.LogRecord = function (args) { this.timestamp_micros = null; this.fields = null; this.runtime_guid = null; this.span_guid = null; this.stable_name = null; this.message = null; this.level = null; this.thread_id = null; this.filename = null; this.line_number = null; this.stack_frames = null; this.payload_json = null; this.error_flag = null; if (args) { if (args.timestamp_micros !== undefined) { this.timestamp_micros = args.timestamp_micros; } if (args.fields !== undefined) { this.fields = args.fields; } if (args.runtime_guid !== undefined) { this.runtime_guid = args.runtime_guid; } if (args.span_guid !== undefined) { this.span_guid = args.span_guid; } if (args.stable_name !== undefined) { this.stable_name = args.stable_name; } if (args.message !== undefined) { this.message = args.message; } if (args.level !== undefined) { this.level = args.level; } if (args.thread_id !== undefined) { this.thread_id = args.thread_id; } if (args.filename !== undefined) { this.filename = args.filename; } if (args.line_number !== undefined) { this.line_number = args.line_number; } if (args.stack_frames !== undefined) { this.stack_frames = args.stack_frames; } if (args.payload_json !== undefined) { this.payload_json = args.payload_json; } if (args.error_flag !== undefined) { this.error_flag = args.error_flag; } } }; crouton_thrift.LogRecord.prototype = {}; crouton_thrift.LogRecord.prototype.read = false && 0; crouton_thrift.LogRecord.prototype.write = false && 0; crouton_thrift.TraceJoinId = function (args) { this.TraceKey = null; this.Value = null; if (args) { if (args.TraceKey !== undefined) { this.TraceKey = args.TraceKey; } else { throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field TraceKey is unset!'); } if (args.Value !== undefined) { this.Value = args.Value; } else { throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Value is unset!'); } } }; crouton_thrift.TraceJoinId.prototype = {}; crouton_thrift.TraceJoinId.prototype.read = false && 0; crouton_thrift.TraceJoinId.prototype.write = false && 0; crouton_thrift.SpanRecord = function (args) { this.span_guid = null; this.trace_guid = null; this.runtime_guid = null; this.span_name = null; this.join_ids = null; this.oldest_micros = null; this.youngest_micros = null; this.attributes = null; this.error_flag = null; this.log_records = null; if (args) { if (args.span_guid !== undefined) { this.span_guid = args.span_guid; } if (args.trace_guid !== undefined) { this.trace_guid = args.trace_guid; } if (args.runtime_guid !== undefined) { this.runtime_guid = args.runtime_guid; } if (args.span_name !== undefined) { this.span_name = args.span_name; } if (args.join_ids !== undefined) { this.join_ids = args.join_ids; } if (args.oldest_micros !== undefined) { this.oldest_micros = args.oldest_micros; } if (args.youngest_micros !== undefined) { this.youngest_micros = args.youngest_micros; } if (args.attributes !== undefined) { this.attributes = args.attributes; } if (args.error_flag !== undefined) { this.error_flag = args.error_flag; } if (args.log_records !== undefined) { this.log_records = args.log_records; } } }; crouton_thrift.SpanRecord.prototype = {}; crouton_thrift.SpanRecord.prototype.read = false && 0; crouton_thrift.SpanRecord.prototype.write = false && 0; crouton_thrift.Auth = function (args) { this.access_token = null; if (args) { if (args.access_token !== undefined) { this.access_token = args.access_token; } } }; crouton_thrift.Auth.prototype = {}; crouton_thrift.Auth.prototype.read = false && 0; crouton_thrift.Auth.prototype.write = false && 0; crouton_thrift.Timing = function (args) { this.receive_micros = null; this.transmit_micros = null; if (args) { if (args.receive_micros !== undefined) { this.receive_micros = args.receive_micros; } if (args.transmit_micros !== undefined) { this.transmit_micros = args.transmit_micros; } } }; crouton_thrift.Timing.prototype = {}; crouton_thrift.Timing.prototype.read = false && 0; crouton_thrift.Timing.prototype.write = false && 0; crouton_thrift.SampleCount = function (args) { this.oldest_micros = null; this.youngest_micros = null; this.count = null; if (args) { if (args.oldest_micros !== undefined) { this.oldest_micros = args.oldest_micros; } if (args.youngest_micros !== undefined) { this.youngest_micros = args.youngest_micros; } if (args.count !== undefined) { this.count = args.count; } } }; crouton_thrift.SampleCount.prototype = {}; crouton_thrift.SampleCount.prototype.read = false && 0; crouton_thrift.SampleCount.prototype.write = false && 0; crouton_thrift.MetricsSample = function (args) { this.name = null; this.int64_value = null; this.double_value = null; if (args) { if (args.name !== undefined) { this.name = args.name; } else { throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field name is unset!'); } if (args.int64_value !== undefined) { this.int64_value = args.int64_value; } if (args.double_value !== undefined) { this.double_value = args.double_value; } } }; crouton_thrift.MetricsSample.prototype = {}; crouton_thrift.MetricsSample.prototype.read = false && 0; crouton_thrift.MetricsSample.prototype.write = false && 0; crouton_thrift.Metrics = function (args) { this.counts = null; this.gauges = null; if (args) { if (args.counts !== undefined) { this.counts = args.counts; } if (args.gauges !== undefined) { this.gauges = args.gauges; } } }; crouton_thrift.Metrics.prototype = {}; crouton_thrift.Metrics.prototype.read = false && 0; crouton_thrift.Metrics.prototype.write = false && 0; crouton_thrift.ReportRequest = function (args) { this.runtime = null; this.span_records = null; this.log_records = null; this.timestamp_offset_micros = null; this.oldest_micros = null; this.youngest_micros = null; this.counters = null; this.internal_logs = null; this.internal_metrics = null; if (args) { if (args.runtime !== undefined) { this.runtime = args.runtime; } if (args.span_records !== undefined) { this.span_records = args.span_records; } if (args.log_records !== undefined) { this.log_records = args.log_records; } if (args.timestamp_offset_micros !== undefined) { this.timestamp_offset_micros = args.timestamp_offset_micros; } if (args.oldest_micros !== undefined) { this.oldest_micros = args.oldest_micros; } if (args.youngest_micros !== undefined) { this.youngest_micros = args.youngest_micros; } if (args.counters !== undefined) { this.counters = args.counters; } if (args.internal_logs !== undefined) { this.internal_logs = args.internal_logs; } if (args.internal_metrics !== undefined) { this.internal_metrics = args.internal_metrics; } } }; crouton_thrift.ReportRequest.prototype = {}; crouton_thrift.ReportRequest.prototype.read = false && 0; crouton_thrift.ReportRequest.prototype.write = false && 0; crouton_thrift.Command = function (args) { this.disable = null; if (args) { if (args.disable !== undefined) { this.disable = args.disable; } } }; crouton_thrift.Command.prototype = {}; crouton_thrift.Command.prototype.read = false && 0; crouton_thrift.Command.prototype.write = false && 0; crouton_thrift.ReportResponse = function (args) { this.commands = null; this.timing = null; if (args) { if (args.commands !== undefined) { this.commands = args.commands; } if (args.timing !== undefined) { this.timing = args.timing; } } }; crouton_thrift.ReportResponse.prototype = {}; crouton_thrift.ReportResponse.prototype.read = false && 0; crouton_thrift.ReportResponse.prototype.write = false && 0; module.exports.crouton_thrift = crouton_thrift; module.exports.Thrift = {}; })(); /***/ }), /***/ "./src/imp/platform/browser/options_parser.js": /*!****************************************************!*\ !*** ./src/imp/platform/browser/options_parser.js ***! \****************************************************/ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; var util = __webpack_require__(/*! ./util */ "./src/imp/platform/browser/util.js"); /* global WorkerGlobalScope */ // Find the HTML element that included the tracing library (if there is one). // This relies on the fact that scripts are executed as soon as they are // included -- thus 'this' script is the last one in the array at the time // this is run. var hostScriptElement = function () { // check to see if we're in a webworker // eslint-disable-next-line no-restricted-globals if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) { return null; } if (!util.isBrowser()) { return null; } var scripts = document.getElementsByTagName('SCRIPT'); if (!(scripts.length > 0)) { return null; } return scripts[scripts.length - 1]; }(); function urlQueryParameters(defaults) { var vars = {}; var qi = window.location.href.indexOf('?'); if (qi < 0) { return vars; } var slice = window.location.href.slice(qi + 1); if (slice.indexOf('#') >= 0) { slice = slice.slice(0, slice.indexOf('#')); } var hashes = slice.replace(/\+/, '%20').split('&'); for (var i = 0; i < hashes.length; i++) { var hash = hashes[i].split('='); vars[decodeURIComponent(hash[0])] = decodeURIComponent(hash[1]); } return vars; } // Parses options out of the host <script> element. Allows for easy configuration // via the HTML element. Example: // // <script src='lightstep.min.js' // data-access_token='{my_access_token}' // data-component_name='my_component'></script> // // Note: relies on the global hostScriptElement variable defined above. // function parseScriptElementOptions(opts, browserOpts) { if (!hostScriptElement) { return; } var dataset = hostScriptElement.dataset; var accessToken = dataset.access_token; if (typeof accessToken === 'string' && accessToken.length > 0) { opts.access_token = accessToken; } var componentName = dataset.component_name; if (typeof componentName === 'string' && componentName.length > 0) { opts.component_name = componentName; } var collectorHost = dataset.collector_host; if (typeof collectorHost === 'string' && collectorHost.length > 0) { opts.collector_host = collectorHost; } var collectorPort = dataset.collector_port; if (collectorPort) { opts.collector_port = parseInt(collectorPort, 10); } var collectorPath = dataset.collector_path; if (typeof collectorPath === 'string' && collectorPath.length > 0) { opts.collector_path = collectorPath; } var collectorEncryption = dataset.collector_encryption; if (collectorEncryption) { opts.collector_encryption = collectorEncryption; } var enable = dataset.enable; if (typeof enable === 'string') { if (enable === 'true') { opts.enable = true; } else if (enable === 'false') { opts.enable = false; } } var verbosity = dataset.verbosity; if (typeof verbosity === 'string') { opts.verbosity = parseInt(verbosity, 10); } var init = dataset.init_global_tracer; if (typeof init === 'string') { if (init === 'true') { browserOpts.init_global_tracer = true; } else if (init === 'false') { browserOpts.init_global_tracer = false; } } // NOTE: this is a little inelegant as this is hard-coding support for a // "plug-in" option. if (typeof dataset.xhr_instrumentation === 'string' && dataset.xhr_instrumentation === 'true') { opts.xhr_instrumentation = true; } if (typeof dataset.instrument_page_load === 'string' && dataset.instrument_page_load === 'true') { opts.instrument_page_load = true; } } function parseScriptElementOptionsNoop(opts, browserOpts) {} // Parses options out of the current URL query string. The query parameters use // the 'lightstep_' prefix to reduce the chance of collision with // application-specific query parameters. // // This mechanism is particularly useful for debugging purposes as it does not // require any code or configuration changes. // function parseURLQueryOptions(opts) { var params = urlQueryParameters(); if (params.lightstep_verbosity) { try { opts.verbosity = parseInt(params.lightstep_verbosity, 10); } catch (_ignored) { /* Ignored */ } } if (params.lightstep_log_to_console) { opts.log_to_console = true; } } function parseURLQueryOptionsNoop(opts) { return {}; } module.exports = { parseScriptElementOptions: util.isBrowser() ? parseScriptElementOptions : parseScriptElementOptionsNoop, parseURLQueryOptions: util.isBrowser() ? parseURLQueryOptions : parseURLQueryOptionsNoop }; /***/ }), /***/ "./src/imp/platform/browser/platform_browser.js": /*!******************************************************!*\ !*** ./src/imp/platform/browser/platform_browser.js ***! \******************************************************/ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } // eslint-disable-next-line import/extensions var optionsParser = __webpack_require__(/*! ./options_parser.js */ "./src/imp/platform/browser/options_parser.js"); var util = __webpack_require__(/*! ./util */ "./src/imp/platform/browser/util.js"); var kRuntimeGUIDCookiePrefix = 'lightstep_guid'; var kSessionIDCookieKey = 'lightstep_session_id'; var kCookieTimeToLiveSeconds = 7 * 24 * 60 * 60; var nowMicrosImp = function () { // Is a hi-res timer available? if (window.performance && window.performance.now && window.performance.timing && window.performance.timing.navigationStart) { var start = performance.timing.navigationStart; return function () { return Math.floor((start + performance.now()) * 1000.0); }; } // The low-res timer is the best we can do return function () { return Date.now() * 1000.0; }; }(); var PlatformBrowser = /*#__PURE__*/function () { function PlatformBrowser() { _classCallCheck(this, PlatformBrowser); } _createClass(PlatformBrowser, [{ key: "name", value: function name() { return 'browser'; } }, { key: "nowMicros", value: function nowMicros() { return nowMicrosImp(); } // Return the GUID to use for the runtime. The intention is to reuse the // GUID so that logically a single browser session looks like a single // runtime. }, { key: "runtimeGUID", value: function runtimeGUID(groupName) { // Account for the groupName in the same that multiple apps or services // are running on the same domain (and should not share the same // runtime GUID). var cookieKey = encodeURIComponent("".concat(kRuntimeGUIDCookiePrefix, "/").concat(groupName)); var uuid = util.cookie(cookieKey) || this._generateLongUUID(); util.cookie(cookieKey, uuid, kCookieTimeToLiveSeconds, '/'); // Also create a session ID as well to give the server more information // to coordinate with. var sessionID = util.cookie(kSessionIDCookieKey) || this._generateLongUUID(); util.cookie(kSessionIDCookieKey, sessionID, kCookieTimeToLiveSeconds, '/'); return uuid; } }, { key: "generateUUID", value: function generateUUID() { return this._generateLongUUID(); } }, { key: "_generateLongUUID", value: function _generateLongUUID() { /* eslint-disable no-bitwise */ var p0 = "00000000".concat(Math.abs(Math.random() * 0xFFFFFFFF | 0).toString(16)).substr(-8); var p1 = "00000000".concat(Math.abs(Math.random() * 0xFFFFFFFF | 0).toString(16)).substr(-8); return "".concat(p0).concat(p1); /* eslint-enable no-bitwise */ } }, { key: "onBeforeExit", value: function onBeforeExit() { // This will result in the final report not being made in non-browser // environments like React Native. Flush should be called explicitly in // those environments if (util.isBrowser()) { var _window; for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } (_window = window).addEventListener.apply(_window, ['beforeunload'].concat(args)); } } }, { key: "plugins", value: function plugins(opts) { return [__webpack_require__(/*! ../../../plugins/instrument_xhr */ "./src/plugins/instrument_xhr.js"), __webpack_require__(/*! ../../../plugins/instrument_fetch */ "./src/plugins/instrument_fetch.js"), __webpack_require__(/*! ../../../plugins/instrument_document_load */ "./src/plugins/instrument_document_load.js")]; } }, { key: "options", value: function options(imp) { var tracerOpts = {}; var browserOpts = {}; optionsParser.parseScriptElementOptions(tracerOpts, browserOpts); optionsParser.parseURLQueryOptions(tracerOpts, browserOpts); return tracerOpts; } }, { key: "tracerTags", value: function tracerTags() { return { 'lightstep.tracer_platform': 'browser' }; } // There's no way to truly "fatal" on the browser; the best approximation // is an Error exception. }, { key: "fatal", value: function fatal(message) { throw new Error(message); } }, { key: "localStoreGet", value: function localStoreGet(key) { try { if (!window.sessionStorage) { return null; } } catch (_ignored) { // Accessing `sessionStorage` or `localStorage` in an `<iframe>` in Chrome throws when // the user setting "block third-party cookies and site data" is turned on. // // eslint-disable-next-line max-len // https://www.chromium.org/for-testers/bug-reporting-guidelines/uncaught-securityerror-failed-to-read-the-localstorage-property-from-window-access-is-denied-for-this-document return null; } try { return JSON.parse(sessionStorage.getItem("lightstep/".concat(key))); } catch (_ignored) { return null; } } }, { key: "localStoreSet", value: function localStoreSet(key, value) { try { if (!window.sessionStorage) { return; } } catch (_ignored) { // (See comment above) return; } try { sessionStorage.setItem("lightstep/".concat(key), JSON.stringify(value)); } catch (_ignored) { /* Ignored */ } } }], [{ key: "initLibrary", value: function initLibrary(lib) { var tracerOpts = {}; var browserOpts = {}; optionsParser.parseScriptElementOptions(tracerOpts, browserOpts); if (browserOpts.init_global_tracer) { PlatformBrowser.initGlobalTracer(lib, tracerOpts); } } }, { key: "initGlobalTracer", value: function initGlobalTracer(lib, opts) { if (typeof window !== 'object') { return; } if (typeof window.opentracing !== 'object') { return; } opentracing.initGlobalTracer(new lib.Tracer(opts)); // eslint-disable-line no-undef } }]); return PlatformBrowser; }(); module.exports = PlatformBrowser; /***/ }), /***/ "./src/imp/platform/browser/thrift.js": /*!********************************************!*\ !*** ./src/imp/platform/browser/thrift.js ***! \********************************************/ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; // eslint-disable-next-line import/extensions module.exports = __webpack_require__(/*! ./generated/thrift_all.js */ "./src/imp/platform/browser/generated/thrift_all.js").Thrift; /***/ }), /***/ "./src/imp/platform/browser/transport_httpthrift.js": /*!**********************************************************!*\ !*** ./src/imp/platform/browser/transport_httpthrift.js ***! \**********************************************************/ /***/ ((module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports["default"] = void 0; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } var TransportBrowser = /*#__PURE__*/function () { function TransportBrowser() { _classCallCheck(this, TransportBrowser); this._host = ''; this._port = 0; this._path = ''; this._encryption = ''; } _createClass(TransportBrowser, [{ key: "ensureConnection", value: function ensureConnection(opts) { this._host = opts.collector_host; this._port = opts.collector_port; this._path = opts.collector_path; this._encryption = opts.collector_encryption; } }, { key: "report", value: function report(detached, auth, _report, done) { try { if (!detached) { this._reportAJAX(auth, _report, done); } else { this._reportAsyncScript(auth, _report, done); } } catch (e) { return done(e, null); } } }, { key: "_reportAJAX", value: function _reportAJAX(auth, report, done) { var payload = JSON.stringify(report.toThrift()); var protocol = this._encryption === 'none' ? 'http' : 'https'; var url = "".concat(protocol, "://").concat(this._host, ":").concat(this._port).concat(this._path, "/api/v0/reports"); var xhr = new XMLHttpRequest(); xhr.open('POST', url); // Note: the browser automatically sets 'Connection' and 'Content-Length' // and *does not* allow they to be set manually xhr.setRequestHeader('LightStep-Access-Token', auth.getAccessToken()); xhr.setRequestHeader('Content-Type', 'application/json'); //req.setRequestHeader('Content-Encoding', 'gzip'); xhr.onreadystatechange = function () { if (this.readyState === 4) { var err = null; var resp = null; if (this.status !== 200) { err = new Error("status code = ".concat(this.status)); } else if (!this.responseText) { err = new Error('unexpected empty response'); } else { try { resp = JSON.parse(this.responseText); } catch (exception) { err = exception; } } return done(err, resp); } }; xhr.send(payload); } // Do a "tail flush" using an async browser script load. This does not get // interrupted as a normal Thirft RPC would when navigating away from // the page. }, { key: "_reportAsyncScript", value: function _reportAsyncScript(auth, report, done) { var authJSON = JSON.stringify(auth.toThrift()); var reportJSON = JSON.stringify(report.toThrift()); var protocol = this._encryption === 'none' ? 'http' : 'https'; var url = "".concat(protocol, "://").concat(this._host, ":").concat(this._port).concat(this._path, "/_rpc/v1/reports/uri_encoded") + "?auth=".concat(encodeURIComponent(authJSON)) + "&report=".concat(encodeURIComponent(reportJSON)); var elem = document.createElement('script'); elem.async = true; elem.defer = true; elem.src = url; elem.type = 'text/javascript'; var hostElem = document.getElementsByTagName('head')[0]; if (hostElem) { hostElem.appendChild(elem); } return done(null, null); } }]); return TransportBrowser; }(); exports["default"] = TransportBrowser; module.exports = exports.default; /***/ }), /***/ "./src/imp/platform/browser/util.js": /*!******************************************!*\ !*** ./src/imp/platform/browser/util.js ***! \******************************************/ /***/ ((module) => { "use strict"; /* eslint-disable */ function isBrowser() { return typeof document !== "undefined"; } // This function is copied directly from https://github.com/litejs/browser-cookie-lite. // It is licensed under the MIT License and authored by Lauri Rooden. function cookie(name, value, ttl, path, domain, secure) { if (arguments.length > 1) { var newCookie = name + '=' + encodeURIComponent(value) + (ttl ? "; expires=" + new Date(+new Date() + ttl * 1000).toUTCString() : '') + (path ? "; path=" + path : '') + (domain ? "; domain=" + domain : '') + (secure ? "; secure" : ''); document.cookie = newCookie; return newCookie; } return decodeURIComponent((("; " + document.cookie).split("; " + name + "=")[1] || "").split(";")[0]); } function cookieNoop() { return null; } /* eslint-enable */ module.exports = { cookie: isBrowser() ? cookie : cookieNoop, isBrowser: isBrowser }; /***/ }), /***/ "./src/imp/propagator.js": /*!*******************************!*\ !*** ./src/imp/propagator.js ***! \*******************************/ /***/ ((module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports["default"] = void 0; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } var UnsupportedPropagator = /*#__PURE__*/function () { function UnsupportedPropagator(tracer, name) { _classCallCheck(this, UnsupportedPropagator); this._tracer = tracer; this._name = name; } _createClass(UnsupportedPropagator, [{ key: "inject", value: function inject(spanContext, carrier) { this._tracer._error("Unsupported format: ".concat(this._name)); return null; } }, { key: "extract", value: function extract(carrier) { this._tracer._error("Unsupported format: ".concat(this._name)); } }]); return UnsupportedPr