1import{Ba as re,C as $,F as J,H as U,O as Z,Q as y,R as ee,S as te,T,X as oe,Z as ie,_ as S,aa as f,b as G,d as K,f as D,ha as x,i as A,j as v,k as w,l as Q,m as W,o as z,p as O,q as E,v as V,w as M,z as X}from"./chunk-2JPUMLBT.js";import{a as Y,b as j}from"./chunk-HQXTCKBE.js";function se(){let o=J();return t=>{o.send("profile",t)}}function ne(o,t,e){let i=re(o,t,e,oe.PROFILING);return({profile:c,trace:a})=>{let l={event:c,"wall-time.json":a};i.send(l)}}var Le=/\/(?![vV]\d{1,2}\/)([^/\d?]*\d+[^/?]*)/g;function ae(o){return o?o.replace(Le,"/?"):"/"}var H=(o,t)=>o||ae(t);function le(o,t,e){let i=X(t),c=Pe(o,t.applicationId,e),a=Me(i);return j(Y({},c),{attachments:["wall-time.json"],start:new Date(o.startClocks.timeStamp).toISOString(),end:new Date(o.endClocks.timeStamp).toISOString(),family:"chrome",runtime:"chrome",format:"json",version:4,tags_profiler:a.join(","),_dd:{clock_drift:W()}})}function Pe(o,t,e){let{ids:i,names:c}=we(o.views),a=o.longTasks.map(m=>m.id).filter(m=>m!==void 0),l=o.actions?.map(m=>m.id).filter(m=>m!==void 0)??[],{ids:p,labels:_}=Ve(o.vitals),u={application:{id:t}};return e&&(u.session={id:e}),i.length&&(u.view={id:i,name:c}),a.length&&(u.long_task={id:a}),l.length&&(u.action={id:l,label:[]}),p.length&&(u.vital={id:p,label:_}),u}function we(o){let t={ids:[],names:[]};for(let e of o)t.ids.push(e.viewId),e.viewName&&t.names.push(e.viewName);return t.names=Array.from(new Set(t.names)),t}function Ve(o){let t={ids:[],labels:[]};if(!o)return t;for(let e of o)t.ids.push(e.id),t.labels.push(e.label);return t.labels=Array.from(new Set(t.labels)),t}function Me(o){return o.concat(["language:javascript","runtime:chrome","family:chrome","host:browser"])}var Ue=T;function ce(o){let t=y({expireDelay:Ue});return o.subscribe(f.RAW_RUM_EVENT_COLLECTED,({rawRumEvent:e,startClocks:i,duration:c})=>{e.type==="long_task"&&t.add({id:e.long_task.id,startClocks:i,duration:c,entryType:e.long_task.entry_type===ie.LONG_TASK?x.LONG_TASK:x.LONG_ANIMATION_FRAME},i.relative).close(v(i.relative,c))}),t}var xe=T;function de(o){let t=y({expireDelay:xe});return o.subscribe(f.ACTION_STARTED,e=>{t.add({id:e.id,label:"",startClocks:e.startClocks,duration:void 0},e.startClocks.relative)}),o.subscribe(f.RAW_RUM_EVENT_COLLECTED,({rawRumEvent:e,startClocks:i,duration:c})=>{if(e.type==="action"){let a=t.getEntries(i.relative).find(p=>p.value.id===e.action.id),l=c??0;a?(a.value.duration=l,a.close(v(i.relative,l))):t.add({id:e.action.id,label:"",startClocks:i,duration:c},i.relative).close(v(i.relative,l))}}),t}var He=T;function ue(o){let t=y({expireDelay:He});return o.subscribe(f.DURATION_VITAL_STARTED,e=>{t.add({id:e.id,type:S.DURATION,startClocks:e.startClocks,duration:void 0,label:e.name},e.startClocks.relative)}),o.subscribe(f.RAW_RUM_EVENT_COLLECTED,({rawRumEvent:e,startClocks:i,duration:c})=>{if(e.type!=="vital")return;if(e.vital.type===S.OPERATION_STEP){if(e.vital.step_type==="start")t.add({id:e.vital.id,type:e.vital.type,operationKey:e.vital.operation_key,startClocks:i,label:e.vital.name},i.relative);else if(e.vital.step_type==="end"){let l=t.findAllEntries().find(p=>p.value.type===S.OPERATION_STEP&&p.value.label===e.vital.name&&p.value.operationKey===e.vital.operation_key);if(!l)return;l.value.duration=A(l.value.startClocks.relative,i.relative),l.close(i.relative)}return}let a=t.getEntries(i.relative).find(l=>l.value.id===e.vital.id);if(a){a.value.duration=c,a.close(v(i.relative,c));return}t.add({id:e.vital.id,type:e.vital.type,operationKey:e.vital.operation_key,startClocks:i,duration:c,label:e.vital.name},i.relative).close(v(i.relative,c))}),t}function Re(o,t){let e=o?.data?.attributes;if(!e||typeof e.admitted!="boolean"||typeof e.reason!="string")return t;let i=e.reason==="backend_client_not_initialized"?"backend_unavailable":e.reason;return{decision:e.admitted?"quota_ok":"quota_ko",reason:i}}function qe(o,t){return z({proxy:o.proxy,site:o.site,path:"/api/v2/profiling/quota",parameters:`session_id=${t}`,subdomain:"quota"})}function pe(o,t,e=5e3){let i=qe(o,t),c=new AbortController,a,l=$(i,{credentials:"omit",signal:c.signal,headers:new Headers({"DD-CLIENT-TOKEN":o.clientToken})}).then(_=>{let u=_.status===429?{decision:"quota_ko",reason:"quota_exceeded"}:{decision:"quota_ok",reason:"api-error"};return _.json().then(m=>(E(a),Re(m,u)),()=>(E(a),u))}).catch(()=>(E(a),{decision:"quota_ok",reason:"api-error"})),p=new Promise(_=>{a=O(()=>{c.abort(),_({decision:"quota_ok",reason:"timeout"})},e)});return Promise.race([l,p])}function fe(o){let t=new Map(Z(o)?.map(i=>[i.url,i.id])),e=[];return o.forEach((i,c)=>{let a=t.get(i);a!==void 0&&e.push({resourceId:c,debugId:a})}),e.length?e:void 0}var Ce={sampleIntervalMs:10,collectIntervalMs:6e4,minProfileDurationMs:5e3};function Lt(o,t,e,i,c,a,l=Ce){let p=U()?se():ne(o,t,c),_,u=[],m=ce(t),me=de(t),_e=ue(t),s={state:"stopped",stateReason:"initializing"},R=0;t.subscribe(f.SESSION_EXPIRED,()=>{N("session-expired")}),t.subscribe(f.SESSION_RENEWED,()=>{if(s.state==="stopped"&&(s.stateReason==="session-expired"||s.stateReason==="quota_ko")){let r=e.findTrackedSession();
1if(!r||!te(r.id,ee(o.sessionSampleRate,o.profilingSampleRate)))return;q()}});function q(){if(s.state==="running")return;let r=a.findView();_=r?{startClocks:r.startClocks,viewId:r.id,viewName:H(r.name,document.location.pathname)}:void 0,u.push(M(window,V.VISIBILITY_CHANGE,he).stop,M(window,V.BEFORE_UNLOAD,ge).stop),I(),be()}function be(){if(U())return;let r=++R,n=e.findTrackedSession()?.id;n&&pe(o,n).then(d=>{r===R&&(s.state!=="running"&&s.state!=="paused"||d.decision==="quota_ko"&&N("quota_ko",d.reason))}).catch(D)}function ve(){N("stopped-by-user")}function N(r,n){ye(r),u.forEach(d=>d()),u.length=0,i.set({status:"stopped",error_reason:void 0,quota_reason:n})}function Ee(r){if(r.state==="running")return{cleanupTasks:r.cleanupTasks};let n=[],d=t.subscribe(f.VIEW_CREATED,b=>{let h={viewId:b.id,viewName:H(b.name,document.location.pathname),startClocks:b.startClocks};C(h),_=h});return n.push(d.unsubscribe),{cleanupTasks:n}}function I(){let r=G.Profiler;if(!r)throw i.set({status:"error",error_reason:"not-supported-by-browser"}),new Error("RUM Profiler is not supported in this browser.");s.state==="running"&&L(s);let{cleanupTasks:n}=Ee(s),d;try{d=new r({sampleInterval:l.sampleIntervalMs,maxBufferSize:Math.round(l.collectIntervalMs*1.5/l.sampleIntervalMs)})}catch(b){b instanceof Error&&b.message.includes("disabled by Document Policy")?(K.warn("[DD_RUM] Profiler startup failed. Ensure your server includes the `Document-Policy: js-profiling` response header when serving HTML pages.",b),i.set({status:"error",error_reason:"missing-document-policy-header"})):i.set({status:"error",error_reason:"unexpected-exception"});return}i.set({status:"running",error_reason:void 0}),s={state:"running",startClocks:w(),profiler:d,timeoutId:O(I,l.collectIntervalMs),views:[],cleanupTasks:n,longTasks:[],sessionId:e.findTrackedSession()?.id},C(_),d.addEventListener("samplebufferfull",P)}function L(r){E(r.timeoutId),r.profiler.removeEventListener("samplebufferfull",P);let{startClocks:n,views:d,sessionId:b}=r;r.profiler.stop().then(h=>{let B=w(),g=A(n.relative,B.relative),F=m.findAll(n.relative,g),Oe=me.findAll(n.relative,g),Se=_e.findAll(n.relative,g).map(k=>({id:k.id,label:k.label,startClocks:k.startClocks,duration:k.duration})),Ne=g<l.minProfileDurationMs;F.length===0&&Ne||Ie(Object.assign({},h,{startClocks:n,endClocks:B,clocksOrigin:Q(),longTasks:F,actions:Oe,vitals:Se,views:d,sampleInterval:l.sampleIntervalMs,debugIds:fe(h.resources)}),b)}).catch(D)}function ye(r){if(s.state!=="running"){(s.state==="paused"||s.state==="stopped"&&r==="stopped-by-user")&&(s={state:"stopped",stateReason:r});return}let n=s;s={state:"stopped",stateReason:r},n.cleanupTasks.forEach(d=>d()),r==="quota_ko"?(E(n.timeoutId),n.profiler.removeEventListener("samplebufferfull",P),n.profiler.stop().catch(D)):L(n)}function Te(){if(s.state!=="running")return;let r=s;s={state:"paused"},r.cleanupTasks.forEach(n=>n()),L(r)}function C(r){s.state!=="running"||!r||s.views.push(r)}function Ie(r,n){let d={profile:le(r,o,n),trace:r};p(d)}function P(){I()}function he(){document.visibilityState==="hidden"&&s.state==="running"?Te():document.visibilityState==="visible"&&s.state==="paused"&&I()}function ge(){I()}function ke(){return s.state==="stopped"}function De(){return s.state==="running"}function Ae(){return s.state==="paused"}return{start:q,stop:ve,isStopped:ke,isRunning:De,isPaused:Ae}}export{Ce as DEFAULT_RUM_PROFILER_CONFIGURATION,Lt as createRumProfiler};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.