UNPKG

@getopenpay/openpay-js

Version:

Accept payments through OpenPay, right on your site

910 lines 195 kB
import { e as nt, t as _, i as it, T as L, b as ot, a as T, I as at, S as st } from "./index-B_XmW797.js"; import { d } from "./diag-api-CWQhqUTV.js"; import { o as I, l as ut, n as k, q as lt, j as pt, m as w, r as dt, s as ct, v as N, w as M, x as ft, p as ht, y as V } from "./url-UQ0zRf8J.js"; import { i as _t, s as x, g as h, a as A, T as v, b as mt, D as vt, c as St, u as yt, B as Z, S as H, C as Et, W as Tt, d as gt, m as Lt, e as Pt } from "./index-BgjVW4yR.js"; import { s as At, i as bt } from "./suppress-tracing-BllHYdAl.js"; import { R as Q } from "./Resource-DyBjMNXo.js"; import { E as U } from "./ExportResult-BacsqwKA.js"; var wt = "exception", D = function() { return D = Object.assign || function(r) { for (var t, e = 1, n = arguments.length; e < n; e++) { t = arguments[e]; for (var o in t) Object.prototype.hasOwnProperty.call(t, o) && (r[o] = t[o]); } return r; }, D.apply(this, arguments); }, Ct = function(r) { var t = typeof Symbol == "function" && Symbol.iterator, e = t && r[t], n = 0; if (e) return e.call(r); if (r && typeof r.length == "number") return { next: function() { return r && n >= r.length && (r = void 0), { value: r && r[n++], done: !r }; } }; throw new TypeError(t ? "Object is not iterable." : "Symbol.iterator is not defined."); }, X = function(r, t) { var e = typeof Symbol == "function" && r[Symbol.iterator]; if (!e) return r; var n = e.call(r), o, i = [], a; try { for (; (t === void 0 || t-- > 0) && !(o = n.next()).done; ) i.push(o.value); } catch (s) { a = { error: s }; } finally { try { o && !o.done && (e = n.return) && e.call(n); } finally { if (a) throw a.error; } } return i; }, Ot = function(r, t, e) { if (e || arguments.length === 2) for (var n = 0, o = t.length, i; n < o; n++) (i || !(n in t)) && (i || (i = Array.prototype.slice.call(t, 0, n)), i[n] = t[n]); return r.concat(i || Array.prototype.slice.call(t)); }, xt = ( /** @class */ (function() { function r(t, e, n, o, i, a, s, l, u, p) { s === void 0 && (s = []), this.attributes = {}, this.links = [], this.events = [], this._droppedAttributesCount = 0, this._droppedEventsCount = 0, this._droppedLinksCount = 0, this.status = { code: nt.UNSET }, this.endTime = [0, 0], this._ended = !1, this._duration = [-1, -1], this.name = n, this._spanContext = o, this.parentSpanId = a, this.kind = i, this.links = s; var c = Date.now(); this._performanceStartTime = I.now(), this._performanceOffset = c - (this._performanceStartTime + ut()), this._startTimeProvided = l != null, this.startTime = this._getTime(l ?? c), this.resource = t.resource, this.instrumentationLibrary = t.instrumentationLibrary, this._spanLimits = t.getSpanLimits(), this._attributeValueLengthLimit = this._spanLimits.attributeValueLengthLimit || 0, p != null && this.setAttributes(p), this._spanProcessor = t.getActiveSpanProcessor(), this._spanProcessor.onStart(this, e); } return r.prototype.spanContext = function() { return this._spanContext; }, r.prototype.setAttribute = function(t, e) { return e == null || this._isSpanEnded() ? this : t.length === 0 ? (d.warn("Invalid attribute key: " + t), this) : _t(e) ? Object.keys(this.attributes).length >= this._spanLimits.attributeCountLimit && !Object.prototype.hasOwnProperty.call(this.attributes, t) ? (this._droppedAttributesCount++, this) : (this.attributes[t] = this._truncateToSize(e), this) : (d.warn("Invalid attribute value set for key: " + t), this); }, r.prototype.setAttributes = function(t) { var e, n; try { for (var o = Ct(Object.entries(t)), i = o.next(); !i.done; i = o.next()) { var a = X(i.value, 2), s = a[0], l = a[1]; this.setAttribute(s, l); } } catch (u) { e = { error: u }; } finally { try { i && !i.done && (n = o.return) && n.call(o); } finally { if (e) throw e.error; } } return this; }, r.prototype.addEvent = function(t, e, n) { if (this._isSpanEnded()) return this; if (this._spanLimits.eventCountLimit === 0) return d.warn("No events allowed."), this._droppedEventsCount++, this; this.events.length >= this._spanLimits.eventCountLimit && (this._droppedEventsCount === 0 && d.debug("Dropping extra events."), this.events.shift(), this._droppedEventsCount++), k(e) && (k(n) || (n = e), e = void 0); var o = x(e); return this.events.push({ name: t, attributes: o, time: this._getTime(n), droppedAttributesCount: 0 }), this; }, r.prototype.addLink = function(t) { return this.links.push(t), this; }, r.prototype.addLinks = function(t) { var e; return (e = this.links).push.apply(e, Ot([], X(t), !1)), this; }, r.prototype.setStatus = function(t) { return this._isSpanEnded() ? this : (this.status = D({}, t), this.status.message != null && typeof t.message != "string" && (d.warn("Dropping invalid status.message of type '" + typeof t.message + "', expected 'string'"), delete this.status.message), this); }, r.prototype.updateName = function(t) { return this._isSpanEnded() ? this : (this.name = t, this); }, r.prototype.end = function(t) { if (this._isSpanEnded()) { d.error(this.name + " " + this._spanContext.traceId + "-" + this._spanContext.spanId + " - You can only call end() on a span once."); return; } this._ended = !0, this.endTime = this._getTime(t), this._duration = lt(this.startTime, this.endTime), this._duration[0] < 0 && (d.warn("Inconsistent start and end time, startTime > endTime. Setting span duration to 0ms.", this.startTime, this.endTime), this.endTime = this.startTime.slice(), this._duration = [0, 0]), this._droppedEventsCount > 0 && d.warn("Dropped " + this._droppedEventsCount + " events because eventCountLimit reached"), this._spanProcessor.onEnd(this); }, r.prototype._getTime = function(t) { if (typeof t == "number" && t <= I.now()) return pt(t + this._performanceOffset); if (typeof t == "number") return w(t); if (t instanceof Date) return w(t.getTime()); if (dt(t)) return t; if (this._startTimeProvided) return w(Date.now()); var e = I.now() - this._performanceStartTime; return ct(this.startTime, w(e)); }, r.prototype.isRecording = function() { return this._ended === !1; }, r.prototype.recordException = function(t, e) { var n = {}; typeof t == "string" ? n[M] = t : t && (t.code ? n[N] = t.code.toString() : t.name && (n[N] = t.name), t.message && (n[M] = t.message), t.stack && (n[ft] = t.stack)), n[N] || n[M] ? this.addEvent(wt, n, e) : d.warn("Failed to record an exception " + t); }, Object.defineProperty(r.prototype, "duration", { get: function() { return this._duration; }, enumerable: !1, configurable: !0 }), Object.defineProperty(r.prototype, "ended", { get: function() { return this._ended; }, enumerable: !1, configurable: !0 }), Object.defineProperty(r.prototype, "droppedAttributesCount", { get: function() { return this._droppedAttributesCount; }, enumerable: !1, configurable: !0 }), Object.defineProperty(r.prototype, "droppedEventsCount", { get: function() { return this._droppedEventsCount; }, enumerable: !1, configurable: !0 }), Object.defineProperty(r.prototype, "droppedLinksCount", { get: function() { return this._droppedLinksCount; }, enumerable: !1, configurable: !0 }), r.prototype._isSpanEnded = function() { return this._ended && d.warn("Can not execute the operation on ended Span {traceId: " + this._spanContext.traceId + ", spanId: " + this._spanContext.spanId + "}"), this._ended; }, r.prototype._truncateToLimitUtil = function(t, e) { return t.length <= e ? t : t.substring(0, e); }, r.prototype._truncateToSize = function(t) { var e = this, n = this._attributeValueLengthLimit; return n <= 0 ? (d.warn("Attribute value limit must be positive, got " + n), t) : typeof t == "string" ? this._truncateToLimitUtil(t, n) : Array.isArray(t) ? t.map(function(o) { return typeof o == "string" ? e._truncateToLimitUtil(o, n) : o; }) : t; }, r; })() ), P; (function(r) { r[r.NOT_RECORD = 0] = "NOT_RECORD", r[r.RECORD = 1] = "RECORD", r[r.RECORD_AND_SAMPLED = 2] = "RECORD_AND_SAMPLED"; })(P || (P = {})); var R = ( /** @class */ (function() { function r() { } return r.prototype.shouldSample = function() { return { decision: P.NOT_RECORD }; }, r.prototype.toString = function() { return "AlwaysOffSampler"; }, r; })() ), g = ( /** @class */ (function() { function r() { } return r.prototype.shouldSample = function() { return { decision: P.RECORD_AND_SAMPLED }; }, r.prototype.toString = function() { return "AlwaysOnSampler"; }, r; })() ), B = ( /** @class */ (function() { function r(t) { var e, n, o, i; this._root = t.root, this._root || (h(new Error("ParentBasedSampler must have a root sampler configured")), this._root = new g()), this._remoteParentSampled = (e = t.remoteParentSampled) !== null && e !== void 0 ? e : new g(), this._remoteParentNotSampled = (n = t.remoteParentNotSampled) !== null && n !== void 0 ? n : new R(), this._localParentSampled = (o = t.localParentSampled) !== null && o !== void 0 ? o : new g(), this._localParentNotSampled = (i = t.localParentNotSampled) !== null && i !== void 0 ? i : new R(); } return r.prototype.shouldSample = function(t, e, n, o, i, a) { var s = _.getSpanContext(t); return !s || !it(s) ? this._root.shouldSample(t, e, n, o, i, a) : s.isRemote ? s.traceFlags & L.SAMPLED ? this._remoteParentSampled.shouldSample(t, e, n, o, i, a) : this._remoteParentNotSampled.shouldSample(t, e, n, o, i, a) : s.traceFlags & L.SAMPLED ? this._localParentSampled.shouldSample(t, e, n, o, i, a) : this._localParentNotSampled.shouldSample(t, e, n, o, i, a); }, r.prototype.toString = function() { return "ParentBased{root=" + this._root.toString() + ", remoteParentSampled=" + this._remoteParentSampled.toString() + ", remoteParentNotSampled=" + this._remoteParentNotSampled.toString() + ", localParentSampled=" + this._localParentSampled.toString() + ", localParentNotSampled=" + this._localParentNotSampled.toString() + "}"; }, r; })() ), W = ( /** @class */ (function() { function r(t) { t === void 0 && (t = 0), this._ratio = t, this._ratio = this._normalize(t), this._upperBound = Math.floor(this._ratio * 4294967295); } return r.prototype.shouldSample = function(t, e) { return { decision: ot(e) && this._accumulate(e) < this._upperBound ? P.RECORD_AND_SAMPLED : P.NOT_RECORD }; }, r.prototype.toString = function() { return "TraceIdRatioBased{" + this._ratio + "}"; }, r.prototype._normalize = function(t) { return typeof t != "number" || isNaN(t) ? 0 : t >= 1 ? 1 : t <= 0 ? 0 : t; }, r.prototype._accumulate = function(t) { for (var e = 0, n = 0; n < t.length / 8; n++) { var o = n * 8, i = parseInt(t.slice(o, o + 8), 16); e = (e ^ i) >>> 0; } return e; }, r; })() ), Rt = v.AlwaysOn, E = 1; function J() { var r = A(); return { sampler: $(r), forceFlushTimeoutMillis: 3e4, generalLimits: { attributeValueLengthLimit: r.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT, attributeCountLimit: r.OTEL_ATTRIBUTE_COUNT_LIMIT }, spanLimits: { attributeValueLengthLimit: r.OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT, attributeCountLimit: r.OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT, linkCountLimit: r.OTEL_SPAN_LINK_COUNT_LIMIT, eventCountLimit: r.OTEL_SPAN_EVENT_COUNT_LIMIT, attributePerEventCountLimit: r.OTEL_SPAN_ATTRIBUTE_PER_EVENT_COUNT_LIMIT, attributePerLinkCountLimit: r.OTEL_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT }, mergeResourceWithDefaults: !0 }; } function $(r) { switch (r === void 0 && (r = A()), r.OTEL_TRACES_SAMPLER) { case v.AlwaysOn: return new g(); case v.AlwaysOff: return new R(); case v.ParentBasedAlwaysOn: return new B({ root: new g() }); case v.ParentBasedAlwaysOff: return new B({ root: new R() }); case v.TraceIdRatio: return new W(Y(r)); case v.ParentBasedTraceIdRatio: return new B({ root: new W(Y(r)) }); default: return d.error('OTEL_TRACES_SAMPLER value "' + r.OTEL_TRACES_SAMPLER + " invalid, defaulting to " + Rt + '".'), new g(); } } function Y(r) { if (r.OTEL_TRACES_SAMPLER_ARG === void 0 || r.OTEL_TRACES_SAMPLER_ARG === "") return d.error("OTEL_TRACES_SAMPLER_ARG is blank, defaulting to " + E + "."), E; var t = Number(r.OTEL_TRACES_SAMPLER_ARG); return isNaN(t) ? (d.error("OTEL_TRACES_SAMPLER_ARG=" + r.OTEL_TRACES_SAMPLER_ARG + " was given, but it is invalid, defaulting to " + E + "."), E) : t < 0 || t > 1 ? (d.error("OTEL_TRACES_SAMPLER_ARG=" + r.OTEL_TRACES_SAMPLER_ARG + " was given, but it is out of range ([0..1]), defaulting to " + E + "."), E) : t; } function It(r) { var t = { sampler: $() }, e = J(), n = Object.assign({}, e, t, r); return n.generalLimits = Object.assign({}, e.generalLimits, r.generalLimits || {}), n.spanLimits = Object.assign({}, e.spanLimits, r.spanLimits || {}), n; } function Nt(r) { var t, e, n, o, i, a, s, l, u, p, c, f, y = Object.assign({}, r.spanLimits), m = mt(); return y.attributeCountLimit = (a = (i = (o = (e = (t = r.spanLimits) === null || t === void 0 ? void 0 : t.attributeCountLimit) !== null && e !== void 0 ? e : (n = r.generalLimits) === null || n === void 0 ? void 0 : n.attributeCountLimit) !== null && o !== void 0 ? o : m.OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT) !== null && i !== void 0 ? i : m.OTEL_ATTRIBUTE_COUNT_LIMIT) !== null && a !== void 0 ? a : vt, y.attributeValueLengthLimit = (f = (c = (p = (l = (s = r.spanLimits) === null || s === void 0 ? void 0 : s.attributeValueLengthLimit) !== null && l !== void 0 ? l : (u = r.generalLimits) === null || u === void 0 ? void 0 : u.attributeValueLengthLimit) !== null && p !== void 0 ? p : m.OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT) !== null && c !== void 0 ? c : m.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT) !== null && f !== void 0 ? f : St, Object.assign({}, r, { spanLimits: y }); } var Mt = ( /** @class */ (function() { function r(t, e) { this._exporter = t, this._isExporting = !1, this._finishedSpans = [], this._droppedSpansCount = 0; var n = A(); this._maxExportBatchSize = typeof e?.maxExportBatchSize == "number" ? e.maxExportBatchSize : n.OTEL_BSP_MAX_EXPORT_BATCH_SIZE, this._maxQueueSize = typeof e?.maxQueueSize == "number" ? e.maxQueueSize : n.OTEL_BSP_MAX_QUEUE_SIZE, this._scheduledDelayMillis = typeof e?.scheduledDelayMillis == "number" ? e.scheduledDelayMillis : n.OTEL_BSP_SCHEDULE_DELAY, this._exportTimeoutMillis = typeof e?.exportTimeoutMillis == "number" ? e.exportTimeoutMillis : n.OTEL_BSP_EXPORT_TIMEOUT, this._shutdownOnce = new Z(this._shutdown, this), this._maxExportBatchSize > this._maxQueueSize && (d.warn("BatchSpanProcessor: maxExportBatchSize must be smaller or equal to maxQueueSize, setting maxExportBatchSize to match maxQueueSize"), this._maxExportBatchSize = this._maxQueueSize); } return r.prototype.forceFlush = function() { return this._shutdownOnce.isCalled ? this._shutdownOnce.promise : this._flushAll(); }, r.prototype.onStart = function(t, e) { }, r.prototype.onEnd = function(t) { this._shutdownOnce.isCalled || (t.spanContext().traceFlags & L.SAMPLED) !== 0 && this._addToBuffer(t); }, r.prototype.shutdown = function() { return this._shutdownOnce.call(); }, r.prototype._shutdown = function() { var t = this; return Promise.resolve().then(function() { return t.onShutdown(); }).then(function() { return t._flushAll(); }).then(function() { return t._exporter.shutdown(); }); }, r.prototype._addToBuffer = function(t) { if (this._finishedSpans.length >= this._maxQueueSize) { this._droppedSpansCount === 0 && d.debug("maxQueueSize reached, dropping spans"), this._droppedSpansCount++; return; } this._droppedSpansCount > 0 && (d.warn("Dropped " + this._droppedSpansCount + " spans because maxQueueSize reached"), this._droppedSpansCount = 0), this._finishedSpans.push(t), this._maybeStartTimer(); }, r.prototype._flushAll = function() { var t = this; return new Promise(function(e, n) { for (var o = [], i = Math.ceil(t._finishedSpans.length / t._maxExportBatchSize), a = 0, s = i; a < s; a++) o.push(t._flushOneBatch()); Promise.all(o).then(function() { e(); }).catch(n); }); }, r.prototype._flushOneBatch = function() { var t = this; return this._clearTimer(), this._finishedSpans.length === 0 ? Promise.resolve() : new Promise(function(e, n) { var o = setTimeout(function() { n(new Error("Timeout")); }, t._exportTimeoutMillis); T.with(At(T.active()), function() { var i; t._finishedSpans.length <= t._maxExportBatchSize ? (i = t._finishedSpans, t._finishedSpans = []) : i = t._finishedSpans.splice(0, t._maxExportBatchSize); for (var a = function() { return t._exporter.export(i, function(c) { var f; clearTimeout(o), c.code === U.SUCCESS ? e() : n((f = c.error) !== null && f !== void 0 ? f : new Error("BatchSpanProcessor: span export failed")); }); }, s = null, l = 0, u = i.length; l < u; l++) { var p = i[l]; p.resource.asyncAttributesPending && p.resource.waitForAsyncAttributes && (s ?? (s = []), s.push(p.resource.waitForAsyncAttributes())); } s === null ? a() : Promise.all(s).then(a, function(c) { h(c), n(c); }); }); }); }, r.prototype._maybeStartTimer = function() { var t = this; if (!this._isExporting) { var e = function() { t._isExporting = !0, t._flushOneBatch().finally(function() { t._isExporting = !1, t._finishedSpans.length > 0 && (t._clearTimer(), t._maybeStartTimer()); }).catch(function(n) { t._isExporting = !1, h(n); }); }; if (this._finishedSpans.length >= this._maxExportBatchSize) return e(); this._timer === void 0 && (this._timer = setTimeout(function() { return e(); }, this._scheduledDelayMillis), yt(this._timer)); } }, r.prototype._clearTimer = function() { this._timer !== void 0 && (clearTimeout(this._timer), this._timer = void 0); }, r; })() ), Bt = /* @__PURE__ */ (function() { var r = function(t, e) { return r = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(n, o) { n.__proto__ = o; } || function(n, o) { for (var i in o) Object.prototype.hasOwnProperty.call(o, i) && (n[i] = o[i]); }, r(t, e); }; return function(t, e) { if (typeof e != "function" && e !== null) throw new TypeError("Class extends value " + String(e) + " is not a constructor or null"); r(t, e); function n() { this.constructor = t; } t.prototype = e === null ? Object.create(e) : (n.prototype = e.prototype, new n()); }; })(), Dt = ( /** @class */ (function(r) { Bt(t, r); function t(e, n) { var o = r.call(this, e, n) || this; return o.onInit(n), o; } return t.prototype.onInit = function(e) { var n = this; e?.disableAutoFlushOnDocumentHide !== !0 && typeof document < "u" && (this._visibilityChangeListener = function() { document.visibilityState === "hidden" && n.forceFlush().catch(function(o) { h(o); }); }, this._pageHideListener = function() { n.forceFlush().catch(function(o) { h(o); }); }, document.addEventListener("visibilitychange", this._visibilityChangeListener), document.addEventListener("pagehide", this._pageHideListener)); }, t.prototype.onShutdown = function() { typeof document < "u" && (this._visibilityChangeListener && document.removeEventListener("visibilitychange", this._visibilityChangeListener), this._pageHideListener && document.removeEventListener("pagehide", this._pageHideListener)); }, t; })(Mt) ), Ut = 8, Ft = 16, Gt = ( /** @class */ /* @__PURE__ */ (function() { function r() { this.generateTraceId = q(Ft), this.generateSpanId = q(Ut); } return r; })() ), C = Array(32); function q(r) { return function() { for (var e = 0; e < r * 2; e++) C[e] = Math.floor(Math.random() * 16) + 48, C[e] >= 58 && (C[e] += 39); return String.fromCharCode.apply(null, C.slice(0, r * 2)); }; } var zt = ( /** @class */ (function() { function r(t, e, n) { this._tracerProvider = n; var o = It(e); this._sampler = o.sampler, this._generalLimits = o.generalLimits, this._spanLimits = o.spanLimits, this._idGenerator = e.idGenerator || new Gt(), this.resource = n.resource, this.instrumentationLibrary = t; } return r.prototype.startSpan = function(t, e, n) { var o, i, a; e === void 0 && (e = {}), n === void 0 && (n = T.active()), e.root && (n = _.deleteSpan(n)); var s = _.getSpan(n); if (bt(n)) { d.debug("Instrumentation suppressed, returning Noop Span"); var l = _.wrapSpanContext(at); return l; } var u = s?.spanContext(), p = this._idGenerator.generateSpanId(), c, f, y; !u || !_.isSpanContextValid(u) ? c = this._idGenerator.generateTraceId() : (c = u.traceId, f = u.traceState, y = u.spanId); var m = (o = e.kind) !== null && o !== void 0 ? o : st.INTERNAL, F = ((i = e.links) !== null && i !== void 0 ? i : []).map(function(j) { return { context: j.context, attributes: x(j.attributes) }; }), G = x(e.attributes), b = this._sampler.shouldSample(n, c, t, m, G, F); f = (a = b.traceState) !== null && a !== void 0 ? a : f; var tt = b.decision === H.RECORD_AND_SAMPLED ? L.SAMPLED : L.NONE, z = { traceId: c, spanId: p, traceFlags: tt, traceState: f }; if (b.decision === H.NOT_RECORD) { d.debug("Recording is off, propagating context in a non-recording span"); var l = _.wrapSpanContext(z); return l; } var et = x(Object.assign(G, b.attributes)), rt = new xt(this, n, t, z, m, y, F, e.startTime, void 0, et); return rt; }, r.prototype.startActiveSpan = function(t, e, n, o) { var i, a, s; if (!(arguments.length < 2)) { arguments.length === 2 ? s = e : arguments.length === 3 ? (i = e, s = n) : (i = e, a = n, s = o); var l = a ?? T.active(), u = this.startSpan(t, i, l), p = _.setSpan(l, u); return T.with(p, s, void 0, u); } }, r.prototype.getGeneralLimits = function() { return this._generalLimits; }, r.prototype.getSpanLimits = function() { return this._spanLimits; }, r.prototype.getActiveSpanProcessor = function() { return this._tracerProvider.getActiveSpanProcessor(); }, r; })() ), O = function(r) { var t = typeof Symbol == "function" && Symbol.iterator, e = t && r[t], n = 0; if (e) return e.call(r); if (r && typeof r.length == "number") return { next: function() { return r && n >= r.length && (r = void 0), { value: r && r[n++], done: !r }; } }; throw new TypeError(t ? "Object is not iterable." : "Symbol.iterator is not defined."); }, K = ( /** @class */ (function() { function r(t) { this._spanProcessors = t; } return r.prototype.forceFlush = function() { var t, e, n = []; try { for (var o = O(this._spanProcessors), i = o.next(); !i.done; i = o.next()) { var a = i.value; n.push(a.forceFlush()); } } catch (s) { t = { error: s }; } finally { try { i && !i.done && (e = o.return) && e.call(o); } finally { if (t) throw t.error; } } return new Promise(function(s) { Promise.all(n).then(function() { s(); }).catch(function(l) { h(l || new Error("MultiSpanProcessor: forceFlush failed")), s(); }); }); }, r.prototype.onStart = function(t, e) { var n, o; try { for (var i = O(this._spanProcessors), a = i.next(); !a.done; a = i.next()) { var s = a.value; s.onStart(t, e); } } catch (l) { n = { error: l }; } finally { try { a && !a.done && (o = i.return) && o.call(i); } finally { if (n) throw n.error; } } }, r.prototype.onEnd = function(t) { var e, n; try { for (var o = O(this._spanProcessors), i = o.next(); !i.done; i = o.next()) { var a = i.value; a.onEnd(t); } } catch (s) { e = { error: s }; } finally { try { i && !i.done && (n = o.return) && n.call(o); } finally { if (e) throw e.error; } } }, r.prototype.shutdown = function() { var t, e, n = []; try { for (var o = O(this._spanProcessors), i = o.next(); !i.done; i = o.next()) { var a = i.value; n.push(a.shutdown()); } } catch (s) { t = { error: s }; } finally { try { i && !i.done && (e = o.return) && e.call(o); } finally { if (t) throw t.error; } } return new Promise(function(s, l) { Promise.all(n).then(function() { s(); }, l); }); }, r; })() ), jt = ( /** @class */ (function() { function r() { } return r.prototype.onStart = function(t, e) { }, r.prototype.onEnd = function(t) { }, r.prototype.shutdown = function() { return Promise.resolve(); }, r.prototype.forceFlush = function() { return Promise.resolve(); }, r; })() ), kt = function(r, t) { var e = typeof Symbol == "function" && r[Symbol.iterator]; if (!e) return r; var n = e.call(r), o, i = [], a; try { for (; (t === void 0 || t-- > 0) && !(o = n.next()).done; ) i.push(o.value); } catch (s) { a = { error: s }; } finally { try { o && !o.done && (e = n.return) && e.call(n); } finally { if (a) throw a.error; } } return i; }, Vt = function(r, t, e) { if (e || arguments.length === 2) for (var n = 0, o = t.length, i; n < o; n++) (i || !(n in t)) && (i || (i = Array.prototype.slice.call(t, 0, n)), i[n] = t[n]); return r.concat(i || Array.prototype.slice.call(t)); }, S; (function(r) { r[r.resolved = 0] = "resolved", r[r.timeout = 1] = "timeout", r[r.error = 2] = "error", r[r.unresolved = 3] = "unresolved"; })(S || (S = {})); var te = ( /** @class */ (function() { function r(t) { t === void 0 && (t = {}); var e, n; this._registeredSpanProcessors = [], this._tracers = /* @__PURE__ */ new Map(); var o = Lt({}, J(), Nt(t)); if (this.resource = (e = o.resource) !== null && e !== void 0 ? e : Q.empty(), o.mergeResourceWithDefaults && (this.resource = Q.default().merge(this.resource)), this._config = Object.assign({}, o, { resource: this.resource }), !((n = t.spanProcessors) === null || n === void 0) && n.length) this._registeredSpanProcessors = Vt([], kt(t.spanProcessors), !1), this.activeSpanProcessor = new K(this._registeredSpanProcessors); else { var i = this._buildExporterFromEnv(); if (i !== void 0) { var a = new Dt(i); this.activeSpanProcessor = a; } else this.activeSpanProcessor = new jt(); } } return r.prototype.getTracer = function(t, e, n) { var o = t + "@" + (e || "") + ":" + (n?.schemaUrl || ""); return this._tracers.has(o) || this._tracers.set(o, new zt({ name: t, version: e, schemaUrl: n?.schemaUrl }, this._config, this)), this._tracers.get(o); }, r.prototype.addSpanProcessor = function(t) { this._registeredSpanProcessors.length === 0 && this.activeSpanProcessor.shutdown().catch(function(e) { return d.error("Error while trying to shutdown current span processor", e); }), this._registeredSpanProcessors.push(t), this.activeSpanProcessor = new K(this._registeredSpanProcessors); }, r.prototype.getActiveSpanProcessor = function() { return this.activeSpanProcessor; }, r.prototype.register = function(t) { t === void 0 && (t = {}), _.setGlobalTracerProvider(this), t.propagator === void 0 && (t.propagator = this._buildPropagatorFromEnv()), t.contextManager && T.setGlobalContextManager(t.contextManager), t.propagator && ht.setGlobalPropagator(t.propagator); }, r.prototype.forceFlush = function() { var t = this._config.forceFlushTimeoutMillis, e = this._registeredSpanProcessors.map(function(n) { return new Promise(function(o) { var i, a = setTimeout(function() { o(new Error("Span processor did not completed within timeout period of " + t + " ms")), i = S.timeout; }, t); n.forceFlush().then(function() { clearTimeout(a), i !== S.timeout && (i = S.resolved, o(i)); }).catch(function(s) { clearTimeout(a), i = S.error, o(s); }); }); }); return new Promise(function(n, o) { Promise.all(e).then(function(i) { var a = i.filter(function(s) { return s !== S.resolved; }); a.length > 0 ? o(a) : n(); }).catch(function(i) { return o([i]); }); }); }, r.prototype.shutdown = function() { return this.activeSpanProcessor.shutdown(); }, r.prototype._getPropagator = function(t) { var e; return (e = this.constructor._registeredPropagators.get(t)) === null || e === void 0 ? void 0 : e(); }, r.prototype._getSpanExporter = function(t) { var e; return (e = this.constructor._registeredExporters.get(t)) === null || e === void 0 ? void 0 : e(); }, r.prototype._buildPropagatorFromEnv = function() { var t = this, e = Array.from(new Set(A().OTEL_PROPAGATORS)), n = e.map(function(i) { var a = t._getPropagator(i); return a || d.warn('Propagator "' + i + '" requested through environment variable is unavailable.'), a; }), o = n.reduce(function(i, a) { return a && i.push(a), i; }, []); if (o.length !== 0) return e.length === 1 ? o[0] : new Et({ propagators: o }); }, r.prototype._buildExporterFromEnv = function() { var t = A().OTEL_TRACES_EXPORTER; if (!(t === "none" || t === "")) { var e = this._getSpanExporter(t); return e || d.error('Exporter "' + t + '" requested through environment variable is unavailable.'), e; } }, r._registeredPropagators = /* @__PURE__ */ new Map([ ["tracecontext", function() { return new Tt(); }], ["baggage", function() { return new gt(); }] ]), r._registeredExporters = /* @__PURE__ */ new Map(), r; })() ), Ht = function(r) { var t = typeof Symbol == "function" && Symbol.iterator, e = t && r[t], n = 0; if (e) return e.call(r); if (r && typeof r.length == "number") return { next: function() { return r && n >= r.length && (r = void 0), { value: r && r[n++], done: !r }; } }; throw new TypeError(t ? "Object is not iterable." : "Symbol.iterator is not defined."); }, ee = ( /** @class */ (function() { function r() { } return r.prototype.export = function(t, e) { return this._sendSpans(t, e); }, r.prototype.shutdown = function() { return this._sendSpans([]), this.forceFlush(); }, r.prototype.forceFlush = function() { return Promise.resolve(); }, r.prototype._exportInfo = function(t) { var e; return { resource: { attributes: t.resource.attributes }, instrumentationScope: t.instrumentationLibrary, traceId: t.spanContext().traceId, parentId: t.parentSpanId, traceState: (e = t.spanContext().traceState) === null || e === void 0 ? void 0 : e.serialize(), name: t.name, id: t.spanContext().spanId, kind: t.kind, timestamp: V(t.startTime), duration: V(t.duration), attributes: t.attributes, status: t.status, events: t.events, links: t.links }; }, r.prototype._sendSpans = function(t, e) { var n, o; try { for (var i = Ht(t), a = i.next(); !a.done; a = i.next()) { var s = a.value; console.dir(this._exportInfo(s), { depth: 3 }); } } catch (l) { n = { error: l }; } finally { try { a && !a.done && (o = i.return) && o.call(i); } finally { if (n) throw n.error; } } if (e) return e({ code: U.SUCCESS }); }, r; })() ), Qt = function(r, t, e, n) { function o(i) { return i instanceof e ? i : new e(function(a) { a(i); }); } return new (e || (e = Promise))(function(i, a) { function s(p) { try { u(n.next(p)); } catch (c) { a(c); } } function l(p) { try { u(n.throw(p)); } catch (c) { a(c); } } function u(p) { p.done ? i(p.value) : o(p.value).then(s, l); } u((n = n.apply(r, t || [])).next()); }); }, Xt = function(r, t) { var e = { label: 0, sent: function() { if (i[0] & 1) throw i[1]; return i[1]; }, trys: [], ops: [] }, n, o, i, a; return a = { next: s(0), throw: s(1), return: s(2) }, typeof Symbol == "function" && (a[Symbol.iterator] = function() { return this; }), a; function s(u) { return function(p) { return l([u, p]); }; } function l(u) { if (n) throw new TypeError("Generator is already executing."); for (; e; ) try { if (n = 1, o && (i = u[0] & 2 ? o.return : u[0] ? o.throw || ((i = o.return) && i.call(o), 0) : o.next) && !(i = i.call(o, u[1])).done) return i; switch (o = 0, i && (u = [u[0] & 2, i.value]), u[0]) { case 0: case 1: i = u; break; case 4: return e.label++, { value: u[1], done: !1 }; case 5: e.label++, o = u[1], u = [0]; continue; case 7: u = e.ops.pop(), e.trys.pop(); continue; default: if (i = e.trys, !(i = i.length > 0 && i[i.length - 1]) && (u[0] === 6 || u[0] === 2)) { e = 0; continue; } if (u[0] === 3 && (!i || u[1] > i[0] && u[1] < i[3])) { e.label = u[1]; break; } if (u[0] === 6 && e.label < i[1]) { e.label = i[1], i = u; break; } if (i && e.label < i[2]) { e.label = i[2], e.ops.push(u); break; } i[2] && e.ops.pop(), e.trys.pop(); continue; } u = t.call(r, e); } catch (p) { u = [6, p], o = 0; } finally { n = i = 0; } if (u[0] & 5) throw u[1]; return { value: u[0] ? u[1] : void 0, done: !0 }; } }, re = ( /** @class */ (function() { function r(t) { this._exporter = t, this._shutdownOnce = new Z(this._shutdown, this), this._unresolvedExports = /* @__PURE__ */ new Set(); } return r.prototype.forceFlush = function() { return Qt(this, void 0, void 0, function() { return Xt(this, function(t) { switch (t.label) { case 0: return [4, Promise.all(Array.from(this._unresolvedExports))]; case 1: return t.sent(), this._exporter.forceFlush ? [4, this._exporter.forceFlush()] : [3, 3]; case 2: t.sent(), t.label = 3; case 3: return [ 2 /*return*/ ]; } }); }); }, r.prototype.onStart = function(t, e) { }, r.prototype.onEnd = function(t) { var e = this, n, o; if (!this._shutdownOnce.isCalled && (t.spanContext().traceFlags & L.SAMPLED) !== 0) { var i = function() { return Pt._export(e._exporter, [t]).then(function(s) { var l; s.code !== U.SUCCESS && h((l = s.error) !== null && l !== void 0 ? l : new Error("SimpleSpanProcessor: span export failed (status " + s + ")")); }).catch(function(s) { h(s); }); }; if (t.resource.asyncAttributesPending) { var a = (o = (n = t.resource).waitForAsyncAttributes) === null || o === void 0 ? void 0 : o.call(n).then(function() { return a != null && e._unresolvedExports.delete(a), i(); }, function(s) { return h(s); }); a != null && this._unresolvedExports.add(a); } else i(); } }, r.prototype.shutdown = function() { return this._shutdownOnce.call(); }, r.prototype._shutdown = function() { return this._exporter.shutdown(); }, r; })() ); export { R as A, te as B, ee as C, S as F, jt as N, B as P, Gt as R, re as S, zt as T, Dt as a, g as b, W as c, P as d, xt as e }; //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiU2ltcGxlU3BhblByb2Nlc3Nvci0hfnswMDR9fi5qcyJdLAogICJzb3VyY2VzQ29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