Files
go-otel/static/otel-rum.js
T
mats 193e6c6e39
Build and Publish / Metadata (push) Successful in 4s
Build and Publish / BuildAndPushAmd64 (push) Failing after 1m27s
update rum
2026-11-04 13:04:34 +01:00

2 lines
14 KiB
JavaScript

"use strict";(()=>{(function(e){"use strict";var ge="https://otel.k6n.net",a=null;try{a=typeof document<"u"?document.currentScript||(function(){for(var i=document.getElementsByTagName("script"),d=i.length-1;d>=0;d--)if(i[d].src&&i[d].src.indexOf("otel-rum")!==-1)return i[d];return null})():null}catch{}var V=typeof e.fetch=="function"?e.fetch:null,Ze=typeof e.XMLHttpRequest=="function"?e.XMLHttpRequest:null;function w(i){for(var d="0123456789abcdef",l="",y=0;y<i;y++)l+=d[Math.random()*16|0];return l}function W(){return w(32)}function X(){return w(16)}function Se(i){try{var d=new e.URL(i,e.location.href);return d.origin===e.location.origin}catch{return!1}}function q(i){var d=[];for(var l in i)if(Object.prototype.hasOwnProperty.call(i,l)){var y=i[l];y==null||y===""||d.push({key:l,value:{stringValue:String(y)}})}return d}function Ee(i={}){i=i||{};var d=a&&(a.getAttribute("data-service-name")||a.getAttribute("data-service"))||"",l=a&&a.getAttribute("data-base-url")||"",y=a&&a.getAttribute("data-endpoint")||"",we=a&&a.getAttribute("data-ingest-key")||"",x=(i.baseUrl||l||ge).replace(/\/+$/,""),R=i.endpoint||y;R?!/^https?:\/\//i.test(R)&&!R.startsWith("//")&&(R=x+"/"+R.replace(/^\/+/,"")):R=x+"/v1/logs";var Le=i.vitalsEndpoint||a&&a.getAttribute("data-vitals-endpoint")||x+"/v1/vitals",Te=i.vitalsLibUrl||a&&a.getAttribute("data-vitals-lib")||(a&&a.src?a.src.replace(/[^\/]*$/,"")+"web-vitals.attribution.iife.js":x+"/static/web-vitals.attribution.iife.js");function re(r){if(!r)return!1;var t=String(r);return!!(R&&t.indexOf(R)===0||t.indexOf("/v1/logs")!==-1||t.indexOf("/v1/traces")!==-1||t.indexOf("/v1/metrics")!==-1||t.indexOf("/v1/vitals")!==-1)}var _=i.serviceName||d||"frontend",G=i.environment||a&&a.getAttribute("data-environment")||"",K=i.release||a&&a.getAttribute("data-release")||"",L=i.ingestKey||we||"",H=(i.consent||a&&a.getAttribute("data-consent"))==="granted"?"granted":"denied",be=typeof i.devMode=="boolean"?i.devMode:!!(a&&a.getAttribute("data-dev-mode")==="true"),xe=i.devModeHosts||(a&&a.getAttribute("data-dev-mode-hosts")||"").split(",").map(function(r){return r.trim()}).filter(Boolean),U=!1;try{U=be&&xe.indexOf(new e.URL(e.location.href).hostname)!==-1}catch{}var D=i.minimalDiagnostics,ne=[],P=typeof i.sampleRate=="number"?i.sampleRate:1,Oe=i.maxBreadcrumbs||20,Ae=i.captureConsoleErrors!==!1,Me=i.autoInstrumentFetch!==!1,Ce=i.autoInstrumentXhr!==!1,ke=i.trackSpaRoutes!==!1,z=i.reportHttpFailures!==!1,He=i.captureWebVitals!==!1,Ue=typeof i.captureWebVitalsWithoutConsent=="boolean"?i.captureWebVitalsWithoutConsent:!!(a&&a.getAttribute("data-vitals-without-consent")==="true"),$=!1,De=typeof i.enableTodo=="boolean"?i.enableTodo:!!(a&&a.getAttribute("data-enable-todo")==="true"),Ie=i.excludeTodo===!0||a&&a.getAttribute("data-exclude-todo")==="true",Pe=i.todoLibUrl||a&&a.getAttribute("data-todo-lib")||(a&&a.src?a.src.replace(/[^\/]*$/,"")+"otel-todo.js":x+"/static/otel-todo.js"),Fe=i.injectTraceHeaders!==!1,ie=i.traceHeaderOrigins,Ne=i.maxEventsPerMinute||60,je=i.batchSize||10,Be=i.flushIntervalMs||5e3,O=[],F="",N=T()?w(16):"",A=[],E=null,I=[],Ve=0;function We(r){var t=r==="granted"?"granted":"denied",n=t==="denied"&&U;H===t&&!n||(n&&(U=!1),H=t,A=[],E&&e.clearTimeout(E),E=null,O=[],B={},F="",N=T()?w(16):"",ne.forEach(function(s){s()}),oe())}function ae(){return H}function T(){return H==="granted"||U}function se(){return U?"development":H==="granted"?"consented":D?"minimal":"counts"}function j(){return He&&(T()||Ue)}function oe(){$||!j()||($=!0,Ke())}function Xe(){for(var r=Date.now();I.length&&r-I[0]>6e4;)I.shift();return I.length>=Ne?!1:(I.push(r),!0)}function qe(r){if(A.push(r),A.length>=je){M();return}E||(E=e.setTimeout(M,Be))}function M(){if(E&&(e.clearTimeout(E),E=null),!!A.length){var r=A.splice(0,A.length);_e(r)}}function _e(r){var t={resourceLogs:[{resource:{attributes:q({"service.name":_})},scopeLogs:[{scope:{name:"otel-rum"},logRecords:r}]}]},n=JSON.stringify(t),s=R;L&&(s+=(s.indexOf("?")===-1?"?":"&")+"key="+encodeURIComponent(L));var o=V||(typeof e.fetch=="function"?e.fetch:null);if(o){var c={"Content-Type":"application/json"};L&&(c["X-Otel-Ingest-Key"]=L),o.call(e,s,{method:"POST",mode:"cors",credentials:"omit",referrerPolicy:"no-referrer",headers:c,body:n,keepalive:!0}).catch(function(){});return}}var J={DEBUG:5,INFO:9,WARN:13,ERROR:17,FATAL:21};function Ge(r,t,n,s){if(!T()){var o={source:"frontend","service.release":K,"service.environment":G,"privacy.mode":"counts"},c=n&&n["exception.type"];typeof c=="string"&&["Error","TypeError","ReferenceError","SyntaxError","RangeError","URIError","EvalError","UnhandledRejection","HttpFailure","ResourceLoadError"].indexOf(c)!==-1&&(o["exception.type"]=c);var p=n&&String(n["http.response.status_code"]||"");p&&/^[1-5][0-9]{2}$/.test(p)&&(o["http.response.status_code"]=p);var g="Frontend event";if(D)try{var f=D.sanitize({message:String(t).slice(0,2e3),type:typeof c=="string"?c.slice(0,100):void 0,stacktrace:n&&typeof n["exception.stacktrace"]=="string"?n["exception.stacktrace"].slice(0,1e4):void 0});f&&typeof f.message=="string"&&f.message.trim()&&(g=f.message.slice(0,2e3),o["privacy.mode"]="minimal",o["exception.message"]=g,typeof f.code=="string"&&(o["error.code"]=f.code.slice(0,100)),typeof f.stacktrace=="string"&&(o["exception.stacktrace"]=f.stacktrace.slice(0,1e4)),D.route&&(o["http.route"]=D.route.slice(0,300)))}catch{}return{timeUnixNano:String(Date.now()*1e6),severityText:Object.prototype.hasOwnProperty.call(J,r)?r:"ERROR",severityNumber:J[r]||17,body:{stringValue:g},attributes:q(o)}}var v={timeUnixNano:String(Date.now()*1e6),severityText:r,severityNumber:J[r]||17,body:{stringValue:String(t).slice(0,2e3)},attributes:q(Object.assign({},B,{source:"frontend","privacy.mode":se(),"browser.url":e.location?e.location.href:"","browser.userAgent":e.navigator?e.navigator.userAgent:"","browser.viewport":e.innerWidth?e.innerWidth+"x"+e.innerHeight:"","session.id":N,"service.release":K,"service.environment":G,breadcrumbs:O.length?JSON.stringify(O):void 0},n||{}))};return s&&(v.traceId=s),v}function ue(r,t,n,s){if(!(P<1&&Math.random()>P)){if(!Xe()){Ve++;return}qe(Ge(r,t,n,s))}}function Ke(){var r=w(16),t={},n="",s=!1,o=P>=1||Math.random()<=P;ne.push(function(){r=w(16),t={},s=!1});var c={LCP:["target","url","timeToFirstByte","resourceLoadDelay","resourceLoadDuration","elementRenderDelay"],INP:["interactionTarget","interactionType","inputDelay","processingDuration","presentationDelay","loadState","totalScriptDuration","totalStyleAndLayoutDuration","totalPaintDuration"],CLS:["largestShiftTarget","largestShiftValue","largestShiftTime","loadState"],FCP:["timeToFirstByte","firstByteToFCP","loadState"],TTFB:["waitingDuration","cacheDuration","dnsDuration","connectionDuration","requestDuration"]};function p(u){return typeof u=="number"?Math.round(u*1e3)/1e3:u}function g(u){var m={},b=u.attribution||{};(c[u.name]||[]).forEach(function(h){b[h]!==void 0&&b[h]!==null&&(m[h]=p(b[h]))});var S=b.longestScript&&b.longestScript.entry;return S&&S.sourceURL&&(m.longestScriptUrl=S.sourceURL,S.sourceFunctionName&&(m.longestScriptFunction=S.sourceFunctionName)),m}function f(u){j()&&(t[u.name]={value:p(u.value),delta:p(u.delta),id:u.id,attribution:g(u)},n=u.navigationType||n,s=!0)}function v(){if(!(!j()||!s||!o)){s=!1;var u=T(),m={};Object.keys(t).forEach(function(h){var ye={};Object.keys(t[h].attribution).forEach(function(Re){var te=t[h].attribution[Re];typeof te=="number"&&Number.isFinite(te)&&(ye[Re]=te)}),m[h]={value:t[h].value,delta:t[h].delta,attribution:ye}});var b=JSON.stringify({service:_,environment:G,release:K,session:N,pageView:r,url:u&&e.location?e.location.href:"",ua:u&&e.navigator?e.navigator.userAgent:"",viewport:u&&e.innerWidth?e.innerWidth+"x"+e.innerHeight:"",nav:n,conn:u&&e.navigator&&e.navigator.connection&&e.navigator.connection.effectiveType||"",metrics:u?t:m}),S=Le;L&&(S+=(S.indexOf("?")===-1?"?":"&")+"key="+encodeURIComponent(L)),V&&V.call(e,S,{method:"POST",mode:"cors",credentials:"omit",referrerPolicy:"no-referrer",headers:{"Content-Type":"text/plain;charset=UTF-8"},body:b,keepalive:!0}).catch(function(){})}}var k=e.document.createElement("script");k.async=!0,k.referrerPolicy="no-referrer",k.src=Te,k.onload=function(){if(!j()){$=!1;return}var u=e.webVitals;u&&([u.onLCP,u.onINP,u.onCLS,u.onFCP,u.onTTFB].forEach(function(m){typeof m=="function"&&m(f)}),e.addEventListener("visibilitychange",function(){e.document.visibilityState==="hidden"&&v()}),e.addEventListener("pagehide",v),e.addEventListener("pageshow",function(m){m.persisted&&(r=w(16),t={})}))},e.document.head.appendChild(k)}function ce(){var r=i.todo||{};function t(){e.OtelTodo&&e.OtelTodo.init({getConsent:ae,getSessionId:function(){return N},baseUrl:x,serviceName:_,ingestKey:L,components:r.components||(a&&a.getAttribute("data-components")||"").split(","),shortcut:r.shortcut||a&&a.getAttribute("data-shortcut")||"",hideButton:r.hideButton===!0||!!(a&&a.getAttribute("data-hide-button")==="true")})}if(e.OtelTodo)return t();var n=e.document.createElement("script");n.async=!0,n.referrerPolicy="no-referrer",n.src=Pe,n.onload=t,e.document.head.appendChild(n)}if(De&&!Ie&&e.document){let r=function(){typeof e.requestIdleCallback=="function"?e.requestIdleCallback(ce):e.setTimeout(ce,3e3)};e.document.readyState==="complete"?r():e.addEventListener("load",r,{once:!0})}function Q(r){var t=r||W(),n=X();return F=t,{traceparent:"00-"+t+"-"+n+"-01"}}function Y(r,t){var n=r&&typeof r=="object"?r:void 0,s=n&&n.message||String(r);ue("ERROR",s,Object.assign({"exception.type":n&&n.name||"Error","exception.message":s,"exception.stacktrace":n&&n.stack||""},t||{}),F)}function Z(r,t,n){ue(t||"ERROR",r,n,F)}function ze(r){T()&&(B=Object.assign({},B,r||{}),M())}var B={};function de(r){var t=r.target;if(t&&r.target!==e&&t.tagName){var n=String(t.tagName).toLowerCase();if(n==="img"||n==="script"||n==="link"){var s=t.src||t.href||"";Z("Failed to load "+n+": "+s,"ERROR",{"exception.type":"ResourceLoadError","resource.tag":n,"resource.url":s})}return}var o=r,c=o.message||"Script error";Y(o.error||{name:"Error",message:c},{"source.file":o.filename||"","source.line":o.lineno,"source.column":o.colno})}function $e(r){var t=r.reason;Y(t instanceof Error?t:{name:"UnhandledRejection",message:String(t)},{"exception.type":t&&t.name||"UnhandledRejection"})}if(e.addEventListener("error",de),e.addEventListener("error",de,!0),e.addEventListener("unhandledrejection",$e),Ae&&e.console&&typeof e.console.error=="function"){var Je=e.console.error;e.console.error=function(...r){try{C("console.error",r.join(" "))}catch{}return Je.apply(e.console,r)}}function fe(r){return Fe?ie?ie.some(function(t){return r.indexOf(t)===0}):Se(r):!1}function ee(r,t,n,s,o,c){try{if(new e.URL(n,e.location.href).pathname==="/api/issues")return}catch{}var p=Object.assign({"exception.type":"HttpFailure","http.request.method":t,"url.full":String(n).slice(0,500),"http.response.status_code":s===void 0||s===0?"":String(s)},c||{});Z(t+" "+n+" failed with "+(s===void 0||s===0?"network error":"HTTP "+s),"ERROR",p)}if(Me&&typeof e.fetch=="function"){var pe=e.fetch;e.fetch=function(r,t){var n=typeof r!="string"&&"url"in r?r:void 0,s=typeof r=="string"?r:n?n.url:String(r);if(re(s))return pe.call(e,r,t);var o=t&&t.method||n&&n.method||"GET",c="";if(fe(s)){t=t||{};var p=new e.Headers(t.headers||n&&n.headers||{}),g=Q();p.set("traceparent",g.traceparent),c=g.traceparent.slice(3,35),t=Object.assign({},t,{headers:p})}var f=Date.now();return pe.call(e,r,t).then(function(v){return C("fetch",o+" "+s+" -> "+v.status,{d:Date.now()-f,tid:c}),z&&v.status>=400&&ee("fetch",o,s,v.status,c),v},function(v){throw C("fetch",o+" "+s+" -> error",{d:Date.now()-f,tid:c}),z&&ee("fetch",o,s,0,c),v})}}if(Ce&&typeof e.XMLHttpRequest=="function"){var ve=e.XMLHttpRequest.prototype.open,Qe=e.XMLHttpRequest.prototype.send,Ye=e.XMLHttpRequest.prototype.setRequestHeader;e.XMLHttpRequest.prototype.open=function(r,t){if(re(t))return ve.apply(this,arguments);try{if(this.__rum={method:String(r),url:String(t)},fe(String(t))){var n=Q();this.__rum.traceId=n.traceparent.slice(3,35),Ye.call(this,"traceparent",n.traceparent)}}catch{}return ve.apply(this,arguments)},e.XMLHttpRequest.prototype.send=function(){var r=this;let t=r.__rum;var n=Date.now();if(t&&t.url){var s=r.onreadystatechange;r.onreadystatechange=function(){try{r.readyState===4&&(C("xhr",t.method+" "+t.url+" -> "+r.status,{d:Date.now()-n,tid:t.traceId}),z&&(r.status===0||r.status>=400)&&ee("xhr",t.method,t.url,r.status,t.traceId))}catch{}if(s)return s.apply(this,arguments)}}return Qe.apply(this,arguments)}}if(ke&&e.history){let r=function(t){C("navigation",t+" "+(e.location?e.location.pathname+e.location.search:""))};var me=e.history.pushState,he=e.history.replaceState;typeof me=="function"&&(e.history.pushState=function(){var t=me.apply(this,arguments);try{r("pushState")}catch{}return t}),typeof he=="function"&&(e.history.replaceState=function(){var t=he.apply(this,arguments);try{r("replaceState")}catch{}return t}),e.addEventListener("popstate",function(){try{r("popstate")}catch{}})}e.addEventListener("pagehide",function(){M()}),e.addEventListener("visibilitychange",function(){e.document&&e.document.visibilityState==="hidden"&&M()}),oe();function C(r,t,n){if(T()){var s={t:Date.now(),category:String(r),message:String(t)};n&&typeof n.d=="number"&&(s.d=n.d),n&&n.tid&&(s.tid=String(n.tid)),O.push(s),O.length>Oe&&O.shift()}}var le={setConsent:We,getConsent:ae,getPrivacyMode:se,captureException:Y,captureMessage:Z,addBreadcrumb:C,setContext:ze,flush:M,newTraceId:W,newSpanId:X,traceHeaders:Q};return e.OtelRUM.last=le,le}e.OtelRUM={init:Ee,newTraceId:W,newSpanId:X,last:void 0};try{typeof document<"u"&&a&&(a.getAttribute("data-auto-init")==="true"||a.getAttribute("data-service-name")||a.getAttribute("data-service"))&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",function(){e.OtelRUM.init()}):e.OtelRUM.init())}catch{}})(typeof window<"u"?window:globalThis);})();