@grafana/faro-transport-otlp-http 1.2.0 → 1.2.1

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 n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function n(e,t){return typeof e===t}const r=e=>n(e,"number")&&!isNaN(e)||n(e,"bigint"),o=e=>!(e=>n(e,"null"))(e)&&n(e,"object"),s=e=>function(e,t){return Object.prototype.toString.call(e)===`[object ${t}]`}(e,"Array");function i(){}var a,l;!function(e){e.EXCEPTION="exception",e.LOG="log",e.MEASUREMENT="measurement",e.TRACE="trace",e.EVENT="event"}(a||(a={})),a.EXCEPTION,a.LOG,a.MEASUREMENT,a.TRACE,a.EVENT,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"}(l||(l={}));const u={debug:i,error:i,info:i,prefix:"Faro",warn:i};l.ERROR;const c=Object.assign({},console);class d{constructor(){this.unpatchedConsole=c,this.internalLogger=u,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 g extends d{isBatched(){return!1}getIgnoreUrls(){return[]}}const p="1.2.0";var v="exception.type",f="exception.message",m="enduser.id",h="http.url",b="deployment.environment",y="service.name",E="service.version",L="telemetry.sdk.name",O="telemetry.sdk.language",R="telemetry.sdk.version",w="webjs";function T(e){return(e=>n(e,"string"))(e)?{stringValue:e}:(e=>r(e)&&Number.isInteger(e))(e)?{intValue:e}:r(e)?{doubleValue:e}:(e=>n(e,"boolean"))(e)?{boolValue:e}:s(e)?{arrayValue:{values:e.map(T)}}:e instanceof Uint8Array?{bytesValue:e}:o(e)?{kvlistValue:{values:Object.entries(e).map((([e,t])=>N(e,t))).filter(I)}}:{}}function N(e,t){if(null!=t&&""!==t)return{key:e,value:T(t)}}function I(e){return Boolean(e)&&"string"==typeof(null==e?void 0:e.key)&&void 0!==(null==e?void 0:e.value)}const k="browser.brands",S="browser.mobile",U="browser.user_agent",x="browser.language";function D(e){function t(e){return{scope:{name:"@grafana/faro-web-sdk",version:p},logRecords:[n(e)]}}function n(t){const{type:n}=t;switch(n){case a.LOG:return function(e){var t,n;const{meta:s,payload:i}=e,a=o(i.timestamp),l=T(i.message);return{timeUnixNano:a,severityNumber:10,severityText:"INFO2",body:l,attributes:[...r(s),N("faro.log.context",i.context)].filter(I),traceId:null===(t=i.trace)||void 0===t?void 0:t.trace_id,spanId:null===(n=i.trace)||void 0===n?void 0:n.span_id}}(t);case a.EXCEPTION:return function(e){var t,n;const{meta:s,payload:i}=e;return{timeUnixNano:o(i.timestamp),attributes:[...r(s),N(v,i.type),N(f,i.value),N("faro.error.stacktrace",i.stacktrace),N("faro.error.context",i.context)].filter(I),traceId:null===(t=i.trace)||void 0===t?void 0:t.trace_id,spanId:null===(n=i.trace)||void 0===n?void 0:n.span_id}}(t);case a.EVENT:return function(e){var t,n;const{meta:s,payload:i}=e,a=o(i.timestamp),l=T(i.name);return{timeUnixNano:a,body:l,attributes:[...r(s),N("event.name",i.name),N("event.domain",i.domain),N("event.attributes",i.attributes)].filter(I),traceId:null===(t=i.trace)||void 0===t?void 0:t.trace_id,spanId:null===(n=i.trace)||void 0===n?void 0:n.span_id}}(t);case a.MEASUREMENT:return function(e){var t,n;const{meta:s,payload:i}=e,a=o(i.timestamp),[l,u]=Object.entries(i.values).flat();return{timeUnixNano:a,attributes:[...r(s),N("measurement.type",i.type),N("measurement.name",l),N("measurement.value",u),N("faro.measurement.context",i.context)].filter(I),traceId:null===(t=i.trace)||void 0===t?void 0:t.trace_id,spanId:null===(n=i.trace)||void 0===n?void 0:n.span_id}}(t);default:return null==e||e.error(`Unknown TransportItemType: ${n}`),{}}}function r(e){const{view:t,page:n,session:r,user:o}=e;return[N("view.name",null==t?void 0:t.name),N(h,null==n?void 0:n.url),N("page.id",null==n?void 0:n.id),N("page.attributes",null==n?void 0:n.attributes),N("session.id",null==r?void 0:r.id),N("session.attributes",null==r?void 0:r.attributes),N(m,null==o?void 0:o.id),N("enduser.name",null==o?void 0:o.username),N("enduser.email",null==o?void 0:o.email),N("enduser.attributes",null==o?void 0:o.attributes)].filter(I)}function o(e){return 1e6*Date.parse(e)}return{toResourceLog:function(e){return{resource:j(e),scopeLogs:[t(e)]}},toScopeLog:t,toLogRecord:n}}function j(e){const{browser:t,sdk:n,app:r}=e.meta;return{attributes:[N(S,null==t?void 0:t.mobile),N(U,null==t?void 0:t.userAgent),N(x,null==t?void 0:t.language),N(k,null==t?void 0:t.brands),N("browser.os",null==t?void 0:t.os),N("browser.name",null==t?void 0:t.name),N("browser.version",null==t?void 0:t.version),N(L,null==n?void 0:n.name),N(R,null==n?void 0:n.version),Boolean(n)?N(O,w):void 0,N(y,null==r?void 0:r.name),N(E,null==r?void 0:r.version),N(b,null==r?void 0:r.environment)].filter(I)}}class A{constructor(e,t){this.internalLogger=e,this.resourceSpans=[],this.internalLogger=e,this.resourceLogs=[],this.getLogTransforms=D(this.internalLogger),this.getTraceTransforms=(this.internalLogger,{toResourceSpan:function(e){var t,n;const r=j(e),o=null===(n=null===(t=e.payload.resourceSpans)||void 0===t?void 0:t[0])||void 0===n?void 0:n.scopeSpans;return{resource:r,scopeSpans:null!=o?o:[]}}}),t&&this.addResourceItem(t)}getPayload(){return{resourceLogs:this.resourceLogs,resourceSpans:this.resourceSpans}}addResourceItem(e){var t,n,r,o;const{type:s}=e;try{switch(s){case a.LOG:case a.EXCEPTION:case a.EVENT:case a.MEASUREMENT:const{toLogRecord:o,toResourceLog:i}=this.getLogTransforms;0===this.resourceLogs.length?this.resourceLogs=[i(e)]:null===(n=null===(t=this.resourceLogs[0])||void 0===t?void 0:t.scopeLogs[0])||void 0===n||n.logRecords.push(o(e));break;case a.TRACE:const{toResourceSpan:l}=this.getTraceTransforms;this.resourceSpans.push(l(e));break;default:null===(r=this.internalLogger)||void 0===r||r.error(`Unknown TransportItemType: ${s}`)}}catch(e){null===(o=this.internalLogger)||void 0===o||o.error(e)}}}return e.OtlpHttpTransport=class extends g{constructor(e){var t,n,r;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:n}=e,r=[];let o=0;const s=()=>{if(o<n&&r.length){const{producer:e,resolve:t,reject:n}=r.shift();o++,e().then((e=>{o--,s(),t(e)}),(e=>{o--,s(),n(e)}))}};return{add:e=>{if(r.length+o>=t)throw new Error("Task buffer full");return new Promise(((t,n)=>{r.push({producer:e,resolve:t,reject:n}),s()}))}}}({size:null!==(n=null==e?void 0:e.bufferSize)&&void 0!==n?n:30,concurrency:null!==(r=null==e?void 0:e.concurrency)&&void 0!==r?r:5})}getIgnoreUrls(){const{tracesURL:e="",logsURL:t=""}=this.options;return[e,t].filter(Boolean)}isBatched(){return!0}send(e){const t=new A(this.internalLogger);e.forEach((e=>t.addResourceItem(e))),this.sendPayload(t.getPayload())}sendPayload(e){try{const{tracesURL:n="",logsURL:r=""}=this.options;for(const[o,i]of Object.entries(e)){if(!(s(i)&&i.length>0))continue;let e,a=e=>{},l="";switch(o){case"resourceSpans":l=n,e=this.sendingTracesDisabledUntil,a=e=>{this.sendingTracesDisabledUntil=e};break;case"resourceLogs":l=r,e=this.sendingLogsDisabledUntil,a=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 u=JSON.stringify({[o]:i}),{requestOptions:c,apiKey:d}=this.options,g=null!=c?c:{},{headers:p}=g,v=t(g,["headers"]);this.promiseBuffer.add((()=>fetch(l,Object.assign({method:"POST",headers:Object.assign(Object.assign({"Content-Type":"application/json"},null!=p?p:{}),d?{"x-api-key":d}:{}),body:u,keepalive:!0},null!=v?v:{})).then((t=>(429===t.status&&(a(this.getRetryAfterDate(t)),this.logWarn(`Too many requests, backing off until ${e}`)),t))).catch((e=>{this.logError("Failed sending payload to the receiver\n",JSON.parse(u),e)}))))}}catch(e){this.logError(e)}}getRetryAfterDate(e){const t=Date.now(),n=e.headers.get("Retry-After");if(n){const e=Number(n);if(!isNaN(e))return new Date(1e3*e+t);const r=Date.parse(n);if(!isNaN(r))return new Date(r)}return new Date(t+this.rateLimitBackoffMs)}},e}({});
1
+ var GrafanaFaroTransportOtlpHttp=function(e){"use strict";function t(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function n(e,t){return typeof e===t}const r=e=>n(e,"number")&&!isNaN(e)||n(e,"bigint"),o=e=>!(e=>n(e,"null"))(e)&&n(e,"object"),s=e=>function(e,t){return Object.prototype.toString.call(e)===`[object ${t}]`}(e,"Array");function i(){}var a,l;!function(e){e.EXCEPTION="exception",e.LOG="log",e.MEASUREMENT="measurement",e.TRACE="trace",e.EVENT="event"}(a||(a={})),a.EXCEPTION,a.LOG,a.MEASUREMENT,a.TRACE,a.EVENT,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"}(l||(l={}));const u={debug:i,error:i,info:i,prefix:"Faro",warn:i};l.ERROR;const c=Object.assign({},console);class d{constructor(){this.unpatchedConsole=c,this.internalLogger=u,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 g extends d{isBatched(){return!1}getIgnoreUrls(){return[]}}const p="1.2.1";var v="exception.type",f="exception.message",m="enduser.id",h="http.url",b="deployment.environment",y="service.name",E="service.version",L="telemetry.sdk.name",O="telemetry.sdk.language",R="telemetry.sdk.version",w="webjs";function T(e){return(e=>n(e,"string"))(e)?{stringValue:e}:(e=>r(e)&&Number.isInteger(e))(e)?{intValue:e}:r(e)?{doubleValue:e}:(e=>n(e,"boolean"))(e)?{boolValue:e}:s(e)?{arrayValue:{values:e.map(T)}}:e instanceof Uint8Array?{bytesValue:e}:o(e)?{kvlistValue:{values:Object.entries(e).map((([e,t])=>N(e,t))).filter(I)}}:{}}function N(e,t){if(null!=t&&""!==t)return{key:e,value:T(t)}}function I(e){return Boolean(e)&&"string"==typeof(null==e?void 0:e.key)&&void 0!==(null==e?void 0:e.value)}const k="browser.brands",S="browser.mobile",U="browser.user_agent",x="browser.language";function D(e){function t(e){return{scope:{name:"@grafana/faro-web-sdk",version:p},logRecords:[n(e)]}}function n(t){const{type:n}=t;switch(n){case a.LOG:return function(e){var t,n;const{meta:s,payload:i}=e,a=o(i.timestamp),l=T(i.message);return{timeUnixNano:a,severityNumber:10,severityText:"INFO2",body:l,attributes:[...r(s),N("faro.log.context",i.context)].filter(I),traceId:null===(t=i.trace)||void 0===t?void 0:t.trace_id,spanId:null===(n=i.trace)||void 0===n?void 0:n.span_id}}(t);case a.EXCEPTION:return function(e){var t,n;const{meta:s,payload:i}=e;return{timeUnixNano:o(i.timestamp),attributes:[...r(s),N(v,i.type),N(f,i.value),N("faro.error.stacktrace",i.stacktrace),N("faro.error.context",i.context)].filter(I),traceId:null===(t=i.trace)||void 0===t?void 0:t.trace_id,spanId:null===(n=i.trace)||void 0===n?void 0:n.span_id}}(t);case a.EVENT:return function(e){var t,n;const{meta:s,payload:i}=e,a=o(i.timestamp),l=T(i.name);return{timeUnixNano:a,body:l,attributes:[...r(s),N("event.name",i.name),N("event.domain",i.domain),N("event.attributes",i.attributes)].filter(I),traceId:null===(t=i.trace)||void 0===t?void 0:t.trace_id,spanId:null===(n=i.trace)||void 0===n?void 0:n.span_id}}(t);case a.MEASUREMENT:return function(e){var t,n;const{meta:s,payload:i}=e,a=o(i.timestamp),[l,u]=Object.entries(i.values).flat();return{timeUnixNano:a,attributes:[...r(s),N("measurement.type",i.type),N("measurement.name",l),N("measurement.value",u),N("faro.measurement.context",i.context)].filter(I),traceId:null===(t=i.trace)||void 0===t?void 0:t.trace_id,spanId:null===(n=i.trace)||void 0===n?void 0:n.span_id}}(t);default:return null==e||e.error(`Unknown TransportItemType: ${n}`),{}}}function r(e){const{view:t,page:n,session:r,user:o}=e;return[N("view.name",null==t?void 0:t.name),N(h,null==n?void 0:n.url),N("page.id",null==n?void 0:n.id),N("page.attributes",null==n?void 0:n.attributes),N("session.id",null==r?void 0:r.id),N("session.attributes",null==r?void 0:r.attributes),N(m,null==o?void 0:o.id),N("enduser.name",null==o?void 0:o.username),N("enduser.email",null==o?void 0:o.email),N("enduser.attributes",null==o?void 0:o.attributes)].filter(I)}function o(e){return 1e6*Date.parse(e)}return{toResourceLog:function(e){return{resource:j(e),scopeLogs:[t(e)]}},toScopeLog:t,toLogRecord:n}}function j(e){const{browser:t,sdk:n,app:r}=e.meta;return{attributes:[N(S,null==t?void 0:t.mobile),N(U,null==t?void 0:t.userAgent),N(x,null==t?void 0:t.language),N(k,null==t?void 0:t.brands),N("browser.os",null==t?void 0:t.os),N("browser.name",null==t?void 0:t.name),N("browser.version",null==t?void 0:t.version),N(L,null==n?void 0:n.name),N(R,null==n?void 0:n.version),Boolean(n)?N(O,w):void 0,N(y,null==r?void 0:r.name),N(E,null==r?void 0:r.version),N(b,null==r?void 0:r.environment)].filter(I)}}class A{constructor(e,t){this.internalLogger=e,this.resourceSpans=[],this.internalLogger=e,this.resourceLogs=[],this.getLogTransforms=D(this.internalLogger),this.getTraceTransforms=(this.internalLogger,{toResourceSpan:function(e){var t,n;const r=j(e),o=null===(n=null===(t=e.payload.resourceSpans)||void 0===t?void 0:t[0])||void 0===n?void 0:n.scopeSpans;return{resource:r,scopeSpans:null!=o?o:[]}}}),t&&this.addResourceItem(t)}getPayload(){return{resourceLogs:this.resourceLogs,resourceSpans:this.resourceSpans}}addResourceItem(e){var t,n,r,o;const{type:s}=e;try{switch(s){case a.LOG:case a.EXCEPTION:case a.EVENT:case a.MEASUREMENT:const{toLogRecord:o,toResourceLog:i}=this.getLogTransforms;0===this.resourceLogs.length?this.resourceLogs=[i(e)]:null===(n=null===(t=this.resourceLogs[0])||void 0===t?void 0:t.scopeLogs[0])||void 0===n||n.logRecords.push(o(e));break;case a.TRACE:const{toResourceSpan:l}=this.getTraceTransforms;this.resourceSpans.push(l(e));break;default:null===(r=this.internalLogger)||void 0===r||r.error(`Unknown TransportItemType: ${s}`)}}catch(e){null===(o=this.internalLogger)||void 0===o||o.error(e)}}}return e.OtlpHttpTransport=class extends g{constructor(e){var t,n,r;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:n}=e,r=[];let o=0;const s=()=>{if(o<n&&r.length){const{producer:e,resolve:t,reject:n}=r.shift();o++,e().then((e=>{o--,s(),t(e)}),(e=>{o--,s(),n(e)}))}};return{add:e=>{if(r.length+o>=t)throw new Error("Task buffer full");return new Promise(((t,n)=>{r.push({producer:e,resolve:t,reject:n}),s()}))}}}({size:null!==(n=null==e?void 0:e.bufferSize)&&void 0!==n?n:30,concurrency:null!==(r=null==e?void 0:e.concurrency)&&void 0!==r?r:5})}getIgnoreUrls(){const{tracesURL:e="",logsURL:t=""}=this.options;return[e,t].filter(Boolean)}isBatched(){return!0}send(e){const t=new A(this.internalLogger);e.forEach((e=>t.addResourceItem(e))),this.sendPayload(t.getPayload())}sendPayload(e){try{const{tracesURL:n="",logsURL:r=""}=this.options;for(const[o,i]of Object.entries(e)){if(!(s(i)&&i.length>0))continue;let e,a=e=>{},l="";switch(o){case"resourceSpans":l=n,e=this.sendingTracesDisabledUntil,a=e=>{this.sendingTracesDisabledUntil=e};break;case"resourceLogs":l=r,e=this.sendingLogsDisabledUntil,a=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 u=JSON.stringify({[o]:i}),{requestOptions:c,apiKey:d}=this.options,g=null!=c?c:{},{headers:p}=g,v=t(g,["headers"]);this.promiseBuffer.add((()=>fetch(l,Object.assign({method:"POST",headers:Object.assign(Object.assign({"Content-Type":"application/json"},null!=p?p:{}),d?{"x-api-key":d}:{}),body:u,keepalive:!0},null!=v?v:{})).then((t=>(429===t.status&&(a(this.getRetryAfterDate(t)),this.logWarn(`Too many requests, backing off until ${e}`)),t))).catch((e=>{this.logError("Failed sending payload to the receiver\n",JSON.parse(u),e)}))))}}catch(e){this.logError(e)}}getRetryAfterDate(e){const t=Date.now(),n=e.headers.get("Retry-After");if(n){const e=Number(n);if(!isNaN(e))return new Date(1e3*e+t);const r=Date.parse(n);if(!isNaN(r))return new Date(r)}return new Date(t+this.rateLimitBackoffMs)}},e}({});
@@ -3,7 +3,7 @@ import type { OtlpHttpTransportOptions } from './types';
3
3
  export declare class OtlpHttpTransport extends BaseTransport {
4
4
  private options;
5
5
  readonly name = "@grafana/faro-web-sdk:transport-otlp-http";
6
- readonly version = "1.2.0";
6
+ readonly version = "1.2.1";
7
7
  private readonly promiseBuffer;
8
8
  private readonly rateLimitBackoffMs;
9
9
  private sendingTracesDisabledUntil;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/faro-transport-otlp-http",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Faro transport which converts the Faro data model to the Otlp data model.",
5
5
  "keywords": [
6
6
  "observability",
@@ -50,10 +50,10 @@
50
50
  "quality:circular-deps": "madge --circular ."
51
51
  },
52
52
  "devDependencies": {
53
- "@grafana/faro-core": "^1.2.0"
53
+ "@grafana/faro-core": "^1.2.1"
54
54
  },
55
55
  "publishConfig": {
56
56
  "access": "public"
57
57
  },
58
- "gitHead": "438d721ff86f5140d999994efbbfa9d6e51ee1be"
58
+ "gitHead": "8bc51d9bd142485d0dd5d5fbf1dfe805aa96bcc8"
59
59
  }