@grafana/faro-transport-otlp-http 2.4.0 → 2.5.0
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
var GrafanaFaroTransportOtlpHttp=function(e){"use strict";function t(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}function r(e,t,r,n){return new(r||(r=Promise))(function(o,s){function i(e){try{l(n.next(e))}catch(e){s(e)}}function a(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(i,a)}l((n=n.apply(e,t||[])).next())})}var n;function o(e,t){return typeof e===t}"function"==typeof SuppressedError&&SuppressedError,function(e){e.EXCEPTION="exception",e.LOG="log",e.MEASUREMENT="measurement",e.TRACE="trace",e.EVENT="event"}(n||(n={})),n.EXCEPTION,n.LOG,n.MEASUREMENT,n.TRACE,n.EVENT;const s=e=>o(e,"number")&&!isNaN(e)||o(e,"bigint"),i=e=>!(e=>o(e,"null"))(e)&&o(e,"object"),a=e=>function(e,t){return Object.prototype.toString.call(e)===`[object ${t}]`}(e,"Array");var l,u;function c(){}!function(e){e.TRACE="trace",e.DEBUG="debug",e.INFO="info",e.LOG="log",e.WARN="warn",e.ERROR="error"}(l||(l={})),l.LOG,l.TRACE,l.DEBUG,l.INFO,l.LOG,l.WARN,l.ERROR,function(e){e[e.OFF=0]="OFF",e[e.ERROR=1]="ERROR",e[e.WARN=2]="WARN",e[e.INFO=3]="INFO",e[e.VERBOSE=4]="VERBOSE"}(u||(u={}));const d={debug:c,error:c,info:c,prefix:"Faro",warn:c};u.ERROR;const v=Object.assign({},console);class g{constructor(){this.unpatchedConsole=v,this.internalLogger=d,this.config={},this.metas={}}logDebug(...e){this.internalLogger.debug(`${this.name}\n`,...e)}logInfo(...e){this.internalLogger.info(`${this.name}\n`,...e)}logWarn(...e){this.internalLogger.warn(`${this.name}\n`,...e)}logError(...e){this.internalLogger.error(`${this.name}\n`,...e)}}class f extends g{isBatched(){return!1}getIgnoreUrls(){return[]}}const p="2.4.0",m="exception.message",h="exception.type";function b(e){return(e=>o(e,"string"))(e)?{stringValue:e}:(e=>s(e)&&Number.isInteger(e))(e)?{intValue:e}:s(e)?{doubleValue:e}:(e=>o(e,"boolean"))(e)?{boolValue:e}:a(e)?{arrayValue:{values:e.map(b)}}:e instanceof Uint8Array?{bytesValue:e}:i(e)?{kvlistValue:{values:Object.entries(e).map(([e,t])=>y(e,t)).filter(O)}}:{}}function y(e,t){if(null!=t&&""!==t)return{key:e,value:b(t)}}function O(e){return Boolean(e)&&"string"==typeof(null==e?void 0:e.key)&&void 0!==(null==e?void 0:e.value)}function E(e,t){function r(e){return{scope:{name:"@grafana/faro-web-sdk",version:p},logRecords:[o(e)]}}function o(r){const{type:o}=r;switch(o){case n.LOG:return function(e){var t,r;const{meta:n,payload:o}=e,a=i(o.timestamp),u=b(o.message);function c(e){switch(e){case l.TRACE:return{severityNumber:1,severityText:"TRACE"};case l.DEBUG:return{severityNumber:5,severityText:"DEBUG"};case l.INFO:return{severityNumber:9,severityText:"INFO"};case l.LOG:return{severityNumber:10,severityText:"INFO2"};case l.WARN:return{severityNumber:13,severityText:"WARN"};case l.ERROR:return{severityNumber:17,severityText:"ERROR"}}}return Object.assign(Object.assign({timeUnixNano:a},c(o.level)),{body:u,attributes:[...s(n),y("faro.log.context",o.context)].filter(O),traceId:null===(t=o.trace)||void 0===t?void 0:t.trace_id,spanId:null===(r=o.trace)||void 0===r?void 0:r.span_id})}(r);case n.EXCEPTION:return function(e){var r,n;const{meta:o,payload:a}=e,l=i(a.timestamp),u=L(e,null==t?void 0:t.createErrorLogBody);return Object.assign(Object.assign({timeUnixNano:l},u?{body:u}:{}),{attributes:[...s(o),y(h,a.type),y(m,a.value),y("faro.error.stacktrace",a.stacktrace),y("faro.error.context",a.context)].filter(O),traceId:null===(r=a.trace)||void 0===r?void 0:r.trace_id,spanId:null===(n=a.trace)||void 0===n?void 0:n.span_id})}(r);case n.EVENT:return function(e){var t,r;const{meta:n,payload:o}=e,a=i(o.timestamp),l=b(o.name);return{timeUnixNano:a,body:l,attributes:[...s(n),y("event.name",o.name),y("event.domain",o.domain),y("event.attributes",o.attributes)].filter(O),traceId:null===(t=o.trace)||void 0===t?void 0:t.trace_id,spanId:null===(r=o.trace)||void 0===r?void 0:r.span_id}}(r);case n.MEASUREMENT:return function(e){var r,n;const{meta:o,payload:a}=e,l=i(a.timestamp),[u,c]=Object.entries(a.values).flat(),d=L(e,null==t?void 0:t.createMeasurementLogBody);return Object.assign(Object.assign({timeUnixNano:l},d?{body:d}:{}),{attributes:[...s(o),y("measurement.type",a.type),y("measurement.name",u),y("measurement.value",c),y("faro.measurement.context",a.context)].filter(O),traceId:null===(r=a.trace)||void 0===r?void 0:r.trace_id,spanId:null===(n=a.trace)||void 0===n?void 0:n.span_id})}(r);default:return null==e||e.error(`Unknown TransportItemType: ${o}`),{}}}function s(e){const{view:t,page:r,session:n,user:o}=e;return[y("view.name",null==t?void 0:t.name),y("url.full",null==r?void 0:r.url),y("page.id",null==r?void 0:r.id),y("page.attributes",null==r?void 0:r.attributes),y("session.id",null==n?void 0:n.id),y("session.attributes",null==n?void 0:n.attributes),y("user.id",null==o?void 0:o.id),y("user.name",null==o?void 0:o.username),y("user.email",null==o?void 0:o.email),y("user.full_name",null==o?void 0:o.fullName),y("user.roles",null==o?void 0:o.roles),y("user.hash",null==o?void 0:o.hash),y("user.attributes",null==o?void 0:o.attributes)].filter(O)}function i(e){return 1e6*Date.parse(e)}return{toResourceLog:function(e){return{resource:R(e),scopeLogs:[r(e)]}},toScopeLog:r,toLogRecord:o}}function R(e){const{browser:t,sdk:r,app:n}=e.meta;return{attributes:[y("browser.mobile",null==t?void 0:t.mobile),y("user_agent.original",null==t?void 0:t.userAgent),y("browser.language",null==t?void 0:t.language),y("browser.brands",null==t?void 0:t.brands),y("browser.platform",null==t?void 0:t.os),y("browser.name",null==t?void 0:t.name),y("browser.version",null==t?void 0:t.version),y("browser.screen_width",null==t?void 0:t.viewportWidth),y("browser.screen_height",null==t?void 0:t.viewportHeight),y("telemetry.sdk.name",null==r?void 0:r.name),y("telemetry.sdk.version",null==r?void 0:r.version),r?y("telemetry.sdk.language","webjs"):void 0,y("service.name",null==n?void 0:n.name),y("service.version",null==n?void 0:n.version),y("service.namespace",null==n?void 0:n.namespace),y("deployment.environment.name",null==n?void 0:n.environment)].filter(O)}}function L(e,t){return"function"==typeof t?b(t(e)):void 0}class T{constructor({internalLogger:e,customOtlpTransform:t,transportItem:r}){this.resourceSpans=[],this.internalLogger=e,this.resourceLogs=[],this.getLogTransforms=E(this.internalLogger,t),this.getTraceTransforms=(this.internalLogger,{toResourceSpan:function(e){var t,r;const n=R(e),o=null===(r=null===(t=e.payload.resourceSpans)||void 0===t?void 0:t[0])||void 0===r?void 0:r.scopeSpans;return{resource:n,scopeSpans:null!=o?o:[]}}}),r&&this.addResourceItem(r)}getPayload(){return{resourceLogs:this.resourceLogs,resourceSpans:this.resourceSpans}}addResourceItem(e){var t,r,o,s;const{type:i}=e;try{switch(i){case n.LOG:case n.EXCEPTION:case n.EVENT:case n.MEASUREMENT:{const{toLogRecord:n,toResourceLog:o}=this.getLogTransforms;0===this.resourceLogs.length?this.resourceLogs=[o(e)]:null===(r=null===(t=this.resourceLogs[0])||void 0===t?void 0:t.scopeLogs[0])||void 0===r||r.logRecords.push(n(e));break}case n.TRACE:{const{toResourceSpan:t}=this.getTraceTransforms;this.resourceSpans.push(t(e));break}default:null===(o=this.internalLogger)||void 0===o||o.error(`Unknown TransportItemType: ${i}`)}}catch(e){null===(s=this.internalLogger)||void 0===s||s.error(e)}}}return e.OtlpHttpTransport=class extends f{constructor(e){var t,r,n;super(),this.options=e,this.name="@grafana/faro-web-sdk:transport-otlp-http",this.version=p,this.sendingTracesDisabledUntil=new Date,this.sendingLogsDisabledUntil=new Date,this.rateLimitBackoffMs=null!==(t=e.defaultRateLimitBackoffMs)&&void 0!==t?t:5e3,this.promiseBuffer=function(e){const{size:t,concurrency:r}=e,n=[];let o=0;const s=()=>{if(o<r&&n.length){const{producer:e,resolve:t,reject:r}=n.shift();o++,e().then(e=>{o--,s(),t(e)},e=>{o--,s(),r(e)})}};return{add:e=>{if(n.length+o>=t)throw new Error("Task buffer full");return new Promise((t,r)=>{n.push({producer:e,resolve:t,reject:r}),s()})}}}({size:null!==(r=null==e?void 0:e.bufferSize)&&void 0!==r?r:30,concurrency:null!==(n=null==e?void 0:e.concurrency)&&void 0!==n?n:5})}getIgnoreUrls(){var e;const{tracesURL:t="",logsURL:r=""}=this.options;return[t,r].filter(Boolean).concat(null!==(e=this.config.ignoreUrls)&&void 0!==e?e:[])}isBatched(){return!0}send(e){return r(this,void 0,void 0,function*(){const t=new T({internalLogger:this.internalLogger,customOtlpTransform:this.options.otlpTransform});e.forEach(e=>t.addResourceItem(e)),yield this.sendPayload(t.getPayload())})}sendPayload(e){return r(this,void 0,void 0,function*(){try{const{tracesURL:n="",logsURL:o=""}=this.options;for(const[s,i]of Object.entries(e)){if(!(a(i)&&i.length>0))continue;let e,l=e=>{},u="";switch(s){case"resourceSpans":u=n,e=this.sendingTracesDisabledUntil,l=e=>{this.sendingTracesDisabledUntil=e};break;case"resourceLogs":u=o,e=this.sendingLogsDisabledUntil,l=e=>{this.sendingLogsDisabledUntil=e}}if(e&&e>new Date(Date.now()))return void this.logWarn(`Dropping transport item due to too many requests. Backoff until ${e}`);const d=JSON.stringify({[s]:i}),{requestOptions:v,apiKey:g}=this.options,f=null!=v?v:{},{headers:p={}}=f,m=t(f,["headers"]);u&&(yield this.promiseBuffer.add(()=>r(this,void 0,void 0,function*(){const t={};for(const[e,r]of Object.entries(p))t[e]="function"==typeof r?yield Promise.resolve(r()):r;return fetch(u,Object.assign({method:"POST",headers:Object.assign(Object.assign({"Content-Type":"application/json"},t),g?{"x-api-key":g}:{}),body:d,keepalive:d.length<=6e4},null!=m?m:{})).then(t=>(429===t.status&&(l(this.getRetryAfterDate(t)),this.logWarn(`Too many requests, backing off until ${e}`)),t.text().catch(c),t)).catch(e=>{this.logError("Failed sending payload to the receiver\n",JSON.parse(d),e)})})))}}catch(e){this.logError(e)}})}getRetryAfterDate(e){const t=Date.now(),r=e.headers.get("Retry-After");if(r){const e=Number(r);if(!isNaN(e))return new Date(1e3*e+t);const n=Date.parse(r);if(!isNaN(n))return new Date(n)}return new Date(t+this.rateLimitBackoffMs)}},e}({});
|
|
1
|
+
var GrafanaFaroTransportOtlpHttp=function(e){"use strict";function t(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}function r(e,t,r,n){return new(r||(r=Promise))(function(o,s){function i(e){try{l(n.next(e))}catch(e){s(e)}}function a(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(i,a)}l((n=n.apply(e,t||[])).next())})}var n;function o(e,t){return typeof e===t}"function"==typeof SuppressedError&&SuppressedError,function(e){e.EXCEPTION="exception",e.LOG="log",e.MEASUREMENT="measurement",e.TRACE="trace",e.EVENT="event"}(n||(n={})),n.EXCEPTION,n.LOG,n.MEASUREMENT,n.TRACE,n.EVENT;const s=e=>o(e,"number")&&!isNaN(e)||o(e,"bigint"),i=e=>!(e=>o(e,"null"))(e)&&o(e,"object"),a=e=>function(e,t){return Object.prototype.toString.call(e)===`[object ${t}]`}(e,"Array");var l,u;function c(){}!function(e){e.TRACE="trace",e.DEBUG="debug",e.INFO="info",e.LOG="log",e.WARN="warn",e.ERROR="error"}(l||(l={})),l.LOG,l.TRACE,l.DEBUG,l.INFO,l.LOG,l.WARN,l.ERROR,function(e){e[e.OFF=0]="OFF",e[e.ERROR=1]="ERROR",e[e.WARN=2]="WARN",e[e.INFO=3]="INFO",e[e.VERBOSE=4]="VERBOSE"}(u||(u={}));const d={debug:c,error:c,info:c,prefix:"Faro",warn:c};u.ERROR;const v=Object.assign({},console);class g{constructor(){this.unpatchedConsole=v,this.internalLogger=d,this.config={},this.metas={}}logDebug(...e){this.internalLogger.debug(`${this.name}\n`,...e)}logInfo(...e){this.internalLogger.info(`${this.name}\n`,...e)}logWarn(...e){this.internalLogger.warn(`${this.name}\n`,...e)}logError(...e){this.internalLogger.error(`${this.name}\n`,...e)}}class f extends g{isBatched(){return!1}getIgnoreUrls(){return[]}}const p="2.5.0",m="exception.message",h="exception.type";function b(e){return(e=>o(e,"string"))(e)?{stringValue:e}:(e=>s(e)&&Number.isInteger(e))(e)?{intValue:e}:s(e)?{doubleValue:e}:(e=>o(e,"boolean"))(e)?{boolValue:e}:a(e)?{arrayValue:{values:e.map(b)}}:e instanceof Uint8Array?{bytesValue:e}:i(e)?{kvlistValue:{values:Object.entries(e).map(([e,t])=>y(e,t)).filter(O)}}:{}}function y(e,t){if(null!=t&&""!==t)return{key:e,value:b(t)}}function O(e){return Boolean(e)&&"string"==typeof(null==e?void 0:e.key)&&void 0!==(null==e?void 0:e.value)}function E(e,t){function r(e){return{scope:{name:"@grafana/faro-web-sdk",version:p},logRecords:[o(e)]}}function o(r){const{type:o}=r;switch(o){case n.LOG:return function(e){var t,r;const{meta:n,payload:o}=e,a=i(o.timestamp),u=b(o.message);function c(e){switch(e){case l.TRACE:return{severityNumber:1,severityText:"TRACE"};case l.DEBUG:return{severityNumber:5,severityText:"DEBUG"};case l.INFO:return{severityNumber:9,severityText:"INFO"};case l.LOG:return{severityNumber:10,severityText:"INFO2"};case l.WARN:return{severityNumber:13,severityText:"WARN"};case l.ERROR:return{severityNumber:17,severityText:"ERROR"}}}return Object.assign(Object.assign({timeUnixNano:a},c(o.level)),{body:u,attributes:[...s(n),y("faro.log.context",o.context)].filter(O),traceId:null===(t=o.trace)||void 0===t?void 0:t.trace_id,spanId:null===(r=o.trace)||void 0===r?void 0:r.span_id})}(r);case n.EXCEPTION:return function(e){var r,n;const{meta:o,payload:a}=e,l=i(a.timestamp),u=L(e,null==t?void 0:t.createErrorLogBody);return Object.assign(Object.assign({timeUnixNano:l},u?{body:u}:{}),{attributes:[...s(o),y(h,a.type),y(m,a.value),y("faro.error.stacktrace",a.stacktrace),y("faro.error.context",a.context)].filter(O),traceId:null===(r=a.trace)||void 0===r?void 0:r.trace_id,spanId:null===(n=a.trace)||void 0===n?void 0:n.span_id})}(r);case n.EVENT:return function(e){var t,r;const{meta:n,payload:o}=e,a=i(o.timestamp),l=b(o.name);return{timeUnixNano:a,body:l,attributes:[...s(n),y("event.name",o.name),y("event.domain",o.domain),y("event.attributes",o.attributes)].filter(O),traceId:null===(t=o.trace)||void 0===t?void 0:t.trace_id,spanId:null===(r=o.trace)||void 0===r?void 0:r.span_id}}(r);case n.MEASUREMENT:return function(e){var r,n;const{meta:o,payload:a}=e,l=i(a.timestamp),[u,c]=Object.entries(a.values).flat(),d=L(e,null==t?void 0:t.createMeasurementLogBody);return Object.assign(Object.assign({timeUnixNano:l},d?{body:d}:{}),{attributes:[...s(o),y("measurement.type",a.type),y("measurement.name",u),y("measurement.value",c),y("faro.measurement.context",a.context)].filter(O),traceId:null===(r=a.trace)||void 0===r?void 0:r.trace_id,spanId:null===(n=a.trace)||void 0===n?void 0:n.span_id})}(r);default:return null==e||e.error(`Unknown TransportItemType: ${o}`),{}}}function s(e){const{view:t,page:r,session:n,user:o}=e;return[y("view.name",null==t?void 0:t.name),y("url.full",null==r?void 0:r.url),y("page.id",null==r?void 0:r.id),y("page.attributes",null==r?void 0:r.attributes),y("session.id",null==n?void 0:n.id),y("session.attributes",null==n?void 0:n.attributes),y("user.id",null==o?void 0:o.id),y("user.name",null==o?void 0:o.username),y("user.email",null==o?void 0:o.email),y("user.full_name",null==o?void 0:o.fullName),y("user.roles",null==o?void 0:o.roles),y("user.hash",null==o?void 0:o.hash),y("user.attributes",null==o?void 0:o.attributes)].filter(O)}function i(e){return 1e6*Date.parse(e)}return{toResourceLog:function(e){return{resource:R(e),scopeLogs:[r(e)]}},toScopeLog:r,toLogRecord:o}}function R(e){const{browser:t,sdk:r,app:n}=e.meta;return{attributes:[y("browser.mobile",null==t?void 0:t.mobile),y("user_agent.original",null==t?void 0:t.userAgent),y("browser.language",null==t?void 0:t.language),y("browser.brands",null==t?void 0:t.brands),y("browser.platform",null==t?void 0:t.os),y("browser.name",null==t?void 0:t.name),y("browser.version",null==t?void 0:t.version),y("browser.screen_width",null==t?void 0:t.viewportWidth),y("browser.screen_height",null==t?void 0:t.viewportHeight),y("telemetry.sdk.name",null==r?void 0:r.name),y("telemetry.sdk.version",null==r?void 0:r.version),r?y("telemetry.sdk.language","webjs"):void 0,y("service.name",null==n?void 0:n.name),y("service.version",null==n?void 0:n.version),y("service.namespace",null==n?void 0:n.namespace),y("deployment.environment.name",null==n?void 0:n.environment)].filter(O)}}function L(e,t){return"function"==typeof t?b(t(e)):void 0}class T{constructor({internalLogger:e,customOtlpTransform:t,transportItem:r}){this.resourceSpans=[],this.internalLogger=e,this.resourceLogs=[],this.getLogTransforms=E(this.internalLogger,t),this.getTraceTransforms=(this.internalLogger,{toResourceSpan:function(e){var t,r;const n=R(e),o=null===(r=null===(t=e.payload.resourceSpans)||void 0===t?void 0:t[0])||void 0===r?void 0:r.scopeSpans;return{resource:n,scopeSpans:null!=o?o:[]}}}),r&&this.addResourceItem(r)}getPayload(){return{resourceLogs:this.resourceLogs,resourceSpans:this.resourceSpans}}addResourceItem(e){var t,r,o,s;const{type:i}=e;try{switch(i){case n.LOG:case n.EXCEPTION:case n.EVENT:case n.MEASUREMENT:{const{toLogRecord:n,toResourceLog:o}=this.getLogTransforms;0===this.resourceLogs.length?this.resourceLogs=[o(e)]:null===(r=null===(t=this.resourceLogs[0])||void 0===t?void 0:t.scopeLogs[0])||void 0===r||r.logRecords.push(n(e));break}case n.TRACE:{const{toResourceSpan:t}=this.getTraceTransforms;this.resourceSpans.push(t(e));break}default:null===(o=this.internalLogger)||void 0===o||o.error(`Unknown TransportItemType: ${i}`)}}catch(e){null===(s=this.internalLogger)||void 0===s||s.error(e)}}}return e.OtlpHttpTransport=class extends f{constructor(e){var t,r,n;super(),this.options=e,this.name="@grafana/faro-web-sdk:transport-otlp-http",this.version=p,this.sendingTracesDisabledUntil=new Date,this.sendingLogsDisabledUntil=new Date,this.rateLimitBackoffMs=null!==(t=e.defaultRateLimitBackoffMs)&&void 0!==t?t:5e3,this.promiseBuffer=function(e){const{size:t,concurrency:r}=e,n=[];let o=0;const s=()=>{if(o<r&&n.length){const{producer:e,resolve:t,reject:r}=n.shift();o++,e().then(e=>{o--,s(),t(e)},e=>{o--,s(),r(e)})}};return{add:e=>{if(n.length+o>=t)throw new Error("Task buffer full");return new Promise((t,r)=>{n.push({producer:e,resolve:t,reject:r}),s()})}}}({size:null!==(r=null==e?void 0:e.bufferSize)&&void 0!==r?r:30,concurrency:null!==(n=null==e?void 0:e.concurrency)&&void 0!==n?n:5})}getIgnoreUrls(){var e;const{tracesURL:t="",logsURL:r=""}=this.options;return[t,r].filter(Boolean).concat(null!==(e=this.config.ignoreUrls)&&void 0!==e?e:[])}isBatched(){return!0}send(e){return r(this,void 0,void 0,function*(){const t=new T({internalLogger:this.internalLogger,customOtlpTransform:this.options.otlpTransform});e.forEach(e=>t.addResourceItem(e)),yield this.sendPayload(t.getPayload())})}sendPayload(e){return r(this,void 0,void 0,function*(){try{const{tracesURL:n="",logsURL:o=""}=this.options;for(const[s,i]of Object.entries(e)){if(!(a(i)&&i.length>0))continue;let e,l=e=>{},u="";switch(s){case"resourceSpans":u=n,e=this.sendingTracesDisabledUntil,l=e=>{this.sendingTracesDisabledUntil=e};break;case"resourceLogs":u=o,e=this.sendingLogsDisabledUntil,l=e=>{this.sendingLogsDisabledUntil=e}}if(e&&e>new Date(Date.now()))return void this.logWarn(`Dropping transport item due to too many requests. Backoff until ${e}`);const d=JSON.stringify({[s]:i}),{requestOptions:v,apiKey:g}=this.options,f=null!=v?v:{},{headers:p={}}=f,m=t(f,["headers"]);u&&(yield this.promiseBuffer.add(()=>r(this,void 0,void 0,function*(){const t={};for(const[e,r]of Object.entries(p))t[e]="function"==typeof r?yield Promise.resolve(r()):r;return fetch(u,Object.assign({method:"POST",headers:Object.assign(Object.assign({"Content-Type":"application/json"},t),g?{"x-api-key":g}:{}),body:d,keepalive:d.length<=6e4},null!=m?m:{})).then(t=>(429===t.status&&(l(this.getRetryAfterDate(t)),this.logWarn(`Too many requests, backing off until ${e}`)),t.text().catch(c),t)).catch(e=>{this.logError("Failed sending payload to the receiver\n",JSON.parse(d),e)})})))}}catch(e){this.logError(e)}})}getRetryAfterDate(e){const t=Date.now(),r=e.headers.get("Retry-After");if(r){const e=Number(r);if(!isNaN(e))return new Date(1e3*e+t);const n=Date.parse(r);if(!isNaN(n))return new Date(n)}return new Date(t+this.rateLimitBackoffMs)}},e}({});
|
|
@@ -4,7 +4,7 @@ import type { OtlpHttpTransportOptions } from './types';
|
|
|
4
4
|
export declare class OtlpHttpTransport extends BaseTransport {
|
|
5
5
|
private options;
|
|
6
6
|
readonly name = "@grafana/faro-web-sdk:transport-otlp-http";
|
|
7
|
-
readonly version = "2.
|
|
7
|
+
readonly version = "2.5.0";
|
|
8
8
|
private readonly promiseBuffer;
|
|
9
9
|
private readonly rateLimitBackoffMs;
|
|
10
10
|
private sendingTracesDisabledUntil;
|
|
@@ -4,7 +4,7 @@ import type { OtlpHttpTransportOptions } from './types';
|
|
|
4
4
|
export declare class OtlpHttpTransport extends BaseTransport {
|
|
5
5
|
private options;
|
|
6
6
|
readonly name = "@grafana/faro-web-sdk:transport-otlp-http";
|
|
7
|
-
readonly version = "2.
|
|
7
|
+
readonly version = "2.5.0";
|
|
8
8
|
private readonly promiseBuffer;
|
|
9
9
|
private readonly rateLimitBackoffMs;
|
|
10
10
|
private sendingTracesDisabledUntil;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grafana/faro-transport-otlp-http",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Faro transport which converts the Faro data model to the Otlp data model.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"observability",
|
|
@@ -53,14 +53,14 @@
|
|
|
53
53
|
"quality:circular-deps": "madge --circular ."
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@grafana/faro-core": "^2.
|
|
56
|
+
"@grafana/faro-core": "^2.5.0"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@opentelemetry/otlp-transformer": "^0.
|
|
62
|
+
"@opentelemetry/otlp-transformer": "^0.216.0",
|
|
63
63
|
"@opentelemetry/semantic-conventions": "^1.28.0"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "be7742480b1b4d936f3476620aab338237ae16ca"
|
|
66
66
|
}
|