UNPKG

@embrace-io/web-sdk

Version:
58 lines (57 loc) 2.56 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const require_constants_attributes = require("../../../constants/attributes.cjs"); const require_instrumentations_EmbraceInstrumentationBase_EmbraceInstrumentationBase = require("../../EmbraceInstrumentationBase/EmbraceInstrumentationBase.cjs"); const require_instrumentations_server_timing_ServerTimingInstrumentation_constants = require("./constants.cjs"); let _opentelemetry_api_logs = require("@opentelemetry/api-logs"); //#region src/instrumentations/server-timing/ServerTimingInstrumentation/ServerTimingInstrumentation.ts var ServerTimingInstrumentation = class extends require_instrumentations_EmbraceInstrumentationBase_EmbraceInstrumentationBase.EmbraceInstrumentationBase { _onLoad; _performanceCollected = false; constructor({ diag, perf, limitManager } = {}) { super({ instrumentationName: "ServerTimingInstrumentation", instrumentationVersion: "1.0.0", diag, perf, limitManager, config: {} }); this._onLoad = () => { this._readServerTiming(); }; if (this._config.enabled) this.enable(); } onEnable() { window.removeEventListener("load", this._onLoad); if (window.document.readyState === "complete") { this._readServerTiming(); return; } window.addEventListener("load", this._onLoad); } onDisable() { window.removeEventListener("load", this._onLoad); } _readServerTiming() { if (this._performanceCollected) return; this._performanceCollected = true; const serverTiming = performance.getEntriesByType("navigation")[0]?.serverTiming; if (!serverTiming?.length) return; for (const entry of serverTiming) { if (this.limitManager?.limitServerTimingEntry()) return; this.logger.emit({ eventName: require_instrumentations_server_timing_ServerTimingInstrumentation_constants.SERVER_TIMING_EVENT_NAME, severityNumber: _opentelemetry_api_logs.SeverityNumber.INFO, attributes: { [require_constants_attributes.KEY_EMB_TYPE]: "ux.server_timing", [require_instrumentations_server_timing_ServerTimingInstrumentation_constants.KEY_EMB_SERVER_TIMING_NAME]: entry.name, [require_instrumentations_server_timing_ServerTimingInstrumentation_constants.KEY_EMB_SERVER_TIMING_DURATION]: entry.duration, [require_instrumentations_server_timing_ServerTimingInstrumentation_constants.KEY_EMB_SERVER_TIMING_DESCRIPTION]: entry.description } }); } } }; //#endregion exports.ServerTimingInstrumentation = ServerTimingInstrumentation; //# sourceMappingURL=ServerTimingInstrumentation.cjs.map