UNPKG

@embrace-io/web-sdk

Version:
71 lines (70 loc) 3.3 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const require_utils_spanPredicates = require("../../utils/spanPredicates.cjs"); let _opentelemetry_api = require("@opentelemetry/api"); let _opentelemetry_core = require("@opentelemetry/core"); //#region src/processors/EmbraceSessionPartBatchedSpanProcessor/EmbraceSessionPartBatchedSpanProcessor.ts const exportFailureAttributeKey = (reason, session) => `emb.${session === "current" ? "export_failed" : "previous_export_failed"}.${reason}`; var EmbraceSessionPartBatchedSpanProcessor = class { _shutdownOnce; _pendingSpans = []; _exporter; _limitManager; _userSessionManager; _diag; constructor({ exporter, limitManager, userSessionManager, diag: diagParam = _opentelemetry_api.diag.createComponentLogger({ namespace: "EmbraceSessionPartBatchedSpanProcessor" }) }) { this._diag = diagParam; this._exporter = exporter; this._shutdownOnce = new _opentelemetry_core.BindOnceFuture(this._shutdown, this); this._limitManager = limitManager; this._userSessionManager = userSessionManager; } forceFlush() { this._diag.debug("forceFlush called for EmbraceSessionPartBatchedSpanProcessor. This is a no op"); return Promise.resolve(void 0); } onEnd(span) { if (this._shutdownOnce.isCalled) { this._diag.debug("span ended after processor shutdown. Ignoring span."); return; } if (!require_utils_spanPredicates.isSessionPartSpan(span)) { this._diag.debug("non-session-part span ended. Adding to pending spans queue."); if (this._limitManager.dropReadableSpan(span)) return; this._pendingSpans.push(span); } else { this._diag.debug("session part span ended. Exporting all pending spans."); this._exportSpans([span, ...this._pendingSpans]); this._pendingSpans = []; } } _exportSpans(spans) { _opentelemetry_core.internal._export(this._exporter, spans).then((result) => { if (result.code === _opentelemetry_core.ExportResultCode.FAILED) { const errorMessage = result.error?.message || "unknown error"; let failureReason = "unknown"; if (errorMessage === "Concurrent export limit reached") failureReason = "concurrent_limit"; else if (errorMessage === "Fetch request errored") failureReason = "fetch_error"; this._userSessionManager.incrSessionPartCountForKey(exportFailureAttributeKey(failureReason, "current")); this._userSessionManager.incrNextSessionPartCountForKey(exportFailureAttributeKey(failureReason, "previous")); this._diag.error(`spans failed to export: ${errorMessage}`); } }).catch((reason) => { let msg = "unknown error"; if (reason && reason instanceof Error) msg = reason.message; else if (typeof reason === "string") msg = reason; this._userSessionManager.incrSessionPartCountForKey(exportFailureAttributeKey("unknown", "current")); this._userSessionManager.incrNextSessionPartCountForKey(exportFailureAttributeKey("unknown", "previous")); this._diag.error(`spans failed to export: ${msg}`); }); } onStart() {} shutdown() { return this._shutdownOnce.call(); } _shutdown = () => { return this._exporter.shutdown(); }; }; //#endregion exports.EmbraceSessionPartBatchedSpanProcessor = EmbraceSessionPartBatchedSpanProcessor; //# sourceMappingURL=EmbraceSessionPartBatchedSpanProcessor.cjs.map