@launchdarkly/browser-telemetry 1.0.10 → 1.0.11
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/CHANGELOG.md +9 -0
- package/dist/index.cjs +5 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
function H(e){try{return e.target}catch(t){return}}
|
|
1
|
+
function H(e){try{return e.target}catch(t){return}}function Re(e){let t=e;return typeof t=="object"&&t!=null&&t.parentNode}function De(e){if(typeof e.className!="string")return;let t=e.className;if(e.className.includes(" ")&&(t=e.className.replace(" ",".")),t!=="")return`.${t}`}function Ce(e){if(!e.tagName)return"";let t=[];t.push(e.tagName.toLowerCase()),e.id&&t.push(`#${e.id}`);let r=De(e);return r&&t.push(r),t.join("")}function A(e,t={maxDepth:10}){let r=[],n=e;for(;Re(n)&&n.parentNode&&r.length<t.maxDepth;){let s=Ce(n);if(s==="html")break;r.push(s),n=n.parentNode}return r.reverse().join(" > ")}var X=class{constructor(){window.addEventListener("click",t=>{var n;let r=H(t);if(r){let s={class:"ui",type:"click",level:"info",timestamp:Date.now(),message:A(r)};(n=this._destination)==null||n.addBreadcrumb(s)}},!0)}register(t,r){this._destination=t}unregister(){this._destination=void 0}};var Me=1e3,Pe=["INPUT","TEXTAREA"],j=class{constructor(){window.addEventListener("keypress",t=>{var s;let r=H(t),n=r;if(r&&(Pe.includes(r.tagName)||n!=null&&n.isContentEditable)){let f={class:"ui",type:"input",level:"info",timestamp:Date.now(),message:A(r)};this._shouldDeduplicate(f)||((s=this._destination)==null||s.addBreadcrumb(f),this._lastEvent=f)}},!0)}register(t,r){this._destination=t}unregister(){this._destination=void 0}_shouldDeduplicate(t){return this._lastEvent?Math.abs(t.timestamp-this._lastEvent.timestamp)<=Me&&this._lastEvent.message===t.message:!1}};var q=class{constructor(){window.addEventListener("error",t=>{var r;(r=this._destination)==null||r.captureErrorEvent(t)},!0),window.addEventListener("unhandledrejection",t=>{var r;t.reason&&((r=this._destination)==null||r.captureError(t.reason))},!0)}register(t){this._destination=t}unregister(){this._destination=void 0}};function ne(e,t){return t?e.reduce((r,n)=>n(r),t):""}function K(e,t){var r;(r=e.data)!=null&&r.url&&(e.data.url=ne(t.urlFilters,e.data.url))}var Ne="__LaunchDarkly_original_fetch",W=window.fetch;function Ue(e,t){var s;let r="",n="GET";return typeof e=="string"&&(r=e),typeof Request!="undefined"&&e instanceof Request&&(r=e.url,n=e.method),typeof URL!="undefined"&&e instanceof URL&&(r=e.toString()),t&&(n=(s=t.method)!=null?s:n),{url:r,method:n}}function ie(e){function t(...r){let n=Date.now();return W.apply(this,r).then(s=>{let f={class:"http",timestamp:n,level:s.ok?"info":"error",type:"fetch",data:{...Ue(r[0],r[1]),statusCode:s.status,statusText:s.statusText}};return e(f),s})}t.prototype=W==null?void 0:W.prototype;try{Object.defineProperty(t,Ne,{value:W,writable:!0,configurable:!0})}catch(r){}window.fetch=t}var G=class{constructor(t){this._loggedIssue=!1;ie(r=>{var s,f,x;let n=!1;try{K(r,t),n=!0}catch(k){this._loggedIssue||((f=(s=t.getLogger)==null?void 0:s.call(t))==null||f.warn("Error filtering http breadcrumb",k),this._loggedIssue=!0)}n&&((x=this._destination)==null||x.addBreadcrumb(r))})}register(t,r){this._destination=t}unregister(){this._destination=void 0}};var Le="__LaunchDarkly_original_xhr",$e=`${Le}_open`,He=`${Le}_send`,ee="__LaunchDarkly_data_xhr",xe=window.XMLHttpRequest.prototype.open,ye=window.XMLHttpRequest.prototype.send;function se(e){function t(...n){this.addEventListener("error",function(s){let f=this[ee];f.error=!0}),this.addEventListener("loadend",function(s){let f=this[ee];f&&f.timestamp&&e({class:"http",timestamp:f.timestamp,level:f.error?"error":"info",type:"xhr",data:{url:f.url,method:f.method,statusCode:this.status,statusText:this.statusText}})},!0),xe.apply(this,n);try{let s={method:n==null?void 0:n[0],url:n==null?void 0:n[1]};Object.defineProperty(this,ee,{value:s,writable:!0,configurable:!0})}catch(s){}}function r(...n){ye.apply(this,n);let s=this[ee];s&&(s.timestamp=Date.now())}window.XMLHttpRequest.prototype.open=t,window.XMLHttpRequest.prototype.send=r;try{Object.defineProperties(window.XMLHttpRequest,{[$e]:{value:xe,writable:!0,configurable:!0},[He]:{value:ye,writable:!0,configurable:!0}})}catch(n){}}var z=class{constructor(t){this._loggedIssue=!1;se(r=>{var s,f,x;let n=!1;try{K(r,t),n=!0}catch(k){this._loggedIssue||((f=(s=t.getLogger)==null?void 0:s.call(t))==null||f.warn("Error filtering http breadcrumb",k),this._loggedIssue=!0)}n&&((x=this._destination)==null||x.addBreadcrumb(r))})}register(t,r){this._destination=t}unregister(){this._destination=void 0}};var Ae=/sdk\/evalx\/[^/]+\/contexts\/(?<context>[^/?]*)\??.*?/,Xe=/\/eval\/[^/]+\/(?<context>[^/?]*)\??.*?/;function je(e){try{if(e.includes("://")){let t=new URL(e),r=!1;if(t.username&&(t.username="redacted",r=!0),t.password&&(t.password="redacted",r=!0),r)return t.toString()}}catch(t){}return e}function qe(e){var t,r;if(e.includes("/sdk/evalx")){let n=e.match(Ae),s=(t=n==null?void 0:n.groups)==null?void 0:t.context;if(s)return e.replace(s,"*".repeat(s.length))}if(e.includes("/eval/")){let n=e.match(Xe),s=(r=n==null?void 0:n.groups)==null?void 0:r.context;if(s)return e.replace(s,"*".repeat(s.length))}return e}function ae(e){return qe(je(e))}function oe(e,t,r){e.breadcrumbs.evaluations&&t.push({type:"flag-used",name:"launchdarkly-browser-telemetry-flag-used",synchronous:!0,method(n,s,f){r.handleFlagUsed(n,s,f)}}),e.breadcrumbs.flagChange&&t.push({type:"flag-detail-changed",name:"launchdarkly-browser-telemetry-flag-used",synchronous:!0,method(n,s){r.handleFlagDetailChanged(n,s)}})}var S={warn:console.warn},Ke="LaunchDarkly - Browser Telemetry:";function T(e){return`${Ke} ${e}`}function P(e){return{warn:(...t)=>{if(!e){S.warn(...t);return}try{e.warn(...t)}catch(r){S.warn(...t),S.warn(T("The provided logger threw an exception, using fallback logger."))}}}}var We={start:0,end:3},Ge={start:4,end:5},ce={start:6,end:7},ue={start:8,end:8},ze={start:9,end:9},Ve={start:10,end:15};function Ye(){if(crypto&&crypto.getRandomValues){let t=new Uint8Array(16);return crypto.getRandomValues(t),[...t.values()]}let e=[];for(let t=0;t<16;t+=1)e.push(Math.floor(Math.random()*256));return e}function N(e,t){let r="";for(let n=t.start;n<=t.end;n+=1)r+=e[n].toString(16).padStart(2,"0");return r}function Ze(e){return e[ue.start]=(e[ue.start]|128)&191,e[ce.start]=e[ce.start]&15|64,`${N(e,We)}-${N(e,Ge)}-${N(e,ce)}-${N(e,ue)}${N(e,ze)}-${N(e,Ve)}`}function Je(){let e=Ye();return Ze(e)}function le(){return typeof crypto!==void 0&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Je()}var y={};(function(e,t){if(!e)return;let r=[].slice,n="?",s=/^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/;function f(k,F){return Object.prototype.hasOwnProperty.call(k,F)}function x(k){return typeof k=="undefined"}y.wrap=function(F){function B(){try{return F.apply(this,arguments)}catch(Z){throw y.report(Z),Z}}return B},y.computeStackTrace=function(){let B={};function Z(a){if(!y.remoteFetching)return"";try{let u=function(){try{return new e.XMLHttpRequest}catch(p){return new e.ActiveXObject("Microsoft.XMLHTTP")}}();return u.open("GET",a,!1),u.send(""),u.responseText}catch(c){return""}}function D(a){if(typeof a!="string")return[];if(!f(B,a)){let c="",u="";try{u=e.document.domain}catch(o){}let p=/(.*)\:\/\/([^:\/]+)([:\d]*)\/{0,1}([\s\S]*)/.exec(a);p&&p[2]===u&&(c=Z(a)),B[a]=c?c.split(`
|
|
2
2
|
`):[]}return B[a]}function C(a,c){typeof c!="number"&&(c=Number(c));let u=/function ([^(]*)\(([^)]*)\)/,p=/['"]?([0-9A-Za-z$_]+)['"]?\s*[:=]\s*(function|eval|new Function)/,o="",b=10,g=D(a),d;if(!g.length)return n;for(let l=0;l<b;++l)if(o=g[c-l]+o,!x(o)&&((d=p.exec(o))||(d=u.exec(o))))return d[1];return n}function $(a,c){typeof c!="number"&&(c=Number(c));let u=D(a);if(!u.length)return null;let p=[],o=Math.floor(y.linesOfContext/2),b=o+y.linesOfContext%2,g=Math.max(0,c-o-1),d=Math.min(u.length,c+b-1);c-=1;for(let l=g;l<d;++l)x(u[l])||p.push(u[l]);return p.length>0?{contextLines:p,startFromSource:g+1}:null}function J(a){return a.replace(/[\-\[\]{}()*+?.,\\\^$|#]/g,"\\$&")}function de(a){return J(a).replace("<","(?:<|<)").replace(">","(?:>|>)").replace("&","(?:&|&)").replace('"','(?:"|")').replace(/\s+/g,"\\s+")}function Q(a,c){let u,p;for(let o=0,b=c.length;o<b;++o)if((u=D(c[o])).length&&(u=u.join(`
|
|
3
3
|
`),p=a.exec(u)))return{url:c[o],line:u.substring(0,p.index).split(`
|
|
4
4
|
`).length,column:p.index-u.lastIndexOf(`
|
|
5
5
|
`,p.index)-1};return null}function re(a,c,u){typeof u!="number"&&(u=Number(u));let p=D(c),o=new RegExp(`\\b${J(a)}\\b`),b;return u-=1,p&&p.length>u&&(b=o.exec(p[u]))?b.index:null}function we(a){if(x(e&&e.document))return;let c=[e.location.href],u=e.document.getElementsByTagName("script"),p,o=`${a}`,b=/^function(?:\s+([\w$]+))?\s*\(([\w\s,]*)\)\s*\{\s*(\S[\s\S]*\S)\s*\}\s*$/,g=/^function on([\w$]+)\s*\(event\)\s*\{\s*(\S[\s\S]*\S)\s*\}\s*$/,d,l,m;for(let i=0;i<u.length;++i){let h=u[i];h.src&&c.push(h.src)}if(!(l=b.exec(o)))d=new RegExp(J(o).replace(/\s+/g,"\\s+"));else{let i=l[1]?`\\s+${l[1]}`:"",h=l[2].split(",").join("\\s*,\\s*");p=J(l[3]).replace(/;$/,";?"),d=new RegExp(`function${i}\\s*\\(\\s*${h}\\s*\\)\\s*{\\s*${p}\\s*}`)}if(m=Q(d,c))return m;if(l=g.exec(o)){let i=l[1];if(p=de(l[2]),d=new RegExp(`on${i}=[\\'"]\\s*${p}\\s*[\\'"]`,"i"),(m=Q(d,c[0]))||(d=new RegExp(p),m=Q(d,c)))return m}return null}function pe(a){var L;if(!a.stack)return null;let c=/^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,u=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i,p=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i,o,b=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,g=/\((\S*)(?::(\d+))(?::(\d+))\)/,d=a.stack.split(`
|
|
6
|
-
`),l=[],m,i,h,E=/^(.*) is undefined$/.exec(a.message);for(let
|
|
7
|
-
`),b=[],g;for(let l=0;l<o.length;l+=2){let m=null;if((g=u.exec(o[l]))?m={url:g[2],line:+g[1],column:null,func:g[3],args:[]}:(g=p.exec(o[l]))&&(m={url:g[6],line:+g[1],column:+g[2],func:g[3]||g[4],args:g[5]?g[5].split(","):[]}),m){if(!m.func&&m.line&&(m.func=C(m.url,m.line)),m.line)try{let i=$(m.url,m.line);m.srcStart=i==null?void 0:i.startFromSource,m.context=m.line&&(d=i==null?void 0:i.contextLines)!=null?d:null}catch(i){}m.context||(m.context=[o[l+1]]),b.push(m)}}return b.length?{mode:"stacktrace",name:a.name,message:a.message,stack:b}:null}function
|
|
6
|
+
`),l=[],m,i,h,E=/^(.*) is undefined$/.exec(a.message);for(let O=0,Ie=d.length;O<Ie;++O){if(i=c.exec(d[O])){let be=i[2]&&i[2].indexOf("native")===0;o=i[2]&&i[2].indexOf("eval")===0,o&&(m=g.exec(i[2]))&&(i[2]=m[1],i[3]=m[2],i[4]=m[3]),h={url:be?null:i[2],func:i[1]||n,args:be?[i[2]]:[],line:i[3]?+i[3]:null,column:i[4]?+i[4]:null}}else if(i=p.exec(d[O]))h={url:i[2],func:i[1]||n,args:[],line:+i[3],column:i[4]?+i[4]:null};else if(i=u.exec(d[O]))o=i[3]&&i[3].indexOf(" > eval")>-1,o&&(m=b.exec(i[3]))?(i[3]=m[1],i[4]=m[2],i[5]=null):O===0&&!i[5]&&!x(a.columnNumber)&&(l[0].column=a.columnNumber+1),h={url:i[3],func:i[1]||n,args:i[2]?i[2].split(","):[],line:i[4]?+i[4]:null,column:i[5]?+i[5]:null};else continue;!h.func&&h.line&&(h.func=C(h.url,h.line));let M=$(h.url,h.line);h.context=h.line&&(L=M==null?void 0:M.contextLines)!=null?L:null,h.srcStart=M==null?void 0:M.startFromSource,l.push(h)}return l.length?(l[0]&&l[0].line&&!l[0].column&&E&&(l[0].column=re(E[1],l[0].url,l[0].line)),{mode:"stack",name:a.name,message:a.message,stack:l}):null}function Oe(a){var d;let{stacktrace:c}=a;if(!c)return null;let u=/ line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i,p=/ line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^\)]+))\((.*)\))? in (.*):\s*$/i,o=c.split(`
|
|
7
|
+
`),b=[],g;for(let l=0;l<o.length;l+=2){let m=null;if((g=u.exec(o[l]))?m={url:g[2],line:+g[1],column:null,func:g[3],args:[]}:(g=p.exec(o[l]))&&(m={url:g[6],line:+g[1],column:+g[2],func:g[3]||g[4],args:g[5]?g[5].split(","):[]}),m){if(!m.func&&m.line&&(m.func=C(m.url,m.line)),m.line)try{let i=$(m.url,m.line);m.srcStart=i==null?void 0:i.startFromSource,m.context=m.line&&(d=i==null?void 0:i.contextLines)!=null?d:null}catch(i){}m.context||(m.context=[o[l+1]]),b.push(m)}}return b.length?{mode:"stacktrace",name:a.name,message:a.message,stack:b}:null}function Fe(a){let c=a.message.split(`
|
|
8
8
|
`);if(c.length<4)return null;let u=/^\s*Line (\d+) of linked script ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,p=/^\s*Line (\d+) of inline#(\d+) script in ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,o=/^\s*Line (\d+) of function script\s*$/i,b=[],g=e&&e.document&&e.document.getElementsByTagName("script"),d=[],l;for(let m in g)f(g,m)&&!g[m].src&&d.push(g[m]);for(let m=2;m<c.length;m+=2){let i=null;if(l=u.exec(c[m]))i={url:l[2],func:l[3],args:[],line:+l[1],column:null};else if(l=p.exec(c[m])){i={url:l[3],func:l[4],args:[],line:+l[1],column:null};let h=+l[1],E=d[l[2]-1];if(E){let L=D(i.url);if(L){L=L.join(`
|
|
9
|
-
`);let
|
|
10
|
-
`).length)}}}else if(l=o.exec(c[m])){let h=e.location.href.replace(/#.*$/,""),E=new RegExp(de(c[m+1])),L=Q(E,[h]);i={url:h,func:"",args:[],line:L?L.line:l[1],column:null}}if(i){i.func||(i.func=C(i.url,i.line));let h=$(i.url,i.line);i.srcStart=h==null?void 0:h.startFromSource;let E=h==null?void 0:h.contextLines,L=E?E[Math.floor(E.length/2)]:null;E&&L&&L.replace(/^\s*/,"")===c[m+1].replace(/^\s*/,"")?i.context=E:i.context=[c[m+1]],b.push(i)}}return b.length?{mode:"multiline",name:a.name,message:c[0],stack:b}:null}function ge(a,c,u,p){var b;let o={url:c,line:u};if(o.url&&o.line){if(a.incomplete=!1,o.func||(o.func=C(o.url,o.line)),!o.context){let d=$(o.url,o.line);o.context=(b=d==null?void 0:d.contextLines)!=null?b:null,o.srcStart=d==null?void 0:d.startFromSource}let g=/ '([^']+)' /.exec(p);if(g&&(o.column=re(g[1],o.url,o.line)),a.stack.length>0&&a.stack[0].url===o.url){if(a.stack[0].line===o.line)return!1;if(!a.stack[0].line&&a.stack[0].func===o.func)return a.stack[0].line=o.line,a.stack[0].context=o.context,!1}return a.stack.unshift(o),a.partial=!0,!0}return a.incomplete=!0,!1}function he(a,c){let u=/function\s+([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)?\s*\(/i,p=[],o={},b=!1,g,d,l;for(let i=he.caller;i&&!b;i=i.caller)if(!(i===w||i===y.report)){if(d={url:null,func:n,args:[],line:null,column:null},i.name?d.func=i.name:(g=u.exec(i.toString()))&&(d.func=g[1]),typeof d.func=="undefined")try{d.func=g.input.substring(0,g.input.indexOf("{"))}catch(h){}if(l=we(i)){d.url=l.url,d.line=l.line,d.func===n&&(d.func=C(d.url,d.line));let h=/ '([^']+)' /.exec(a.message||a.description);h&&(d.column=re(h[1],l.url,l.line))}o[`${i}`]?b=!0:o[`${i}`]=!0,p.push(d)}c&&p.splice(0,c);let m={mode:"callers",name:a.name,message:a.message,stack:p};return ge(m,a.sourceURL||a.fileName,a.line||a.lineNumber,a.message||a.description),m}function w(a,c){let u=null;c=c==null?0:+c;try{if(u=Fe(a),u)return u}catch(p){}try{if(u=pe(a),u)return u}catch(p){}try{if(u=Oe(a),u)return u}catch(p){}try{if(u=he(a,c+1),u)return u}catch(p){}return{name:a.name,message:a.message,mode:"failed",stack:[]}}function Be(a){a=(a==null?0:+a)+1;try{throw new Error}catch(c){return w(c,a+1)}}return w.augmentStackTraceWithInitialElement=ge,w.computeStackTraceFromStackProp=pe,w.guessFunctionName=C,w.gatherContext=$,w.ofCaller=Be,w.getSource=D,w}(),y.remoteFetching||(y.remoteFetching=!0),y.collectWindowErrors||(y.collectWindowErrors=!0),(!y.linesOfContext||y.linesOfContext<1)&&(y.linesOfContext=11)})(typeof window!="undefined"?window:global);function te(){return y}var ve="(index)";function tt(e,t){let r=e;if(e.startsWith(t)){if(r=e.slice(t.length),r.startsWith("/")&&(r=r.slice(1)),r==="")return ve;r.endsWith("/")&&(r+=ve)}return r}function rt(e,t,r){return Math.min(t,Math.max(e,r))}function Ee(e,t,r){if(t.length<=e.maxLength)return t;let n=Math.max(0,r-e.beforeColumnCharacters),s=Math.min(t.length,n+e.maxLength);return t.slice(n,s)}function _e(e,t,r,n){let s=e<0?0:e,f=t>r.length?r.length:t;return s<f?r.slice(s,f).map(n):[]}function nt(e,t){var k,O;let{context:r}=e;if(!r)return{};let{maxLineLength:n}=t.source,s=Math.floor(n/2),f=B=>Ee({maxLength:t.source.maxLineLength,beforeColumnCharacters:s},B,0),x=rt(0,r.length-1,((k=e==null?void 0:e.line)!=null?k:0)-((O=e.srcStart)!=null?O:0));return{srcBefore:_e(x-t.source.beforeLines,x,r,f),srcLine:Ee({maxLength:n,beforeColumnCharacters:s},r[x],e.column||0),srcAfter:_e(x+1,x+1+t.source.afterLines,r,f)}}function fe(e,t){return t.enabled?{frames:te().computeStackTrace(e).stack.reverse().map(s=>{var f,x;return{fileName:tt(s.url,window.location.origin),function:s.func,line:(f=s.line)!=null?f:void 0,col:(x=s.column)!=null?x:void 0,...nt(s,t)}})}:{frames:[]}}var Se="$ld:telemetry",it=`${Se}:error`,st=`${Se}:session:init`,ke="generic",at="exception was null or undefined",ot="exception had no message",ct=5;function Te(e){switch(typeof e){case"string":case"boolean":case"number":return e;default:return}}function ut(e,t){return e===void 0?void 0:t(e)}function lt(e){if(!e.enabled)return;let t=te(),r=Math.max(e.source.afterLines,e.source.beforeLines),n=t;n.linesOfContext=r*2+1}function ft(e){return e.logger!==void 0}function mt(e){return e.waitForInitialization!==void 0}var I=class{constructor(t){this._options=t;this._pendingEvents=[];this._breadcrumbs=[];this._inspectorInstances=[];this._collectors=[];this._sessionId=le();this._registrationComplete=!1;this._eventsDropped=!1;this._breadcrumbFilterError=!1;this._errorFilterError=!1;var f;lt(t.stack),this._collectors.push(new q),this._collectors.push(...t.collectors),this._maxPendingEvents=t.maxPendingEvents,this._maxBreadcrumbs=t.breadcrumbs.maxBreadcrumbs,this._logger=(f=this._options.logger)!=null?f:S;let r=[ae];t.breadcrumbs.http.customUrlFilter&&r.push(t.breadcrumbs.http.customUrlFilter),t.breadcrumbs.http.instrumentFetch&&this._collectors.push(new G({urlFilters:r,getLogger:()=>this._logger})),t.breadcrumbs.http.instrumentXhr&&this._collectors.push(new z({urlFilters:r,getLogger:()=>this._logger})),t.breadcrumbs.click&&this._collectors.push(new X),t.breadcrumbs.keyboardInput&&this._collectors.push(new j),this._collectors.forEach(x=>x.register(this,this._sessionId));let n=this,s=[];oe(t,s,n),this._inspectorInstances.push(...s)}register(t){if(this._client!==void 0)return;this._client=t,this._setLogger();let r=()=>{var n;(n=this._client)==null||n.track(st,{sessionId:this._sessionId}),this._pendingEvents.forEach(s=>{var f;(f=this._client)==null||f.track(s.type,s.data)}),this._pendingEvents=[],this._registrationComplete=!0};mt(t)?(async()=>{try{await t.waitForInitialization(ct)}catch(n){}r()})():r()}_setLogger(){this._options.logger?this._logger=this._options.logger:ft(this._client)?this._logger=this._client.logger:this._logger=S}inspectors(){return this._inspectorInstances}_capture(t,r){var s;let n=this._applyFilters(r,this._options.errorFilters,f=>{this._errorFilterError||(this._errorFilterError=!0,this._logger.warn(T(`Error applying error filters: ${f}`)))});n!==void 0&&(this._registrationComplete?(s=this._client)==null||s.track(t,n):(this._pendingEvents.push({type:t,data:n}),this._pendingEvents.length>this._maxPendingEvents&&(this._eventsDropped||(this._eventsDropped=!0,this._logger.warn(T("Maximum pending events reached. Old events will be dropped until the SDK client is registered."))),this._pendingEvents.shift())))}captureError(t){var s,f;let n=t!=null?{type:t.name||((s=t.constructor)==null?void 0:s.name)||ke,message:(f=t.message)!=null?f:ot,stack:fe(t,this._options.stack),breadcrumbs:[...this._breadcrumbs],sessionId:this._sessionId}:{type:ke,message:at,stack:{frames:[]},breadcrumbs:[...this._breadcrumbs],sessionId:this._sessionId};this._capture(it,n)}captureErrorEvent(t){this.captureError(t.error)}_applyFilters(t,r,n){try{return r.reduce((s,f)=>ut(s,f),t)}catch(s){n(s);return}}addBreadcrumb(t){let r=this._applyFilters(t,this._options.breadcrumbs.filters,n=>{this._breadcrumbFilterError||(this._breadcrumbFilterError=!0,this._logger.warn(T(`Error applying breadcrumb filters: ${n}`)))});r!==void 0&&(this._breadcrumbs.push(r),this._breadcrumbs.length>this._maxBreadcrumbs&&this._breadcrumbs.shift())}close(){this._collectors.forEach(t=>t.unregister())}handleFlagUsed(t,r,n){let s={type:"flag-evaluated",data:{key:t,value:Te(r.value)},timestamp:new Date().getTime(),class:"feature-management",level:"info"};this.addBreadcrumb(s)}handleFlagDetailChanged(t,r){let n={type:"flag-detail-changed",data:{key:t,value:Te(r.value)},timestamp:new Date().getTime(),class:"feature-management",level:"info"};this.addBreadcrumb(n)}};var dt={maxBreadcrumbs:0,evaluations:!1,flagChange:!1,click:!1,keyboardInput:!1,http:{instrumentFetch:!1,instrumentXhr:!1,customUrlFilter:void 0},filters:[]},pt={enabled:!1,source:{beforeLines:0,afterLines:0,maxLineLength:0}};function gt(){return{breadcrumbs:{maxBreadcrumbs:50,evaluations:!0,flagChange:!0,click:!0,keyboardInput:!0,http:{instrumentFetch:!0,instrumentXhr:!0},filters:[]},stack:{enabled:!0,source:{beforeLines:3,afterLines:3,maxLineLength:280}},maxPendingEvents:100,collectors:[],errorFilters:[]}}function U(e,t,r){return T(`Config option "${e}" should be of type ${t}, got ${r}, using default value`)}function _(e,t,r){return n=>{let s=typeof n;return s===e?!0:(r==null||r.warn(U(t,e,s)),!1)}}function v(e,t,r){return e!=null&&(!r||r(e))?e:t}function ht(e,t,r){if(e!==void 0&&e!==!1&&typeof e!="object")return r==null||r.warn(U("breadcrumbs.http","HttpBreadCrumbOptions | false",typeof e)),t;if(e===!1)return{instrumentFetch:!1,instrumentXhr:!1};e!=null&&e.customUrlFilter&&typeof e.customUrlFilter!="function"&&(r==null||r.warn(T(`The "breadcrumbs.http.customUrlFilter" must be a function. Received ${typeof e.customUrlFilter}`)));let n=e!=null&&e.customUrlFilter&&typeof(e==null?void 0:e.customUrlFilter)=="function"?e.customUrlFilter:void 0;return{instrumentFetch:v(e==null?void 0:e.instrumentFetch,t.instrumentFetch,_("boolean","breadcrumbs.http.instrumentFetch",r)),instrumentXhr:v(e==null?void 0:e.instrumentXhr,t.instrumentXhr,_("boolean","breadcrumbs.http.instrumentXhr",r)),customUrlFilter:n}}function bt(e){if(e.logger){let{logger:t}=e;if(typeof t=="object"&&t!==null&&"warn"in t)return P(t);S.warn(U("logger","MinLogger or LDLogger",typeof t))}}function xt(e,t,r){var n,s,f;return e===!1?pt:{enabled:!0,source:{beforeLines:v((n=e==null?void 0:e.source)==null?void 0:n.beforeLines,t.source.beforeLines,_("number","stack.beforeLines",r)),afterLines:v((s=e==null?void 0:e.source)==null?void 0:s.afterLines,t.source.afterLines,_("number","stack.afterLines",r)),maxLineLength:v((f=e==null?void 0:e.source)==null?void 0:f.maxLineLength,t.source.maxLineLength,_("number","stack.maxLineLength",r))}}}function yt(e,t,r){return e===!1?dt:{maxBreadcrumbs:v(e==null?void 0:e.maxBreadcrumbs,t.maxBreadcrumbs,_("number","breadcrumbs.maxBreadcrumbs",r)),evaluations:v(e==null?void 0:e.evaluations,t.evaluations,_("boolean","breadcrumbs.evaluations",r)),flagChange:v(e==null?void 0:e.flagChange,t.flagChange,_("boolean","breadcrumbs.flagChange",r)),click:v(e==null?void 0:e.click,t.click,_("boolean","breadcrumbs.click",r)),keyboardInput:v(e==null?void 0:e.keyboardInput,t.keyboardInput,_("boolean","breadcrumbs.keyboardInput",r)),http:ht(e==null?void 0:e.http,t.http,r),filters:v(e==null?void 0:e.filters,t.filters,n=>Array.isArray(n)?!0:(r==null||r.warn(U("breadcrumbs.filters","BreadcrumbFilter[]",typeof n)),!1))}}function V(e,t){let r=gt();return e.breadcrumbs&&_("object","breadcrumbs",t)(e.breadcrumbs),e.stack&&_("object","stack",t)(e.stack),{breadcrumbs:yt(e.breadcrumbs,r.breadcrumbs,t),stack:xt(e.stack,r.stack,t),maxPendingEvents:v(e.maxPendingEvents,r.maxPendingEvents,_("number","maxPendingEvents",t)),collectors:[...v(e.collectors,r.collectors,n=>Array.isArray(n)?!0:(t==null||t.warn(U("collectors","Collector[]",typeof n)),!1))],logger:bt(e),errorFilters:v(e.errorFilters,r.errorFilters,n=>Array.isArray(n)?!0:(t==null||t.warn(U("errorFilters","ErrorDataFilter[]",typeof n)),!1))}}var Y,me=!1;function Tr(e){let t=P(e==null?void 0:e.logger);if(Y){t.warn(T("Telemetry has already been initialized. Ignoring new options."));return}let r=V(e||{},t);Y=new I(r)}function R(){if(!Y){if(me)return;S.warn(T("Telemetry has not been initialized")),me=!0;return}return Y}function Sr(){Y=void 0,me=!1}function Or(){var e;return((e=R())==null?void 0:e.inspectors())||[]}function Br(e){var t;(t=R())==null||t.captureError(e)}function Ir(e){var t;(t=R())==null||t.captureErrorEvent(e)}function Rr(e){var t;(t=R())==null||t.addBreadcrumb(e)}function Dr(e){var t;(t=R())==null||t.register(e)}function Cr(){var e;(e=R())==null||e.close()}function Xr(e){let t=V(e||{},P(e==null?void 0:e.logger));return new I(t)}export{Rr as addBreadcrumb,Br as captureError,Ir as captureErrorEvent,Cr as close,R as getTelemetryInstance,Tr as initTelemetry,Xr as initTelemetryInstance,Or as inspectors,Dr as register,Sr as resetTelemetryInstance};
|
|
9
|
+
`);let O=L.indexOf(E.innerText);O>=0&&(i.line=h+L.substring(0,O).split(`
|
|
10
|
+
`).length)}}}else if(l=o.exec(c[m])){let h=e.location.href.replace(/#.*$/,""),E=new RegExp(de(c[m+1])),L=Q(E,[h]);i={url:h,func:"",args:[],line:L?L.line:l[1],column:null}}if(i){i.func||(i.func=C(i.url,i.line));let h=$(i.url,i.line);i.srcStart=h==null?void 0:h.startFromSource;let E=h==null?void 0:h.contextLines,L=E?E[Math.floor(E.length/2)]:null;E&&L&&L.replace(/^\s*/,"")===c[m+1].replace(/^\s*/,"")?i.context=E:i.context=[c[m+1]],b.push(i)}}return b.length?{mode:"multiline",name:a.name,message:c[0],stack:b}:null}function ge(a,c,u,p){var b;let o={url:c,line:u};if(o.url&&o.line){if(a.incomplete=!1,o.func||(o.func=C(o.url,o.line)),!o.context){let d=$(o.url,o.line);o.context=(b=d==null?void 0:d.contextLines)!=null?b:null,o.srcStart=d==null?void 0:d.startFromSource}let g=/ '([^']+)' /.exec(p);if(g&&(o.column=re(g[1],o.url,o.line)),a.stack.length>0&&a.stack[0].url===o.url){if(a.stack[0].line===o.line)return!1;if(!a.stack[0].line&&a.stack[0].func===o.func)return a.stack[0].line=o.line,a.stack[0].context=o.context,!1}return a.stack.unshift(o),a.partial=!0,!0}return a.incomplete=!0,!1}function he(a,c){let u=/function\s+([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)?\s*\(/i,p=[],o={},b=!1,g,d,l;for(let i=he.caller;i&&!b;i=i.caller)if(!(i===w||i===y.report)){if(d={url:null,func:n,args:[],line:null,column:null},i.name?d.func=i.name:(g=u.exec(i.toString()))&&(d.func=g[1]),typeof d.func=="undefined")try{d.func=g.input.substring(0,g.input.indexOf("{"))}catch(h){}if(l=we(i)){d.url=l.url,d.line=l.line,d.func===n&&(d.func=C(d.url,d.line));let h=/ '([^']+)' /.exec(a.message||a.description);h&&(d.column=re(h[1],l.url,l.line))}o[`${i}`]?b=!0:o[`${i}`]=!0,p.push(d)}c&&p.splice(0,c);let m={mode:"callers",name:a.name,message:a.message,stack:p};return ge(m,a.sourceURL||a.fileName,a.line||a.lineNumber,a.message||a.description),m}function w(a,c){let u=null;c=c==null?0:+c;try{if(u=Oe(a),u)return u}catch(p){}try{if(u=pe(a),u)return u}catch(p){}try{if(u=Fe(a),u)return u}catch(p){}try{if(u=he(a,c+1),u)return u}catch(p){}return{name:a.name,message:a.message,mode:"failed",stack:[]}}function Be(a){a=(a==null?0:+a)+1;try{throw new Error}catch(c){return w(c,a+1)}}return w.augmentStackTraceWithInitialElement=ge,w.computeStackTraceFromStackProp=pe,w.guessFunctionName=C,w.gatherContext=$,w.ofCaller=Be,w.getSource=D,w}(),y.remoteFetching||(y.remoteFetching=!0),y.collectWindowErrors||(y.collectWindowErrors=!0),(!y.linesOfContext||y.linesOfContext<1)&&(y.linesOfContext=11)})(typeof window!="undefined"?window:global);function te(){return y}var ve="(index)";function Qe(e,t){let r=e;if(e.startsWith(t)){if(r=e.slice(t.length),r.startsWith("/")&&(r=r.slice(1)),r==="")return ve;r.endsWith("/")&&(r+=ve)}return r}function et(e,t,r){return Math.min(t,Math.max(e,r))}function Ee(e,t,r){if(t.length<=e.maxLength)return t;let n=Math.max(0,r-e.beforeColumnCharacters),s=Math.min(t.length,n+e.maxLength);return t.slice(n,s)}function _e(e,t,r,n){let s=e<0?0:e,f=t>r.length?r.length:t;return s<f?r.slice(s,f).map(n):[]}function tt(e,t){var k,F;let{context:r}=e;if(!r)return{};let{maxLineLength:n}=t.source,s=Math.floor(n/2),f=B=>Ee({maxLength:t.source.maxLineLength,beforeColumnCharacters:s},B,0),x=et(0,r.length-1,((k=e==null?void 0:e.line)!=null?k:0)-((F=e.srcStart)!=null?F:0));return{srcBefore:_e(x-t.source.beforeLines,x,r,f),srcLine:Ee({maxLength:n,beforeColumnCharacters:s},r[x],e.column||0),srcAfter:_e(x+1,x+1+t.source.afterLines,r,f)}}function fe(e,t){return t.enabled?{frames:te().computeStackTrace(e).stack.reverse().map(s=>{var f,x;return{fileName:Qe(s.url,window.location.origin),function:s.func,line:(f=s.line)!=null?f:void 0,col:(x=s.column)!=null?x:void 0,...tt(s,t)}})}:{frames:[]}}var Se="$ld:telemetry",rt=`${Se}:error`,nt=`${Se}:session:init`,ke="generic",it="exception was null or undefined",st="exception had no message",at=5;function Te(e){switch(typeof e){case"string":case"boolean":case"number":return e;default:return}}function ot(e,t){return e===void 0?void 0:t(e)}function ct(e){if(!e.enabled)return;let t=te(),r=Math.max(e.source.afterLines,e.source.beforeLines),n=t;n.linesOfContext=r*2+1}function ut(e){return e.logger!==void 0}function lt(e){return e.waitForInitialization!==void 0}var I=class{constructor(t){this._options=t;this._pendingEvents=[];this._breadcrumbs=[];this._inspectorInstances=[];this._collectors=[];this._sessionId=le();this._registrationComplete=!1;this._eventsDropped=!1;this._breadcrumbFilterError=!1;this._errorFilterError=!1;var f;ct(t.stack),this._collectors.push(new q),this._collectors.push(...t.collectors),this._maxPendingEvents=t.maxPendingEvents,this._maxBreadcrumbs=t.breadcrumbs.maxBreadcrumbs,this._logger=(f=this._options.logger)!=null?f:S;let r=[ae];t.breadcrumbs.http.customUrlFilter&&r.push(t.breadcrumbs.http.customUrlFilter),t.breadcrumbs.http.instrumentFetch&&this._collectors.push(new G({urlFilters:r,getLogger:()=>this._logger})),t.breadcrumbs.http.instrumentXhr&&this._collectors.push(new z({urlFilters:r,getLogger:()=>this._logger})),t.breadcrumbs.click&&this._collectors.push(new X),t.breadcrumbs.keyboardInput&&this._collectors.push(new j),this._collectors.forEach(x=>x.register(this,this._sessionId));let n=this,s=[];oe(t,s,n),this._inspectorInstances.push(...s)}register(t){if(this._client!==void 0)return;this._client=t,this._setLogger();let r=()=>{var n;(n=this._client)==null||n.track(nt,{sessionId:this._sessionId}),this._pendingEvents.forEach(s=>{var f;(f=this._client)==null||f.track(s.type,s.data)}),this._pendingEvents=[],this._registrationComplete=!0};lt(t)?(async()=>{try{await t.waitForInitialization(at)}catch(n){}r()})():r()}_setLogger(){this._options.logger?this._logger=this._options.logger:ut(this._client)?this._logger=this._client.logger:this._logger=S}inspectors(){return this._inspectorInstances}_capture(t,r){var s;let n=this._applyFilters(r,this._options.errorFilters,f=>{this._errorFilterError||(this._errorFilterError=!0,this._logger.warn(T(`Error applying error filters: ${f}`)))});n!==void 0&&(this._registrationComplete?(s=this._client)==null||s.track(t,n):(this._pendingEvents.push({type:t,data:n}),this._pendingEvents.length>this._maxPendingEvents&&(this._eventsDropped||(this._eventsDropped=!0,this._logger.warn(T("Maximum pending events reached. Old events will be dropped until the SDK client is registered."))),this._pendingEvents.shift())))}captureError(t){var s,f;let n=t!=null?{type:t.name||((s=t.constructor)==null?void 0:s.name)||ke,message:(f=t.message)!=null?f:st,stack:fe(t,this._options.stack),breadcrumbs:[...this._breadcrumbs],sessionId:this._sessionId}:{type:ke,message:it,stack:{frames:[]},breadcrumbs:[...this._breadcrumbs],sessionId:this._sessionId};this._capture(rt,n)}captureErrorEvent(t){this.captureError(t.error)}_applyFilters(t,r,n){try{return r.reduce((s,f)=>ot(s,f),t)}catch(s){n(s);return}}addBreadcrumb(t){let r=this._applyFilters(t,this._options.breadcrumbs.filters,n=>{this._breadcrumbFilterError||(this._breadcrumbFilterError=!0,this._logger.warn(T(`Error applying breadcrumb filters: ${n}`)))});r!==void 0&&(this._breadcrumbs.push(r),this._breadcrumbs.length>this._maxBreadcrumbs&&this._breadcrumbs.shift())}close(){this._collectors.forEach(t=>t.unregister())}handleFlagUsed(t,r,n){let s={type:"flag-evaluated",data:{key:t,value:Te(r.value)},timestamp:new Date().getTime(),class:"feature-management",level:"info"};this.addBreadcrumb(s)}handleFlagDetailChanged(t,r){let n={type:"flag-detail-changed",data:{key:t,value:Te(r.value)},timestamp:new Date().getTime(),class:"feature-management",level:"info"};this.addBreadcrumb(n)}};var ft={maxBreadcrumbs:0,evaluations:!1,flagChange:!1,click:!1,keyboardInput:!1,http:{instrumentFetch:!1,instrumentXhr:!1,customUrlFilter:void 0},filters:[]},mt={enabled:!1,source:{beforeLines:0,afterLines:0,maxLineLength:0}};function dt(){return{breadcrumbs:{maxBreadcrumbs:50,evaluations:!0,flagChange:!0,click:!0,keyboardInput:!0,http:{instrumentFetch:!0,instrumentXhr:!0},filters:[]},stack:{enabled:!0,source:{beforeLines:3,afterLines:3,maxLineLength:280}},maxPendingEvents:100,collectors:[],errorFilters:[]}}function U(e,t,r){return T(`Config option "${e}" should be of type ${t}, got ${r}, using default value`)}function _(e,t,r){return n=>{let s=typeof n;return s===e?!0:(r==null||r.warn(U(t,e,s)),!1)}}function v(e,t,r){return e!=null&&(!r||r(e))?e:t}function pt(e,t,r){if(e!==void 0&&e!==!1&&typeof e!="object")return r==null||r.warn(U("breadcrumbs.http","HttpBreadCrumbOptions | false",typeof e)),t;if(e===!1)return{instrumentFetch:!1,instrumentXhr:!1};e!=null&&e.customUrlFilter&&typeof e.customUrlFilter!="function"&&(r==null||r.warn(T(`The "breadcrumbs.http.customUrlFilter" must be a function. Received ${typeof e.customUrlFilter}`)));let n=e!=null&&e.customUrlFilter&&typeof(e==null?void 0:e.customUrlFilter)=="function"?e.customUrlFilter:void 0;return{instrumentFetch:v(e==null?void 0:e.instrumentFetch,t.instrumentFetch,_("boolean","breadcrumbs.http.instrumentFetch",r)),instrumentXhr:v(e==null?void 0:e.instrumentXhr,t.instrumentXhr,_("boolean","breadcrumbs.http.instrumentXhr",r)),customUrlFilter:n}}function gt(e){if(e.logger){let{logger:t}=e;if(typeof t=="object"&&t!==null&&"warn"in t)return P(t);S.warn(U("logger","MinLogger or LDLogger",typeof t))}}function ht(e,t,r){var n,s,f;return e===!1?mt:{enabled:!0,source:{beforeLines:v((n=e==null?void 0:e.source)==null?void 0:n.beforeLines,t.source.beforeLines,_("number","stack.beforeLines",r)),afterLines:v((s=e==null?void 0:e.source)==null?void 0:s.afterLines,t.source.afterLines,_("number","stack.afterLines",r)),maxLineLength:v((f=e==null?void 0:e.source)==null?void 0:f.maxLineLength,t.source.maxLineLength,_("number","stack.maxLineLength",r))}}}function bt(e,t,r){return e===!1?ft:{maxBreadcrumbs:v(e==null?void 0:e.maxBreadcrumbs,t.maxBreadcrumbs,_("number","breadcrumbs.maxBreadcrumbs",r)),evaluations:v(e==null?void 0:e.evaluations,t.evaluations,_("boolean","breadcrumbs.evaluations",r)),flagChange:v(e==null?void 0:e.flagChange,t.flagChange,_("boolean","breadcrumbs.flagChange",r)),click:v(e==null?void 0:e.click,t.click,_("boolean","breadcrumbs.click",r)),keyboardInput:v(e==null?void 0:e.keyboardInput,t.keyboardInput,_("boolean","breadcrumbs.keyboardInput",r)),http:pt(e==null?void 0:e.http,t.http,r),filters:v(e==null?void 0:e.filters,t.filters,n=>Array.isArray(n)?!0:(r==null||r.warn(U("breadcrumbs.filters","BreadcrumbFilter[]",typeof n)),!1))}}function V(e,t){let r=dt();return e.breadcrumbs&&_("object","breadcrumbs",t)(e.breadcrumbs),e.stack&&_("object","stack",t)(e.stack),{breadcrumbs:bt(e.breadcrumbs,r.breadcrumbs,t),stack:ht(e.stack,r.stack,t),maxPendingEvents:v(e.maxPendingEvents,r.maxPendingEvents,_("number","maxPendingEvents",t)),collectors:[...v(e.collectors,r.collectors,n=>Array.isArray(n)?!0:(t==null||t.warn(U("collectors","Collector[]",typeof n)),!1))],logger:gt(e),errorFilters:v(e.errorFilters,r.errorFilters,n=>Array.isArray(n)?!0:(t==null||t.warn(U("errorFilters","ErrorDataFilter[]",typeof n)),!1))}}var Y,me=!1;function _r(e){let t=P(e==null?void 0:e.logger);if(Y){t.warn(T("Telemetry has already been initialized. Ignoring new options."));return}let r=V(e||{},t);Y=new I(r)}function R(){if(!Y){if(me)return;S.warn(T("Telemetry has not been initialized")),me=!0;return}return Y}function kr(){Y=void 0,me=!1}function wr(){var e;return((e=R())==null?void 0:e.inspectors())||[]}function Or(e){var t;(t=R())==null||t.captureError(e)}function Fr(e){var t;(t=R())==null||t.captureErrorEvent(e)}function Br(e){var t;(t=R())==null||t.addBreadcrumb(e)}function Ir(e){var t;(t=R())==null||t.register(e)}function Rr(){var e;(e=R())==null||e.close()}function Hr(e){let t=V(e||{},P(e==null?void 0:e.logger));return new I(t)}export{Br as addBreadcrumb,Or as captureError,Fr as captureErrorEvent,Rr as close,R as getTelemetryInstance,_r as initTelemetry,Hr as initTelemetryInstance,wr as inspectors,Ir as register,kr as resetTelemetryInstance};
|
|
11
11
|
/**
|
|
12
12
|
* https://github.com/csnover/TraceKit
|
|
13
13
|
* @license MIT
|