"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[890],{90950:(G,L,a)=>{a.d(L,{n:()=>P});var E=a(9892),n=a(66111),t=a(73446),N=a(72648),j=a(11543),O=a(81764),T=a(8944),x=a(62911);function P({options:D,onOptionsChange:U}){const C=(0,N.wW)(F);return n.createElement("div",{className:C.container},n.createElement("h3",{className:"page-heading"},"Node graph"),n.createElement("div",{className:C.infoText},"Show or hide the node graph visualization",n.createElement(x.j,{hrefSuffix:`${D.type}/#node-graph`})),n.createElement(j.Z,{className:C.row},n.createElement(O._,{tooltip:"Displays the node graph above the trace view. Default: disabled",label:"Enable node graph",labelWidth:26},n.createElement(T.x,{id:"enableNodeGraph",value:D.jsonData.nodeGraph?.enabled,onChange:l=>(0,t.tp)({onOptionsChange:U,options:D},"nodeGraph",{...D.jsonData.nodeGraph,enabled:l.currentTarget.checked})}))))}const F=D=>({infoText:E.css`
    label: infoText;
    padding-bottom: ${D.spacing(2)};
    color: ${D.colors.text.secondary};
  `,container:E.css`
    label: container;
    width: 100%;
  `,row:E.css`
    label: row;
    align-items: baseline;
  `})},48288:(G,L,a)=>{a.d(L,{F:()=>U});var E=a(9892),n=a(66111),t=a(73446),N=a(53117),j=a(72648),O=a(11543),T=a(81764),x=a(31403),P=a(46967),F=a(62911),D=a(33045);function U({options:l,onOptionsChange:m}){const g=(0,j.wW)(C);return n.createElement("div",{className:(0,E.css)({width:"100%"})},n.createElement("h3",{className:"page-heading"},"Trace to metrics"),n.createElement("div",{className:g.infoText},"Navigate from a trace span to the selected data source's metrics",n.createElement(F.j,{hrefSuffix:`${l.type}/#trace-to-metrics`})),n.createElement(O.Z,{className:g.row},n.createElement(T._,{tooltip:"The Prometheus data source the trace is going to navigate to",label:"Data source",labelWidth:26},n.createElement(N.q,{inputId:"trace-to-metrics-data-source-picker",pluginId:"prometheus",current:l.jsonData.tracesToMetrics?.datasourceUid,noDefault:!0,width:40,onChange:p=>(0,t.tp)({onOptionsChange:m,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,datasourceUid:p.uid})})),l.jsonData.tracesToMetrics?.datasourceUid?n.createElement(x.zx,{type:"button",variant:"secondary",size:"sm",fill:"text",onClick:()=>{(0,t.tp)({onOptionsChange:m,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,datasourceUid:void 0})}},"Clear"):null),n.createElement(O.Z,null,n.createElement(T._,{label:"Span start time shift",labelWidth:26,grow:!0,tooltip:"Shifts the start time of the span. Default: 0 (Time units can be used here, for example: 5s, -1m, 3h)"},n.createElement(P.I,{type:"text",placeholder:"0",width:40,onChange:p=>(0,t.tp)({onOptionsChange:m,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,spanStartTimeShift:p.currentTarget.value}),value:l.jsonData.tracesToMetrics?.spanStartTimeShift||""}))),n.createElement(O.Z,null,n.createElement(T._,{label:"Span end time shift",labelWidth:26,grow:!0,tooltip:"Shifts the end time of the span. Default: 0 (Time units can be used here, for example: 5s, -1m, 3h)"},n.createElement(P.I,{type:"text",placeholder:"0",width:40,onChange:p=>(0,t.tp)({onOptionsChange:m,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,spanEndTimeShift:p.currentTarget.value}),value:l.jsonData.tracesToMetrics?.spanEndTimeShift||""}))),n.createElement(O.Z,null,n.createElement(T._,{tooltip:"Tags that will be used in the metrics query",label:"Tags",labelWidth:26},n.createElement(D.a,{values:l.jsonData.tracesToMetrics?.tags??[],onChange:p=>(0,t.tp)({onOptionsChange:m,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,tags:p})}))),l.jsonData.tracesToMetrics?.queries?.map((p,W)=>n.createElement("div",{key:W,className:g.queryRow},n.createElement(T._,{label:"Link Label",labelWidth:26,tooltip:"Descriptive label for the linked query"},n.createElement(P.I,{label:"Link Label",type:"text",allowFullScreen:!0,value:p.name,width:40,onChange:M=>{let S=l.jsonData.tracesToMetrics?.queries.slice()??[];S[W].name=M.currentTarget.value,(0,t.tp)({onOptionsChange:m,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,queries:S})}})),n.createElement(T._,{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},n.createElement(P.I,{label:"Query",type:"text",allowFullScreen:!0,value:p.query,onChange:M=>{let S=l.jsonData.tracesToMetrics?.queries.slice()??[];S[W].query=M.currentTarget.value,(0,t.tp)({onOptionsChange:m,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,queries:S})}})),n.createElement(x.zx,{variant:"destructive",title:"Remove query",icon:"times",type:"button",onClick:()=>{let M=l.jsonData.tracesToMetrics?.queries.slice();M?.splice(W,1),(0,t.tp)({onOptionsChange:m,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,queries:M})}}))),n.createElement(x.zx,{variant:"secondary",title:"Add query",icon:"plus",type:"button",onClick:()=>{(0,t.tp)({onOptionsChange:m,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,queries:[...l.jsonData.tracesToMetrics?.queries??[],{query:""}]})}},"Add query"))}const C=l=>({infoText:E.css`
    padding-bottom: ${l.spacing(2)};
    color: ${l.colors.text.secondary};
  `,row:E.css`
    label: row;
    align-items: baseline;
  `,queryRow:E.css`
    display: flex;
  `})},94053:(G,L,a)=>{a.r(L),a.d(L,{plugin:()=>De});var E=a(89424),n=a(9892),t=a(66111),N=a(72648);function j(){const s=(0,N.wW)(O);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:s.anchorTag},"the documentation"),"."),t.createElement("hr",null),t.createElement("ul",{className:s.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:s.anchorTag},"this section")," ","of the documentation.")))}const O=s=>({anchorTag:n.css`
    color: ${s.colors.text.link};
  `,unorderedList:n.css`
    list-style-type: none;
  `});var T=a(35645),x=a(12006),P=a(90950),F=a(83437),D=a(48288),U=a(95638);const C=({options:s,onOptionsChange:e})=>t.createElement(t.Fragment,null,t.createElement(x.E,{defaultUrl:"http://localhost:16686",dataSourceConfig:s,showAccessOptions:!1,onChange:e,secureSocksDSProxyEnabled:T.v.secureSocksDSProxyEnabled}),t.createElement("div",{className:"gf-form-group"},t.createElement(F.Z,{options:s,onOptionsChange:e})),T.v.featureToggles.traceToMetrics?t.createElement("div",{className:"gf-form-group"},t.createElement(D.F,{options:s,onOptionsChange:e})):null,t.createElement("div",{className:"gf-form-group"},t.createElement(P.n,{options:s,onOptionsChange:e})),t.createElement("div",{className:"gf-form-group"},t.createElement(U.SpanBarSettings,{options:s,onOptionsChange:e})));var l=a(30784),m=a(11543),g=a(81764),p=a(69659),W=a(2594),M=a(13572),S=a(20308),_=a(27303),Z=a(8581),J=a(46967),ee=a(659),te=a(60499),ae=a(3153),re=a(27854),V=a.n(re);function se(s){if(!s)return"";const e=V().parse(s);return Object.keys(e).forEach(r=>{const o=e[r];typeof o!="string"&&(e[r]=String(o))}),JSON.stringify(e)}function ne(s){if(!s)return"";try{return V().stringify(JSON.parse(s))}catch{return s}}const H="e.g. 1.2s, 100ms, 500us",Y="All",le={label:Y,value:void 0};function oe({datasource:s,query:e,onChange:r}){const[o,u]=(0,t.useState)(),[i,d]=(0,t.useState)(),[f,R]=(0,t.useState)({services:!1,operations:!1}),I=(0,t.useCallback)(async(c,h,A="")=>{R(v=>({...v,[h]:!0}));try{const v=await s.metadataRequest(c);return v?v.sort().map(B=>({label:B,value:B})).filter(B=>B.value?(0,_.C)(B.value,A).found:!1):[{label:`No ${h} found`,value:`No ${h} found`}]}catch(v){return v instanceof Error&&(0,ae.WI)((0,ee.$l)((0,te.t_)("Error",v))),[]}finally{R(v=>({...v,[h]:!1}))}},[s]);return(0,t.useEffect)(()=>{(async()=>{const h=await I("/api/services","services");e.service&&(0,S.J)().containsTemplate(e.service)&&h.push((0,M.E)(e.service)),u(h)})()},[s,I,e.service]),(0,t.useEffect)(()=>{const c=async()=>{const h=await I(`/api/services/${encodeURIComponent((0,S.J)().replace(e.service))}/operations`,"operations");e.operation&&(0,S.J)().containsTemplate(e.operation)&&h.push((0,M.E)(e.operation)),d([le,...h])};e.service&&c()},[s,e.service,I,e.operation]),t.createElement("div",{className:(0,n.css)({maxWidth:"500px"})},t.createElement(m.Z,null,t.createElement(g._,{label:"Service Name",labelWidth:14,grow:!0},t.createElement(Z.Ph,{inputId:"service",options:o,onOpenMenu:()=>I("/api/services","services"),isLoading:f.services,value:o?.find(c=>c?.value===e.service)||void 0,placeholder:"Select a service",onChange:c=>r({...e,service:c?.value,operation:e.service!==c?.value?void 0:e.operation}),menuPlacement:"bottom",isClearable:!0,"aria-label":"select-service-name",allowCustomValue:!0}))),t.createElement(m.Z,null,t.createElement(g._,{label:"Operation Name",labelWidth:14,grow:!0,disabled:!e.service},t.createElement(Z.Ph,{inputId:"operation",options:i,onOpenMenu:()=>I(`/api/services/${encodeURIComponent((0,S.J)().replace(e.service))}/operations`,"operations"),isLoading:f.operations,value:i?.find(c=>c.value===e.operation)||null,placeholder:"Select an operation",onChange:c=>r({...e,operation:c?.value||void 0}),menuPlacement:"bottom",isClearable:!0,"aria-label":"select-operation-name",allowCustomValue:!0}))),t.createElement(m.Z,null,t.createElement(g._,{label:"Tags",labelWidth:14,grow:!0,tooltip:"Values should be in logfmt."},t.createElement(J.I,{id:"tags",value:ne(e.tags),placeholder:"http.status_code=200 error=true",onChange:c=>r({...e,tags:c.currentTarget.value})}))),t.createElement(m.Z,null,t.createElement(g._,{label:"Min Duration",labelWidth:14,grow:!0},t.createElement(J.I,{id:"minDuration",name:"minDuration",value:e.minDuration||"",placeholder:H,onChange:c=>r({...e,minDuration:c.currentTarget.value})}))),t.createElement(m.Z,null,t.createElement(g._,{label:"Max Duration",labelWidth:14,grow:!0},t.createElement(J.I,{id:"maxDuration",name:"maxDuration",value:e.maxDuration||"",placeholder:H,onChange:c=>r({...e,maxDuration:c.currentTarget.value})}))),t.createElement(m.Z,null,t.createElement(g._,{label:"Limit",labelWidth:14,grow:!0,tooltip:"Maximum number of returned results"},t.createElement(J.I,{id:"limit",name:"limit",value:e.limit||"",type:"number",onChange:c=>r({...e,limit:c.currentTarget.value?parseInt(c.currentTarget.value,10):void 0})}))))}const Se=null;function ie({datasource:s,query:e,onChange:r,onRunQuery:o}){const u=(0,N.wW)(ce),i=f=>{const R={...e,query:f};r(R)},d=()=>{switch(e.queryType){case"search":return t.createElement(oe,{datasource:s,query:e,onChange:r});case"upload":return t.createElement("div",{className:u.fileDropzoneContainer},t.createElement(l.Yo,{options:{multiple:!1},onLoad:f=>{s.uploadedJson=f,o()}}));default:return t.createElement(m.Z,null,t.createElement(g._,{label:"Trace ID",labelWidth:14,grow:!0},t.createElement(p.q,{query:e.query,onChange:i,onRunQuery:o,onBlur:()=>{},placeholder:"Enter a Trace ID (run with Shift+Enter)",portalOrigin:"jaeger"})))}};return t.createElement(t.Fragment,null,t.createElement("div",{className:u.container},t.createElement(m.Z,null,t.createElement(g._,{label:"Query type"},t.createElement(W.S,{options:[{value:"search",label:"Search"},{value:void 0,label:"TraceID"},{value:"upload",label:"JSON File"}],value:e.queryType,onChange:f=>r({...e,queryType:f}),size:"md"}))),d()))}const ce=s=>({container:n.css`
    width: 100%;
  `,fileDropzoneContainer:n.css`
    padding: ${s.spacing(2)};
  `});var $=a(82897),X=a(65583),b=a(59980),K=a(9471),ue=a(59724),me=a(47406),de=a(53678),fe=a(99098),he=a(54899),ve=a(8878),ge=a(19349),y=a(92468),z=a(49427);function w(s){const{nodes:e,edges:r}=pe(s),[o,u]=(0,z.np)();for(const i of e)o.add(i);for(const i of r)u.add(i);return[o,u]}function pe(s){const e=[],r=[],o=Ee(s.spans),u=(0,z.nO)(i=>{if(i>=s.spans.length)return;const d=s.spans[i];return{span:d,id:d.spanID,parentIds:d.references?.filter(f=>f.refType==="CHILD_OF").map(f=>f.spanID)||[]}});for(const i of s.spans){const d=s.processes[i.processID],f=u[i.spanID].children.map(A=>{const v=u[A].span;return[v.startTime,v.startTime+v.duration]}),R=(0,z.et)(f),I=i.duration-R,c=(0,z.fy)(i.duration/1e3,o/1e3,I/1e3);e.push({[y.z.id]:i.spanID,[y.z.title]:d?.serviceName??"",[y.z.subTitle]:i.operationName,[y.z.mainStat]:c.main,[y.z.secondaryStat]:c.secondary,[y.z.color]:I/o});const h=i.references?.find(A=>A.refType==="CHILD_OF")?.spanID;h&&u[h].span&&r.push({[y.z.id]:h+"--"+i.spanID,[y.z.target]:i.spanID,[y.z.source]:h})}return{nodes:e,edges:r}}function Ee(s){let e=0,r=1/0;for(const o of s)o.startTime<r&&(r=o.startTime),o.startTime+o.duration>e&&(e=o.startTime+o.duration);return e-r}var Q=a(96606);class Te extends E.MF{constructor(e,r=(0,ge.$t)(),o=(0,S.J)()){super(e),this.instanceSettings=e,this.timeSrv=r,this.templateSrv=o,this.uploadedJson=null,this.nodeGraph=e.jsonData.nodeGraph}async metadataRequest(e,r){return(await(0,X.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,b.of)({data:[q]});if(r.queryType==="search"&&!this.isSearchFormValid(r))return(0,b.of)({error:{message:"You must select a service."},data:[]});if(r.queryType!=="search"&&r.query)return this._request(`/api/traces/${encodeURIComponent(this.templateSrv.replace(r.query,e.scopedVars))}`).pipe((0,K.U)(i=>{const d=i?.data?.data?.[0];if(!d)return{data:[q]};let f=[(0,Q.xM)(d)];return this.nodeGraph?.enabled&&f.push(...w(d)),{data:f}}));if(r.queryType==="upload"){if(!this.uploadedJson)return(0,b.of)({data:[]});try{const i=JSON.parse(this.uploadedJson).data[0];let d=[(0,Q.xM)(i)];return this.nodeGraph?.enabled&&d.push(...w(i)),(0,b.of)({data:d})}catch{return(0,b.of)({error:{message:"The JSON file uploaded is not in a valid Jaeger format"},data:[]})}}let o=(0,$.pick)(this.applyVariables(r,e.scopedVars),["service","operation","tags","minDuration","maxDuration","limit"]),u=(0,$.pickBy)(o,$.identity);return u.operation===Y&&(u=(0,$.omit)(u,"operation")),u.tags&&(u={...u,tags:se(u.tags.toString())}),this._request("/api/traces",{...u,...this.getTimeRange(),lookback:"custom"}).pipe((0,K.U)(i=>({data:[(0,Q.Wp)(i.data.data,this.instanceSettings)]})))}interpolateVariablesInQueries(e,r){return!e||e.length===0?[]:e.map(o=>({...o,datasource:this.getRef(),...this.applyVariables(o,r)}))}applyVariables(e,r){let o={...e};return e.tags&&this.templateSrv.containsTemplate(e.tags)&&(o={...e,tags:this.templateSrv.replace(e.tags,r)}),{...o,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,X.n)(this._request("/api/services").pipe((0,K.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,ue.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,b.of)({status:"error",message:r})})))}getTimeRange(){const e=this.timeSrv.timeRange();return{start:k(e.from,!1),end:k(e.to,!0)}}getQueryDisplayText(e){return e.query||""}_request(e,r,o){const u=r?(0,ve.tW)(r):"",i=`${this.instanceSettings.url}${e}${u.length?`?${u}`:""}`,d={...o,url:i};return(0,he.i)().fetch(d)}}function k(s,e){return typeof s=="string"&&(s=me.parse(s,e)),s.valueOf()*1e3}const q=new de.v({fields:[{name:"trace",type:fe.fS.trace,values:[]}],meta:{preferredVisualisationType:"trace",custom:{traceFormat:"jaeger"}}}),De=new E.hf(Te).setConfigEditor(C).setQueryEditor(ie).setQueryEditorHelp(j)}}]);

//# sourceMappingURL=jaegerPlugin.b9b7f16c3ba1f23292ca.js.map