@perses-dev/tracing-gantt-chart-plugin 0.9.2 → 0.9.3

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 +0,0 @@
1
- "use strict";(self.chunk_TracingGanttChart=self.chunk_TracingGanttChart||[]).push([["76"],{79098:function(e,t,n){n.r(t),n.d(t,{TracingGanttChart:()=>eZ});var s=n(24246),i=n(95700),r=n(36372),a=n(54538),o=n(94776),l=n(25283),d=n(12709),u=n(49581),c=n(83915);let x=new c.Z({hue:{min:20,max:360}}),p=new c.Z({hue:{min:0,max:20}}),m={},h="2rem",f=e=>{var t;return(null==(t=e.status)?void 0:t.code)===u.StatusCodeError};function v(e,t,n,s){return function(e,t,n,s){let i=arguments.length>4&&void 0!==arguments[4]&&arguments[4];if("categorical"===n){let n=t.echartsTheme.color,r=[e.palette.error.light,e.palette.error.main,e.palette.error.dark],a=i?r:n;if(0===a.length)return console.warn("getConsistentCategoricalColor() called with empty color palette, fallback to #000"),"#000";let o=0;for(let e=0;e<s.length;e++)o=s.charCodeAt(e)+((o<<5)-o);return a[Math.abs(o)%a.length]??"#000"}{let e=`${s}_____${i}`,t=m[e];return t||(t=function(e,t){let[n,s,i]=t?p.hsl(e):x.hsl(e),r=`${(100*s).toFixed(0)}%`,a=`${(100*i).toFixed(0)}%`;return`hsla(${n.toFixed(2)},${r},${a},0.9)`}(s,i),m[e]=t),t}}(e,t,n,s.resource.serviceName??"",f(s))}function j(e){return e<1?`${Math.round(1e3*e)}\u{3BC}s`:e<1e3?`${+e.toFixed(2)}ms`:`${+(e/1e3).toFixed(2)}s`}function g(e){let{trace:t,viewport:n}=e,i=n.endTimeUnixMs-n.startTimeUnixMs,r=n.startTimeUnixMs-t.startTimeUnixMs;return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(M,{style:{left:"0%",borderWidth:0},children:j(r+0*i)}),(0,s.jsx)(M,{style:{left:"25%"},children:j(r+.25*i)}),(0,s.jsx)(M,{style:{left:"50%"},children:j(r+.5*i)}),(0,s.jsx)(M,{style:{left:"75%"},children:j(r+.75*i)}),(0,s.jsx)(M,{style:{left:"100%"},children:(0,s.jsx)("span",{style:{position:"absolute",right:".75rem"},children:j(r+ +i)})})]})}function b(){return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(M,{style:{left:"25%"}}),(0,s.jsx)(M,{style:{left:"50%"}}),(0,s.jsx)(M,{style:{left:"75%"}})]})}let M=(0,d.ZP)(r.Z)(e=>{let{theme:t}=e;return{position:"absolute",height:"100%",borderLeft:`1px solid ${t.palette.divider}`,padding:".25rem"}});var k=n(75276),T=n(67469);function U(e){var t,n;let{options:l,trace:d,viewport:u,setViewport:c}=e,x=(0,o.Z)(),p=(0,i.useChartsTheme)(),{width:m,ref:h}=(0,k.default)(),f=(0,a.useRef)(null),[j,g]=(0,a.useState)({type:"none"}),M=d.endTimeUnixMs-d.startTimeUnixMs,U=(u.startTimeUnixMs-d.startTimeUnixMs)/M,w=(d.endTimeUnixMs-u.endTimeUnixMs)/M,Z=(0,a.useCallback)(e=>{var t,n;return v(x,p,null==(n=l.visual)||null==(t=n.palette)?void 0:t.mode,e)},[x,p,null==(n=l.visual)||null==(t=n.palette)?void 0:t.mode]);(0,a.useEffect)(()=>{if(!f.current||!m)return;let e=f.current.getContext("2d");e&&function(e,t,n,s,i){let r=s.spanById.size,a=Math.round(Math.min(Math.max(60/r,1),7)),o=s.endTimeUnixMs-s.startTimeUnixMs,l=60/r,d=0,u=n=>{let r=n.endTimeUnixMs-n.startTimeUnixMs,c=(n.startTimeUnixMs-s.startTimeUnixMs)/o;for(let s of(e.fillStyle=i(n),e.beginPath(),e.rect(Math.round(c*t),Math.round(d),Math.max(2,Math.round(r/o*t)),a),e.fill(),d+=l,n.childSpans))u(s)};for(let e of s.rootSpans)u(e)}(e,m,60,d,Z)},[m,60,d,Z]);let S=e=>{if(!f.current||!m)return 0;let t=e.clientX-f.current.getBoundingClientRect().left;return d.startTimeUnixMs+t/m*M},C=(0,T.z)(e=>{switch(e.preventDefault(),j.type){case"none":return;case"resize":{let t,n,s=j.fixedPoint,i=S(e);s<i?(t=s,n=i):(t=i,n=s),c({startTimeUnixMs:Math.max(t,d.startTimeUnixMs),endTimeUnixMs:Math.min(n,d.endTimeUnixMs)});return}case"drag":{let{start:t,end:n}=j,s=S(e);s-t<d.startTimeUnixMs&&(s=d.startTimeUnixMs+t),s+n>d.endTimeUnixMs&&(s=d.endTimeUnixMs-n),c({startTimeUnixMs:s-t,endTimeUnixMs:s+n});return}}}),L=(0,T.z)(e=>{e.preventDefault(),g({type:"none"}),u.startTimeUnixMs===u.endTimeUnixMs&&c({startTimeUnixMs:d.startTimeUnixMs,endTimeUnixMs:d.endTimeUnixMs})});return(0,a.useEffect)(()=>{function e(){window.removeEventListener("mousemove",C),window.removeEventListener("mouseup",L),document.body.style.cursor="inherit"}return"none"===j.type?e():(window.addEventListener("mousemove",C),window.addEventListener("mouseup",L),document.body.style.cursor="resize"===j.type?"col-resize":"move"),e},[j,C,L]),(0,s.jsxs)(r.Z,{ref:h,sx:{position:"relative",height:60},onMouseDown:e=>{if(e.preventDefault(),!(e.target instanceof HTMLElement))return;let t=u.startTimeUnixMs===d.startTimeUnixMs&&u.endTimeUnixMs===d.endTimeUnixMs,n=e.target.dataset.elem,s=S(e);"resizerLeft"===n?g({type:"resize",fixedPoint:u.endTimeUnixMs}):"resizerRight"===n?g({type:"resize",fixedPoint:u.startTimeUnixMs}):"cutoffBox"===n||t?(g({type:"resize",fixedPoint:s}),c({startTimeUnixMs:s,endTimeUnixMs:s})):g({type:"drag",start:s-u.startTimeUnixMs,end:u.endTimeUnixMs-s})},children:[(0,s.jsx)("canvas",{ref:f,width:m,height:60,style:{position:"absolute"}}),(0,s.jsx)(b,{}),(0,s.jsx)(y,{"data-elem":"cutoffBox",style:{left:0,width:`${100*U}%`}}),(0,s.jsx)(I,{"data-elem":"resizerLeft",style:{left:`${100*U}%`}}),(0,s.jsx)(I,{"data-elem":"resizerRight",style:{right:`${100*w}%`}}),(0,s.jsx)(y,{"data-elem":"cutoffBox",style:{right:0,width:`${100*w}%`}})]})}let y=(0,d.ZP)(r.Z)({position:"absolute",height:"100%",backgroundColor:"rgba(225, 225, 225, .5)"}),I=(0,d.ZP)(r.Z)(e=>{let{theme:t}=e;return{position:"absolute",height:"100%",backgroundColor:t.palette.divider,width:"2px",cursor:"col-resize","&:before":{position:"absolute",width:"8px",left:"-3px",top:0,bottom:0,content:'" "',zIndex:1}}});function w(e){let{options:t,trace:n,viewport:i,setViewport:a}=e,l=(0,o.Z)();return(0,s.jsxs)(r.Z,{sx:{border:`1px solid ${l.palette.divider}`,borderRadius:`${l.shape.borderRadius}px`},children:[(0,s.jsx)(r.Z,{sx:{position:"relative",height:h,borderBottom:`1px solid ${l.palette.divider}`},children:(0,s.jsx)(g,{trace:n,viewport:{startTimeUnixMs:n.startTimeUnixMs,endTimeUnixMs:n.endTimeUnixMs}})}),(0,s.jsx)(U,{options:t,trace:n,viewport:i,setViewport:a})]})}var Z=n(75094),S=n(52054),C=n(51781),L=n(49408),$=n(52889),z=n(10763),E=n(71852),P=n(79119),R=n(60886),V=n(2259),B=n(12577),F=n(8887);function O(e){let{customLinks:t,trace:n,span:i}=e;return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(E.Z,{children:[(0,s.jsx)(A,{name:"span ID",value:i.spanId}),(0,s.jsx)(A,{name:"start",value:j(i.startTimeUnixMs-n.startTimeUnixMs)}),(0,s.jsx)(A,{name:"duration",value:j(i.endTimeUnixMs-i.startTimeUnixMs)})]}),(0,s.jsx)(P.Z,{}),i.attributes.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(D,{customLinks:t,attributes:i.attributes.toSorted((e,t)=>e.key.localeCompare(t.key))}),(0,s.jsx)(P.Z,{})]}),(0,s.jsx)(D,{customLinks:t,attributes:i.resource.attributes.toSorted((e,t)=>e.key.localeCompare(t.key))})]})}function D(e){let{customLinks:t,attributes:n}=e;return(0,s.jsx)(E.Z,{children:(0,s.jsx)(N,{customLinks:t,attributes:n})})}function N(e){let{customLinks:t,attributes:n}=e,i=(0,F.useAllVariableValues)(),r=(0,a.useMemo)(()=>Object.fromEntries(((null==t?void 0:t.links.attributes)??[]).map(e=>[e.name,e.link])),[t]),o=(0,a.useMemo)(()=>{let e=n.map(e=>[e.key.replaceAll(".","_"),G(e.value)]);return{...null==t?void 0:t.variables,...Object.fromEntries(e)}},[t,n]);return(0,s.jsx)(s.Fragment,{children:n.map((e,t)=>(0,s.jsx)(A,{name:e.key,value:G(e.value),link:r[e.key]?(0,F.replaceVariablesInString)(r[e.key],i,o):void 0},t))})}function A(e){let{name:t,value:n,link:i}=e,{RouterComponent:r}=(0,F.useRouterContext)(),a=r&&i?(0,s.jsx)(R.Z,{component:r,to:i,children:n}):n;return(0,s.jsx)(V.ZP,{sx:{px:1,py:0},children:(0,s.jsx)(B.Z,{primary:t,secondary:a,slotProps:{primary:{variant:"h5"},secondary:{variant:"body1",sx:{wordBreak:"break-word"}}}})})}function G(e){return"stringValue"in e?e.stringValue.length>0?e.stringValue:"<empty string>":"intValue"in e?e.intValue:"boolValue"in e?e.boolValue.toString():"arrayValue"in e?e.arrayValue.values.map(G).join(", "):"unknown"}var _=n(73845),W=n(33711),H=n(6849),J=n(12449);function X(e){let{customLinks:t,trace:n,span:i}=e;return(0,s.jsx)(s.Fragment,{children:i.events.sort((e,t)=>e.timeUnixMs-t.timeUnixMs).map((e,i)=>(0,s.jsxs)(a.Fragment,{children:[i>0&&(0,s.jsx)(P.Z,{}),(0,s.jsx)(Q,{customLinks:t,trace:n,event:e})]},i))})}function Q(e){let{customLinks:t,trace:n,event:i}=e,r=i.timeUnixMs-n.startTimeUnixMs,[o,l]=(0,a.useState)(!1);return(0,s.jsxs)(E.Z,{children:[(0,s.jsxs)(_.Z,{onClick:()=>{l(!o)},sx:{px:1},children:[(0,s.jsx)(B.Z,{primary:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("strong",{children:[j(r),":"]})," ",i.name]}),slotProps:{primary:{noWrap:!0}}}),o?(0,s.jsx)(H.default,{}):(0,s.jsx)(J.default,{})]}),(0,s.jsx)(W.Z,{in:o,timeout:"auto",unmountOnExit:!0,children:(0,s.jsxs)(E.Z,{sx:{px:1},children:[(0,s.jsx)(A,{name:"name",value:i.name}),(0,s.jsx)(A,{name:"time",value:j(r)}),(0,s.jsx)(N,{customLinks:t,attributes:i.attributes})]})})]})}function Y(e){let{customLinks:t,span:n}=e;return(0,s.jsx)(s.Fragment,{children:n.links.map((e,n)=>(0,s.jsxs)(a.Fragment,{children:[n>0&&(0,s.jsx)(P.Z,{}),(0,s.jsx)(q,{link:e,customLinks:t})]},n))})}function q(e){let{customLinks:t,link:n}=e,i=(0,F.useAllVariableValues)(),r=(null==t?void 0:t.links.trace)?(0,F.replaceVariablesInString)(t.links.trace,i,{...null==t?void 0:t.variables,traceId:n.traceId}):void 0,a=(null==t?void 0:t.links.span)?(0,F.replaceVariablesInString)(t.links.span,i,{...null==t?void 0:t.variables,traceId:n.traceId,spanId:n.spanId}):void 0;return(0,s.jsxs)(E.Z,{children:[(0,s.jsx)(A,{name:"trace ID",value:n.traceId,link:r}),(0,s.jsx)(A,{name:"span ID",value:n.spanId,link:a}),(0,s.jsx)(N,{customLinks:t,attributes:n.attributes})]})}function K(e){let{customLinks:t,trace:n,span:i,onCloseBtnClick:o}=e,[l,d]=(0,a.useState)("attributes");return"events"===l&&0===i.events.length&&d("attributes"),"links"===l&&0===i.links.length&&d("attributes"),(0,s.jsxs)(r.Z,{children:[(0,s.jsx)(Z.Z,{sx:{float:"right"},onClick:o,children:(0,s.jsx)(z.default,{})}),(0,s.jsx)(S.Z,{sx:{wordBreak:"break-word"},children:i.resource.serviceName}),(0,s.jsx)(S.Z,{variant:"h2",sx:{wordBreak:"break-word"},children:i.name}),(0,s.jsx)(r.Z,{sx:{borderBottom:1,borderColor:"divider"},children:(0,s.jsxs)(C.Z,{value:l,onChange:(e,t)=>d(t),variant:"scrollable",children:[(0,s.jsx)(L.Z,{sx:{p:0},value:"attributes",label:"Attributes"}),i.events.length>0&&(0,s.jsx)(L.Z,{value:"events",label:"Events",icon:(0,s.jsx)($.Z,{label:i.events.length}),iconPosition:"end",sx:{minHeight:48,height:48}}),i.links.length>0&&(0,s.jsx)(L.Z,{value:"links",label:"Links",icon:(0,s.jsx)($.Z,{label:i.links.length}),iconPosition:"end",sx:{minHeight:48,height:48}})]})}),"attributes"===l&&(0,s.jsx)(O,{customLinks:t,trace:n,span:i}),"events"===l&&(0,s.jsx)(X,{customLinks:t,trace:n,span:i}),"links"===l&&(0,s.jsx)(Y,{customLinks:t,span:i})]})}var ee=n(83675);let et=(0,a.createContext)(void 0);function en(e){let{children:t}=e,[n,i]=(0,a.useState)([]),[r,o]=(0,a.useState)([]),[l,d]=(0,a.useState)(void 0);return(0,s.jsx)(et.Provider,{value:{collapsedSpans:n,setCollapsedSpans:i,visibleSpans:r,setVisibleSpans:o,hoveredParent:l,setHoveredParent:d},children:t})}function es(){let e=(0,a.useContext)(et);if(void 0===e)throw Error("No GanttTableContext found. Did you forget a Provider?");return e}var ei=n(84944),er=n(84974);function ea(e){let{span:t}=e,{collapsedSpans:n,setCollapsedSpans:i,visibleSpans:r,hoveredParent:l,setHoveredParent:d}=es(),u=(0,o.Z)(),c=(0,a.useCallback)(e=>{e.stopPropagation(),n.includes(t.spanId)?i(n.filter(e=>e!==t.spanId)):i([...n,t.spanId])},[t,n,i]),x=(0,a.useCallback)(()=>{d(t.spanId)},[t,d]),p=[t],m=t.parentSpan;for(;m;)p.unshift(m),m=m.parentSpan;return(0,s.jsx)(s.Fragment,{children:p.map((e,t)=>(0,s.jsx)(eo,{style:{width:t===p.length-1||0===r.length||r.includes(e.spanId)?24:8,borderLeft:`${l===(e.parentSpanId??"")?3:1}px solid ${u.palette.divider}`},onMouseEnter:()=>d(e.parentSpanId??""),onMouseLeave:()=>d(void 0),children:t===p.length-1&&e.childSpans.length>0&&(n.includes(e.spanId)?(0,s.jsx)(er.default,{titleAccess:"expand",onClick:c,onMouseEnter:x}):(0,s.jsx)(J.default,{titleAccess:"collapse",onClick:c,onMouseEnter:x}))},e.spanId))})}let eo=(0,d.ZP)("div")({display:"flex",height:"100%",alignItems:"center",justifyContent:"flex-end",flexShrink:0,transition:"width 1s"});var el=n(5549),ed=n(10517),eu=n(14434);function ec(e){let{customLinks:t,span:n}=e,r=(0,F.useAllVariableValues)(),{RouterComponent:o}=(0,F.useRouterContext)(),[l,d]=(0,a.useState)(null),u=!!l;if(!o||!t.links.span)return null;if(1==n.links.length&&n.links[0]){let e=n.links[0];return(0,s.jsx)(i.InfoTooltip,{description:"open linked span",children:(0,s.jsx)(Z.Z,{size:"small",component:o,to:(0,F.replaceVariablesInString)(t.links.span,r,{...t.variables,traceId:e.traceId,spanId:e.spanId}),children:(0,s.jsx)(eu.default,{fontSize:"inherit"})})})}let c=e=>{e.stopPropagation(),d(null)};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(i.InfoTooltip,{description:`${n.links.length} linked spans`,children:(0,s.jsx)(Z.Z,{"aria-label":"span links","aria-haspopup":"true","aria-expanded":u?"true":void 0,size:"small",onClick:e=>{e.stopPropagation(),d(e.currentTarget)},children:(0,s.jsx)(eu.default,{fontSize:"inherit"})})}),(0,s.jsx)(el.Z,{anchorEl:l,open:u,onClose:c,children:n.links.map(e=>(0,s.jsxs)(ed.Z,{component:o,onClick:c,to:(0,F.replaceVariablesInString)(t.links.span,r,{...t.variables,traceId:e.traceId,spanId:e.spanId}),children:["Open linked span ",e.spanId]},e.spanId))})]})}function ex(e){let{customLinks:t,span:n,nameColumnWidth:i}=e;return(0,s.jsxs)(l.Z,{direction:"row",sx:{alignItems:"center"},style:{width:`${100*i}%`},children:[(0,s.jsx)(ea,{span:n}),f(n)&&(0,s.jsx)(ei.default,{titleAccess:"error",color:"error",sx:{marginRight:"5px"}}),(0,s.jsxs)(r.Z,{sx:{whiteSpace:"nowrap",overflow:"hidden"},children:[(0,s.jsxs)("strong",{children:[n.resource.serviceName,":"]})," ",n.name]}),t&&t.links.span&&n.links.length>0&&(0,s.jsx)(r.Z,{sx:{marginLeft:"auto",px:1},children:(0,s.jsx)(ec,{customLinks:t,span:n})})]})}function ep(e){var t,n;let{options:a,span:l,viewport:d}=e,u=(0,o.Z)(),c=(0,i.useChartsTheme)(),x=l.endTimeUnixMs-l.startTimeUnixMs,p=d.endTimeUnixMs-d.startTimeUnixMs,m=x/p,h=(l.startTimeUnixMs-d.startTimeUnixMs)/p;return(0,s.jsxs)(r.Z,{sx:{position:"relative",height:"100%",flexGrow:1,overflow:"hidden"},children:[(0,s.jsx)(b,{}),(0,s.jsx)(r.Z,{"data-testid":"span-duration-bar",sx:{position:"absolute",top:0,bottom:0,margin:"auto",minWidth:"2px",height:"8px",borderRadius:u.shape.borderRadius},style:{left:`${100*h}%`,width:`${100*m}%`,backgroundColor:v(u,c,null==(n=a.visual)||null==(t=n.palette)?void 0:t.mode,l)}}),(0,s.jsx)(r.Z,{sx:{position:"absolute",top:"50%",transform:"translateY(-50%)",padding:"0 8px",color:u.palette.grey[700],fontSize:".7rem"},style:h+m<.95?{left:`${(h+m)*100}%`}:{left:`${100*h}%`,transform:"translateY(-50%) translateX(-100%)"},children:j(x)})]})}let em=(0,a.memo)(function(e){let{options:t,customLinks:n,span:i,viewport:r,selected:a,nameColumnWidth:l,divider:d,onClick:u}=e,c=(0,o.Z)();return(0,s.jsxs)(eh,{sx:{backgroundColor:a?c.palette.action.selected:"inherit"},direction:"row",onClick:()=>{var e;(null==(e=document.getSelection())?void 0:e.type)!=="Range"&&u(i)},children:[(0,s.jsx)(ex,{customLinks:n,span:i,nameColumnWidth:l}),d,(0,s.jsx)(ep,{options:t,span:i,viewport:r})]})}),eh=(0,d.ZP)(l.Z)(e=>{let{theme:t}=e;return{height:h,"&:hover":{backgroundColor:t.palette.action.hover,borderTop:`1px solid ${t.palette.divider}`,borderBottom:`1px solid ${t.palette.divider}`}}});function ef(e){let{trace:t,viewport:n,nameColumnWidth:i,divider:a}=e,d=(0,o.Z)();return(0,s.jsxs)(l.Z,{direction:"row",alignItems:"center",sx:{height:h,fontSize:"0.9rem",borderBottom:`1px solid ${d.palette.divider}`},children:[(0,s.jsx)(r.Z,{style:{width:`${100*i}%`},children:(0,s.jsx)("span",{style:{padding:".25rem"},children:"Service & Operation"})}),a,(0,s.jsx)(r.Z,{sx:{position:"relative",height:"100%",flexGrow:1},children:(0,s.jsx)(g,{trace:t,viewport:n})})]})}function ev(e){let{parentRef:t,spacing:n=0,onMove:i}=e,[r,o]=(0,a.useState)(!1),l=(0,T.z)(e=>{if(!t.current)return;let s=(e.clientX-t.current.getBoundingClientRect().left+n)/t.current.getBoundingClientRect().width;.05<=s&&s<=.95&&i(s)}),d=(0,T.z)(()=>{o(!1)});return(0,a.useEffect)(()=>{function e(){window.removeEventListener("mousemove",l),window.removeEventListener("mouseup",d),document.body.style.cursor="inherit"}return r?(window.addEventListener("mousemove",l),window.addEventListener("mouseup",d),document.body.style.cursor="col-resize"):e(),e},[r,l,d]),(0,s.jsx)(ej,{onMouseDown:e=>{e.preventDefault(),o(!0)},onClick:e=>e.stopPropagation()})}let ej=(0,d.ZP)(r.Z)(e=>{let{theme:t}=e;return{position:"relative",width:"1px",height:"100%",backgroundColor:t.palette.divider,cursor:"col-resize","&:before":{position:"absolute",width:"7px",left:"-3px",top:0,bottom:0,content:'" "',zIndex:1}}});function eg(e){let{options:t,customLinks:n,trace:i,viewport:l,selectedSpan:d,onSpanClick:u}=e,{collapsedSpans:c,setVisibleSpans:x}=es(),[p,m]=(0,a.useState)(.25),h=(0,a.useRef)(null),f=(0,o.Z)(),v=(0,a.useMemo)(()=>{let e=[];for(let t of i.rootSpans)!function e(t,n,s){if(t.push(n),!s.includes(n.spanId))for(let i of n.childSpans)e(t,i,s)}(e,t,c);return e},[i.rootSpans,c]),j=(0,a.useMemo)(()=>{if(d)for(let t=0;t<v.length;t++){var e;if((null==(e=v[t])?void 0:e.spanId)===d.spanId)return t}},[v,d]),g=(0,s.jsx)(ev,{parentRef:h,onMove:m});return(0,s.jsxs)(r.Z,{ref:h,sx:{display:"flex",flexDirection:"column",flexGrow:1,border:`1px solid ${f.palette.divider}`,borderRadius:`${f.shape.borderRadius}px`},children:[(0,s.jsx)(ef,{trace:i,viewport:l,nameColumnWidth:p,divider:g}),(0,s.jsx)(ee.OO,{data:v,initialTopMostItemIndex:j??0,itemContent:(e,i)=>(0,s.jsx)(em,{options:t,customLinks:n,span:i,viewport:l,selected:i===d,nameColumnWidth:p,divider:g,onClick:u}),rangeChanged:function(e){let{startIndex:t,endIndex:n}=e,s=[];for(let e=t;e<=n;e++)s.push(v[e].spanId);x(s)}})]})}var eb=n(93098);function eM(e){return{timeUnixMs:1e-6*parseInt(e.timeUnixNano),name:e.name,attributes:e.attributes??[]}}function ek(e){return{traceId:e.traceId,spanId:e.spanId,attributes:e.attributes??[]}}let eT={year:"numeric",month:"long",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",fractionalSecondDigits:3,timeZoneName:"short"};function eU(e){let{trace:t}=e,{dateFormatOptionsWithUserTimeZone:n}=(0,i.useTimeZone)(),r=n(eT),a=new Intl.DateTimeFormat(void 0,r),o=t.rootSpans[0];return o?(0,s.jsxs)(l.Z,{direction:"row",sx:{justifyContent:"space-between"},children:[(0,s.jsxs)(S.Z,{variant:"h3",children:[o.resource.serviceName,": ",o.name," (",j(t.endTimeUnixMs-t.startTimeUnixMs),")"]}),(0,s.jsxs)(S.Z,{variant:"h4",children:[(0,s.jsxs)(S.Z,{component:"span",sx:{px:1},children:[(0,s.jsx)("strong",{children:"Start:"})," ",a.format(t.startTimeUnixMs)]}),(0,s.jsxs)(S.Z,{component:"span",sx:{px:1},children:[(0,s.jsx)("strong",{children:"Trace ID:"})," ",o.traceId]})]})]}):(0,s.jsx)(S.Z,{children:"Trace contains no spans."})}function ey(e){let{options:t,customLinks:n,trace:i}=e,d=(0,o.Z)(),u=(0,a.useMemo)(()=>{try{return function(e){let t=new Map,n=[],s=0,i=0;for(let n of e.resourceSpans){let e=function(e){let t="unknown";for(let n of(null==e?void 0:e.attributes)??[])if("service.name"===n.key&&"stringValue"in n.value){t=n.value.stringValue;break}return{serviceName:t,attributes:(null==e?void 0:e.attributes)??[]}}(n.resource);for(let a of n.scopeSpans){let n=a.scope??{};for(let o of a.spans){var r;let a={resource:e,scope:n,childSpans:[],...{traceId:(r=o).traceId,spanId:r.spanId,parentSpanId:r.parentSpanId,name:r.name,kind:r.kind,startTimeUnixMs:1e-6*parseInt(r.startTimeUnixNano),endTimeUnixMs:1e-6*parseInt(r.endTimeUnixNano),attributes:r.attributes??[],events:(r.events??[]).map(eM),links:(r.links??[]).map(ek),status:r.status??{}}};t.set(o.spanId,a),(0===s||a.startTimeUnixMs<s)&&(s=a.startTimeUnixMs),(0===i||a.endTimeUnixMs>i)&&(i=a.endTimeUnixMs)}}}for(let[,e]of t){if(!e.parentSpanId){n.push(e);continue}let s=t.get(e.parentSpanId);if(!s){console.trace(`span ${e.spanId} has parent ${e.parentSpanId} which has not been received yet`),n.push(e);continue}e.parentSpan=s;let i=(0,eb.sortedIndexBy)(s.childSpans,e,e=>e.startTimeUnixMs);s.childSpans.splice(i,0,e)}return{trace:e,rootSpans:n,spanById:t,startTimeUnixMs:s,endTimeUnixMs:i}}(i)}catch(e){throw Error(`Error: unable to parse trace: ${e}`)}},[i]),[c,x]=(0,a.useState)({startTimeUnixMs:u.startTimeUnixMs,endTimeUnixMs:u.endTimeUnixMs}),[p,m]=(0,a.useState)(()=>t.selectedSpanId?u.spanById.get(t.selectedSpanId):void 0),h=(0,a.useRef)(null),[f,v]=(0,a.useState)(.82);return(0,s.jsxs)(l.Z,{ref:h,direction:"row",sx:{height:"100%",minHeight:"240px",gap:2},children:[(0,s.jsxs)(l.Z,{sx:{flexGrow:1,gap:2},children:[(0,s.jsx)(eU,{trace:u}),(0,s.jsx)(w,{options:t,trace:u,viewport:c,setViewport:x}),(0,s.jsx)(en,{children:(0,s.jsx)(eg,{options:t,customLinks:n,trace:u,viewport:c,selectedSpan:p,onSpanClick:m})})]}),p&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(ev,{parentRef:h,spacing:parseInt(d.spacing(2)),onMove:v}),(0,s.jsx)(r.Z,{sx:{width:`${(1-f)*100}%`,overflow:"auto"},children:(0,s.jsx)(K,{customLinks:n,trace:u,span:p,onCloseBtnClick:()=>m(void 0)})})]})]})}var eI=n(29379),ew=n(28458);let eZ={PanelComponent:function(e){var t,n,a;let{spec:o,queryResults:l}=e,d=(0,i.useChartsTheme)().container.padding.default;if(l.length>1)return(0,s.jsx)(i.TextOverlay,{message:"This panel does not support more than one query."});let u=null==(t=l[0])?void 0:t.data.trace;if(!u)return(0,s.jsx)(i.NoDataOverlay,{resource:"trace"});let c=null==(n=l[0])?void 0:n.definition.spec.plugin.spec,x=null==c||null==(a=c.datasource)?void 0:a.name,p=o.links?{variables:{datasourceName:x??""},links:o.links}:void 0;return(0,s.jsx)(r.Z,{sx:{height:"100%",padding:`${d}px`},children:(0,s.jsx)(ey,{options:o,customLinks:p,trace:u})})},supportedQueryTypes:["TraceQuery"],createInitialOptions:function(){return{}},actions:[{component:function(e){var t,n;let{queryResults:r}=e,o=null==(n=r[0])||null==(t=n.data)?void 0:t.trace,l=(0,a.useCallback)(()=>{if(!o)return;let e=JSON.stringify(o,null,2);var t=function(e){for(let t of e.resourceSpans)for(let e of t.scopeSpans)for(let t of e.spans)return`${t.traceId}.json`;return"trace.json"}(o),n="application/json",s=e;let i=URL.createObjectURL(new Blob([s],{type:n})),r=document.createElement("a");r.download=t,r.href=i,r.click(),URL.revokeObjectURL(i)},[o]);return o?(0,s.jsx)(i.InfoTooltip,{description:"download OTLP/JSON trace",children:(0,s.jsx)(ew.I,{"aria-label":"download OTLP/JSON trace",size:"small",onClick:l,children:(0,s.jsx)(eI.default,{fontSize:"inherit"})})}):null}}]}}}]);