@vercel/otel 1.8.2 → 1.8.3

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.
package/README.md CHANGED
@@ -14,7 +14,7 @@ npm install @vercel/otel
14
14
 
15
15
  ## 📚 Usage
16
16
 
17
- To configure OpenTelemetry SDK, call the `registerOTel` in the `instumentation.ts`:
17
+ To configure OpenTelemetry SDK, call the `registerOTel` in the `instrumentation.ts`:
18
18
 
19
19
  ```javascript
20
20
  import { registerOTel } from "@vercel/otel";
@@ -13,4 +13,5 @@ var au=Object.create;var Ir=Object.defineProperty;var su=Object.getOwnPropertyDe
13
13
  To resolve the conflict:`,gn(a,e))),i=c):f.diag.warn("A view or instrument with the name ",e.name,` has already been registered and is incompatible with another registered view.
14
14
  `,`Details:
15
15
  `,Sn(a,e),`To resolve the conflict:
16
- `,gn(a,e))}}catch(l){n={error:l}}finally{try{u&&!u.done&&(o=s.return)&&o.call(s)}finally{if(n)throw n.error}}return i},t}();var _a=function(){function t(e){this._backingStorages=e}return t.prototype.record=function(e,r,n,o){this._backingStorages.forEach(function(i){i.record(e,r,n,o)})},t}();E();E();var da=function(){function t(e,r){this._instrumentName=e,this._valueType=r,this._buffer=new Q}return t.prototype.observe=function(e,r){if(r===void 0&&(r={}),typeof e!="number"){f.diag.warn("non-number value provided to metric "+this._instrumentName+": "+e);return}this._valueType===f.ValueType.INT&&!Number.isInteger(e)&&(f.diag.warn("INT value type cannot accept a floating-point value for "+this._instrumentName+", ignoring the fractional digits."),e=Math.trunc(e),!Number.isInteger(e))||this._buffer.set(r,e)},t}();var ha=function(){function t(){this._buffer=new Map}return t.prototype.observe=function(e,r,n){if(n===void 0&&(n={}),!!lt(e)){var o=this._buffer.get(e);if(o==null&&(o=new Q,this._buffer.set(e,o)),typeof r!="number"){f.diag.warn("non-number value provided to metric "+e._descriptor.name+": "+r);return}e._descriptor.valueType===f.ValueType.INT&&!Number.isInteger(r)&&(f.diag.warn("INT value type cannot accept a floating-point value for "+e._descriptor.name+", ignoring the fractional digits."),r=Math.trunc(r),!Number.isInteger(r))||o.set(n,r)}},t}();var vn=function(t,e,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function u(l){try{a(n.next(l))}catch(p){s(p)}}function c(l){try{a(n.throw(l))}catch(p){s(p)}}function a(l){l.done?i(l.value):o(l.value).then(u,c)}a((n=n.apply(t,e||[])).next())})},An=function(t,e){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:u(0),throw:u(1),return:u(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function u(a){return function(l){return c([a,l])}}function c(a){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return r.label++,{value:a[1],done:!1};case 5:r.label++,o=a[1],a=[0];continue;case 7:a=r.ops.pop(),r.trys.pop();continue;default:if(i=r.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){r=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){r.label=a[1];break}if(a[0]===6&&r.label<i[1]){r.label=i[1],i=a;break}if(i&&r.label<i[2]){r.label=i[2],r.ops.push(a);break}i[2]&&r.ops.pop(),r.trys.pop();continue}a=e.call(t,r)}catch(l){a=[6,l],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Ea=function(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),o,i=[],s;try{for(;(e===void 0||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(u){s={error:u}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(s)throw s.error}}return i},ma=function(t,e,r){if(r||arguments.length===2)for(var n=0,o=e.length,i;n<o;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return t.concat(i||Array.prototype.slice.call(e))},Ta=function(){function t(){this._callbacks=[],this._batchCallbacks=[]}return t.prototype.addCallback=function(e,r){var n=this._findCallback(e,r);n>=0||this._callbacks.push({callback:e,instrument:r})},t.prototype.removeCallback=function(e,r){var n=this._findCallback(e,r);n<0||this._callbacks.splice(n,1)},t.prototype.addBatchCallback=function(e,r){var n=new Set(r.filter(lt));if(n.size===0){f.diag.error("BatchObservableCallback is not associated with valid instruments",r);return}var o=this._findBatchCallback(e,n);o>=0||this._batchCallbacks.push({callback:e,instruments:n})},t.prototype.removeBatchCallback=function(e,r){var n=new Set(r.filter(lt)),o=this._findBatchCallback(e,n);o<0||this._batchCallbacks.splice(o,1)},t.prototype.observe=function(e,r){return vn(this,void 0,void 0,function(){var n,o,i,s;return An(this,function(u){switch(u.label){case 0:return n=this._observeCallbacks(e,r),o=this._observeBatchCallbacks(e,r),[4,Yo(ma(ma([],Ea(n),!1),Ea(o),!1))];case 1:return i=u.sent(),s=i.filter(zo).map(function(c){return c.reason}),[2,s]}})})},t.prototype._observeCallbacks=function(e,r){var n=this;return this._callbacks.map(function(o){var i=o.callback,s=o.instrument;return vn(n,void 0,void 0,function(){var u,c;return An(this,function(a){switch(a.label){case 0:return u=new da(s._descriptor.name,s._descriptor.valueType),c=Promise.resolve(i(u)),r!=null&&(c=En(c,r)),[4,c];case 1:return a.sent(),s._metricStorages.forEach(function(l){l.record(u._buffer,e)}),[2]}})})})},t.prototype._observeBatchCallbacks=function(e,r){var n=this;return this._batchCallbacks.map(function(o){var i=o.callback,s=o.instruments;return vn(n,void 0,void 0,function(){var u,c;return An(this,function(a){switch(a.label){case 0:return u=new ha,c=Promise.resolve(i(u)),r!=null&&(c=En(c,r)),[4,c];case 1:return a.sent(),s.forEach(function(l){var p=u._buffer.get(l);p!=null&&l._metricStorages.forEach(function(d){d.record(p,e)})}),[2]}})})})},t.prototype._findCallback=function(e,r){return this._callbacks.findIndex(function(n){return n.callback===e&&n.instrument===r})},t.prototype._findBatchCallback=function(e,r){return this._batchCallbacks.findIndex(function(n){return n.callback===e&&$o(n.instruments,r)})},t}();var ql=function(){var t=function(e,r){return t=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])},t(e,r)};return function(e,r){if(typeof r!="function"&&r!==null)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");t(e,r);function n(){this.constructor=e}e.prototype=r===null?Object.create(r):(n.prototype=r.prototype,new n)}}(),Sa=function(t){ql(e,t);function e(r,n,o,i){var s=t.call(this,r)||this;return s._attributesProcessor=o,s._deltaMetricStorage=new cr(n),s._temporalMetricStorage=new lr(n,i),s}return e.prototype.record=function(r,n,o,i){n=this._attributesProcessor.process(n,o),this._deltaMetricStorage.record(r,n,o,i)},e.prototype.collect=function(r,n){var o=this._deltaMetricStorage.collect();return this._temporalMetricStorage.buildMetrics(r,this._instrumentDescriptor,o,n)},e}(ur);var ga=function(){var t=function(e,r){return t=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])},t(e,r)};return function(e,r){if(typeof r!="function"&&r!==null)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");t(e,r);function n(){this.constructor=e}e.prototype=r===null?Object.create(r):(n.prototype=r.prototype,new n)}}(),fr=function(){function t(){}return t.Noop=function(){return Kl},t}();var Xl=function(t){ga(e,t);function e(){return t!==null&&t.apply(this,arguments)||this}return e.prototype.process=function(r,n){return r},e}(fr);var gh=function(t){ga(e,t);function e(r){var n=t.call(this)||this;return n._allowedAttributeNames=r,n}return e.prototype.process=function(r,n){var o=this,i={};return Object.keys(r).filter(function(s){return o._allowedAttributeNames.includes(s)}).forEach(function(s){return i[s]=r[s]}),i},e}(fr);var Kl=new Xl;var Wl=function(t,e,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function u(l){try{a(n.next(l))}catch(p){s(p)}}function c(l){try{a(n.throw(l))}catch(p){s(p)}}function a(l){l.done?i(l.value):o(l.value).then(u,c)}a((n=n.apply(t,e||[])).next())})},Yl=function(t,e){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:u(0),throw:u(1),return:u(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function u(a){return function(l){return c([a,l])}}function c(a){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return r.label++,{value:a[1],done:!1};case 5:r.label++,o=a[1],a=[0];continue;case 7:a=r.ops.pop(),r.trys.pop();continue;default:if(i=r.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){r=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){r.label=a[1];break}if(a[0]===6&&r.label<i[1]){r.label=i[1],i=a;break}if(i&&r.label<i[2]){r.label=i[2],r.ops.push(a);break}i[2]&&r.ops.pop(),r.trys.pop();continue}a=e.call(t,r)}catch(l){a=[6,l],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},zl=function(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),o,i=[],s;try{for(;(e===void 0||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(u){s={error:u}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(s)throw s.error}}return i},ya=function(){function t(e,r){this._meterProviderSharedState=e,this._instrumentationScope=r,this.metricStorageRegistry=new pa,this.observableRegistry=new Ta,this.meter=new ua(this)}return t.prototype.registerMetricStorage=function(e){var r=this._registerMetricStorage(e,Sa);return r.length===1?r[0]:new _a(r)},t.prototype.registerAsyncMetricStorage=function(e){var r=this._registerMetricStorage(e,fa);return r},t.prototype.collect=function(e,r,n){return Wl(this,void 0,void 0,function(){var o,i,s;return Yl(this,function(u){switch(u.label){case 0:return[4,this.observableRegistry.observe(r,n?.timeoutMillis)];case 1:return o=u.sent(),i=this.metricStorageRegistry.getStorages(e),i.length===0?[2,null]:(s=i.map(function(c){return c.collect(e,r)}).filter(Xo),s.length===0?[2,{errors:o}]:[2,{scopeMetrics:{scope:this._instrumentationScope,metrics:s},errors:o}])}})})},t.prototype._registerMetricStorage=function(e,r){var n=this,o=this._meterProviderSharedState.viewRegistry.findViews(e,this._instrumentationScope),i=o.map(function(c){var a=Zo(c,e),l=n.metricStorageRegistry.findOrUpdateCompatibleStorage(a);if(l!=null)return l;var p=c.aggregation.createAggregator(a),d=new r(a,p,c.attributesProcessor,n._meterProviderSharedState.metricCollectors);return n.metricStorageRegistry.register(d),d});if(i.length===0){var s=this._meterProviderSharedState.selectAggregations(e.type),u=s.map(function(c){var a=zl(c,2),l=a[0],p=a[1],d=n.metricStorageRegistry.findOrUpdateCompatibleCollectorStorage(l,e);if(d!=null)return d;var g=p.createAggregator(e),U=new r(e,g,fr.Noop(),[l]);return n.metricStorageRegistry.registerForCollector(l,U),U});i=i.concat(u)}return i},t}();var $l=function(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},va=function(){function t(e){this.resource=e,this.viewRegistry=new ea,this.metricCollectors=[],this.meterSharedStates=new Map}return t.prototype.getMeterSharedState=function(e){var r=Wo(e),n=this.meterSharedStates.get(r);return n==null&&(n=new ya(this,e),this.meterSharedStates.set(r,n)),n},t.prototype.selectAggregations=function(e){var r,n,o=[];try{for(var i=$l(this.metricCollectors),s=i.next();!s.done;s=i.next()){var u=s.value;o.push([u,u.selectAggregation(e)])}}catch(c){r={error:c}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return o},t}();var Aa=y(C()),pr=function(t,e,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function u(l){try{a(n.next(l))}catch(p){s(p)}}function c(l){try{a(n.throw(l))}catch(p){s(p)}}function a(l){l.done?i(l.value):o(l.value).then(u,c)}a((n=n.apply(t,e||[])).next())})},_r=function(t,e){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:u(0),throw:u(1),return:u(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function u(a){return function(l){return c([a,l])}}function c(a){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return r.label++,{value:a[1],done:!1};case 5:r.label++,o=a[1],a=[0];continue;case 7:a=r.ops.pop(),r.trys.pop();continue;default:if(i=r.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){r=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){r.label=a[1];break}if(a[0]===6&&r.label<i[1]){r.label=i[1],i=a;break}if(i&&r.label<i[2]){r.label=i[2],r.ops.push(a);break}i[2]&&r.ops.pop(),r.trys.pop();continue}a=e.call(t,r)}catch(l){a=[6,l],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Ql=function(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),o,i=[],s;try{for(;(e===void 0||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(u){s={error:u}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(s)throw s.error}}return i},Zl=function(t,e,r){if(r||arguments.length===2)for(var n=0,o=e.length,i;n<o;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return t.concat(i||Array.prototype.slice.call(e))},Oa=function(){function t(e,r){this._sharedState=e,this._metricReader=r}return t.prototype.collect=function(e){return pr(this,void 0,void 0,function(){var r,n,o,i,s=this;return _r(this,function(u){switch(u.label){case 0:return r=(0,Aa.millisToHrTime)(Date.now()),n=[],o=[],i=Array.from(this._sharedState.meterSharedStates.values()).map(function(c){return pr(s,void 0,void 0,function(){var a;return _r(this,function(l){switch(l.label){case 0:return[4,c.collect(this,r,e)];case 1:return a=l.sent(),a?.scopeMetrics!=null&&n.push(a.scopeMetrics),a?.errors!=null&&o.push.apply(o,Zl([],Ql(a.errors),!1)),[2]}})})}),[4,Promise.all(i)];case 1:return u.sent(),[2,{resourceMetrics:{resource:this._sharedState.resource,scopeMetrics:n},errors:o}]}})})},t.prototype.forceFlush=function(e){return pr(this,void 0,void 0,function(){return _r(this,function(r){switch(r.label){case 0:return[4,this._metricReader.forceFlush(e)];case 1:return r.sent(),[2]}})})},t.prototype.shutdown=function(e){return pr(this,void 0,void 0,function(){return _r(this,function(r){switch(r.label){case 0:return[4,this._metricReader.shutdown(e)];case 1:return r.sent(),[2]}})})},t.prototype.selectAggregationTemporality=function(e){return this._metricReader.selectAggregationTemporality(e)},t.prototype.selectAggregation=function(e){return this._metricReader.selectAggregation(e)},t}();var Ra=function(t,e,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function u(l){try{a(n.next(l))}catch(p){s(p)}}function c(l){try{a(n.throw(l))}catch(p){s(p)}}function a(l){l.done?i(l.value):o(l.value).then(u,c)}a((n=n.apply(t,e||[])).next())})},ba=function(t,e){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:u(0),throw:u(1),return:u(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function u(a){return function(l){return c([a,l])}}function c(a){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return r.label++,{value:a[1],done:!1};case 5:r.label++,o=a[1],a=[0];continue;case 7:a=r.ops.pop(),r.trys.pop();continue;default:if(i=r.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){r=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){r.label=a[1];break}if(a[0]===6&&r.label<i[1]){r.label=i[1],i=a;break}if(i&&r.label<i[2]){r.label=i[2],r.ops.push(a);break}i[2]&&r.ops.pop(),r.trys.pop();continue}a=e.call(t,r)}catch(l){a=[6,l],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Jl=function(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},On=function(){function t(e){var r,n,o;this._shutdown=!1;var i=F.default().merge((o=e?.resource)!==null&&o!==void 0?o:F.empty());if(this._sharedState=new va(i),e?.views!=null&&e.views.length>0)try{for(var s=Jl(e.views),u=s.next();!u.done;u=s.next()){var c=u.value;this._sharedState.viewRegistry.addView(c)}}catch(a){r={error:a}}finally{try{u&&!u.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}}return t.prototype.getMeter=function(e,r,n){return r===void 0&&(r=""),n===void 0&&(n={}),this._shutdown?(f.diag.warn("A shutdown MeterProvider cannot provide a Meter"),(0,f.createNoopMeter)()):this._sharedState.getMeterSharedState({name:e,version:r,schemaUrl:n.schemaUrl}).meter},t.prototype.addMetricReader=function(e){var r=new Oa(this._sharedState,e);e.setMetricProducer(r),this._sharedState.metricCollectors.push(r)},t.prototype.shutdown=function(e){return Ra(this,void 0,void 0,function(){return ba(this,function(r){switch(r.label){case 0:return this._shutdown?(f.diag.warn("shutdown may only be called once per MeterProvider"),[2]):(this._shutdown=!0,[4,Promise.all(this._sharedState.metricCollectors.map(function(n){return n.shutdown(e)}))]);case 1:return r.sent(),[2]}})})},t.prototype.forceFlush=function(e){return Ra(this,void 0,void 0,function(){return ba(this,function(r){switch(r.label){case 0:return this._shutdown?(f.diag.warn("invalid attempt to force flush after MeterProvider shutdown"),[2]):[4,Promise.all(this._sharedState.metricCollectors.map(function(n){return n.forceFlush(e)}))];case 1:return r.sent(),[2]}})})},t}();var ru=y(me(),1),nt=y(bt(),1),nu=y(Ca(),1),te=y(C(),1);E();var af=Symbol.for("@vercel/request-context");function $e(){return globalThis[af]?.get()}var Ln=y(me(),1);function Er(t){return Object.fromEntries(Object.entries(t).filter(([e,r])=>r!==void 0))}function Na(t){return t?t.split("::").at(-1):void 0}function wa(t=$e(),e){if(!t)return;let r=e?uf(e,t.headers):void 0;return Er({[Ln.SemanticAttributes.HTTP_HOST]:t.headers.host,[Ln.SemanticAttributes.HTTP_USER_AGENT]:t.headers["user-agent"],"http.referer":t.headers.referer,"vercel.request_id":Na(t.headers["x-vercel-id"]),"vercel.matched_path":t.headers["x-matched-path"],"vercel.edge_region":t.headers["x-vercel-edge-region"],...r})}var sf={keys(t){return[]},get(t,e){return t[e.toLocaleLowerCase()]}};function uf(t,e){if(typeof t=="function")return t(e,sf);let r={};for(let[n,o]of Object.entries(t)){let i=e[o.toLocaleLowerCase()];i!==void 0&&(r[n]=i)}return r}E();function _t(t){return(t&f.TraceFlags.SAMPLED)!==0}var mr=class{constructor(e,r){this.processors=e;this.attributesFromHeaders=r;this.rootSpanIds=new Map;this.waitSpanEnd=new Map}forceFlush(){return Promise.all(this.processors.map(e=>e.forceFlush().catch(r=>{f.diag.error("@vercel/otel: forceFlush failed:",r)}))).then(()=>{})}shutdown(){return Promise.all(this.processors.map(e=>e.shutdown().catch(()=>{}))).then(()=>{})}onStart(e,r){let{traceId:n,spanId:o,traceFlags:i}=e.spanContext(),s=!e.parentSpanId||!this.rootSpanIds.has(n);if(s?this.rootSpanIds.set(n,{rootSpanId:o,open:[]}):this.rootSpanIds.get(n)?.open.push(e),s&&_t(i)){let u=$e(),c=wa(u,this.attributesFromHeaders);c&&e.setAttributes(c),u&&u.waitUntil(async()=>{if(this.rootSpanIds.has(n)){let a=new Promise(p=>{this.waitSpanEnd.set(n,p)}),l;await Promise.race([a,new Promise(p=>{l=setTimeout(()=>{this.waitSpanEnd.delete(n),p(void 0)},50)})]),l&&clearTimeout(l)}return this.forceFlush()})}for(let u of this.processors)u.onStart(e,r)}onEnd(e){let{traceId:r,spanId:n,traceFlags:o}=e.spanContext(),i=_t(o),s=this.rootSpanIds.get(r),u=s?.rootSpanId===n;if(i){let c=lf(e);c&&Object.assign(e.attributes,c)}if(u){if(this.rootSpanIds.delete(r),s.open.length>0){for(let c of s.open)if(!c.ended&&c.spanContext().spanId!==n)try{c.end()}catch(a){f.diag.error("@vercel/otel: onEnd failed:",a)}}}else if(s)for(let c=0;c<s.open.length;c++)s.open[c]?.spanContext().spanId===n&&s.open.splice(c,1);for(let c of this.processors)c.onEnd(e);if(u){let c=this.waitSpanEnd.get(r);c&&(this.waitSpanEnd.delete(r),c())}}},cf={[f.SpanKind.INTERNAL]:"internal",[f.SpanKind.SERVER]:"server",[f.SpanKind.CLIENT]:"client",[f.SpanKind.PRODUCER]:"producer",[f.SpanKind.CONSUMER]:"consumer"};function lf(t){let{kind:e,attributes:r}=t,{"operation.name":n,"resouce.name":o,"span.type":i,"next.span_type":s,"http.method":u,"http.route":c}=r;if(n)return;let a=o??(u&&typeof u=="string"&&c&&typeof c=="string"?`${u} ${c}`:c);if(t.kind===f.SpanKind.SERVER&&u&&c&&typeof u=="string"&&typeof c=="string")return{"operation.name":"web.request","resource.name":a};let l=t.instrumentationLibrary.name,p=s??i;if(p&&typeof p=="string"){let d=Ma(l,p);return c?{"operation.name":d,"resource.name":a}:{"operation.name":d}}return{"operation.name":Ma(l,e===f.SpanKind.INTERNAL?"":cf[e])}}function Ma(t,e){if(!t)return e;let r=t.replace(/[ @./]/g,"_");return r.startsWith("_")&&(r=r.slice(1)),e?`${r}.${e}`:r}var Ya=y(xn(),1);var Wa=y(Ka(),1);E();var Qe=class extends Wa.OTLPExporterBase{constructor(e={}){super(e),e.headers&&(this._headers=e.headers)}onShutdown(){f.diag.debug("@vercel/otel/otlp: onShutdown")}onInit(){f.diag.debug("@vercel/otel/otlp: onInit")}send(e,r,n){if(this._shutdownOnce.isCalled){f.diag.debug("@vercel/otel/otlp: Shutdown already started. Cannot send objects");return}let o=this.convert(e),i,s,u;try{({body:i,contentType:s,headers:u}=this.toMessage(o))}catch(a){f.diag.warn("@vercel/otel/otlp: no proto",a);return}let c=fetch(this.url,{method:"POST",body:i,headers:{...this._headers,...u,"Content-Type":s,"User-Agent":"OTel-OTLP-Exporter-JavaScript/0.46.0"},next:{internal:!0}}).then(a=>{f.diag.debug("@vercel/otel/otlp: onSuccess",a.status,a.statusText),r(),a.arrayBuffer().catch(()=>{})}).catch(a=>{f.diag.error("@vercel/otel/otlp: onError",a),n(a)}).finally(()=>{let a=this._sendingPromises.indexOf(c);this._sendingPromises.splice(a,1)});this._sendingPromises.push(c)}getDefaultUrl(e){throw new Error("Method not implemented.")}};var Nf="v1/traces",wf=`http://localhost:4318/${Nf}`;function yr(t){return typeof t.url=="string"?t.url:wf}var Ze=class{constructor(e={}){this.impl=new Gn(e)}export(e,r){this.impl.export(e,r)}shutdown(){return this.impl.shutdown()}forceFlush(){return this.impl.forceFlush()}},Gn=class extends Qe{convert(e){return(0,Ya.createExportTraceServiceRequest)(e,{useHex:!0,useLongBits:!1})}toMessage(e){return{body:JSON.stringify(e),contentType:"application/json"}}getDefaultUrl(e){return yr(e)}};var $s=y(xn(),1);var Ws=y(Ks(),1);function Ys(t){let e=new Ws.Writer;return kf(t,e),e.finish()}function kf(t,e){if(t.resourceSpans!=null&&t.resourceSpans.length)for(let r=0;r<t.resourceSpans.length;++r)qf(t.resourceSpans[r],e.uint32(10).fork()).ldelim();return e}function qf(t,e){if(t.resource!=null&&Xf(t.resource,e.uint32(10).fork()).ldelim(),t.scopeSpans!=null&&t.scopeSpans.length)for(let r=0;r<t.scopeSpans.length;++r)Kf(t.scopeSpans[r],e.uint32(18).fork()).ldelim();return t.schemaUrl!=null&&e.uint32(26).string(t.schemaUrl),e}function Xf(t,e){if(t.attributes!=null&&t.attributes.length)for(let r=0;r<t.attributes.length;++r)et(t.attributes[r],e.uint32(10).fork()).ldelim();return t.droppedAttributesCount!=null&&e.uint32(16).uint32(t.droppedAttributesCount),e}function Kf(t,e){if(t.scope!=null&&zf(t.scope,e.uint32(10).fork()).ldelim(),t.spans!=null&&t.spans.length)for(let r=0;r<t.spans.length;++r)$f(t.spans[r],e.uint32(18).fork()).ldelim();return t.schemaUrl!=null&&e.uint32(26).string(t.schemaUrl),e}function et(t,e){return t.key!=null&&e.uint32(10).string(t.key),t.value!=null&&zs(t.value,e.uint32(18).fork()).ldelim(),e}function zs(t,e){return t.stringValue!=null&&e.uint32(10).string(t.stringValue),t.boolValue!=null&&e.uint32(16).bool(t.boolValue),t.intValue!=null&&e.uint32(24).int64(t.intValue),t.doubleValue!=null&&e.uint32(33).double(t.doubleValue),t.arrayValue!=null&&Wf(t.arrayValue,e.uint32(42).fork()).ldelim(),t.kvlistValue!=null&&Yf(t.kvlistValue,e.uint32(50).fork()).ldelim(),t.bytesValue!=null&&e.uint32(58).bytes(t.bytesValue),e}function Wf(t,e){if(t.values!=null&&t.values.length)for(let r=0;r<t.values.length;++r)zs(t.values[r],e.uint32(10).fork()).ldelim();return e}function Yf(t,e){if(t.values!=null&&t.values.length)for(let r=0;r<t.values.length;++r)et(t.values[r],e.uint32(10).fork()).ldelim();return e}function zf(t,e){if(t.name!=null&&e.uint32(10).string(t.name),t.version!=null&&e.uint32(18).string(t.version),t.attributes!=null&&t.attributes.length)for(let r=0;r<t.attributes.length;++r)et(t.attributes[r],e.uint32(26).fork()).ldelim();return t.droppedAttributesCount!=null&&e.uint32(32).uint32(t.droppedAttributesCount),e}function $f(t,e){if(t.traceId!=null&&e.uint32(10).bytes(t.traceId),t.spanId!=null&&e.uint32(18).bytes(t.spanId),t.traceState!=null&&e.uint32(26).string(t.traceState),t.parentSpanId!=null&&e.uint32(34).bytes(t.parentSpanId),t.name!=null&&e.uint32(42).string(t.name),t.kind!=null&&e.uint32(48).int32(t.kind),t.startTimeUnixNano!=null&&e.uint32(57).fixed64(t.startTimeUnixNano),t.endTimeUnixNano!=null&&e.uint32(65).fixed64(t.endTimeUnixNano),t.attributes!=null&&t.attributes.length)for(let r=0;r<t.attributes.length;++r)et(t.attributes[r],e.uint32(74).fork()).ldelim();if(t.droppedAttributesCount!=null&&e.uint32(80).uint32(t.droppedAttributesCount),t.events!=null&&t.events.length)for(let r=0;r<t.events.length;++r)Zf(t.events[r],e.uint32(90).fork()).ldelim();if(t.droppedEventsCount!=null&&e.uint32(96).uint32(t.droppedEventsCount),t.links!=null&&t.links.length)for(let r=0;r<t.links.length;++r)Jf(t.links[r],e.uint32(106).fork()).ldelim();return t.droppedLinksCount!=null&&e.uint32(112).uint32(t.droppedLinksCount),t.status!=null&&Qf(t.status,e.uint32(122).fork()).ldelim(),e}function Qf(t,e){return t.message!=null&&e.uint32(18).string(t.message),t.code!=null&&e.uint32(24).int32(t.code),e}function Zf(t,e){if(t.timeUnixNano!=null&&e.uint32(9).fixed64(t.timeUnixNano),t.name!=null&&e.uint32(18).string(t.name),t.attributes!=null&&t.attributes.length)for(let r=0;r<t.attributes.length;++r)et(t.attributes[r],e.uint32(26).fork()).ldelim();return t.droppedAttributesCount!=null&&e.uint32(32).uint32(t.droppedAttributesCount),e}function Jf(t,e){if(t.traceId!=null&&e.uint32(10).bytes(t.traceId),t.spanId!=null&&e.uint32(18).bytes(t.spanId),t.traceState!=null&&e.uint32(26).string(t.traceState),t.attributes!=null&&t.attributes.length)for(let r=0;r<t.attributes.length;++r)et(t.attributes[r],e.uint32(34).fork()).ldelim();return t.droppedAttributesCount!=null&&e.uint32(40).uint32(t.droppedAttributesCount),e}var Be=class{constructor(e={}){this.impl=new Zn(e)}export(e,r){this.impl.export(e,r)}shutdown(){return this.impl.shutdown()}forceFlush(){return this.impl.forceFlush()}},Zn=class extends Qe{convert(e){return(0,$s.createExportTraceServiceRequest)(e,void 0)}toMessage(e){return{body:Ys(e),contentType:"application/x-protobuf",headers:{accept:"application/x-protobuf"}}}getDefaultUrl(e){return yr(e)}};E();var fe=y(me(),1);function Qs(t,e){return t.replace(/\{(?<temp1>[^{}]+)\}/g,(r,n)=>{let o=e[n];return o!==void 0?String(o):r})}var tt=class{constructor(e={}){this.instrumentationName="@vercel/otel/fetch";this.instrumentationVersion="1.0.0";this.config=e}getConfig(){return this.config}setConfig(){}setTracerProvider(e){this.tracerProvider=e}setMeterProvider(){}enable(){this.disable();let{tracerProvider:e}=this;if(!e)return;let r=e.getTracer(this.instrumentationName,this.instrumentationVersion),n=this.config.ignoreUrls??[],o=(P,B)=>{if(B?.opentelemetry?.ignore!==void 0)return B.opentelemetry.ignore;if(n.length===0)return!1;let A=P.toString();return n.some(m=>typeof m=="string"?m==="*"?!0:A.startsWith(m):m.test(A))},i=process.env.VERCEL_URL||process.env.NEXT_PUBLIC_VERCEL_URL||null,s=process.env.VERCEL_BRANCH_URL||process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL||null,u=this.config.propagateContextUrls??[],c=this.config.dontPropagateContextUrls??[],a=this.config.resourceNameTemplate,{attributesFromRequestHeaders:l,attributesFromResponseHeaders:p}=this.config,d=(P,B)=>{if(B?.opentelemetry?.propagateContext)return B.opentelemetry.propagateContext;let A=P.toString();return c.length>0&&c.some(m=>typeof m=="string"?m==="*"?!0:A.startsWith(m):m.test(A))?!1:i&&P.protocol==="https:"&&(P.host===i||P.host===s||P.host===$e()?.headers.host)||!i&&P.protocol==="http:"&&P.hostname==="localhost"?!0:u.some(m=>typeof m=="string"?m==="*"?!0:A.startsWith(m):m.test(A))};process.env.NEXT_OTEL_FETCH_DISABLED="1";let g=globalThis.fetch;this.originalFetch=g;let U=async(P,B)=>{let A=B;if(A?.next?.internal)return g(P,A);let m=new Request(P instanceof Request?P.clone():P,A),ie=new URL(m.url);if(o(ie,A))return g(P,A);let Tt={[fe.SemanticAttributes.HTTP_METHOD]:m.method,[fe.SemanticAttributes.HTTP_URL]:m.url,[fe.SemanticAttributes.HTTP_HOST]:ie.host,[fe.SemanticAttributes.HTTP_SCHEME]:ie.protocol.replace(":",""),[fe.SemanticAttributes.NET_PEER_NAME]:ie.hostname,[fe.SemanticAttributes.NET_PEER_PORT]:ie.port},Lr=a?Qs(a,Tt):tp(m.url),St=A?.opentelemetry?.spanName??`fetch ${m.method} ${m.url}`,ei=f.context.active(),x=r.startSpan(St,{kind:f.SpanKind.CLIENT,attributes:{...Tt,"operation.name":`fetch.${m.method}`,"resource.name":Lr,...A?.opentelemetry?.attributes}},ei);if(!x.isRecording()||!_t(x.spanContext().traceFlags))return x.end(),g(P,A);if(d(ie,A)){let Ge=f.trace.setSpan(ei,x);f.propagation.inject(Ge,m.headers,ep)}l&&Zs(x,l,m.headers);try{let Ge=Date.now(),pe=await g(P,{...A,headers:m.headers}),ou=Date.now()-Ge;return x.setAttribute(fe.SemanticAttributes.HTTP_STATUS_CODE,pe.status),x.setAttribute("http.response_time",ou),p&&Zs(x,p,pe.headers),pe.status>=500&&Jn(x,`Status: ${pe.status} (${pe.statusText})`),pe.body?rp(pe).then(Pr=>{x.isRecording()&&(x.setAttribute(fe.SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED,Pr),x.end())},Pr=>{x.isRecording()&&(Jn(x,Pr),x.end())}):x.end(),pe}catch(Ge){throw Jn(x,Ge),x.end(),Ge}};globalThis.fetch=U}disable(){this.originalFetch&&(globalThis.fetch=this.originalFetch)}},ep={set(t,e,r){t.set(e,r)}};function tp(t){let e=t.indexOf("?");return e===-1?t:t.substring(0,e)}function rp(t){let e=0,n=t.clone().body?.getReader();if(!n)return Promise.resolve(0);let o=()=>n.read().then(({done:i,value:s})=>{if(!i)return e+=s.byteLength,o()});return o().then(()=>e)}function Jn(t,e){if(e instanceof Error)t.recordException(e),t.setStatus({code:f.SpanStatusCode.ERROR,message:e.message});else{let r=String(e);t.setStatus({code:f.SpanStatusCode.ERROR,message:r})}}function Zs(t,e,r){for(let[n,o]of Object.entries(e)){let i=r.get(o);i!==null&&t.setAttribute(n,i)}}var br=class{constructor(e={}){this.configuration=e}start(){let e=np(),r=(0,nt.getEnvWithoutDefaults)(),n=this.configuration,o=process.env.NEXT_RUNTIME||"nodejs",i=!!e.OTEL_SDK_DISABLED;if(r.OTEL_LOG_LEVEL&&f.diag.setLogger(new f.DiagConsoleLogger,{logLevel:r.OTEL_LOG_LEVEL}),i)return;let s=n.idGenerator??new tr,u=n.contextManager??new nu.AsyncLocalStorageContextManager;u.enable(),this.contextManager=u;let c=e.OTEL_SERVICE_NAME||n.serviceName||"app",a=new F(Er({[ru.SemanticResourceAttributes.SERVICE_NAME]:c,"node.ci":process.env.CI?!0:void 0,"node.env":"production",env:process.env.VERCEL_ENV||process.env.NEXT_PUBLIC_VERCEL_ENV,"vercel.region":process.env.VERCEL_REGION,"vercel.runtime":o,"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,...n.attributes})),l=n.resourceDetectors??[vo];if(n.autoDetectResources??!0){let m={detectors:l};a=a.merge(Oo(m))}let d=op(n.propagators,e),g=ap(n.traceSampler,e),U=sp(n.spanProcessors,n,e);U.length===0&&f.diag.warn("@vercel/otel: No span processors configured. No spans will be exported.");let P=n.spanLimits,B=new Po({resource:a,idGenerator:s,sampler:g,spanLimits:P});if(B.addSpanProcessor(new mr(U,n.attributesFromHeaders)),B.register({contextManager:u,propagator:new te.CompositePropagator({propagators:d})}),this.tracerProvider=B,n.logRecordProcessor){let m=new hn({resource:a});this.loggerProvider=m,m.addLogRecordProcessor(n.logRecordProcessor),se.logs.setGlobalLoggerProvider(m)}if(n.metricReader||n.views){let m=new On({resource:a,views:n.views??[]});n.metricReader&&m.addMetricReader(n.metricReader),f.metrics.setGlobalMeterProvider(m),this.meterProvider=m}let A=ip(n.instrumentations,n.instrumentationConfig);this.disableInstumentations=(0,tu.registerInstrumentations)({instrumentations:A}),f.diag.info("@vercel/otel: started",c,o)}async shutdown(){let e=[];this.tracerProvider&&e.push(this.tracerProvider.shutdown()),this.loggerProvider&&e.push(this.loggerProvider.shutdown()),this.meterProvider&&e.push(this.meterProvider.shutdown()),f.diag.info("@vercel/otel: shutting down",e.length,process.env.NEXT_RUNTIME),await Promise.all(e),this.contextManager&&this.contextManager.disable();let{disableInstumentations:r}=this;r&&r()}};function np(){let t=(0,nt.parseEnvironment)(process.env);return{...nt.DEFAULT_ENVIRONMENT,...t}}function ip(t,e){return(t??["auto"]).map(r=>r==="auto"?(f.diag.debug("@vercel/otel: Configure instrumentations: fetch",e?.fetch),[new tt(e?.fetch)]):r==="fetch"?(f.diag.debug("@vercel/otel: Configure instrumentations: fetch",e?.fetch),new tt(e?.fetch)):r).flat()}function op(t,e){let r=e.OTEL_PROPAGATORS&&e.OTEL_PROPAGATORS.length>0?e.OTEL_PROPAGATORS:void 0;return(t??r??["auto"]).map(n=>{if(n==="none")return[];if(n==="auto")return f.diag.debug("@vercel/otel: Configure propagators: tracecontext, baggage"),[new te.W3CTraceContextPropagator,new te.W3CBaggagePropagator];if(n==="tracecontext")return f.diag.debug("@vercel/otel: Configure propagator: tracecontext"),new te.W3CTraceContextPropagator;if(n==="baggage")return f.diag.debug("@vercel/otel: Configure propagator: baggage"),new te.W3CBaggagePropagator;if(typeof n=="string")throw new Error(`Unknown propagator: "${n}"`);return n}).flat()}var Js="always_on",rt=1;function ap(t,e){if(t&&typeof t!="string")return t;let r=t&&t!=="auto"?t:e.OTEL_TRACES_SAMPLER||Js;switch(f.diag.debug("@vercel/otel: Configure sampler: ",r),r){case"always_on":return new X;case"always_off":return new ae;case"parentbased_always_on":return new Se({root:new X});case"parentbased_always_off":return new Se({root:new ae});case"traceidratio":return new ke(eu(e));case"parentbased_traceidratio":return new Se({root:new ke(eu(e))});default:return f.diag.error(`@vercel/otel: OTEL_TRACES_SAMPLER value "${String(e.OTEL_TRACES_SAMPLER)} invalid, defaulting to ${Js}".`),new X}}function eu(t){if(t.OTEL_TRACES_SAMPLER_ARG===void 0||t.OTEL_TRACES_SAMPLER_ARG==="")return f.diag.error(`@vercel/otel: OTEL_TRACES_SAMPLER_ARG is blank, defaulting to ${rt}.`),rt;f.diag.debug("@vercel/otel: Configure sampler probability: ",t.OTEL_TRACES_SAMPLER_ARG);let e=Number(t.OTEL_TRACES_SAMPLER_ARG);return isNaN(e)?(f.diag.error(`@vercel/otel: OTEL_TRACES_SAMPLER_ARG=${t.OTEL_TRACES_SAMPLER_ARG} was given, but it is invalid, defaulting to ${rt}.`),rt):e<0||e>1?(f.diag.error(`@vercel/otel: OTEL_TRACES_SAMPLER_ARG=${t.OTEL_TRACES_SAMPLER_ARG} was given, but it is out of range ([0..1]), defaulting to ${rt}.`),rt):e}function sp(t,e,r){return[...(t??["auto"]).map(n=>{if(n==="auto"){if(process.env.VERCEL_OTEL_ENDPOINTS){let o=process.env.VERCEL_OTEL_ENDPOINTS_PORT||"4318",i=process.env.VERCEL_OTEL_ENDPOINTS_PROTOCOL||"http/protobuf";f.diag.debug("@vercel/otel: Configure vercel otel collector on port: ",o,i);let s={url:`http://localhost:${o}/v1/traces`,headers:{}},u=i==="http/protobuf"?new Be(s):new Ze(s);return new Ke(u)}return!e.traceExporter||e.traceExporter==="auto"||r.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT||r.OTEL_EXPORTER_OTLP_ENDPOINT?new Ke(up(r)):void 0}return n}).filter(fp),...e.traceExporter&&e.traceExporter!=="auto"?[new Ke(e.traceExporter)]:[]]}function up(t){let e=process.env.OTEL_EXPORTER_OTLP_TRACES_PROTOCOL??process.env.OTEL_EXPORTER_OTLP_PROTOCOL??"http/protobuf",r=lp(t),n={...te.baggageUtils.parseKeyPairsIntoRecord(t.OTEL_EXPORTER_OTLP_HEADERS),...te.baggageUtils.parseKeyPairsIntoRecord(t.OTEL_EXPORTER_OTLP_TRACES_HEADERS)};switch(f.diag.debug("@vercel/otel: Configure trace exporter: ",e,r,`headers: ${Object.keys(n).join(",")||"<none>"}`),e){case"http/json":return new Ze({url:r,headers:n});case"http/protobuf":return new Be({url:r,headers:n});default:return f.diag.warn(`@vercel/otel: Unsupported OTLP traces protocol: ${e}. Using http/protobuf.`),new Be}}var iu="v1/traces",cp=`http://localhost:4318/${iu}`;function lp(t){let e=t.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT;if(e&&typeof e=="string")return e;let r=t.OTEL_EXPORTER_OTLP_ENDPOINT;return r&&typeof r=="string"?`${r}/${iu}`:cp}function fp(t){return t!=null}function um(t){let e;t?typeof t=="string"?e={serviceName:t}:e=t:e={},new br(e).start()}export{tt as FetchInstrumentation,Ze as OTLPHttpJsonTraceExporter,Be as OTLPHttpProtoTraceExporter,um as registerOTel};
16
+ `,gn(a,e))}}catch(l){n={error:l}}finally{try{u&&!u.done&&(o=s.return)&&o.call(s)}finally{if(n)throw n.error}}return i},t}();var _a=function(){function t(e){this._backingStorages=e}return t.prototype.record=function(e,r,n,o){this._backingStorages.forEach(function(i){i.record(e,r,n,o)})},t}();E();E();var da=function(){function t(e,r){this._instrumentName=e,this._valueType=r,this._buffer=new Q}return t.prototype.observe=function(e,r){if(r===void 0&&(r={}),typeof e!="number"){f.diag.warn("non-number value provided to metric "+this._instrumentName+": "+e);return}this._valueType===f.ValueType.INT&&!Number.isInteger(e)&&(f.diag.warn("INT value type cannot accept a floating-point value for "+this._instrumentName+", ignoring the fractional digits."),e=Math.trunc(e),!Number.isInteger(e))||this._buffer.set(r,e)},t}();var ha=function(){function t(){this._buffer=new Map}return t.prototype.observe=function(e,r,n){if(n===void 0&&(n={}),!!lt(e)){var o=this._buffer.get(e);if(o==null&&(o=new Q,this._buffer.set(e,o)),typeof r!="number"){f.diag.warn("non-number value provided to metric "+e._descriptor.name+": "+r);return}e._descriptor.valueType===f.ValueType.INT&&!Number.isInteger(r)&&(f.diag.warn("INT value type cannot accept a floating-point value for "+e._descriptor.name+", ignoring the fractional digits."),r=Math.trunc(r),!Number.isInteger(r))||o.set(n,r)}},t}();var vn=function(t,e,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function u(l){try{a(n.next(l))}catch(p){s(p)}}function c(l){try{a(n.throw(l))}catch(p){s(p)}}function a(l){l.done?i(l.value):o(l.value).then(u,c)}a((n=n.apply(t,e||[])).next())})},An=function(t,e){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:u(0),throw:u(1),return:u(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function u(a){return function(l){return c([a,l])}}function c(a){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return r.label++,{value:a[1],done:!1};case 5:r.label++,o=a[1],a=[0];continue;case 7:a=r.ops.pop(),r.trys.pop();continue;default:if(i=r.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){r=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){r.label=a[1];break}if(a[0]===6&&r.label<i[1]){r.label=i[1],i=a;break}if(i&&r.label<i[2]){r.label=i[2],r.ops.push(a);break}i[2]&&r.ops.pop(),r.trys.pop();continue}a=e.call(t,r)}catch(l){a=[6,l],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Ea=function(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),o,i=[],s;try{for(;(e===void 0||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(u){s={error:u}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(s)throw s.error}}return i},ma=function(t,e,r){if(r||arguments.length===2)for(var n=0,o=e.length,i;n<o;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return t.concat(i||Array.prototype.slice.call(e))},Ta=function(){function t(){this._callbacks=[],this._batchCallbacks=[]}return t.prototype.addCallback=function(e,r){var n=this._findCallback(e,r);n>=0||this._callbacks.push({callback:e,instrument:r})},t.prototype.removeCallback=function(e,r){var n=this._findCallback(e,r);n<0||this._callbacks.splice(n,1)},t.prototype.addBatchCallback=function(e,r){var n=new Set(r.filter(lt));if(n.size===0){f.diag.error("BatchObservableCallback is not associated with valid instruments",r);return}var o=this._findBatchCallback(e,n);o>=0||this._batchCallbacks.push({callback:e,instruments:n})},t.prototype.removeBatchCallback=function(e,r){var n=new Set(r.filter(lt)),o=this._findBatchCallback(e,n);o<0||this._batchCallbacks.splice(o,1)},t.prototype.observe=function(e,r){return vn(this,void 0,void 0,function(){var n,o,i,s;return An(this,function(u){switch(u.label){case 0:return n=this._observeCallbacks(e,r),o=this._observeBatchCallbacks(e,r),[4,Yo(ma(ma([],Ea(n),!1),Ea(o),!1))];case 1:return i=u.sent(),s=i.filter(zo).map(function(c){return c.reason}),[2,s]}})})},t.prototype._observeCallbacks=function(e,r){var n=this;return this._callbacks.map(function(o){var i=o.callback,s=o.instrument;return vn(n,void 0,void 0,function(){var u,c;return An(this,function(a){switch(a.label){case 0:return u=new da(s._descriptor.name,s._descriptor.valueType),c=Promise.resolve(i(u)),r!=null&&(c=En(c,r)),[4,c];case 1:return a.sent(),s._metricStorages.forEach(function(l){l.record(u._buffer,e)}),[2]}})})})},t.prototype._observeBatchCallbacks=function(e,r){var n=this;return this._batchCallbacks.map(function(o){var i=o.callback,s=o.instruments;return vn(n,void 0,void 0,function(){var u,c;return An(this,function(a){switch(a.label){case 0:return u=new ha,c=Promise.resolve(i(u)),r!=null&&(c=En(c,r)),[4,c];case 1:return a.sent(),s.forEach(function(l){var p=u._buffer.get(l);p!=null&&l._metricStorages.forEach(function(d){d.record(p,e)})}),[2]}})})})},t.prototype._findCallback=function(e,r){return this._callbacks.findIndex(function(n){return n.callback===e&&n.instrument===r})},t.prototype._findBatchCallback=function(e,r){return this._batchCallbacks.findIndex(function(n){return n.callback===e&&$o(n.instruments,r)})},t}();var ql=function(){var t=function(e,r){return t=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])},t(e,r)};return function(e,r){if(typeof r!="function"&&r!==null)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");t(e,r);function n(){this.constructor=e}e.prototype=r===null?Object.create(r):(n.prototype=r.prototype,new n)}}(),Sa=function(t){ql(e,t);function e(r,n,o,i){var s=t.call(this,r)||this;return s._attributesProcessor=o,s._deltaMetricStorage=new cr(n),s._temporalMetricStorage=new lr(n,i),s}return e.prototype.record=function(r,n,o,i){n=this._attributesProcessor.process(n,o),this._deltaMetricStorage.record(r,n,o,i)},e.prototype.collect=function(r,n){var o=this._deltaMetricStorage.collect();return this._temporalMetricStorage.buildMetrics(r,this._instrumentDescriptor,o,n)},e}(ur);var ga=function(){var t=function(e,r){return t=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])},t(e,r)};return function(e,r){if(typeof r!="function"&&r!==null)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");t(e,r);function n(){this.constructor=e}e.prototype=r===null?Object.create(r):(n.prototype=r.prototype,new n)}}(),fr=function(){function t(){}return t.Noop=function(){return Kl},t}();var Xl=function(t){ga(e,t);function e(){return t!==null&&t.apply(this,arguments)||this}return e.prototype.process=function(r,n){return r},e}(fr);var gh=function(t){ga(e,t);function e(r){var n=t.call(this)||this;return n._allowedAttributeNames=r,n}return e.prototype.process=function(r,n){var o=this,i={};return Object.keys(r).filter(function(s){return o._allowedAttributeNames.includes(s)}).forEach(function(s){return i[s]=r[s]}),i},e}(fr);var Kl=new Xl;var Wl=function(t,e,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function u(l){try{a(n.next(l))}catch(p){s(p)}}function c(l){try{a(n.throw(l))}catch(p){s(p)}}function a(l){l.done?i(l.value):o(l.value).then(u,c)}a((n=n.apply(t,e||[])).next())})},Yl=function(t,e){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:u(0),throw:u(1),return:u(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function u(a){return function(l){return c([a,l])}}function c(a){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return r.label++,{value:a[1],done:!1};case 5:r.label++,o=a[1],a=[0];continue;case 7:a=r.ops.pop(),r.trys.pop();continue;default:if(i=r.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){r=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){r.label=a[1];break}if(a[0]===6&&r.label<i[1]){r.label=i[1],i=a;break}if(i&&r.label<i[2]){r.label=i[2],r.ops.push(a);break}i[2]&&r.ops.pop(),r.trys.pop();continue}a=e.call(t,r)}catch(l){a=[6,l],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},zl=function(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),o,i=[],s;try{for(;(e===void 0||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(u){s={error:u}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(s)throw s.error}}return i},ya=function(){function t(e,r){this._meterProviderSharedState=e,this._instrumentationScope=r,this.metricStorageRegistry=new pa,this.observableRegistry=new Ta,this.meter=new ua(this)}return t.prototype.registerMetricStorage=function(e){var r=this._registerMetricStorage(e,Sa);return r.length===1?r[0]:new _a(r)},t.prototype.registerAsyncMetricStorage=function(e){var r=this._registerMetricStorage(e,fa);return r},t.prototype.collect=function(e,r,n){return Wl(this,void 0,void 0,function(){var o,i,s;return Yl(this,function(u){switch(u.label){case 0:return[4,this.observableRegistry.observe(r,n?.timeoutMillis)];case 1:return o=u.sent(),i=this.metricStorageRegistry.getStorages(e),i.length===0?[2,null]:(s=i.map(function(c){return c.collect(e,r)}).filter(Xo),s.length===0?[2,{errors:o}]:[2,{scopeMetrics:{scope:this._instrumentationScope,metrics:s},errors:o}])}})})},t.prototype._registerMetricStorage=function(e,r){var n=this,o=this._meterProviderSharedState.viewRegistry.findViews(e,this._instrumentationScope),i=o.map(function(c){var a=Zo(c,e),l=n.metricStorageRegistry.findOrUpdateCompatibleStorage(a);if(l!=null)return l;var p=c.aggregation.createAggregator(a),d=new r(a,p,c.attributesProcessor,n._meterProviderSharedState.metricCollectors);return n.metricStorageRegistry.register(d),d});if(i.length===0){var s=this._meterProviderSharedState.selectAggregations(e.type),u=s.map(function(c){var a=zl(c,2),l=a[0],p=a[1],d=n.metricStorageRegistry.findOrUpdateCompatibleCollectorStorage(l,e);if(d!=null)return d;var g=p.createAggregator(e),U=new r(e,g,fr.Noop(),[l]);return n.metricStorageRegistry.registerForCollector(l,U),U});i=i.concat(u)}return i},t}();var $l=function(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},va=function(){function t(e){this.resource=e,this.viewRegistry=new ea,this.metricCollectors=[],this.meterSharedStates=new Map}return t.prototype.getMeterSharedState=function(e){var r=Wo(e),n=this.meterSharedStates.get(r);return n==null&&(n=new ya(this,e),this.meterSharedStates.set(r,n)),n},t.prototype.selectAggregations=function(e){var r,n,o=[];try{for(var i=$l(this.metricCollectors),s=i.next();!s.done;s=i.next()){var u=s.value;o.push([u,u.selectAggregation(e)])}}catch(c){r={error:c}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return o},t}();var Aa=y(C()),pr=function(t,e,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function u(l){try{a(n.next(l))}catch(p){s(p)}}function c(l){try{a(n.throw(l))}catch(p){s(p)}}function a(l){l.done?i(l.value):o(l.value).then(u,c)}a((n=n.apply(t,e||[])).next())})},_r=function(t,e){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:u(0),throw:u(1),return:u(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function u(a){return function(l){return c([a,l])}}function c(a){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return r.label++,{value:a[1],done:!1};case 5:r.label++,o=a[1],a=[0];continue;case 7:a=r.ops.pop(),r.trys.pop();continue;default:if(i=r.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){r=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){r.label=a[1];break}if(a[0]===6&&r.label<i[1]){r.label=i[1],i=a;break}if(i&&r.label<i[2]){r.label=i[2],r.ops.push(a);break}i[2]&&r.ops.pop(),r.trys.pop();continue}a=e.call(t,r)}catch(l){a=[6,l],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Ql=function(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),o,i=[],s;try{for(;(e===void 0||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(u){s={error:u}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(s)throw s.error}}return i},Zl=function(t,e,r){if(r||arguments.length===2)for(var n=0,o=e.length,i;n<o;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return t.concat(i||Array.prototype.slice.call(e))},Oa=function(){function t(e,r){this._sharedState=e,this._metricReader=r}return t.prototype.collect=function(e){return pr(this,void 0,void 0,function(){var r,n,o,i,s=this;return _r(this,function(u){switch(u.label){case 0:return r=(0,Aa.millisToHrTime)(Date.now()),n=[],o=[],i=Array.from(this._sharedState.meterSharedStates.values()).map(function(c){return pr(s,void 0,void 0,function(){var a;return _r(this,function(l){switch(l.label){case 0:return[4,c.collect(this,r,e)];case 1:return a=l.sent(),a?.scopeMetrics!=null&&n.push(a.scopeMetrics),a?.errors!=null&&o.push.apply(o,Zl([],Ql(a.errors),!1)),[2]}})})}),[4,Promise.all(i)];case 1:return u.sent(),[2,{resourceMetrics:{resource:this._sharedState.resource,scopeMetrics:n},errors:o}]}})})},t.prototype.forceFlush=function(e){return pr(this,void 0,void 0,function(){return _r(this,function(r){switch(r.label){case 0:return[4,this._metricReader.forceFlush(e)];case 1:return r.sent(),[2]}})})},t.prototype.shutdown=function(e){return pr(this,void 0,void 0,function(){return _r(this,function(r){switch(r.label){case 0:return[4,this._metricReader.shutdown(e)];case 1:return r.sent(),[2]}})})},t.prototype.selectAggregationTemporality=function(e){return this._metricReader.selectAggregationTemporality(e)},t.prototype.selectAggregation=function(e){return this._metricReader.selectAggregation(e)},t}();var Ra=function(t,e,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function u(l){try{a(n.next(l))}catch(p){s(p)}}function c(l){try{a(n.throw(l))}catch(p){s(p)}}function a(l){l.done?i(l.value):o(l.value).then(u,c)}a((n=n.apply(t,e||[])).next())})},ba=function(t,e){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:u(0),throw:u(1),return:u(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function u(a){return function(l){return c([a,l])}}function c(a){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return r.label++,{value:a[1],done:!1};case 5:r.label++,o=a[1],a=[0];continue;case 7:a=r.ops.pop(),r.trys.pop();continue;default:if(i=r.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){r=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){r.label=a[1];break}if(a[0]===6&&r.label<i[1]){r.label=i[1],i=a;break}if(i&&r.label<i[2]){r.label=i[2],r.ops.push(a);break}i[2]&&r.ops.pop(),r.trys.pop();continue}a=e.call(t,r)}catch(l){a=[6,l],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Jl=function(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},On=function(){function t(e){var r,n,o;this._shutdown=!1;var i=F.default().merge((o=e?.resource)!==null&&o!==void 0?o:F.empty());if(this._sharedState=new va(i),e?.views!=null&&e.views.length>0)try{for(var s=Jl(e.views),u=s.next();!u.done;u=s.next()){var c=u.value;this._sharedState.viewRegistry.addView(c)}}catch(a){r={error:a}}finally{try{u&&!u.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}}return t.prototype.getMeter=function(e,r,n){return r===void 0&&(r=""),n===void 0&&(n={}),this._shutdown?(f.diag.warn("A shutdown MeterProvider cannot provide a Meter"),(0,f.createNoopMeter)()):this._sharedState.getMeterSharedState({name:e,version:r,schemaUrl:n.schemaUrl}).meter},t.prototype.addMetricReader=function(e){var r=new Oa(this._sharedState,e);e.setMetricProducer(r),this._sharedState.metricCollectors.push(r)},t.prototype.shutdown=function(e){return Ra(this,void 0,void 0,function(){return ba(this,function(r){switch(r.label){case 0:return this._shutdown?(f.diag.warn("shutdown may only be called once per MeterProvider"),[2]):(this._shutdown=!0,[4,Promise.all(this._sharedState.metricCollectors.map(function(n){return n.shutdown(e)}))]);case 1:return r.sent(),[2]}})})},t.prototype.forceFlush=function(e){return Ra(this,void 0,void 0,function(){return ba(this,function(r){switch(r.label){case 0:return this._shutdown?(f.diag.warn("invalid attempt to force flush after MeterProvider shutdown"),[2]):[4,Promise.all(this._sharedState.metricCollectors.map(function(n){return n.forceFlush(e)}))];case 1:return r.sent(),[2]}})})},t}();var ru=y(me(),1),nt=y(bt(),1),nu=y(Ca(),1),te=y(C(),1);E();var af=Symbol.for("@vercel/request-context");function $e(){return globalThis[af]?.get()}var Ln=y(me(),1);function Er(t){return Object.fromEntries(Object.entries(t).filter(([e,r])=>r!==void 0))}function Na(t){return t?t.split("::").at(-1):void 0}function wa(t=$e(),e){if(!t)return;let r=e?uf(e,t.headers):void 0;return Er({[Ln.SemanticAttributes.HTTP_HOST]:t.headers.host,[Ln.SemanticAttributes.HTTP_USER_AGENT]:t.headers["user-agent"],"http.referer":t.headers.referer,"vercel.request_id":Na(t.headers["x-vercel-id"]),"vercel.matched_path":t.headers["x-matched-path"],"vercel.edge_region":t.headers["x-vercel-edge-region"],...r})}var sf={keys(t){return[]},get(t,e){return t[e.toLocaleLowerCase()]}};function uf(t,e){if(typeof t=="function")return t(e,sf);let r={};for(let[n,o]of Object.entries(t)){let i=e[o.toLocaleLowerCase()];i!==void 0&&(r[n]=i)}return r}E();function _t(t){return(t&f.TraceFlags.SAMPLED)!==0}var mr=class{constructor(e,r){this.processors=e;this.attributesFromHeaders=r;this.rootSpanIds=new Map;this.waitSpanEnd=new Map}forceFlush(){return Promise.all(this.processors.map(e=>e.forceFlush().catch(r=>{f.diag.error("@vercel/otel: forceFlush failed:",r)}))).then(()=>{})}shutdown(){return Promise.all(this.processors.map(e=>e.shutdown().catch(()=>{}))).then(()=>{})}onStart(e,r){let{traceId:n,spanId:o,traceFlags:i}=e.spanContext(),s=!e.parentSpanId||!this.rootSpanIds.has(n);if(s?this.rootSpanIds.set(n,{rootSpanId:o,open:[]}):this.rootSpanIds.get(n)?.open.push(e),s&&_t(i)){let u=$e(),c=wa(u,this.attributesFromHeaders);c&&e.setAttributes(c),u&&u.waitUntil(async()=>{if(this.rootSpanIds.has(n)){let a=new Promise(p=>{this.waitSpanEnd.set(n,p)}),l;await Promise.race([a,new Promise(p=>{l=setTimeout(()=>{this.waitSpanEnd.delete(n),p(void 0)},50)})]),l&&clearTimeout(l)}return this.forceFlush()})}for(let u of this.processors)u.onStart(e,r)}onEnd(e){let{traceId:r,spanId:n,traceFlags:o}=e.spanContext(),i=_t(o),s=this.rootSpanIds.get(r),u=s?.rootSpanId===n;if(i){let c=lf(e);c&&Object.assign(e.attributes,c)}if(u){if(this.rootSpanIds.delete(r),s.open.length>0){for(let c of s.open)if(!c.ended&&c.spanContext().spanId!==n)try{c.end()}catch(a){f.diag.error("@vercel/otel: onEnd failed:",a)}}}else if(s)for(let c=0;c<s.open.length;c++)s.open[c]?.spanContext().spanId===n&&s.open.splice(c,1);for(let c of this.processors)c.onEnd(e);if(u){let c=this.waitSpanEnd.get(r);c&&(this.waitSpanEnd.delete(r),c())}}},cf={[f.SpanKind.INTERNAL]:"internal",[f.SpanKind.SERVER]:"server",[f.SpanKind.CLIENT]:"client",[f.SpanKind.PRODUCER]:"producer",[f.SpanKind.CONSUMER]:"consumer"};function lf(t){let{kind:e,attributes:r}=t,{"operation.name":n,"resouce.name":o,"span.type":i,"next.span_type":s,"http.method":u,"http.route":c}=r;if(n)return;let a=o??(u&&typeof u=="string"&&c&&typeof c=="string"?`${u} ${c}`:c);if(t.kind===f.SpanKind.SERVER&&u&&c&&typeof u=="string"&&typeof c=="string")return{"operation.name":"web.request","resource.name":a};let l=t.instrumentationLibrary.name,p=s??i;if(p&&typeof p=="string"){let d=Ma(l,p);return c?{"operation.name":d,"resource.name":a}:{"operation.name":d}}return{"operation.name":Ma(l,e===f.SpanKind.INTERNAL?"":cf[e])}}function Ma(t,e){if(!t)return e;let r=t.replace(/[ @./]/g,"_");return r.startsWith("_")&&(r=r.slice(1)),e?`${r}.${e}`:r}var Ya=y(xn(),1);var Wa=y(Ka(),1);E();var Qe=class extends Wa.OTLPExporterBase{constructor(e={}){super(e),e.headers&&(this._headers=e.headers)}onShutdown(){f.diag.debug("@vercel/otel/otlp: onShutdown")}onInit(){f.diag.debug("@vercel/otel/otlp: onInit")}send(e,r,n){if(this._shutdownOnce.isCalled){f.diag.debug("@vercel/otel/otlp: Shutdown already started. Cannot send objects");return}let o=this.convert(e),i,s,u;try{({body:i,contentType:s,headers:u}=this.toMessage(o))}catch(a){f.diag.warn("@vercel/otel/otlp: no proto",a);return}let c=fetch(this.url,{method:"POST",body:i,headers:{...this._headers,...u,"Content-Type":s,"User-Agent":"OTel-OTLP-Exporter-JavaScript/0.46.0"},next:{internal:!0}}).then(a=>{f.diag.debug("@vercel/otel/otlp: onSuccess",a.status,a.statusText),r(),a.arrayBuffer().catch(()=>{})}).catch(a=>{f.diag.error("@vercel/otel/otlp: onError",a),n(a)}).finally(()=>{let a=this._sendingPromises.indexOf(c);this._sendingPromises.splice(a,1)});this._sendingPromises.push(c)}getDefaultUrl(e){throw new Error("Method not implemented.")}};var Nf="v1/traces",wf=`http://localhost:4318/${Nf}`;function yr(t){return typeof t.url=="string"?t.url:wf}var Ze=class{constructor(e={}){this.impl=new Gn(e)}export(e,r){this.impl.export(e,r)}shutdown(){return this.impl.shutdown()}forceFlush(){return this.impl.forceFlush()}},Gn=class extends Qe{convert(e){return(0,Ya.createExportTraceServiceRequest)(e,{useHex:!0,useLongBits:!1})}toMessage(e){return{body:JSON.stringify(e),contentType:"application/json"}}getDefaultUrl(e){return yr(e)}};var $s=y(xn(),1);var Ws=y(Ks(),1);function Ys(t){let e=new Ws.Writer;return kf(t,e),e.finish()}function kf(t,e){if(t.resourceSpans!=null&&t.resourceSpans.length)for(let r=0;r<t.resourceSpans.length;++r)qf(t.resourceSpans[r],e.uint32(10).fork()).ldelim();return e}function qf(t,e){if(t.resource!=null&&Xf(t.resource,e.uint32(10).fork()).ldelim(),t.scopeSpans!=null&&t.scopeSpans.length)for(let r=0;r<t.scopeSpans.length;++r)Kf(t.scopeSpans[r],e.uint32(18).fork()).ldelim();return t.schemaUrl!=null&&e.uint32(26).string(t.schemaUrl),e}function Xf(t,e){if(t.attributes!=null&&t.attributes.length)for(let r=0;r<t.attributes.length;++r)et(t.attributes[r],e.uint32(10).fork()).ldelim();return t.droppedAttributesCount!=null&&e.uint32(16).uint32(t.droppedAttributesCount),e}function Kf(t,e){if(t.scope!=null&&zf(t.scope,e.uint32(10).fork()).ldelim(),t.spans!=null&&t.spans.length)for(let r=0;r<t.spans.length;++r)$f(t.spans[r],e.uint32(18).fork()).ldelim();return t.schemaUrl!=null&&e.uint32(26).string(t.schemaUrl),e}function et(t,e){return t.key!=null&&e.uint32(10).string(t.key),t.value!=null&&zs(t.value,e.uint32(18).fork()).ldelim(),e}function zs(t,e){return t.stringValue!=null&&e.uint32(10).string(t.stringValue),t.boolValue!=null&&e.uint32(16).bool(t.boolValue),t.intValue!=null&&e.uint32(24).int64(t.intValue),t.doubleValue!=null&&e.uint32(33).double(t.doubleValue),t.arrayValue!=null&&Wf(t.arrayValue,e.uint32(42).fork()).ldelim(),t.kvlistValue!=null&&Yf(t.kvlistValue,e.uint32(50).fork()).ldelim(),t.bytesValue!=null&&e.uint32(58).bytes(t.bytesValue),e}function Wf(t,e){if(t.values!=null&&t.values.length)for(let r=0;r<t.values.length;++r)zs(t.values[r],e.uint32(10).fork()).ldelim();return e}function Yf(t,e){if(t.values!=null&&t.values.length)for(let r=0;r<t.values.length;++r)et(t.values[r],e.uint32(10).fork()).ldelim();return e}function zf(t,e){if(t.name!=null&&e.uint32(10).string(t.name),t.version!=null&&e.uint32(18).string(t.version),t.attributes!=null&&t.attributes.length)for(let r=0;r<t.attributes.length;++r)et(t.attributes[r],e.uint32(26).fork()).ldelim();return t.droppedAttributesCount!=null&&e.uint32(32).uint32(t.droppedAttributesCount),e}function $f(t,e){if(t.traceId!=null&&e.uint32(10).bytes(t.traceId),t.spanId!=null&&e.uint32(18).bytes(t.spanId),t.traceState!=null&&e.uint32(26).string(t.traceState),t.parentSpanId!=null&&e.uint32(34).bytes(t.parentSpanId),t.name!=null&&e.uint32(42).string(t.name),t.kind!=null&&e.uint32(48).int32(t.kind),t.startTimeUnixNano!=null&&e.uint32(57).fixed64(t.startTimeUnixNano),t.endTimeUnixNano!=null&&e.uint32(65).fixed64(t.endTimeUnixNano),t.attributes!=null&&t.attributes.length)for(let r=0;r<t.attributes.length;++r)et(t.attributes[r],e.uint32(74).fork()).ldelim();if(t.droppedAttributesCount!=null&&e.uint32(80).uint32(t.droppedAttributesCount),t.events!=null&&t.events.length)for(let r=0;r<t.events.length;++r)Zf(t.events[r],e.uint32(90).fork()).ldelim();if(t.droppedEventsCount!=null&&e.uint32(96).uint32(t.droppedEventsCount),t.links!=null&&t.links.length)for(let r=0;r<t.links.length;++r)Jf(t.links[r],e.uint32(106).fork()).ldelim();return t.droppedLinksCount!=null&&e.uint32(112).uint32(t.droppedLinksCount),t.status!=null&&Qf(t.status,e.uint32(122).fork()).ldelim(),e}function Qf(t,e){return t.message!=null&&e.uint32(18).string(t.message),t.code!=null&&e.uint32(24).int32(t.code),e}function Zf(t,e){if(t.timeUnixNano!=null&&e.uint32(9).fixed64(t.timeUnixNano),t.name!=null&&e.uint32(18).string(t.name),t.attributes!=null&&t.attributes.length)for(let r=0;r<t.attributes.length;++r)et(t.attributes[r],e.uint32(26).fork()).ldelim();return t.droppedAttributesCount!=null&&e.uint32(32).uint32(t.droppedAttributesCount),e}function Jf(t,e){if(t.traceId!=null&&e.uint32(10).bytes(t.traceId),t.spanId!=null&&e.uint32(18).bytes(t.spanId),t.traceState!=null&&e.uint32(26).string(t.traceState),t.attributes!=null&&t.attributes.length)for(let r=0;r<t.attributes.length;++r)et(t.attributes[r],e.uint32(34).fork()).ldelim();return t.droppedAttributesCount!=null&&e.uint32(40).uint32(t.droppedAttributesCount),e}var Be=class{constructor(e={}){this.impl=new Zn(e)}export(e,r){this.impl.export(e,r)}shutdown(){return this.impl.shutdown()}forceFlush(){return this.impl.forceFlush()}},Zn=class extends Qe{convert(e){return(0,$s.createExportTraceServiceRequest)(e,void 0)}toMessage(e){return{body:Ys(e),contentType:"application/x-protobuf",headers:{accept:"application/x-protobuf"}}}getDefaultUrl(e){return yr(e)}};E();var fe=y(me(),1);function Qs(t,e){return t.replace(/\{(?<temp1>[^{}]+)\}/g,(r,n)=>{let o=e[n];return o!==void 0?String(o):r})}var tt=class{constructor(e={}){this.instrumentationName="@vercel/otel/fetch";this.instrumentationVersion="1.0.0";this.config=e}getConfig(){return this.config}setConfig(){}setTracerProvider(e){this.tracerProvider=e}setMeterProvider(){}enable(){this.disable();let{tracerProvider:e}=this;if(!e)return;let r=e.getTracer(this.instrumentationName,this.instrumentationVersion),n=this.config.ignoreUrls??[],o=(P,B)=>{if(B?.opentelemetry?.ignore!==void 0)return B.opentelemetry.ignore;if(n.length===0)return!1;let A=P.toString();return n.some(m=>typeof m=="string"?m==="*"?!0:A.startsWith(m):m.test(A))},i=process.env.VERCEL_URL||process.env.NEXT_PUBLIC_VERCEL_URL||null,s=process.env.VERCEL_BRANCH_URL||process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL||null,u=this.config.propagateContextUrls??[],c=this.config.dontPropagateContextUrls??[],a=this.config.resourceNameTemplate,{attributesFromRequestHeaders:l,attributesFromResponseHeaders:p}=this.config,d=(P,B)=>{if(B?.opentelemetry?.propagateContext)return B.opentelemetry.propagateContext;let A=P.toString();return c.length>0&&c.some(m=>typeof m=="string"?m==="*"?!0:A.startsWith(m):m.test(A))?!1:i&&P.protocol==="https:"&&(P.host===i||P.host===s||P.host===$e()?.headers.host)||!i&&P.protocol==="http:"&&P.hostname==="localhost"?!0:u.some(m=>typeof m=="string"?m==="*"?!0:A.startsWith(m):m.test(A))};process.env.NEXT_OTEL_FETCH_DISABLED="1";let g=globalThis.fetch;this.originalFetch=g;let U=async(P,B)=>{let A=B;if(A?.next?.internal)return g(P,A);let m=new Request(P instanceof Request?P.clone():P,A),ie=new URL(m.url);if(o(ie,A))return g(P,A);let Tt={[fe.SemanticAttributes.HTTP_METHOD]:m.method,[fe.SemanticAttributes.HTTP_URL]:m.url,[fe.SemanticAttributes.HTTP_HOST]:ie.host,[fe.SemanticAttributes.HTTP_SCHEME]:ie.protocol.replace(":",""),[fe.SemanticAttributes.NET_PEER_NAME]:ie.hostname,[fe.SemanticAttributes.NET_PEER_PORT]:ie.port},Lr=a?Qs(a,Tt):tp(m.url),St=A?.opentelemetry?.spanName??`fetch ${m.method} ${m.url}`,ei=f.context.active(),x=r.startSpan(St,{kind:f.SpanKind.CLIENT,attributes:{...Tt,"operation.name":`fetch.${m.method}`,"resource.name":Lr,...A?.opentelemetry?.attributes}},ei);if(!x.isRecording()||!_t(x.spanContext().traceFlags))return x.end(),g(P,A);if(d(ie,A)){let Ge=f.trace.setSpan(ei,x);f.propagation.inject(Ge,m.headers,ep)}l&&Zs(x,l,m.headers);try{let Ge=Date.now(),pe=await g(P,{...A,headers:m.headers}),ou=Date.now()-Ge;return x.setAttribute(fe.SemanticAttributes.HTTP_STATUS_CODE,pe.status),x.setAttribute("http.response_time",ou),p&&Zs(x,p,pe.headers),pe.status>=500&&Jn(x,`Status: ${pe.status} (${pe.statusText})`),pe.body?rp(pe).then(Pr=>{x.isRecording()&&(x.setAttribute(fe.SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED,Pr),x.end())},Pr=>{x.isRecording()&&(Jn(x,Pr),x.end())}):x.end(),pe}catch(Ge){throw Jn(x,Ge),x.end(),Ge}};globalThis.fetch=U}disable(){this.originalFetch&&(globalThis.fetch=this.originalFetch)}},ep={set(t,e,r){t.set(e,r)}};function tp(t){let e=t.indexOf("?");return e===-1?t:t.substring(0,e)}function rp(t){let e=0,n=t.clone().body?.getReader();if(!n)return Promise.resolve(0);let o=()=>n.read().then(({done:i,value:s})=>{if(!i)return e+=s.byteLength,o()});return o().then(()=>e)}function Jn(t,e){if(e instanceof Error)t.recordException(e),t.setStatus({code:f.SpanStatusCode.ERROR,message:e.message});else{let r=String(e);t.setStatus({code:f.SpanStatusCode.ERROR,message:r})}}function Zs(t,e,r){for(let[n,o]of Object.entries(e)){let i=r.get(o);i!==null&&t.setAttribute(n,i)}}var br=class{constructor(e={}){this.configuration=e}start(){let e=np(),r=(0,nt.getEnvWithoutDefaults)(),n=this.configuration,o=process.env.NEXT_RUNTIME||"nodejs",i=!!e.OTEL_SDK_DISABLED;if(r.OTEL_LOG_LEVEL&&f.diag.setLogger(new f.DiagConsoleLogger,{logLevel:r.OTEL_LOG_LEVEL}),i)return;let s=n.idGenerator??new tr,u=n.contextManager??new nu.AsyncLocalStorageContextManager;u.enable(),this.contextManager=u;let c=e.OTEL_SERVICE_NAME||n.serviceName||"app",a=new F(Er({[ru.SemanticResourceAttributes.SERVICE_NAME]:c,"node.ci":process.env.CI?!0:void 0,"node.env":"production",env:process.env.VERCEL_ENV||process.env.NEXT_PUBLIC_VERCEL_ENV,"vercel.region":process.env.VERCEL_REGION,"vercel.runtime":o,"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,...n.attributes})),l=n.resourceDetectors??[vo];if(n.autoDetectResources??!0){let m={detectors:l};a=a.merge(Oo(m))}let d=op(n.propagators,e),g=ap(n.traceSampler,e),U=sp(n.spanProcessors,n,e);U.length===0&&f.diag.warn("@vercel/otel: No span processors configured. No spans will be exported.");let P=n.spanLimits,B=new Po({resource:a,idGenerator:s,sampler:g,spanLimits:P});if(B.addSpanProcessor(new mr(U,n.attributesFromHeaders)),B.register({contextManager:u,propagator:new te.CompositePropagator({propagators:d})}),this.tracerProvider=B,n.logRecordProcessor){let m=new hn({resource:a});this.loggerProvider=m,m.addLogRecordProcessor(n.logRecordProcessor),se.logs.setGlobalLoggerProvider(m)}if(n.metricReader||n.views){let m=new On({resource:a,views:n.views??[]});n.metricReader&&m.addMetricReader(n.metricReader),f.metrics.setGlobalMeterProvider(m),this.meterProvider=m}let A=ip(n.instrumentations,n.instrumentationConfig);this.disableInstrumentations=(0,tu.registerInstrumentations)({instrumentations:A}),f.diag.info("@vercel/otel: started",c,o)}async shutdown(){let e=[];this.tracerProvider&&e.push(this.tracerProvider.shutdown()),this.loggerProvider&&e.push(this.loggerProvider.shutdown()),this.meterProvider&&e.push(this.meterProvider.shutdown()),f.diag.info("@vercel/otel: shutting down",e.length,process.env.NEXT_RUNTIME),await Promise.all(e),this.contextManager&&this.contextManager.disable();let{disableInstrumentations:r}=this;r&&r()}};function np(){let t=(0,nt.parseEnvironment)(process.env);return{...nt.DEFAULT_ENVIRONMENT,...t}}function ip(t,e){return(t??["auto"]).map(r=>r==="auto"?(f.diag.debug("@vercel/otel: Configure instrumentations: fetch",e?.fetch),[new tt(e?.fetch)]):r==="fetch"?(f.diag.debug("@vercel/otel: Configure instrumentations: fetch",e?.fetch),new tt(e?.fetch)):r).flat()}function op(t,e){let r=e.OTEL_PROPAGATORS&&e.OTEL_PROPAGATORS.length>0?e.OTEL_PROPAGATORS:void 0;return(t??r??["auto"]).map(n=>{if(n==="none")return[];if(n==="auto")return f.diag.debug("@vercel/otel: Configure propagators: tracecontext, baggage"),[new te.W3CTraceContextPropagator,new te.W3CBaggagePropagator];if(n==="tracecontext")return f.diag.debug("@vercel/otel: Configure propagator: tracecontext"),new te.W3CTraceContextPropagator;if(n==="baggage")return f.diag.debug("@vercel/otel: Configure propagator: baggage"),new te.W3CBaggagePropagator;if(typeof n=="string")throw new Error(`Unknown propagator: "${n}"`);return n}).flat()}var Js="always_on",rt=1;function ap(t,e){if(t&&typeof t!="string")return t;let r=t&&t!=="auto"?t:e.OTEL_TRACES_SAMPLER||Js;switch(f.diag.debug("@vercel/otel: Configure sampler: ",r),r){case"always_on":return new X;case"always_off":return new ae;case"parentbased_always_on":return new Se({root:new X});case"parentbased_always_off":return new Se({root:new ae});case"traceidratio":return new ke(eu(e));case"parentbased_traceidratio":return new Se({root:new ke(eu(e))});default:return f.diag.error(`@vercel/otel: OTEL_TRACES_SAMPLER value "${String(e.OTEL_TRACES_SAMPLER)} invalid, defaulting to ${Js}".`),new X}}function eu(t){if(t.OTEL_TRACES_SAMPLER_ARG===void 0||t.OTEL_TRACES_SAMPLER_ARG==="")return f.diag.error(`@vercel/otel: OTEL_TRACES_SAMPLER_ARG is blank, defaulting to ${rt}.`),rt;f.diag.debug("@vercel/otel: Configure sampler probability: ",t.OTEL_TRACES_SAMPLER_ARG);let e=Number(t.OTEL_TRACES_SAMPLER_ARG);return isNaN(e)?(f.diag.error(`@vercel/otel: OTEL_TRACES_SAMPLER_ARG=${t.OTEL_TRACES_SAMPLER_ARG} was given, but it is invalid, defaulting to ${rt}.`),rt):e<0||e>1?(f.diag.error(`@vercel/otel: OTEL_TRACES_SAMPLER_ARG=${t.OTEL_TRACES_SAMPLER_ARG} was given, but it is out of range ([0..1]), defaulting to ${rt}.`),rt):e}function sp(t,e,r){return[...(t??["auto"]).map(n=>{if(n==="auto"){if(process.env.VERCEL_OTEL_ENDPOINTS){let o=process.env.VERCEL_OTEL_ENDPOINTS_PORT||"4318",i=process.env.VERCEL_OTEL_ENDPOINTS_PROTOCOL||"http/protobuf";f.diag.debug("@vercel/otel: Configure vercel otel collector on port: ",o,i);let s={url:`http://localhost:${o}/v1/traces`,headers:{}},u=i==="http/protobuf"?new Be(s):new Ze(s);return new Ke(u)}return!e.traceExporter||e.traceExporter==="auto"||r.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT||r.OTEL_EXPORTER_OTLP_ENDPOINT?new Ke(up(r)):void 0}return n}).filter(fp),...e.traceExporter&&e.traceExporter!=="auto"?[new Ke(e.traceExporter)]:[]]}function up(t){let e=process.env.OTEL_EXPORTER_OTLP_TRACES_PROTOCOL??process.env.OTEL_EXPORTER_OTLP_PROTOCOL??"http/protobuf",r=lp(t),n={...te.baggageUtils.parseKeyPairsIntoRecord(t.OTEL_EXPORTER_OTLP_HEADERS),...te.baggageUtils.parseKeyPairsIntoRecord(t.OTEL_EXPORTER_OTLP_TRACES_HEADERS)};switch(f.diag.debug("@vercel/otel: Configure trace exporter: ",e,r,`headers: ${Object.keys(n).join(",")||"<none>"}`),e){case"http/json":return new Ze({url:r,headers:n});case"http/protobuf":return new Be({url:r,headers:n});default:return f.diag.warn(`@vercel/otel: Unsupported OTLP traces protocol: ${e}. Using http/protobuf.`),new Be}}var iu="v1/traces",cp=`http://localhost:4318/${iu}`;function lp(t){let e=t.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT;if(e&&typeof e=="string")return e;let r=t.OTEL_EXPORTER_OTLP_ENDPOINT;return r&&typeof r=="string"?`${r}/${iu}`:cp}function fp(t){return t!=null}function um(t){let e;t?typeof t=="string"?e={serviceName:t}:e=t:e={},new br(e).start()}export{tt as FetchInstrumentation,Ze as OTLPHttpJsonTraceExporter,Be as OTLPHttpProtoTraceExporter,um as registerOTel};
17
+ //# sourceMappingURL=index.js.map