"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[890],{25243:(Z,C,a)=>{a.d(C,{i:()=>P});var p=a(41407),s=a(39953),t=a(82803);const P=({hideLine:T=!1})=>{const d=(0,t.wW)(R);return T?s.createElement("hr",{className:d.dividerHideLine}):s.createElement("hr",{className:d.divider})},R=T=>({divider:(0,p.css)`
    margin: ${T.spacing(4,0)};
  `,dividerHideLine:(0,p.css)`
    border: none;
    margin: ${T.spacing(3,0)};
  `})},23846:(Z,C,a)=>{a.d(C,{I:()=>K});var p=a(41407),s=a(39953),t=a(47635),P=a(99242),R=a(82803),T=a(74661),d=a(69171),g=a(26286),U=a(43997);function B({options:D,onOptionsChange:I}){const N=(0,R.wW)(b);return s.createElement("div",{className:N.container},s.createElement(T.Z,{className:N.row},s.createElement(d._,{tooltip:"Displays the node graph above the trace view. Default: disabled",label:"Enable node graph",labelWidth:26},s.createElement(g.x,{id:"enableNodeGraph",value:D.jsonData.nodeGraph?.enabled,onChange:O=>(0,t.tp)({onOptionsChange:I,options:D},"nodeGraph",{...D.jsonData.nodeGraph,enabled:O.currentTarget.checked})}))))}const K=({options:D,onOptionsChange:I})=>s.createElement(P._,{title:"Node graph",description:s.createElement(U.W,{description:"Show or hide the node graph visualization.",suffix:`${D.type}/#node-graph`,feature:"the node graph"})},s.createElement(B,{options:D,onOptionsChange:I})),b=D=>({infoText:(0,p.css)`
    label: infoText;
    padding-bottom: ${D.spacing(2)};
    color: ${D.colors.text.secondary};
  `,container:(0,p.css)`
    label: container;
    width: 100%;
  `,row:(0,p.css)`
    label: row;
    align-items: baseline;
  `})},49605:(Z,C,a)=>{a.d(C,{Y:()=>O});var p=a(41407),s=a(39953),t=a(47635),P=a(27770),R=a(82803),T=a(74661),d=a(69171),g=a(4919),U=a(38637),B=a(92811),K=a(43997),b=a(13273),D=a(60317),I=a(36516);function N({options:l,onOptionsChange:f}){const z=(0,R.wW)(V);return s.createElement("div",{className:(0,p.css)({width:"100%"})},s.createElement(T.Z,{className:z.row},s.createElement(d._,{tooltip:"The Prometheus data source the trace is going to navigate to",label:"Data source",labelWidth:26},s.createElement(B.q,{inputId:"trace-to-metrics-data-source-picker",pluginId:"prometheus",current:l.jsonData.tracesToMetrics?.datasourceUid,noDefault:!0,width:40,onChange:y=>(0,t.tp)({onOptionsChange:f,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,datasourceUid:y.uid})})),l.jsonData.tracesToMetrics?.datasourceUid?s.createElement(g.zx,{type:"button",variant:"secondary",size:"sm",fill:"text",onClick:()=>{(0,t.tp)({onOptionsChange:f,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,datasourceUid:void 0})}},"Clear"):null),s.createElement(T.Z,null,s.createElement(b.w,{label:(0,I.mH)("start"),tooltip:(0,I.rr)("start","-2m"),value:l.jsonData.tracesToMetrics?.spanStartTimeShift||"",onChange:y=>{(0,t.tp)({onOptionsChange:f,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,spanStartTimeShift:y})},placeholder:"-2m",isInvalidError:I.Ny})),s.createElement(T.Z,null,s.createElement(b.w,{label:(0,I.mH)("end"),tooltip:(0,I.rr)("end","2m"),value:l.jsonData.tracesToMetrics?.spanEndTimeShift||"",onChange:y=>{(0,t.tp)({onOptionsChange:f,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,spanEndTimeShift:y})},placeholder:"2m",isInvalidError:I.Ny})),s.createElement(T.Z,null,s.createElement(d._,{tooltip:"Tags that will be used in the metrics query",label:"Tags",labelWidth:26},s.createElement(D.a,{values:l.jsonData.tracesToMetrics?.tags??[],onChange:y=>(0,t.tp)({onOptionsChange:f,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,tags:y})}))),l.jsonData.tracesToMetrics?.queries?.map((y,j)=>s.createElement("div",{key:j,className:z.queryRow},s.createElement(d._,{label:"Link Label",labelWidth:26,tooltip:"Descriptive label for the linked query"},s.createElement(U.I,{label:"Link Label",type:"text",allowFullScreen:!0,value:y.name,width:40,onChange:W=>{let x=l.jsonData.tracesToMetrics?.queries.slice()??[];x[j].name=W.currentTarget.value,(0,t.tp)({onOptionsChange:f,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,queries:x})}})),s.createElement(d._,{label:"Query",labelWidth:10,tooltip:"The Prometheus query that will run when navigating from a trace to metrics. Interpolate tags using the `$__tags` keyword",grow:!0},s.createElement(U.I,{label:"Query",type:"text",allowFullScreen:!0,value:y.query,onChange:W=>{let x=l.jsonData.tracesToMetrics?.queries.slice()??[];x[j].query=W.currentTarget.value,(0,t.tp)({onOptionsChange:f,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,queries:x})}})),s.createElement(g.zx,{variant:"destructive",title:"Remove query",icon:"times",type:"button",onClick:()=>{let W=l.jsonData.tracesToMetrics?.queries.slice();W?.splice(j,1),(0,t.tp)({onOptionsChange:f,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,queries:W})}}))),s.createElement(g.zx,{variant:"secondary",title:"Add query",icon:"plus",type:"button",onClick:()=>{(0,t.tp)({onOptionsChange:f,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,queries:[...l.jsonData.tracesToMetrics?.queries??[],{query:""}]})}},"Add query"))}const O=({options:l,onOptionsChange:f})=>s.createElement(P.K,{title:"Trace to metrics",description:s.createElement(K.W,{description:"Navigate from a trace span to the selected data source's metrics.",suffix:`${l.type}/#trace-to-metrics`,feature:"trace to metrics"}),isCollapsible:!0,isInitiallyOpen:!0},s.createElement(N,{options:l,onOptionsChange:f})),V=l=>({infoText:(0,p.css)`
    padding-bottom: ${l.spacing(2)};
    color: ${l.colors.text.secondary};
  `,row:(0,p.css)`
    label: row;
    align-items: baseline;
  `,queryRow:(0,p.css)`
    label: queryRow;
    display: flex;
    flex-flow: wrap;
  `})},99330:(Z,C,a)=>{a.r(C),a.d(C,{plugin:()=>Re});var p=a(54721),s=a(41407),t=a(39953),P=a(82803);function R(){const n=(0,P.wW)(T);return t.createElement(t.Fragment,null,t.createElement("h2",{id:"jaeger-cheat-sheet"},"Jaeger Cheat Sheet"),t.createElement("p",null,"This cheat sheet provides a quick overview of the query types that are available. For more details about the Jaeger data source, check out"," ",t.createElement("a",{href:"https://grafana.com/docs/grafana/latest/datasources/jaeger",target:"_blank",rel:"noreferrer",className:n.anchorTag},"the documentation"),"."),t.createElement("hr",null),t.createElement("ul",{className:n.unorderedList},t.createElement("li",null,"Search - filter traces by service name. Addtionally, you can filter by tags or min/max duration, as well as limit the number of traces that are returned."),t.createElement("li",null,"TraceID - if you have a trace ID, simply enter the trace ID to see the trace."),t.createElement("li",null,"JSON File - you can upload a JSON file that contains a single trace to visualize it. If the file has multiple traces then the first trace is used for visualization. An example of a valid JSON file can be found in"," ",t.createElement("a",{href:"https://grafana.com/docs/grafana/latest/datasources/jaeger/#upload-json-trace-file",target:"_blank",rel:"noreferrer",className:n.anchorTag},"this section")," ","of the documentation.")))}const T=n=>({anchorTag:(0,s.css)`
    color: ${n.colors.text.link};
  `,unorderedList:(0,s.css)`
    list-style-type: none;
  `});var d=a(74661),g=a(69171),U=a(54795),B=a(73075),K=a(17789),b=a(12223),D=a(20454),I=a(4919),N=a(99456),O=a(79059),V=a(52184),l=a(9558),f=a(38637),z=a(97316),y=a(90634),j=a(74600),W=a(49036),x=a.n(W);function re(n){if(!n)return"";const e=x().parse(n);return Object.keys(e).forEach(r=>{const i=e[r];typeof i!="string"&&(e[r]=String(i))}),JSON.stringify(e)}function ne(n){if(!n)return"";try{return x().stringify(JSON.parse(n))}catch{return n}}const X="e.g. 1.2s, 100ms, 500us",w="All",se={label:w,value:void 0};function le({datasource:n,query:e,onChange:r}){const[i,E]=(0,t.useState)(),[c,m]=(0,t.useState)(),[u,S]=(0,t.useState)({services:!1,operations:!1}),h=(0,t.useCallback)(async(o,v,$="")=>{S(M=>({...M,[v]:!0}));try{const M=await n.metadataRequest(o);return M?M.sort().map(J=>({label:J,value:J})).filter(J=>J.value?(0,V.C)(J.value,$).found:!1):[{label:`No ${v} found`,value:`No ${v} found`}]}catch(M){return M instanceof Error&&(0,j.WI)((0,z.$l)((0,y.t_)("Error",M))),[]}finally{S(M=>({...M,[v]:!1}))}},[n]);return(0,t.useEffect)(()=>{(async()=>{const v=await h("/api/services","services");e.service&&(0,O.J)().containsTemplate(e.service)&&v.push((0,N.E)(e.service)),E(v)})()},[n,h,e.service]),(0,t.useEffect)(()=>{const o=async()=>{const v=await h(`/api/services/${encodeURIComponent((0,O.J)().replace(e.service))}/operations`,"operations");e.operation&&(0,O.J)().containsTemplate(e.operation)&&v.push((0,N.E)(e.operation)),m([se,...v])};e.service&&o()},[n,e.service,h,e.operation]),t.createElement("div",{className:(0,s.css)({maxWidth:"500px"})},t.createElement(d.Z,null,t.createElement(g._,{label:"Service Name",labelWidth:14,grow:!0},t.createElement(l.Ph,{inputId:"service",options:i,onOpenMenu:()=>h("/api/services","services"),isLoading:u.services,value:i?.find(o=>o?.value===e.service)||void 0,placeholder:"Select a service",onChange:o=>r({...e,service:o?.value,operation:e.service!==o?.value?void 0:e.operation}),menuPlacement:"bottom",isClearable:!0,"aria-label":"select-service-name",allowCustomValue:!0}))),t.createElement(d.Z,null,t.createElement(g._,{label:"Operation Name",labelWidth:14,grow:!0,disabled:!e.service},t.createElement(l.Ph,{inputId:"operation",options:c,onOpenMenu:()=>h(`/api/services/${encodeURIComponent((0,O.J)().replace(e.service))}/operations`,"operations"),isLoading:u.operations,value:c?.find(o=>o.value===e.operation)||null,placeholder:"Select an operation",onChange:o=>r({...e,operation:o?.value||void 0}),menuPlacement:"bottom",isClearable:!0,"aria-label":"select-operation-name",allowCustomValue:!0}))),t.createElement(d.Z,null,t.createElement(g._,{label:"Tags",labelWidth:14,grow:!0,tooltip:"Values should be in logfmt."},t.createElement(f.I,{id:"tags",value:ne(e.tags),placeholder:"http.status_code=200 error=true",onChange:o=>r({...e,tags:o.currentTarget.value})}))),t.createElement(d.Z,null,t.createElement(g._,{label:"Min Duration",labelWidth:14,grow:!0},t.createElement(f.I,{id:"minDuration",name:"minDuration",value:e.minDuration||"",placeholder:X,onChange:o=>r({...e,minDuration:o.currentTarget.value})}))),t.createElement(d.Z,null,t.createElement(g._,{label:"Max Duration",labelWidth:14,grow:!0},t.createElement(f.I,{id:"maxDuration",name:"maxDuration",value:e.maxDuration||"",placeholder:X,onChange:o=>r({...e,maxDuration:o.currentTarget.value})}))),t.createElement(d.Z,null,t.createElement(g._,{label:"Limit",labelWidth:14,grow:!0,tooltip:"Maximum number of returned results"},t.createElement(f.I,{id:"limit",name:"limit",value:e.limit||"",type:"number",onChange:o=>r({...e,limit:o.currentTarget.value?parseInt(o.currentTarget.value,10):void 0})}))))}const Ne=null;function ie({datasource:n,query:e,onChange:r,onRunQuery:i}){const[E,c]=(0,t.useState)(!1),m=(0,P.l4)(),u=(0,P.wW)(oe),S=o=>{const v={...e,query:o};r(v)},h=()=>{switch(e.queryType){case"search":return t.createElement(le,{datasource:n,query:e,onChange:r});default:return t.createElement(d.Z,null,t.createElement(g._,{label:"Trace ID",labelWidth:14,grow:!0},t.createElement(U.q,{query:e.query,onChange:S,onRunQuery:i,placeholder:"Enter a Trace ID (run with Shift+Enter)",portalOrigin:"jaeger"})))}};return t.createElement(t.Fragment,null,t.createElement(B.u,{title:"Upload trace",isOpen:E,onDismiss:()=>c(!1)},t.createElement("div",{className:(0,s.css)({padding:m.spacing(2)})},t.createElement(K.Yo,{options:{multiple:!1},onLoad:o=>{n.uploadedJson=o,r({...e,queryType:"upload"}),c(!1),i()}}))),t.createElement("div",{className:u.container},t.createElement(d.Z,null,t.createElement(g._,{label:"Query type",grow:!0},t.createElement(b.Lh,{spacing:"sm",align:"center",justify:"space-between"},t.createElement(D.S,{options:[{value:"search",label:"Search"},{value:void 0,label:"TraceID"}],value:e.queryType,onChange:o=>r({...e,queryType:o}),size:"md"}),t.createElement(I.zx,{variant:"secondary",size:"sm",onClick:()=>{c(!0)}},"Import trace")))),h()))}const oe=()=>({container:(0,s.css)`
    width: 100%;
  `});var ce=a(17613),me=a(27770),k=a(32688),de=a(3782),F=a(25243),ue=a(23846),ve=a(36516),fe=a(49605),ge=a(95577),Ee=a(47635),he=a(26286);function pe({options:n,onOptionsChange:e}){return t.createElement("div",{className:q.container},t.createElement("h3",{className:"page-heading"},"Query Trace by ID with Time Params"),t.createElement(d.Z,{className:q.row},t.createElement(g._,{tooltip:"pass time parameters when querying trace by ID",label:"Enable Time Parameters",labelWidth:26},t.createElement(he.x,{id:"enableTraceIdTimeParams",value:n.jsonData.traceIdTimeParams?.enabled,onChange:r=>(0,Ee.tp)({onOptionsChange:e,options:n},"traceIdTimeParams",{...n.jsonData.traceIdTimeParams,enabled:r.currentTarget.checked})}))))}const q={container:(0,s.css)`
    label: container;
    width: 100%;
  `,row:(0,s.css)`
    label: row;
    align-items: baseline;
  `},Te=({options:n,onOptionsChange:e})=>{const r=(0,P.wW)(De);return t.createElement("div",{className:r.container},t.createElement(ce.j,{dataSourceName:"Jaeger",docsLink:"https://grafana.com/docs/grafana/latest/datasources/jaeger",hasRequiredFields:!1}),t.createElement(F.i,null),t.createElement(de.E,{defaultUrl:"http://localhost:16686",dataSourceConfig:n,showAccessOptions:!1,onChange:e,secureSocksDSProxyEnabled:k.config.secureSocksDSProxyEnabled}),t.createElement(ve.dw,{options:n,onOptionsChange:e}),t.createElement(F.i,null),k.config.featureToggles.traceToMetrics?t.createElement(t.Fragment,null,t.createElement(fe.Y,{options:n,onOptionsChange:e}),t.createElement(F.i,null)):null,t.createElement(me.K,{title:"Additional settings",description:"Additional settings are optional settings that can be configured for more control over your data source.",isCollapsible:!0,isInitiallyOpen:!1},t.createElement(ue.I,{options:n,onOptionsChange:e}),t.createElement(F.i,{hideLine:!0}),t.createElement(ge.vc,{options:n,onOptionsChange:e}),t.createElement(F.i,{hideLine:!0}),t.createElement(pe,{options:n,onOptionsChange:e})))},De=n=>({container:(0,s.css)`
    label: container;
    margin-bottom: ${n.spacing(2)};
    max-width: 900px;
  `});var Q=a(86832),_=a(31312),A=a(63302),H=a(71476),Me=a(10752),Ie=a(77877),ye=a(7906),Se=a(89591),Pe=a(4148),Oe=a(5365),Le=a(6278),L=a(2221),G=a(68586);function ee(n){const{nodes:e,edges:r}=Ce(n),[i,E]=(0,G.np)();for(const c of e)i.add(c);for(const c of r)E.add(c);return[i,E]}function Ce(n){const e=[],r=[],i=We(n.spans),E=(0,G.nO)(c=>{if(c>=n.spans.length)return;const m=n.spans[c];return{span:m,id:m.spanID,parentIds:m.references?.filter(u=>u.refType==="CHILD_OF").map(u=>u.spanID)||[]}});for(const c of n.spans){const m=n.processes[c.processID],u=E[c.spanID].children.map($=>{const M=E[$].span;return[M.startTime,M.startTime+M.duration]}),S=(0,G.et)(u),h=c.duration-S,o=(0,G.fy)(c.duration/1e3,i/1e3,h/1e3);e.push({[L.z.id]:c.spanID,[L.z.title]:m?.serviceName??"",[L.z.subTitle]:c.operationName,[L.z.mainStat]:o.main,[L.z.secondaryStat]:o.secondary,[L.z.color]:h/i});const v=c.references?.find($=>$.refType==="CHILD_OF")?.spanID;v&&E[v].span&&r.push({[L.z.id]:v+"--"+c.spanID,[L.z.target]:c.spanID,[L.z.source]:v})}return{nodes:e,edges:r}}function We(n){let e=0,r=1/0;for(const i of n)i.startTime<r&&(r=i.startTime),i.startTime+i.duration>e&&(e=i.startTime+i.duration);return e-r}var Y=a(26923);class xe extends p.MF{constructor(e,r=(0,Le.$t)(),i=(0,O.J)()){super(e),this.instanceSettings=e,this.timeSrv=r,this.templateSrv=i,this.uploadedJson=null,this.nodeGraph=e.jsonData.nodeGraph,this.traceIdTimeParams=e.jsonData.traceIdTimeParams}async metadataRequest(e,r){return(await(0,_.n)(this._request(e,r,{hideFromInspector:!0}))).data.data}isSearchFormValid(e){return!!e.service}query(e){const r=e.targets[0];if(!r)return(0,A.of)({data:[ae]});if(r.queryType==="search"&&!this.isSearchFormValid(r))return(0,A.of)({error:{message:"You must select a service."},data:[]});let{start:i,end:E}=this.getTimeRange();if(r.queryType!=="search"&&r.query){let u=`/api/traces/${encodeURIComponent(this.templateSrv.replace(r.query,e.scopedVars))}`;return this.traceIdTimeParams&&(u+=`?start=${i}&end=${E}`),this._request(u).pipe((0,H.U)(S=>{const h=S?.data?.data?.[0];if(!h)return{data:[ae]};let o=[(0,Y.xM)(h)];return this.nodeGraph?.enabled&&o.push(...ee(h)),{data:o}}))}if(r.queryType==="upload"){if(!this.uploadedJson)return(0,A.of)({data:[]});try{const u=JSON.parse(this.uploadedJson).data[0];let S=[(0,Y.xM)(u)];return this.nodeGraph?.enabled&&S.push(...ee(u)),(0,A.of)({data:S})}catch{return(0,A.of)({error:{message:"The JSON file uploaded is not in a valid Jaeger format"},data:[]})}}let c=(0,Q.pick)(this.applyVariables(r,e.scopedVars),["service","operation","tags","minDuration","maxDuration","limit"]),m=(0,Q.pickBy)(c,Q.identity);return m.operation===w&&(m=(0,Q.omit)(m,"operation")),m.tags&&(m={...m,tags:re(m.tags.toString())}),this._request("/api/traces",{...m,...this.getTimeRange(),lookback:"custom"}).pipe((0,H.U)(u=>({data:[(0,Y.Wp)(u.data.data,this.instanceSettings)]})))}interpolateVariablesInQueries(e,r){return!e||e.length===0?[]:e.map(i=>({...i,datasource:this.getRef(),...this.applyVariables(i,r)}))}applyVariables(e,r){let i={...e};return e.tags&&this.templateSrv.containsTemplate(e.tags)&&(i={...e,tags:this.templateSrv.replace(e.tags,r)}),{...i,service:this.templateSrv.replace(e.service??"",r),operation:this.templateSrv.replace(e.operation??"",r),minDuration:this.templateSrv.replace(e.minDuration??"",r),maxDuration:this.templateSrv.replace(e.maxDuration??"",r)}}async testDatasource(){return(0,_.n)(this._request("/api/services").pipe((0,H.U)(e=>(e?.data?.data||[]).length>0?{status:"success",message:"Data source connected and services found."}:{status:"error",message:"Data source connected, but no services received. Verify that Jaeger is configured properly."}),(0,Me.K)(e=>{let r="Jaeger: ";return e.statusText?r+=e.statusText:r+="Cannot connect to Jaeger",e.status&&(r+=`. ${e.status}`),e.data&&e.data.message?r+=`. ${e.data.message}`:e.data&&(r+=`. ${JSON.stringify(e.data)}`),(0,A.of)({status:"error",message:r})})))}getTimeRange(){const e=this.timeSrv.timeRange();return{start:te(e.from,!1),end:te(e.to,!0)}}getQueryDisplayText(e){return e.query||""}_request(e,r,i){const E=r?(0,Oe.tW)(r):"",c=`${this.instanceSettings.url}${e}${E.length?`?${E}`:""}`,m={...i,url:c};return(0,Pe.i)().fetch(m)}}function te(n,e){return typeof n=="string"&&(n=Ie.parse(n,e)),n.valueOf()*1e3}const ae=new ye.v({fields:[{name:"trace",type:Se.fS.trace,values:[]}],meta:{preferredVisualisationType:"trace",custom:{traceFormat:"jaeger"}}}),Re=new p.hf(xe).setConfigEditor(Te).setQueryEditor(ie).setQueryEditorHelp(R)}}]);

//# sourceMappingURL=jaegerPlugin.2d4828f82cbd1c93c267.js.map