@vercel/otel 1.6.1 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,4 +13,4 @@ var kl=Object.create;var Xr=Object.defineProperty;var Bl=Object.getOwnPropertyDe
13
13
  To resolve the conflict:`,kn(a,n))),i=r):y.diag.warn("A view or instrument with the name ",n.name,` has already been registered and is incompatible with another registered view.
14
14
  `,`Details:
15
15
  `,Dn(a,n),`To resolve the conflict:
16
- `,kn(a,n))}}catch(s){c={error:s}}finally{try{t&&!t.done&&(l=e.return)&&l.call(e)}finally{if(c)throw c.error}}return i},u}();var Va=function(){function u(n){this._backingStorages=n}return u.prototype.record=function(n,o,c,l){this._backingStorages.forEach(function(i){i.record(n,o,c,l)})},u}();b();b();var Ga=function(){function u(n,o){this._instrumentName=n,this._valueType=o,this._buffer=new nt}return u.prototype.observe=function(n,o){if(o===void 0&&(o={}),typeof n!="number"){y.diag.warn("non-number value provided to metric "+this._instrumentName+": "+n);return}this._valueType===y.ValueType.INT&&!Number.isInteger(n)&&(y.diag.warn("INT value type cannot accept a floating-point value for "+this._instrumentName+", ignoring the fractional digits."),n=Math.trunc(n),!Number.isInteger(n))||this._buffer.set(o,n)},u}();var Ha=function(){function u(){this._buffer=new Map}return u.prototype.observe=function(n,o,c){if(c===void 0&&(c={}),!!_e(n)){var l=this._buffer.get(n);if(l==null&&(l=new nt,this._buffer.set(n,l)),typeof o!="number"){y.diag.warn("non-number value provided to metric "+n._descriptor.name+": "+o);return}n._descriptor.valueType===y.ValueType.INT&&!Number.isInteger(o)&&(y.diag.warn("INT value type cannot accept a floating-point value for "+n._descriptor.name+", ignoring the fractional digits."),o=Math.trunc(o),!Number.isInteger(o))||l.set(c,o)}},u}();var Vn=function(u,n,o,c){function l(i){return i instanceof o?i:new o(function(e){e(i)})}return new(o||(o=Promise))(function(i,e){function t(s){try{a(c.next(s))}catch(d){e(d)}}function r(s){try{a(c.throw(s))}catch(d){e(d)}}function a(s){s.done?i(s.value):l(s.value).then(t,r)}a((c=c.apply(u,n||[])).next())})},Gn=function(u,n){var o={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},c,l,i,e;return e={next:t(0),throw:t(1),return:t(2)},typeof Symbol=="function"&&(e[Symbol.iterator]=function(){return this}),e;function t(a){return function(s){return r([a,s])}}function r(a){if(c)throw new TypeError("Generator is already executing.");for(;o;)try{if(c=1,l&&(i=a[0]&2?l.return:a[0]?l.throw||((i=l.return)&&i.call(l),0):l.next)&&!(i=i.call(l,a[1])).done)return i;switch(l=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,l=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(i=o.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){o=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(a[0]===6&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=n.call(u,o)}catch(s){a=[6,s],l=0}finally{c=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},ja=function(u,n){var o=typeof Symbol=="function"&&u[Symbol.iterator];if(!o)return u;var c=o.call(u),l,i=[],e;try{for(;(n===void 0||n-- >0)&&!(l=c.next()).done;)i.push(l.value)}catch(t){e={error:t}}finally{try{l&&!l.done&&(o=c.return)&&o.call(c)}finally{if(e)throw e.error}}return i},Fa=function(u,n,o){if(o||arguments.length===2)for(var c=0,l=n.length,i;c<l;c++)(i||!(c in n))&&(i||(i=Array.prototype.slice.call(n,0,c)),i[c]=n[c]);return u.concat(i||Array.prototype.slice.call(n))},qa=function(){function u(){this._callbacks=[],this._batchCallbacks=[]}return u.prototype.addCallback=function(n,o){var c=this._findCallback(n,o);c>=0||this._callbacks.push({callback:n,instrument:o})},u.prototype.removeCallback=function(n,o){var c=this._findCallback(n,o);c<0||this._callbacks.splice(c,1)},u.prototype.addBatchCallback=function(n,o){var c=new Set(o.filter(_e));if(c.size===0){y.diag.error("BatchObservableCallback is not associated with valid instruments",o);return}var l=this._findBatchCallback(n,c);l>=0||this._batchCallbacks.push({callback:n,instruments:c})},u.prototype.removeBatchCallback=function(n,o){var c=new Set(o.filter(_e)),l=this._findBatchCallback(n,c);l<0||this._batchCallbacks.splice(l,1)},u.prototype.observe=function(n,o){return Vn(this,void 0,void 0,function(){var c,l,i,e;return Gn(this,function(t){switch(t.label){case 0:return c=this._observeCallbacks(n,o),l=this._observeBatchCallbacks(n,o),[4,ba(Fa(Fa([],ja(c),!1),ja(l),!1))];case 1:return i=t.sent(),e=i.filter(Sa).map(function(r){return r.reason}),[2,e]}})})},u.prototype._observeCallbacks=function(n,o){var c=this;return this._callbacks.map(function(l){var i=l.callback,e=l.instrument;return Vn(c,void 0,void 0,function(){var t,r;return Gn(this,function(a){switch(a.label){case 0:return t=new Ga(e._descriptor.name,e._descriptor.valueType),r=Promise.resolve(i(t)),o!=null&&(r=Cn(r,o)),[4,r];case 1:return a.sent(),e._metricStorages.forEach(function(s){s.record(t._buffer,n)}),[2]}})})})},u.prototype._observeBatchCallbacks=function(n,o){var c=this;return this._batchCallbacks.map(function(l){var i=l.callback,e=l.instruments;return Vn(c,void 0,void 0,function(){var t,r;return Gn(this,function(a){switch(a.label){case 0:return t=new Ha,r=Promise.resolve(i(t)),o!=null&&(r=Cn(r,o)),[4,r];case 1:return a.sent(),e.forEach(function(s){var d=t._buffer.get(s);d!=null&&s._metricStorages.forEach(function(v){v.record(d,n)})}),[2]}})})})},u.prototype._findCallback=function(n,o){return this._callbacks.findIndex(function(c){return c.callback===n&&c.instrument===o})},u.prototype._findBatchCallback=function(n,o){return this._batchCallbacks.findIndex(function(c){return c.callback===n&&Ta(c.instruments,o)})},u}();var Sp=function(){var u=function(n,o){return u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,l){c.__proto__=l}||function(c,l){for(var i in l)Object.prototype.hasOwnProperty.call(l,i)&&(c[i]=l[i])},u(n,o)};return function(n,o){if(typeof o!="function"&&o!==null)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");u(n,o);function c(){this.constructor=n}n.prototype=o===null?Object.create(o):(c.prototype=o.prototype,new c)}}(),Ka=function(u){Sp(n,u);function n(o,c,l,i){var e=u.call(this,o)||this;return e._attributesProcessor=l,e._deltaMetricStorage=new br(c),e._temporalMetricStorage=new Sr(c,i),e}return n.prototype.record=function(o,c,l,i){c=this._attributesProcessor.process(c,l),this._deltaMetricStorage.record(o,c,l,i)},n.prototype.collect=function(o,c){var l=this._deltaMetricStorage.collect();return this._temporalMetricStorage.buildMetrics(o,this._instrumentDescriptor,l,c)},n}(Er);var Xa=function(){var u=function(n,o){return u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,l){c.__proto__=l}||function(c,l){for(var i in l)Object.prototype.hasOwnProperty.call(l,i)&&(c[i]=l[i])},u(n,o)};return function(n,o){if(typeof o!="function"&&o!==null)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");u(n,o);function c(){this.constructor=n}n.prototype=o===null?Object.create(o):(c.prototype=o.prototype,new c)}}(),Tr=function(){function u(){}return u.Noop=function(){return Op},u}();var Tp=function(u){Xa(n,u);function n(){return u!==null&&u.apply(this,arguments)||this}return n.prototype.process=function(o,c){return o},n}(Tr);var Zh=function(u){Xa(n,u);function n(o){var c=u.call(this)||this;return c._allowedAttributeNames=o,c}return n.prototype.process=function(o,c){var l=this,i={};return Object.keys(o).filter(function(e){return l._allowedAttributeNames.includes(e)}).forEach(function(e){return i[e]=o[e]}),i},n}(Tr);var Op=new Tp;var gp=function(u,n,o,c){function l(i){return i instanceof o?i:new o(function(e){e(i)})}return new(o||(o=Promise))(function(i,e){function t(s){try{a(c.next(s))}catch(d){e(d)}}function r(s){try{a(c.throw(s))}catch(d){e(d)}}function a(s){s.done?i(s.value):l(s.value).then(t,r)}a((c=c.apply(u,n||[])).next())})},Ap=function(u,n){var o={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},c,l,i,e;return e={next:t(0),throw:t(1),return:t(2)},typeof Symbol=="function"&&(e[Symbol.iterator]=function(){return this}),e;function t(a){return function(s){return r([a,s])}}function r(a){if(c)throw new TypeError("Generator is already executing.");for(;o;)try{if(c=1,l&&(i=a[0]&2?l.return:a[0]?l.throw||((i=l.return)&&i.call(l),0):l.next)&&!(i=i.call(l,a[1])).done)return i;switch(l=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,l=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(i=o.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){o=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(a[0]===6&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=n.call(u,o)}catch(s){a=[6,s],l=0}finally{c=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Np=function(u,n){var o=typeof Symbol=="function"&&u[Symbol.iterator];if(!o)return u;var c=o.call(u),l,i=[],e;try{for(;(n===void 0||n-- >0)&&!(l=c.next()).done;)i.push(l.value)}catch(t){e={error:t}}finally{try{l&&!l.done&&(o=c.return)&&o.call(c)}finally{if(e)throw e.error}}return i},Ya=function(){function u(n,o){this._meterProviderSharedState=n,this._instrumentationScope=o,this.metricStorageRegistry=new Ba,this.observableRegistry=new qa,this.meter=new Ua(this)}return u.prototype.registerMetricStorage=function(n){var o=this._registerMetricStorage(n,Ka);return o.length===1?o[0]:new Va(o)},u.prototype.registerAsyncMetricStorage=function(n){var o=this._registerMetricStorage(n,ka);return o},u.prototype.collect=function(n,o,c){return gp(this,void 0,void 0,function(){var l,i,e;return Ap(this,function(t){switch(t.label){case 0:return[4,this.observableRegistry.observe(o,c?.timeoutMillis)];case 1:return l=t.sent(),i=this.metricStorageRegistry.getStorages(n),i.length===0?[2,null]:(e=i.map(function(r){return r.collect(n,o)}).filter(va),e.length===0?[2,{errors:l}]:[2,{scopeMetrics:{scope:this._instrumentationScope,metrics:e},errors:l}])}})})},u.prototype._registerMetricStorage=function(n,o){var c=this,l=this._meterProviderSharedState.viewRegistry.findViews(n,this._instrumentationScope),i=l.map(function(r){var a=ga(r,n),s=c.metricStorageRegistry.findOrUpdateCompatibleStorage(a);if(s!=null)return s;var d=r.aggregation.createAggregator(a),v=new o(a,d,r.attributesProcessor,c._meterProviderSharedState.metricCollectors);return c.metricStorageRegistry.register(v),v});if(i.length===0){var e=this._meterProviderSharedState.selectAggregations(n.type),t=e.map(function(r){var a=Np(r,2),s=a[0],d=a[1],v=c.metricStorageRegistry.findOrUpdateCompatibleCollectorStorage(s,n);if(v!=null)return v;var S=d.createAggregator(n),g=new o(n,S,Tr.Noop(),[s]);return c.metricStorageRegistry.registerForCollector(s,g),g});i=i.concat(t)}return i},u}();var Pp=function(u){var n=typeof Symbol=="function"&&Symbol.iterator,o=n&&u[n],c=0;if(o)return o.call(u);if(u&&typeof u.length=="number")return{next:function(){return u&&c>=u.length&&(u=void 0),{value:u&&u[c++],done:!u}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},Ja=function(){function u(n){this.resource=n,this.viewRegistry=new Na,this.metricCollectors=[],this.meterSharedStates=new Map}return u.prototype.getMeterSharedState=function(n){var o=Ea(n),c=this.meterSharedStates.get(o);return c==null&&(c=new Ya(this,n),this.meterSharedStates.set(o,c)),c},u.prototype.selectAggregations=function(n){var o,c,l=[];try{for(var i=Pp(this.metricCollectors),e=i.next();!e.done;e=i.next()){var t=e.value;l.push([t,t.selectAggregation(n)])}}catch(r){o={error:r}}finally{try{e&&!e.done&&(c=i.return)&&c.call(i)}finally{if(o)throw o.error}}return l},u}();var za=P(D()),Or=function(u,n,o,c){function l(i){return i instanceof o?i:new o(function(e){e(i)})}return new(o||(o=Promise))(function(i,e){function t(s){try{a(c.next(s))}catch(d){e(d)}}function r(s){try{a(c.throw(s))}catch(d){e(d)}}function a(s){s.done?i(s.value):l(s.value).then(t,r)}a((c=c.apply(u,n||[])).next())})},gr=function(u,n){var o={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},c,l,i,e;return e={next:t(0),throw:t(1),return:t(2)},typeof Symbol=="function"&&(e[Symbol.iterator]=function(){return this}),e;function t(a){return function(s){return r([a,s])}}function r(a){if(c)throw new TypeError("Generator is already executing.");for(;o;)try{if(c=1,l&&(i=a[0]&2?l.return:a[0]?l.throw||((i=l.return)&&i.call(l),0):l.next)&&!(i=i.call(l,a[1])).done)return i;switch(l=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,l=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(i=o.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){o=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(a[0]===6&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=n.call(u,o)}catch(s){a=[6,s],l=0}finally{c=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},xp=function(u,n){var o=typeof Symbol=="function"&&u[Symbol.iterator];if(!o)return u;var c=o.call(u),l,i=[],e;try{for(;(n===void 0||n-- >0)&&!(l=c.next()).done;)i.push(l.value)}catch(t){e={error:t}}finally{try{l&&!l.done&&(o=c.return)&&o.call(c)}finally{if(e)throw e.error}}return i},Rp=function(u,n,o){if(o||arguments.length===2)for(var c=0,l=n.length,i;c<l;c++)(i||!(c in n))&&(i||(i=Array.prototype.slice.call(n,0,c)),i[c]=n[c]);return u.concat(i||Array.prototype.slice.call(n))},Wa=function(){function u(n,o){this._sharedState=n,this._metricReader=o}return u.prototype.collect=function(n){return Or(this,void 0,void 0,function(){var o,c,l,i,e=this;return gr(this,function(t){switch(t.label){case 0:return o=(0,za.millisToHrTime)(Date.now()),c=[],l=[],i=Array.from(this._sharedState.meterSharedStates.values()).map(function(r){return Or(e,void 0,void 0,function(){var a;return gr(this,function(s){switch(s.label){case 0:return[4,r.collect(this,o,n)];case 1:return a=s.sent(),a?.scopeMetrics!=null&&c.push(a.scopeMetrics),a?.errors!=null&&l.push.apply(l,Rp([],xp(a.errors),!1)),[2]}})})}),[4,Promise.all(i)];case 1:return t.sent(),[2,{resourceMetrics:{resource:this._sharedState.resource,scopeMetrics:c},errors:l}]}})})},u.prototype.forceFlush=function(n){return Or(this,void 0,void 0,function(){return gr(this,function(o){switch(o.label){case 0:return[4,this._metricReader.forceFlush(n)];case 1:return o.sent(),[2]}})})},u.prototype.shutdown=function(n){return Or(this,void 0,void 0,function(){return gr(this,function(o){switch(o.label){case 0:return[4,this._metricReader.shutdown(n)];case 1:return o.sent(),[2]}})})},u.prototype.selectAggregationTemporality=function(n){return this._metricReader.selectAggregationTemporality(n)},u.prototype.selectAggregation=function(n){return this._metricReader.selectAggregation(n)},u}();var $a=function(u,n,o,c){function l(i){return i instanceof o?i:new o(function(e){e(i)})}return new(o||(o=Promise))(function(i,e){function t(s){try{a(c.next(s))}catch(d){e(d)}}function r(s){try{a(c.throw(s))}catch(d){e(d)}}function a(s){s.done?i(s.value):l(s.value).then(t,r)}a((c=c.apply(u,n||[])).next())})},Qa=function(u,n){var o={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},c,l,i,e;return e={next:t(0),throw:t(1),return:t(2)},typeof Symbol=="function"&&(e[Symbol.iterator]=function(){return this}),e;function t(a){return function(s){return r([a,s])}}function r(a){if(c)throw new TypeError("Generator is already executing.");for(;o;)try{if(c=1,l&&(i=a[0]&2?l.return:a[0]?l.throw||((i=l.return)&&i.call(l),0):l.next)&&!(i=i.call(l,a[1])).done)return i;switch(l=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,l=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(i=o.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){o=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(a[0]===6&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=n.call(u,o)}catch(s){a=[6,s],l=0}finally{c=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Lp=function(u){var n=typeof Symbol=="function"&&Symbol.iterator,o=n&&u[n],c=0;if(o)return o.call(u);if(u&&typeof u.length=="number")return{next:function(){return u&&c>=u.length&&(u=void 0),{value:u&&u[c++],done:!u}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},Hn=function(){function u(n){var o,c,l;this._shutdown=!1;var i=K.default().merge((l=n?.resource)!==null&&l!==void 0?l:K.empty());if(this._sharedState=new Ja(i),n?.views!=null&&n.views.length>0)try{for(var e=Lp(n.views),t=e.next();!t.done;t=e.next()){var r=t.value;this._sharedState.viewRegistry.addView(r)}}catch(a){o={error:a}}finally{try{t&&!t.done&&(c=e.return)&&c.call(e)}finally{if(o)throw o.error}}}return u.prototype.getMeter=function(n,o,c){return o===void 0&&(o=""),c===void 0&&(c={}),this._shutdown?(y.diag.warn("A shutdown MeterProvider cannot provide a Meter"),(0,y.createNoopMeter)()):this._sharedState.getMeterSharedState({name:n,version:o,schemaUrl:c.schemaUrl}).meter},u.prototype.addMetricReader=function(n){var o=new Wa(this._sharedState,n);n.setMetricProducer(o),this._sharedState.metricCollectors.push(o)},u.prototype.shutdown=function(n){return $a(this,void 0,void 0,function(){return Qa(this,function(o){switch(o.label){case 0:return this._shutdown?(y.diag.warn("shutdown may only be called once per MeterProvider"),[2]):(this._shutdown=!0,[4,Promise.all(this._sharedState.metricCollectors.map(function(c){return c.shutdown(n)}))]);case 1:return o.sent(),[2]}})})},u.prototype.forceFlush=function(n){return $a(this,void 0,void 0,function(){return Qa(this,function(o){switch(o.label){case 0:return this._shutdown?(y.diag.warn("invalid attempt to force flush after MeterProvider shutdown"),[2]):[4,Promise.all(this._sharedState.metricCollectors.map(function(c){return c.forceFlush(n)}))];case 1:return o.sent(),[2]}})})},u}();var Cl=P(St(),1),se=P(ke(),1),Ul=P(ru(),1),ut=P(D(),1);b();var Dp=Symbol.for("@vercel/request-context");function te(){return globalThis[Dp]?.get()}var qn=P(St(),1);function Pr(u){return Object.fromEntries(Object.entries(u).filter(([n,o])=>o!==void 0))}function nu(u){return u?u.split("::").at(-1):void 0}function ou(u=te()){if(u)return Pr({[qn.SemanticAttributes.HTTP_HOST]:u.headers.host,[qn.SemanticAttributes.HTTP_USER_AGENT]:u.headers["user-agent"],"http.referer":u.headers.referer,"vercel.request_id":nu(u.headers["x-vercel-id"]),"vercel.matched_path":u.headers["x-matched-path"],"vercel.edge_region":u.headers["x-vercel-edge-region"]})}b();function Se(u){return(u&y.TraceFlags.SAMPLED)!==0}var xr=class{constructor(n){this.processors=n;this.rootSpanIds=new Map;this.waitSpanEnd=new Map}forceFlush(){return Promise.all(this.processors.map(n=>n.forceFlush().catch(o=>{y.diag.error("@vercel/otel: forceFlush failed:",o)}))).then(()=>{})}shutdown(){return Promise.all(this.processors.map(n=>n.shutdown().catch(()=>{}))).then(()=>{})}onStart(n,o){let{traceId:c,spanId:l,traceFlags:i}=n.spanContext(),e=!n.parentSpanId||!this.rootSpanIds.has(c);if(e?this.rootSpanIds.set(c,{rootSpanId:l,open:[]}):this.rootSpanIds.get(c)?.open.push(n),e&&Se(i)){let t=ou();t&&n.setAttributes(t);let r=te();r&&r.waitUntil(async()=>{if(this.rootSpanIds.has(c)){let a=new Promise(d=>{this.waitSpanEnd.set(c,d)}),s;await Promise.race([a,new Promise(d=>{s=setTimeout(()=>{this.waitSpanEnd.delete(c),d(void 0)},50)})]),s&&clearTimeout(s)}return this.forceFlush()})}for(let t of this.processors)t.onStart(n,o)}onEnd(n){let{traceId:o,spanId:c,traceFlags:l}=n.spanContext(),i=Se(l),e=this.rootSpanIds.get(o),t=e?.rootSpanId===c;if(i){let r=kp(n);r&&Object.assign(n.attributes,r)}if(t){if(this.rootSpanIds.delete(o),e.open.length>0){for(let r of e.open)if(!r.ended&&r.spanContext().spanId!==c)try{r.end()}catch(a){y.diag.error("@vercel/otel: onEnd failed:",a)}}}else if(e)for(let r=0;r<e.open.length;r++)e.open[r]?.spanContext().spanId===c&&e.open.splice(r,1);for(let r of this.processors)r.onEnd(n);if(t){let r=this.waitSpanEnd.get(o);r&&(this.waitSpanEnd.delete(o),r())}}},iu={[y.SpanKind.INTERNAL]:"internal",[y.SpanKind.SERVER]:"server",[y.SpanKind.CLIENT]:"client",[y.SpanKind.PRODUCER]:"producer",[y.SpanKind.CONSUMER]:"consumer"};function kp(u){let{kind:n,attributes:o}=u,{"operation.name":c,"resouce.name":l,"span.type":i,"next.span_type":e,"http.method":t,"http.route":r}=o;if(c)return;let a=u.instrumentationLibrary.name,s=e??i;if(s&&typeof s=="string"){let d=Kn(a,s);return r?{"operation.name":d,"resource.name":l??r}:{"operation.name":d}}return t&&r&&typeof t=="string"&&typeof r=="string"?{"operation.name":Kn(a,`http.${iu[n]||"internal"}.${t}`),"resource.name":l??r}:{"operation.name":Kn(a,n===y.SpanKind.INTERNAL?"":iu[n])}}function Kn(u,n){if(!u)return n;let o=u.replace(/[ @./]/g,"_");return o.startsWith("_")&&(o=o.slice(1)),n?`${o}.${n}`:o}var _u=P(Qn(),1);var vu=P(wr(),1);b();var ee=class extends vu.OTLPExporterBase{constructor(n={}){super(n),n.headers&&(this._headers=n.headers)}onShutdown(){y.diag.debug("@vercel/otel/otlp: onShutdown")}onInit(){y.diag.debug("@vercel/otel/otlp: onInit")}send(n,o,c){if(this._shutdownOnce.isCalled){y.diag.debug("@vercel/otel/otlp: Shutdown already started. Cannot send objects");return}let l=this.convert(n),i,e,t;try{({body:i,contentType:e,headers:t}=this.toMessage(l))}catch(a){y.diag.warn("@vercel/otel/otlp: no proto",a);return}let r=fetch(this.url,{method:"POST",body:i,headers:{...this._headers,...t,"Content-Type":e,"User-Agent":"OTel-OTLP-Exporter-JavaScript/0.46.0"},next:{internal:!0}}).then(a=>{y.diag.debug("@vercel/otel/otlp: onSuccess",a.status,a.statusText),o(),a.arrayBuffer().catch(()=>{})}).catch(a=>{y.diag.error("@vercel/otel/otlp: onError",a),c(a)}).finally(()=>{let a=this._sendingPromises.indexOf(r);this._sendingPromises.splice(a,1)});this._sendingPromises.push(r)}getDefaultUrl(n){throw new Error("Method not implemented.")}};var of="v1/traces",af=`http://localhost:4318/${of}`;function Cr(u){return typeof u.url=="string"?u.url:af}var re=class{constructor(n={}){this.impl=new ro(n)}export(n,o){this.impl.export(n,o)}shutdown(){return this.impl.shutdown()}forceFlush(){return this.impl.forceFlush()}},ro=class extends ee{convert(n){return(0,_u.createExportTraceServiceRequest)(n,{useHex:!0,useLongBits:!1})}toMessage(n){return{body:JSON.stringify(n),contentType:"application/json"}}getDefaultUrl(n){return Cr(n)}};var Nl=P(Qn(),1),Pl=P(Al(),1),xl=P(Oo(),1);var Ft=class{constructor(n={}){this.impl=new No(n)}export(n,o){this.impl.export(n,o)}shutdown(){return this.impl.shutdown()}forceFlush(){return this.impl.forceFlush()}},No=class extends ee{convert(n){return(0,Nl.createExportTraceServiceRequest)(n,void 0)}toMessage(n){let o=Pl.ServiceClientType.SPANS,c=(0,xl.getExportRequestProto)(o),l=c.create(n);return{body:c.encode(l).finish(),contentType:"application/x-protobuf",headers:{accept:"application/x-protobuf"}}}getDefaultUrl(n){return Cr(n)}};b();var mt=P(St(),1);function Rl(u,n){return u.replace(/\{(?<temp1>[^{}]+)\}/g,(o,c)=>{let l=n[c];return l!==void 0?String(l):o})}var le=class{constructor(n={}){this.instrumentationName="@vercel/otel/fetch";this.instrumentationVersion="1.0.0";this.config=n}getConfig(){return this.config}setConfig(){}setTracerProvider(n){this.tracerProvider=n}setMeterProvider(){}enable(){this.disable();let{tracerProvider:n}=this;if(!n)return;let o=n.getTracer(this.instrumentationName,this.instrumentationVersion),c=this.config.ignoreUrls??[],l=(S,g)=>{if(g?.opentelemetry?.ignore!==void 0)return g.opentelemetry.ignore;if(c.length===0)return!1;let R=S.toString();return c.some(A=>typeof A=="string"?A==="*"?!0:R.startsWith(A):A.test(R))},i=process.env.VERCEL_URL||process.env.NEXT_PUBLIC_VERCEL_URL||null,e=process.env.VERCEL_BRANCH_URL||process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL||null,t=this.config.propagateContextUrls??[],r=this.config.dontPropagateContextUrls??[],a=this.config.resourceNameTemplate,s=(S,g)=>{if(g?.opentelemetry?.propagateContext)return g.opentelemetry.propagateContext;let R=S.toString();return r.length>0&&r.some(A=>typeof A=="string"?A==="*"?!0:R.startsWith(A):A.test(R))?!1:i&&S.protocol==="https:"&&(S.host===i||S.host===e||S.host===te()?.headers.host)||!i&&S.protocol==="http:"&&S.hostname==="localhost"?!0:t.some(A=>typeof A=="string"?A==="*"?!0:R.startsWith(A):A.test(R))};process.env.NEXT_OTEL_FETCH_DISABLED="1";let d=globalThis.fetch;this.originalFetch=d;let v=async(S,g)=>{let R=g;if(R?.next?.internal)return d(S,R);let A=new Request(S,R),X=new URL(A.url);if(l(X,R))return d(S,R);let Y={[mt.SemanticAttributes.HTTP_METHOD]:A.method,[mt.SemanticAttributes.HTTP_URL]:A.url,[mt.SemanticAttributes.HTTP_HOST]:X.host,[mt.SemanticAttributes.HTTP_SCHEME]:X.protocol.replace(":",""),[mt.SemanticAttributes.NET_PEER_NAME]:X.hostname,[mt.SemanticAttributes.NET_PEER_PORT]:X.port},Le=a?Rl(a,Y):Uf(A.url),qr=R?.opentelemetry?.spanName??`fetch ${A.method} ${A.url}`,H=o.startSpan(qr,{kind:y.SpanKind.CLIENT,attributes:{...Y,"operation.name":`fetch.${A.method}`,"resource.name":Le,...R?.opentelemetry?.attributes}},y.context.active());if(!H.isRecording()||!Se(H.spanContext().traceFlags))return H.end(),d(S,R);s(X,R)&&y.propagation.inject(y.context.active(),A.headers,Cf);try{let wt=Date.now(),Ct=await d(S,{...R,headers:A.headers}),Dl=Date.now()-wt;return H.setAttribute(mt.SemanticAttributes.HTTP_STATUS_CODE,Ct.status),H.setAttribute("http.response_time",Dl),Ct.status>=500&&Po(H,`Status: ${Ct.status} (${Ct.statusText})`),Ct.body?Mf(Ct).then(Kr=>{H.isRecording()&&(H.setAttribute(mt.SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED,Kr),H.end())},Kr=>{H.isRecording()&&(Po(H,Kr),H.end())}):H.end(),Ct}catch(wt){throw Po(H,wt),H.end(),wt}};globalThis.fetch=v}disable(){this.originalFetch&&(globalThis.fetch=this.originalFetch)}},Cf={set(u,n,o){u.set(n,o)}};function Uf(u){let n=u.indexOf("?");return n===-1?u:u.substring(0,n)}function Mf(u){let n=0,c=u.clone().body?.getReader();if(!c)return Promise.resolve(0);let l=()=>c.read().then(({done:i,value:e})=>{if(!i)return n+=e.byteLength,l()});return l().then(()=>n)}function Po(u,n){if(n instanceof Error)u.recordException(n),u.setStatus({code:y.SpanStatusCode.ERROR,message:n.message});else{let o=String(n);u.setStatus({code:y.SpanStatusCode.ERROR,message:o})}}var Fr=class{constructor(n={}){this.configuration=n}start(){let n=Df(),o=(0,se.getEnvWithoutDefaults)(),c=this.configuration,l=process.env.NEXT_RUNTIME||"nodejs",i=!!n.OTEL_SDK_DISABLED;if(o.OTEL_LOG_LEVEL&&y.diag.setLogger(new y.DiagConsoleLogger,{logLevel:o.OTEL_LOG_LEVEL}),i)return;let e=c.idGenerator??new fr,t=c.contextManager??new Ul.AsyncLocalStorageContextManager;t.enable(),this.contextManager=t;let r=n.OTEL_SERVICE_NAME||c.serviceName||"app",a=new K(Pr({[Cl.SemanticResourceAttributes.SERVICE_NAME]:r,"node.ci":process.env.CI?!0:void 0,"node.env":"production","vercel.env":process.env.VERCEL_ENV||process.env.NEXT_PUBLIC_VERCEL_ENV,"vercel.region":process.env.VERCEL_REGION,"vercel.runtime":l,"vercel.sha":process.env.VERCEL_GIT_COMMIT_SHA||process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA,"vercel.host":process.env.VERCEL_URL||process.env.NEXT_PUBLIC_VERCEL_URL||void 0,"vercel.branch_host":process.env.VERCEL_BRANCH_URL||process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL||void 0,...c.attributes})),s=c.resourceDetectors??[Ji];if(c.autoDetectResources??!0){let Y={detectors:s};a=a.merge(Wi(Y))}let v=Bf(c.propagators,n),S=Vf(c.traceSampler,n),g=Gf(c.spanProcessors,c,n);g.length===0&&y.diag.warn("@vercel/otel: No span processors configured. No spans will be exported.");let R=c.spanLimits,A=new ta({resource:a,idGenerator:e,sampler:S,spanLimits:R});if(A.addSpanProcessor(new xr(g)),A.register({contextManager:t,propagator:new ut.CompositePropagator({propagators:v})}),this.tracerProvider=A,c.logRecordProcessor){let Y=new wn({resource:a});this.loggerProvider=Y,Y.addLogRecordProcessor(c.logRecordProcessor),ft.logs.setGlobalLoggerProvider(Y)}if(c.metricReader||c.views){let Y=new Hn({resource:a,views:c.views??[]});c.metricReader&&Y.addMetricReader(c.metricReader),y.metrics.setGlobalMeterProvider(Y),this.meterProvider=Y}let X=kf(c.instrumentations,c.instrumentationConfig);this.disableInstumentations=(0,wl.registerInstrumentations)({instrumentations:X}),y.diag.info("@vercel/otel: started",r,l)}async shutdown(){let n=[];this.tracerProvider&&n.push(this.tracerProvider.shutdown()),this.loggerProvider&&n.push(this.loggerProvider.shutdown()),this.meterProvider&&n.push(this.meterProvider.shutdown()),y.diag.info("@vercel/otel: shutting down",n.length,process.env.NEXT_RUNTIME),await Promise.all(n),this.contextManager&&this.contextManager.disable();let{disableInstumentations:o}=this;o&&o()}};function Df(){let u=(0,se.parseEnvironment)(process.env);return{...se.DEFAULT_ENVIRONMENT,...u}}function kf(u,n){return(u??["auto"]).map(o=>o==="auto"?(y.diag.debug("@vercel/otel: Configure instrumentations: fetch",n?.fetch),[new le(n?.fetch)]):o==="fetch"?(y.diag.debug("@vercel/otel: Configure instrumentations: fetch",n?.fetch),new le(n?.fetch)):o).flat()}function Bf(u,n){let o=n.OTEL_PROPAGATORS&&n.OTEL_PROPAGATORS.length>0?n.OTEL_PROPAGATORS:void 0;return(u??o??["auto"]).map(c=>{if(c==="none")return[];if(c==="auto")return y.diag.debug("@vercel/otel: Configure propagators: tracecontext, baggage"),[new ut.W3CTraceContextPropagator,new ut.W3CBaggagePropagator];if(c==="tracecontext")return y.diag.debug("@vercel/otel: Configure propagator: tracecontext"),new ut.W3CTraceContextPropagator;if(c==="baggage")return y.diag.debug("@vercel/otel: Configure propagator: baggage"),new ut.W3CBaggagePropagator;if(typeof c=="string")throw new Error(`Unknown propagator: "${c}"`);return c}).flat()}var Ll="always_on",ce=1;function Vf(u,n){if(u&&typeof u!="string")return u;let o=u&&u!=="auto"?u:n.OTEL_TRACES_SAMPLER||Ll;switch(y.diag.debug("@vercel/otel: Configure sampler: ",o),o){case"always_on":return new $;case"always_off":return new pt;case"parentbased_always_on":return new Ot({root:new $});case"parentbased_always_off":return new Ot({root:new pt});case"traceidratio":return new Jt(Il(n));case"parentbased_traceidratio":return new Ot({root:new Jt(Il(n))});default:return y.diag.error(`@vercel/otel: OTEL_TRACES_SAMPLER value "${String(n.OTEL_TRACES_SAMPLER)} invalid, defaulting to ${Ll}".`),new $}}function Il(u){if(u.OTEL_TRACES_SAMPLER_ARG===void 0||u.OTEL_TRACES_SAMPLER_ARG==="")return y.diag.error(`@vercel/otel: OTEL_TRACES_SAMPLER_ARG is blank, defaulting to ${ce}.`),ce;y.diag.debug("@vercel/otel: Configure sampler probability: ",u.OTEL_TRACES_SAMPLER_ARG);let n=Number(u.OTEL_TRACES_SAMPLER_ARG);return isNaN(n)?(y.diag.error(`@vercel/otel: OTEL_TRACES_SAMPLER_ARG=${u.OTEL_TRACES_SAMPLER_ARG} was given, but it is invalid, defaulting to ${ce}.`),ce):n<0||n>1?(y.diag.error(`@vercel/otel: OTEL_TRACES_SAMPLER_ARG=${u.OTEL_TRACES_SAMPLER_ARG} was given, but it is out of range ([0..1]), defaulting to ${ce}.`),ce):n}function Gf(u,n,o){return(u??["auto"]).map(c=>{if(c==="auto"){if(process.env.VERCEL_OTEL_ENDPOINTS){let l=process.env.VERCEL_OTEL_ENDPOINTS_PORT||"4318",i=process.env.VERCEL_OTEL_ENDPOINTS_PROTOCOL||"http/protobuf";y.diag.debug("@vercel/otel: Configure vercel otel collector on port: ",l,i);let e={url:`http://localhost:${l}/v1/traces`,headers:{}},t=i==="http/protobuf"?new Ft(e):new re(e);return new ve(t)}return n.traceExporter||o.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT||o.OTEL_EXPORTER_OTLP_ENDPOINT?new ve(Hf(n.traceExporter,o)):void 0}return c}).filter(qf)}function Hf(u,n){if(u&&u!=="auto")return u;let o=process.env.OTEL_EXPORTER_OTLP_TRACES_PROTOCOL??process.env.OTEL_EXPORTER_OTLP_PROTOCOL??"http/protobuf",c=Ff(n),l={...ut.baggageUtils.parseKeyPairsIntoRecord(n.OTEL_EXPORTER_OTLP_HEADERS),...ut.baggageUtils.parseKeyPairsIntoRecord(n.OTEL_EXPORTER_OTLP_TRACES_HEADERS)};switch(y.diag.debug("@vercel/otel: Configure trace exporter: ",o,c,`headers: ${Object.keys(l).join(",")||"<none>"}`),o){case"http/json":return new re({url:c,headers:l});case"http/protobuf":return new Ft({url:c,headers:l});default:return y.diag.warn(`@vercel/otel: Unsupported OTLP traces protocol: ${o}. Using http/protobuf.`),new Ft}}var Ml="v1/traces",jf=`http://localhost:4318/${Ml}`;function Ff(u){let n=u.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT;if(n&&typeof n=="string")return n;let o=u.OTEL_EXPORTER_OTLP_ENDPOINT;return o&&typeof o=="string"?`${o}/${Ml}`:jf}function qf(u){return u!=null}function Jv(u){let n;u?typeof u=="string"?n={serviceName:u}:n=u:n={},new Fr(n).start()}export{le as FetchInstrumentation,re as OTLPHttpJsonTraceExporter,Ft as OTLPHttpProtoTraceExporter,Jv as registerOTel};
16
+ `,kn(a,n))}}catch(s){c={error:s}}finally{try{t&&!t.done&&(l=e.return)&&l.call(e)}finally{if(c)throw c.error}}return i},u}();var Va=function(){function u(n){this._backingStorages=n}return u.prototype.record=function(n,o,c,l){this._backingStorages.forEach(function(i){i.record(n,o,c,l)})},u}();b();b();var Ga=function(){function u(n,o){this._instrumentName=n,this._valueType=o,this._buffer=new nt}return u.prototype.observe=function(n,o){if(o===void 0&&(o={}),typeof n!="number"){y.diag.warn("non-number value provided to metric "+this._instrumentName+": "+n);return}this._valueType===y.ValueType.INT&&!Number.isInteger(n)&&(y.diag.warn("INT value type cannot accept a floating-point value for "+this._instrumentName+", ignoring the fractional digits."),n=Math.trunc(n),!Number.isInteger(n))||this._buffer.set(o,n)},u}();var Ha=function(){function u(){this._buffer=new Map}return u.prototype.observe=function(n,o,c){if(c===void 0&&(c={}),!!_e(n)){var l=this._buffer.get(n);if(l==null&&(l=new nt,this._buffer.set(n,l)),typeof o!="number"){y.diag.warn("non-number value provided to metric "+n._descriptor.name+": "+o);return}n._descriptor.valueType===y.ValueType.INT&&!Number.isInteger(o)&&(y.diag.warn("INT value type cannot accept a floating-point value for "+n._descriptor.name+", ignoring the fractional digits."),o=Math.trunc(o),!Number.isInteger(o))||l.set(c,o)}},u}();var Vn=function(u,n,o,c){function l(i){return i instanceof o?i:new o(function(e){e(i)})}return new(o||(o=Promise))(function(i,e){function t(s){try{a(c.next(s))}catch(d){e(d)}}function r(s){try{a(c.throw(s))}catch(d){e(d)}}function a(s){s.done?i(s.value):l(s.value).then(t,r)}a((c=c.apply(u,n||[])).next())})},Gn=function(u,n){var o={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},c,l,i,e;return e={next:t(0),throw:t(1),return:t(2)},typeof Symbol=="function"&&(e[Symbol.iterator]=function(){return this}),e;function t(a){return function(s){return r([a,s])}}function r(a){if(c)throw new TypeError("Generator is already executing.");for(;o;)try{if(c=1,l&&(i=a[0]&2?l.return:a[0]?l.throw||((i=l.return)&&i.call(l),0):l.next)&&!(i=i.call(l,a[1])).done)return i;switch(l=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,l=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(i=o.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){o=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(a[0]===6&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=n.call(u,o)}catch(s){a=[6,s],l=0}finally{c=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},ja=function(u,n){var o=typeof Symbol=="function"&&u[Symbol.iterator];if(!o)return u;var c=o.call(u),l,i=[],e;try{for(;(n===void 0||n-- >0)&&!(l=c.next()).done;)i.push(l.value)}catch(t){e={error:t}}finally{try{l&&!l.done&&(o=c.return)&&o.call(c)}finally{if(e)throw e.error}}return i},Fa=function(u,n,o){if(o||arguments.length===2)for(var c=0,l=n.length,i;c<l;c++)(i||!(c in n))&&(i||(i=Array.prototype.slice.call(n,0,c)),i[c]=n[c]);return u.concat(i||Array.prototype.slice.call(n))},qa=function(){function u(){this._callbacks=[],this._batchCallbacks=[]}return u.prototype.addCallback=function(n,o){var c=this._findCallback(n,o);c>=0||this._callbacks.push({callback:n,instrument:o})},u.prototype.removeCallback=function(n,o){var c=this._findCallback(n,o);c<0||this._callbacks.splice(c,1)},u.prototype.addBatchCallback=function(n,o){var c=new Set(o.filter(_e));if(c.size===0){y.diag.error("BatchObservableCallback is not associated with valid instruments",o);return}var l=this._findBatchCallback(n,c);l>=0||this._batchCallbacks.push({callback:n,instruments:c})},u.prototype.removeBatchCallback=function(n,o){var c=new Set(o.filter(_e)),l=this._findBatchCallback(n,c);l<0||this._batchCallbacks.splice(l,1)},u.prototype.observe=function(n,o){return Vn(this,void 0,void 0,function(){var c,l,i,e;return Gn(this,function(t){switch(t.label){case 0:return c=this._observeCallbacks(n,o),l=this._observeBatchCallbacks(n,o),[4,ba(Fa(Fa([],ja(c),!1),ja(l),!1))];case 1:return i=t.sent(),e=i.filter(Sa).map(function(r){return r.reason}),[2,e]}})})},u.prototype._observeCallbacks=function(n,o){var c=this;return this._callbacks.map(function(l){var i=l.callback,e=l.instrument;return Vn(c,void 0,void 0,function(){var t,r;return Gn(this,function(a){switch(a.label){case 0:return t=new Ga(e._descriptor.name,e._descriptor.valueType),r=Promise.resolve(i(t)),o!=null&&(r=Cn(r,o)),[4,r];case 1:return a.sent(),e._metricStorages.forEach(function(s){s.record(t._buffer,n)}),[2]}})})})},u.prototype._observeBatchCallbacks=function(n,o){var c=this;return this._batchCallbacks.map(function(l){var i=l.callback,e=l.instruments;return Vn(c,void 0,void 0,function(){var t,r;return Gn(this,function(a){switch(a.label){case 0:return t=new Ha,r=Promise.resolve(i(t)),o!=null&&(r=Cn(r,o)),[4,r];case 1:return a.sent(),e.forEach(function(s){var d=t._buffer.get(s);d!=null&&s._metricStorages.forEach(function(v){v.record(d,n)})}),[2]}})})})},u.prototype._findCallback=function(n,o){return this._callbacks.findIndex(function(c){return c.callback===n&&c.instrument===o})},u.prototype._findBatchCallback=function(n,o){return this._batchCallbacks.findIndex(function(c){return c.callback===n&&Ta(c.instruments,o)})},u}();var Sp=function(){var u=function(n,o){return u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,l){c.__proto__=l}||function(c,l){for(var i in l)Object.prototype.hasOwnProperty.call(l,i)&&(c[i]=l[i])},u(n,o)};return function(n,o){if(typeof o!="function"&&o!==null)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");u(n,o);function c(){this.constructor=n}n.prototype=o===null?Object.create(o):(c.prototype=o.prototype,new c)}}(),Ka=function(u){Sp(n,u);function n(o,c,l,i){var e=u.call(this,o)||this;return e._attributesProcessor=l,e._deltaMetricStorage=new br(c),e._temporalMetricStorage=new Sr(c,i),e}return n.prototype.record=function(o,c,l,i){c=this._attributesProcessor.process(c,l),this._deltaMetricStorage.record(o,c,l,i)},n.prototype.collect=function(o,c){var l=this._deltaMetricStorage.collect();return this._temporalMetricStorage.buildMetrics(o,this._instrumentDescriptor,l,c)},n}(Er);var Xa=function(){var u=function(n,o){return u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,l){c.__proto__=l}||function(c,l){for(var i in l)Object.prototype.hasOwnProperty.call(l,i)&&(c[i]=l[i])},u(n,o)};return function(n,o){if(typeof o!="function"&&o!==null)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");u(n,o);function c(){this.constructor=n}n.prototype=o===null?Object.create(o):(c.prototype=o.prototype,new c)}}(),Tr=function(){function u(){}return u.Noop=function(){return Op},u}();var Tp=function(u){Xa(n,u);function n(){return u!==null&&u.apply(this,arguments)||this}return n.prototype.process=function(o,c){return o},n}(Tr);var Zh=function(u){Xa(n,u);function n(o){var c=u.call(this)||this;return c._allowedAttributeNames=o,c}return n.prototype.process=function(o,c){var l=this,i={};return Object.keys(o).filter(function(e){return l._allowedAttributeNames.includes(e)}).forEach(function(e){return i[e]=o[e]}),i},n}(Tr);var Op=new Tp;var gp=function(u,n,o,c){function l(i){return i instanceof o?i:new o(function(e){e(i)})}return new(o||(o=Promise))(function(i,e){function t(s){try{a(c.next(s))}catch(d){e(d)}}function r(s){try{a(c.throw(s))}catch(d){e(d)}}function a(s){s.done?i(s.value):l(s.value).then(t,r)}a((c=c.apply(u,n||[])).next())})},Ap=function(u,n){var o={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},c,l,i,e;return e={next:t(0),throw:t(1),return:t(2)},typeof Symbol=="function"&&(e[Symbol.iterator]=function(){return this}),e;function t(a){return function(s){return r([a,s])}}function r(a){if(c)throw new TypeError("Generator is already executing.");for(;o;)try{if(c=1,l&&(i=a[0]&2?l.return:a[0]?l.throw||((i=l.return)&&i.call(l),0):l.next)&&!(i=i.call(l,a[1])).done)return i;switch(l=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,l=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(i=o.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){o=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(a[0]===6&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=n.call(u,o)}catch(s){a=[6,s],l=0}finally{c=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Np=function(u,n){var o=typeof Symbol=="function"&&u[Symbol.iterator];if(!o)return u;var c=o.call(u),l,i=[],e;try{for(;(n===void 0||n-- >0)&&!(l=c.next()).done;)i.push(l.value)}catch(t){e={error:t}}finally{try{l&&!l.done&&(o=c.return)&&o.call(c)}finally{if(e)throw e.error}}return i},Ya=function(){function u(n,o){this._meterProviderSharedState=n,this._instrumentationScope=o,this.metricStorageRegistry=new Ba,this.observableRegistry=new qa,this.meter=new Ua(this)}return u.prototype.registerMetricStorage=function(n){var o=this._registerMetricStorage(n,Ka);return o.length===1?o[0]:new Va(o)},u.prototype.registerAsyncMetricStorage=function(n){var o=this._registerMetricStorage(n,ka);return o},u.prototype.collect=function(n,o,c){return gp(this,void 0,void 0,function(){var l,i,e;return Ap(this,function(t){switch(t.label){case 0:return[4,this.observableRegistry.observe(o,c?.timeoutMillis)];case 1:return l=t.sent(),i=this.metricStorageRegistry.getStorages(n),i.length===0?[2,null]:(e=i.map(function(r){return r.collect(n,o)}).filter(va),e.length===0?[2,{errors:l}]:[2,{scopeMetrics:{scope:this._instrumentationScope,metrics:e},errors:l}])}})})},u.prototype._registerMetricStorage=function(n,o){var c=this,l=this._meterProviderSharedState.viewRegistry.findViews(n,this._instrumentationScope),i=l.map(function(r){var a=ga(r,n),s=c.metricStorageRegistry.findOrUpdateCompatibleStorage(a);if(s!=null)return s;var d=r.aggregation.createAggregator(a),v=new o(a,d,r.attributesProcessor,c._meterProviderSharedState.metricCollectors);return c.metricStorageRegistry.register(v),v});if(i.length===0){var e=this._meterProviderSharedState.selectAggregations(n.type),t=e.map(function(r){var a=Np(r,2),s=a[0],d=a[1],v=c.metricStorageRegistry.findOrUpdateCompatibleCollectorStorage(s,n);if(v!=null)return v;var S=d.createAggregator(n),g=new o(n,S,Tr.Noop(),[s]);return c.metricStorageRegistry.registerForCollector(s,g),g});i=i.concat(t)}return i},u}();var Pp=function(u){var n=typeof Symbol=="function"&&Symbol.iterator,o=n&&u[n],c=0;if(o)return o.call(u);if(u&&typeof u.length=="number")return{next:function(){return u&&c>=u.length&&(u=void 0),{value:u&&u[c++],done:!u}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},Ja=function(){function u(n){this.resource=n,this.viewRegistry=new Na,this.metricCollectors=[],this.meterSharedStates=new Map}return u.prototype.getMeterSharedState=function(n){var o=Ea(n),c=this.meterSharedStates.get(o);return c==null&&(c=new Ya(this,n),this.meterSharedStates.set(o,c)),c},u.prototype.selectAggregations=function(n){var o,c,l=[];try{for(var i=Pp(this.metricCollectors),e=i.next();!e.done;e=i.next()){var t=e.value;l.push([t,t.selectAggregation(n)])}}catch(r){o={error:r}}finally{try{e&&!e.done&&(c=i.return)&&c.call(i)}finally{if(o)throw o.error}}return l},u}();var za=P(D()),Or=function(u,n,o,c){function l(i){return i instanceof o?i:new o(function(e){e(i)})}return new(o||(o=Promise))(function(i,e){function t(s){try{a(c.next(s))}catch(d){e(d)}}function r(s){try{a(c.throw(s))}catch(d){e(d)}}function a(s){s.done?i(s.value):l(s.value).then(t,r)}a((c=c.apply(u,n||[])).next())})},gr=function(u,n){var o={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},c,l,i,e;return e={next:t(0),throw:t(1),return:t(2)},typeof Symbol=="function"&&(e[Symbol.iterator]=function(){return this}),e;function t(a){return function(s){return r([a,s])}}function r(a){if(c)throw new TypeError("Generator is already executing.");for(;o;)try{if(c=1,l&&(i=a[0]&2?l.return:a[0]?l.throw||((i=l.return)&&i.call(l),0):l.next)&&!(i=i.call(l,a[1])).done)return i;switch(l=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,l=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(i=o.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){o=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(a[0]===6&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=n.call(u,o)}catch(s){a=[6,s],l=0}finally{c=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},xp=function(u,n){var o=typeof Symbol=="function"&&u[Symbol.iterator];if(!o)return u;var c=o.call(u),l,i=[],e;try{for(;(n===void 0||n-- >0)&&!(l=c.next()).done;)i.push(l.value)}catch(t){e={error:t}}finally{try{l&&!l.done&&(o=c.return)&&o.call(c)}finally{if(e)throw e.error}}return i},Rp=function(u,n,o){if(o||arguments.length===2)for(var c=0,l=n.length,i;c<l;c++)(i||!(c in n))&&(i||(i=Array.prototype.slice.call(n,0,c)),i[c]=n[c]);return u.concat(i||Array.prototype.slice.call(n))},Wa=function(){function u(n,o){this._sharedState=n,this._metricReader=o}return u.prototype.collect=function(n){return Or(this,void 0,void 0,function(){var o,c,l,i,e=this;return gr(this,function(t){switch(t.label){case 0:return o=(0,za.millisToHrTime)(Date.now()),c=[],l=[],i=Array.from(this._sharedState.meterSharedStates.values()).map(function(r){return Or(e,void 0,void 0,function(){var a;return gr(this,function(s){switch(s.label){case 0:return[4,r.collect(this,o,n)];case 1:return a=s.sent(),a?.scopeMetrics!=null&&c.push(a.scopeMetrics),a?.errors!=null&&l.push.apply(l,Rp([],xp(a.errors),!1)),[2]}})})}),[4,Promise.all(i)];case 1:return t.sent(),[2,{resourceMetrics:{resource:this._sharedState.resource,scopeMetrics:c},errors:l}]}})})},u.prototype.forceFlush=function(n){return Or(this,void 0,void 0,function(){return gr(this,function(o){switch(o.label){case 0:return[4,this._metricReader.forceFlush(n)];case 1:return o.sent(),[2]}})})},u.prototype.shutdown=function(n){return Or(this,void 0,void 0,function(){return gr(this,function(o){switch(o.label){case 0:return[4,this._metricReader.shutdown(n)];case 1:return o.sent(),[2]}})})},u.prototype.selectAggregationTemporality=function(n){return this._metricReader.selectAggregationTemporality(n)},u.prototype.selectAggregation=function(n){return this._metricReader.selectAggregation(n)},u}();var $a=function(u,n,o,c){function l(i){return i instanceof o?i:new o(function(e){e(i)})}return new(o||(o=Promise))(function(i,e){function t(s){try{a(c.next(s))}catch(d){e(d)}}function r(s){try{a(c.throw(s))}catch(d){e(d)}}function a(s){s.done?i(s.value):l(s.value).then(t,r)}a((c=c.apply(u,n||[])).next())})},Qa=function(u,n){var o={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},c,l,i,e;return e={next:t(0),throw:t(1),return:t(2)},typeof Symbol=="function"&&(e[Symbol.iterator]=function(){return this}),e;function t(a){return function(s){return r([a,s])}}function r(a){if(c)throw new TypeError("Generator is already executing.");for(;o;)try{if(c=1,l&&(i=a[0]&2?l.return:a[0]?l.throw||((i=l.return)&&i.call(l),0):l.next)&&!(i=i.call(l,a[1])).done)return i;switch(l=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,l=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(i=o.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){o=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(a[0]===6&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=n.call(u,o)}catch(s){a=[6,s],l=0}finally{c=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Lp=function(u){var n=typeof Symbol=="function"&&Symbol.iterator,o=n&&u[n],c=0;if(o)return o.call(u);if(u&&typeof u.length=="number")return{next:function(){return u&&c>=u.length&&(u=void 0),{value:u&&u[c++],done:!u}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},Hn=function(){function u(n){var o,c,l;this._shutdown=!1;var i=K.default().merge((l=n?.resource)!==null&&l!==void 0?l:K.empty());if(this._sharedState=new Ja(i),n?.views!=null&&n.views.length>0)try{for(var e=Lp(n.views),t=e.next();!t.done;t=e.next()){var r=t.value;this._sharedState.viewRegistry.addView(r)}}catch(a){o={error:a}}finally{try{t&&!t.done&&(c=e.return)&&c.call(e)}finally{if(o)throw o.error}}}return u.prototype.getMeter=function(n,o,c){return o===void 0&&(o=""),c===void 0&&(c={}),this._shutdown?(y.diag.warn("A shutdown MeterProvider cannot provide a Meter"),(0,y.createNoopMeter)()):this._sharedState.getMeterSharedState({name:n,version:o,schemaUrl:c.schemaUrl}).meter},u.prototype.addMetricReader=function(n){var o=new Wa(this._sharedState,n);n.setMetricProducer(o),this._sharedState.metricCollectors.push(o)},u.prototype.shutdown=function(n){return $a(this,void 0,void 0,function(){return Qa(this,function(o){switch(o.label){case 0:return this._shutdown?(y.diag.warn("shutdown may only be called once per MeterProvider"),[2]):(this._shutdown=!0,[4,Promise.all(this._sharedState.metricCollectors.map(function(c){return c.shutdown(n)}))]);case 1:return o.sent(),[2]}})})},u.prototype.forceFlush=function(n){return $a(this,void 0,void 0,function(){return Qa(this,function(o){switch(o.label){case 0:return this._shutdown?(y.diag.warn("invalid attempt to force flush after MeterProvider shutdown"),[2]):[4,Promise.all(this._sharedState.metricCollectors.map(function(c){return c.forceFlush(n)}))];case 1:return o.sent(),[2]}})})},u}();var Cl=P(St(),1),se=P(ke(),1),Ul=P(ru(),1),ut=P(D(),1);b();var Dp=Symbol.for("@vercel/request-context");function te(){return globalThis[Dp]?.get()}var qn=P(St(),1);function Pr(u){return Object.fromEntries(Object.entries(u).filter(([n,o])=>o!==void 0))}function nu(u){return u?u.split("::").at(-1):void 0}function ou(u=te()){if(u)return Pr({[qn.SemanticAttributes.HTTP_HOST]:u.headers.host,[qn.SemanticAttributes.HTTP_USER_AGENT]:u.headers["user-agent"],"http.referer":u.headers.referer,"vercel.request_id":nu(u.headers["x-vercel-id"]),"vercel.matched_path":u.headers["x-matched-path"],"vercel.edge_region":u.headers["x-vercel-edge-region"]})}b();function Se(u){return(u&y.TraceFlags.SAMPLED)!==0}var xr=class{constructor(n){this.processors=n;this.rootSpanIds=new Map;this.waitSpanEnd=new Map}forceFlush(){return Promise.all(this.processors.map(n=>n.forceFlush().catch(o=>{y.diag.error("@vercel/otel: forceFlush failed:",o)}))).then(()=>{})}shutdown(){return Promise.all(this.processors.map(n=>n.shutdown().catch(()=>{}))).then(()=>{})}onStart(n,o){let{traceId:c,spanId:l,traceFlags:i}=n.spanContext(),e=!n.parentSpanId||!this.rootSpanIds.has(c);if(e?this.rootSpanIds.set(c,{rootSpanId:l,open:[]}):this.rootSpanIds.get(c)?.open.push(n),e&&Se(i)){let t=ou();t&&n.setAttributes(t);let r=te();r&&r.waitUntil(async()=>{if(this.rootSpanIds.has(c)){let a=new Promise(d=>{this.waitSpanEnd.set(c,d)}),s;await Promise.race([a,new Promise(d=>{s=setTimeout(()=>{this.waitSpanEnd.delete(c),d(void 0)},50)})]),s&&clearTimeout(s)}return this.forceFlush()})}for(let t of this.processors)t.onStart(n,o)}onEnd(n){let{traceId:o,spanId:c,traceFlags:l}=n.spanContext(),i=Se(l),e=this.rootSpanIds.get(o),t=e?.rootSpanId===c;if(i){let r=kp(n);r&&Object.assign(n.attributes,r)}if(t){if(this.rootSpanIds.delete(o),e.open.length>0){for(let r of e.open)if(!r.ended&&r.spanContext().spanId!==c)try{r.end()}catch(a){y.diag.error("@vercel/otel: onEnd failed:",a)}}}else if(e)for(let r=0;r<e.open.length;r++)e.open[r]?.spanContext().spanId===c&&e.open.splice(r,1);for(let r of this.processors)r.onEnd(n);if(t){let r=this.waitSpanEnd.get(o);r&&(this.waitSpanEnd.delete(o),r())}}},iu={[y.SpanKind.INTERNAL]:"internal",[y.SpanKind.SERVER]:"server",[y.SpanKind.CLIENT]:"client",[y.SpanKind.PRODUCER]:"producer",[y.SpanKind.CONSUMER]:"consumer"};function kp(u){let{kind:n,attributes:o}=u,{"operation.name":c,"resouce.name":l,"span.type":i,"next.span_type":e,"http.method":t,"http.route":r}=o;if(c)return;let a=u.instrumentationLibrary.name,s=e??i;if(s&&typeof s=="string"){let d=Kn(a,s);return r?{"operation.name":d,"resource.name":l??r}:{"operation.name":d}}return t&&r&&typeof t=="string"&&typeof r=="string"?{"operation.name":Kn(a,`http.${iu[n]||"internal"}.${t}`),"resource.name":l??r}:{"operation.name":Kn(a,n===y.SpanKind.INTERNAL?"":iu[n])}}function Kn(u,n){if(!u)return n;let o=u.replace(/[ @./]/g,"_");return o.startsWith("_")&&(o=o.slice(1)),n?`${o}.${n}`:o}var _u=P(Qn(),1);var vu=P(wr(),1);b();var ee=class extends vu.OTLPExporterBase{constructor(n={}){super(n),n.headers&&(this._headers=n.headers)}onShutdown(){y.diag.debug("@vercel/otel/otlp: onShutdown")}onInit(){y.diag.debug("@vercel/otel/otlp: onInit")}send(n,o,c){if(this._shutdownOnce.isCalled){y.diag.debug("@vercel/otel/otlp: Shutdown already started. Cannot send objects");return}let l=this.convert(n),i,e,t;try{({body:i,contentType:e,headers:t}=this.toMessage(l))}catch(a){y.diag.warn("@vercel/otel/otlp: no proto",a);return}let r=fetch(this.url,{method:"POST",body:i,headers:{...this._headers,...t,"Content-Type":e,"User-Agent":"OTel-OTLP-Exporter-JavaScript/0.46.0"},next:{internal:!0}}).then(a=>{y.diag.debug("@vercel/otel/otlp: onSuccess",a.status,a.statusText),o(),a.arrayBuffer().catch(()=>{})}).catch(a=>{y.diag.error("@vercel/otel/otlp: onError",a),c(a)}).finally(()=>{let a=this._sendingPromises.indexOf(r);this._sendingPromises.splice(a,1)});this._sendingPromises.push(r)}getDefaultUrl(n){throw new Error("Method not implemented.")}};var of="v1/traces",af=`http://localhost:4318/${of}`;function Cr(u){return typeof u.url=="string"?u.url:af}var re=class{constructor(n={}){this.impl=new ro(n)}export(n,o){this.impl.export(n,o)}shutdown(){return this.impl.shutdown()}forceFlush(){return this.impl.forceFlush()}},ro=class extends ee{convert(n){return(0,_u.createExportTraceServiceRequest)(n,{useHex:!0,useLongBits:!1})}toMessage(n){return{body:JSON.stringify(n),contentType:"application/json"}}getDefaultUrl(n){return Cr(n)}};var Nl=P(Qn(),1),Pl=P(Al(),1),xl=P(Oo(),1);var Ft=class{constructor(n={}){this.impl=new No(n)}export(n,o){this.impl.export(n,o)}shutdown(){return this.impl.shutdown()}forceFlush(){return this.impl.forceFlush()}},No=class extends ee{convert(n){return(0,Nl.createExportTraceServiceRequest)(n,void 0)}toMessage(n){let o=Pl.ServiceClientType.SPANS,c=(0,xl.getExportRequestProto)(o),l=c.create(n);return{body:c.encode(l).finish(),contentType:"application/x-protobuf",headers:{accept:"application/x-protobuf"}}}getDefaultUrl(n){return Cr(n)}};b();var mt=P(St(),1);function Rl(u,n){return u.replace(/\{(?<temp1>[^{}]+)\}/g,(o,c)=>{let l=n[c];return l!==void 0?String(l):o})}var le=class{constructor(n={}){this.instrumentationName="@vercel/otel/fetch";this.instrumentationVersion="1.0.0";this.config=n}getConfig(){return this.config}setConfig(){}setTracerProvider(n){this.tracerProvider=n}setMeterProvider(){}enable(){this.disable();let{tracerProvider:n}=this;if(!n)return;let o=n.getTracer(this.instrumentationName,this.instrumentationVersion),c=this.config.ignoreUrls??[],l=(S,g)=>{if(g?.opentelemetry?.ignore!==void 0)return g.opentelemetry.ignore;if(c.length===0)return!1;let R=S.toString();return c.some(A=>typeof A=="string"?A==="*"?!0:R.startsWith(A):A.test(R))},i=process.env.VERCEL_URL||process.env.NEXT_PUBLIC_VERCEL_URL||null,e=process.env.VERCEL_BRANCH_URL||process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL||null,t=this.config.propagateContextUrls??[],r=this.config.dontPropagateContextUrls??[],a=this.config.resourceNameTemplate,s=(S,g)=>{if(g?.opentelemetry?.propagateContext)return g.opentelemetry.propagateContext;let R=S.toString();return r.length>0&&r.some(A=>typeof A=="string"?A==="*"?!0:R.startsWith(A):A.test(R))?!1:i&&S.protocol==="https:"&&(S.host===i||S.host===e||S.host===te()?.headers.host)||!i&&S.protocol==="http:"&&S.hostname==="localhost"?!0:t.some(A=>typeof A=="string"?A==="*"?!0:R.startsWith(A):A.test(R))};process.env.NEXT_OTEL_FETCH_DISABLED="1";let d=globalThis.fetch;this.originalFetch=d;let v=async(S,g)=>{let R=g;if(R?.next?.internal)return d(S,R);let A=new Request(S instanceof Request?S.clone():S,R),X=new URL(A.url);if(l(X,R))return d(S,R);let Y={[mt.SemanticAttributes.HTTP_METHOD]:A.method,[mt.SemanticAttributes.HTTP_URL]:A.url,[mt.SemanticAttributes.HTTP_HOST]:X.host,[mt.SemanticAttributes.HTTP_SCHEME]:X.protocol.replace(":",""),[mt.SemanticAttributes.NET_PEER_NAME]:X.hostname,[mt.SemanticAttributes.NET_PEER_PORT]:X.port},Le=a?Rl(a,Y):Uf(A.url),qr=R?.opentelemetry?.spanName??`fetch ${A.method} ${A.url}`,H=o.startSpan(qr,{kind:y.SpanKind.CLIENT,attributes:{...Y,"operation.name":`fetch.${A.method}`,"resource.name":Le,...R?.opentelemetry?.attributes}},y.context.active());if(!H.isRecording()||!Se(H.spanContext().traceFlags))return H.end(),d(S,R);s(X,R)&&y.propagation.inject(y.context.active(),A.headers,Cf);try{let wt=Date.now(),Ct=await d(S,{...R,headers:A.headers}),Dl=Date.now()-wt;return H.setAttribute(mt.SemanticAttributes.HTTP_STATUS_CODE,Ct.status),H.setAttribute("http.response_time",Dl),Ct.status>=500&&Po(H,`Status: ${Ct.status} (${Ct.statusText})`),Ct.body?Mf(Ct).then(Kr=>{H.isRecording()&&(H.setAttribute(mt.SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED,Kr),H.end())},Kr=>{H.isRecording()&&(Po(H,Kr),H.end())}):H.end(),Ct}catch(wt){throw Po(H,wt),H.end(),wt}};globalThis.fetch=v}disable(){this.originalFetch&&(globalThis.fetch=this.originalFetch)}},Cf={set(u,n,o){u.set(n,o)}};function Uf(u){let n=u.indexOf("?");return n===-1?u:u.substring(0,n)}function Mf(u){let n=0,c=u.clone().body?.getReader();if(!c)return Promise.resolve(0);let l=()=>c.read().then(({done:i,value:e})=>{if(!i)return n+=e.byteLength,l()});return l().then(()=>n)}function Po(u,n){if(n instanceof Error)u.recordException(n),u.setStatus({code:y.SpanStatusCode.ERROR,message:n.message});else{let o=String(n);u.setStatus({code:y.SpanStatusCode.ERROR,message:o})}}var Fr=class{constructor(n={}){this.configuration=n}start(){let n=Df(),o=(0,se.getEnvWithoutDefaults)(),c=this.configuration,l=process.env.NEXT_RUNTIME||"nodejs",i=!!n.OTEL_SDK_DISABLED;if(o.OTEL_LOG_LEVEL&&y.diag.setLogger(new y.DiagConsoleLogger,{logLevel:o.OTEL_LOG_LEVEL}),i)return;let e=c.idGenerator??new fr,t=c.contextManager??new Ul.AsyncLocalStorageContextManager;t.enable(),this.contextManager=t;let r=n.OTEL_SERVICE_NAME||c.serviceName||"app",a=new K(Pr({[Cl.SemanticResourceAttributes.SERVICE_NAME]:r,"node.ci":process.env.CI?!0:void 0,"node.env":"production","vercel.env":process.env.VERCEL_ENV||process.env.NEXT_PUBLIC_VERCEL_ENV,"vercel.region":process.env.VERCEL_REGION,"vercel.runtime":l,"vercel.sha":process.env.VERCEL_GIT_COMMIT_SHA||process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA,"vercel.host":process.env.VERCEL_URL||process.env.NEXT_PUBLIC_VERCEL_URL||void 0,"vercel.branch_host":process.env.VERCEL_BRANCH_URL||process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL||void 0,...c.attributes})),s=c.resourceDetectors??[Ji];if(c.autoDetectResources??!0){let Y={detectors:s};a=a.merge(Wi(Y))}let v=Bf(c.propagators,n),S=Vf(c.traceSampler,n),g=Gf(c.spanProcessors,c,n);g.length===0&&y.diag.warn("@vercel/otel: No span processors configured. No spans will be exported.");let R=c.spanLimits,A=new ta({resource:a,idGenerator:e,sampler:S,spanLimits:R});if(A.addSpanProcessor(new xr(g)),A.register({contextManager:t,propagator:new ut.CompositePropagator({propagators:v})}),this.tracerProvider=A,c.logRecordProcessor){let Y=new wn({resource:a});this.loggerProvider=Y,Y.addLogRecordProcessor(c.logRecordProcessor),ft.logs.setGlobalLoggerProvider(Y)}if(c.metricReader||c.views){let Y=new Hn({resource:a,views:c.views??[]});c.metricReader&&Y.addMetricReader(c.metricReader),y.metrics.setGlobalMeterProvider(Y),this.meterProvider=Y}let X=kf(c.instrumentations,c.instrumentationConfig);this.disableInstumentations=(0,wl.registerInstrumentations)({instrumentations:X}),y.diag.info("@vercel/otel: started",r,l)}async shutdown(){let n=[];this.tracerProvider&&n.push(this.tracerProvider.shutdown()),this.loggerProvider&&n.push(this.loggerProvider.shutdown()),this.meterProvider&&n.push(this.meterProvider.shutdown()),y.diag.info("@vercel/otel: shutting down",n.length,process.env.NEXT_RUNTIME),await Promise.all(n),this.contextManager&&this.contextManager.disable();let{disableInstumentations:o}=this;o&&o()}};function Df(){let u=(0,se.parseEnvironment)(process.env);return{...se.DEFAULT_ENVIRONMENT,...u}}function kf(u,n){return(u??["auto"]).map(o=>o==="auto"?(y.diag.debug("@vercel/otel: Configure instrumentations: fetch",n?.fetch),[new le(n?.fetch)]):o==="fetch"?(y.diag.debug("@vercel/otel: Configure instrumentations: fetch",n?.fetch),new le(n?.fetch)):o).flat()}function Bf(u,n){let o=n.OTEL_PROPAGATORS&&n.OTEL_PROPAGATORS.length>0?n.OTEL_PROPAGATORS:void 0;return(u??o??["auto"]).map(c=>{if(c==="none")return[];if(c==="auto")return y.diag.debug("@vercel/otel: Configure propagators: tracecontext, baggage"),[new ut.W3CTraceContextPropagator,new ut.W3CBaggagePropagator];if(c==="tracecontext")return y.diag.debug("@vercel/otel: Configure propagator: tracecontext"),new ut.W3CTraceContextPropagator;if(c==="baggage")return y.diag.debug("@vercel/otel: Configure propagator: baggage"),new ut.W3CBaggagePropagator;if(typeof c=="string")throw new Error(`Unknown propagator: "${c}"`);return c}).flat()}var Ll="always_on",ce=1;function Vf(u,n){if(u&&typeof u!="string")return u;let o=u&&u!=="auto"?u:n.OTEL_TRACES_SAMPLER||Ll;switch(y.diag.debug("@vercel/otel: Configure sampler: ",o),o){case"always_on":return new $;case"always_off":return new pt;case"parentbased_always_on":return new Ot({root:new $});case"parentbased_always_off":return new Ot({root:new pt});case"traceidratio":return new Jt(Il(n));case"parentbased_traceidratio":return new Ot({root:new Jt(Il(n))});default:return y.diag.error(`@vercel/otel: OTEL_TRACES_SAMPLER value "${String(n.OTEL_TRACES_SAMPLER)} invalid, defaulting to ${Ll}".`),new $}}function Il(u){if(u.OTEL_TRACES_SAMPLER_ARG===void 0||u.OTEL_TRACES_SAMPLER_ARG==="")return y.diag.error(`@vercel/otel: OTEL_TRACES_SAMPLER_ARG is blank, defaulting to ${ce}.`),ce;y.diag.debug("@vercel/otel: Configure sampler probability: ",u.OTEL_TRACES_SAMPLER_ARG);let n=Number(u.OTEL_TRACES_SAMPLER_ARG);return isNaN(n)?(y.diag.error(`@vercel/otel: OTEL_TRACES_SAMPLER_ARG=${u.OTEL_TRACES_SAMPLER_ARG} was given, but it is invalid, defaulting to ${ce}.`),ce):n<0||n>1?(y.diag.error(`@vercel/otel: OTEL_TRACES_SAMPLER_ARG=${u.OTEL_TRACES_SAMPLER_ARG} was given, but it is out of range ([0..1]), defaulting to ${ce}.`),ce):n}function Gf(u,n,o){return(u??["auto"]).map(c=>{if(c==="auto"){if(process.env.VERCEL_OTEL_ENDPOINTS){let l=process.env.VERCEL_OTEL_ENDPOINTS_PORT||"4318",i=process.env.VERCEL_OTEL_ENDPOINTS_PROTOCOL||"http/protobuf";y.diag.debug("@vercel/otel: Configure vercel otel collector on port: ",l,i);let e={url:`http://localhost:${l}/v1/traces`,headers:{}},t=i==="http/protobuf"?new Ft(e):new re(e);return new ve(t)}return n.traceExporter||o.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT||o.OTEL_EXPORTER_OTLP_ENDPOINT?new ve(Hf(n.traceExporter,o)):void 0}return c}).filter(qf)}function Hf(u,n){if(u&&u!=="auto")return u;let o=process.env.OTEL_EXPORTER_OTLP_TRACES_PROTOCOL??process.env.OTEL_EXPORTER_OTLP_PROTOCOL??"http/protobuf",c=Ff(n),l={...ut.baggageUtils.parseKeyPairsIntoRecord(n.OTEL_EXPORTER_OTLP_HEADERS),...ut.baggageUtils.parseKeyPairsIntoRecord(n.OTEL_EXPORTER_OTLP_TRACES_HEADERS)};switch(y.diag.debug("@vercel/otel: Configure trace exporter: ",o,c,`headers: ${Object.keys(l).join(",")||"<none>"}`),o){case"http/json":return new re({url:c,headers:l});case"http/protobuf":return new Ft({url:c,headers:l});default:return y.diag.warn(`@vercel/otel: Unsupported OTLP traces protocol: ${o}. Using http/protobuf.`),new Ft}}var Ml="v1/traces",jf=`http://localhost:4318/${Ml}`;function Ff(u){let n=u.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT;if(n&&typeof n=="string")return n;let o=u.OTEL_EXPORTER_OTLP_ENDPOINT;return o&&typeof o=="string"?`${o}/${Ml}`:jf}function qf(u){return u!=null}function Jv(u){let n;u?typeof u=="string"?n={serviceName:u}:n=u:n={},new Fr(n).start()}export{le as FetchInstrumentation,re as OTLPHttpJsonTraceExporter,Ft as OTLPHttpProtoTraceExporter,Jv as registerOTel};