@embrace-io/web-sdk
Version:
3 lines (2 loc) • 1.56 kB
JavaScript
import{__rest as s}from"tslib";import{BindOnceFuture as e,internal as r,ExportResultCode as n}from"@opentelemetry/core";import{KEY_EMB_TYPE as o,EMB_TYPES as t}from"../../constants/attributes.js";import{EmbraceProcessor as i}from"../EmbraceProcessor/EmbraceProcessor.js";class a extends i{constructor(r){var{exporter:n}=r,o=s(r,["exporter"]);super(Object.assign(Object.assign({},o),{processorName:"EmbraceSessionBatchedSpanProcessor"})),this._pendingSpans=[],this._shutdown=()=>this._exporter.shutdown(),this._exporter=n,this._shutdownOnce=new e(this._shutdown,this)}forceFlush(){return this.diag.debug("forceFlush called for EmbraceSessionBatchedSpanProcessor. This is a no op"),Promise.resolve(void 0)}onEnd(s){this._shutdownOnce.isCalled?this.diag.debug("span ended after processor shutdown. Ignoring span."):(s=>s.attributes[o]===t.Session)(s)?(this.diag.debug("session span ended. Exporting all pending spans."),r._export(this._exporter,[s,...this._pendingSpans]).then((s=>{var e;s.code===n.FAILED&&this.diag.error(`spans failed to export: ${(null===(e=s.error)||void 0===e?void 0:e.message)||"unknown error"}`)})).catch((s=>{let e="unknown error";s&&s instanceof Error?e=s.message:"string"==typeof s&&(e=s),this.diag.error(`spans failed to export: ${e}`)})),this._pendingSpans=[]):(this.diag.debug("non-session span ended. Adding to pending spans queue."),this._pendingSpans.push(s))}onStart(){}shutdown(){return this._shutdownOnce.call()}}export{a as EmbraceSessionBatchedSpanProcessor};
//# sourceMappingURL=EmbraceSessionBatchedSpanProcessor.js.map