"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4156],{"./public/app/core/components/NodeGraphSettings.tsx":(e,a,t)=>{t.d(a,{n:()=>l});t("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/index.js");var s,n=t("./.yarn/__virtual__/@emotion-css-virtual-72c314ddb1/3/opt/drone/yarncache/@emotion-css-npm-11.7.1-25ff8755a7-ac1f56656f.zip/node_modules/@emotion/css/dist/emotion-css.esm.js"),r=t("./packages/grafana-data/src/index.ts"),i=t("./packages/grafana-ui/src/index.ts"),o=t("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/jsx-runtime.js");function l(e){var a;let{options:t,onOptionsChange:n}=e;const l=(0,i.useStyles)(c);return(0,o.jsxs)("div",{className:l.container,children:[s||(s=(0,o.jsx)("h3",{className:"page-heading",children:"Node Graph"})),(0,o.jsx)(i.InlineFieldRow,{className:l.row,children:(0,o.jsx)(i.InlineField,{tooltip:"Enables the Node Graph visualization in the trace viewer.",label:"Enable Node Graph",labelWidth:26,children:(0,o.jsx)(i.InlineSwitch,{id:"enableNodeGraph",value:null===(a=t.jsonData.nodeGraph)||void 0===a?void 0:a.enabled,onChange:e=>(0,r.updateDatasourcePluginJsonDataOption)({onOptionsChange:n,options:t},"nodeGraph",Object.assign({},t.jsonData.nodeGraph,{enabled:e.currentTarget.checked}))})})})]})}const c=e=>({container:n.css`
    label: container;
    width: 100%;
  `,row:n.css`
    label: row;
    align-items: baseline;
  `})},"./public/app/core/components/TraceToLogs/TraceToLogsSettings.tsx":(e,a,t)=>{t.d(a,{Z:()=>g});var s,n,r,i=t("./.yarn/__virtual__/@emotion-css-virtual-72c314ddb1/3/opt/drone/yarncache/@emotion-css-npm-11.7.1-25ff8755a7-ac1f56656f.zip/node_modules/@emotion/css/dist/emotion-css.esm.js"),o=t("./packages/grafana-data/src/index.ts"),l=t("./packages/grafana-runtime/src/index.ts"),c=t("./packages/grafana-ui/src/index.ts"),d=(t("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/index.js"),t("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/jsx-runtime.js"));const u=e=>{let{values:a,onChange:t,id:i,keyPlaceholder:o="Key",valuePlaceholder:l="Value (optional)"}=e;const u=(0,c.useStyles)(p);return(0,d.jsx)("div",{className:u.wrapper,children:a.length?a.map(((e,r)=>(0,d.jsxs)("div",{className:u.pair,children:[(0,d.jsx)(c.SegmentInput,{id:`${i}-key-${r}`,placeholder:o,value:e.key,onChange:e=>{t(a.map(((a,t)=>(t===r&&(a.key=String(e)),a))))}}),(0,d.jsx)(c.InlineLabel,{"aria-label":"equals",className:u.operator,width:3,children:"="}),(0,d.jsx)(c.SegmentInput,{id:`${i}-value-${r}`,placeholder:l,value:e.value,onChange:e=>{t(a.map(((a,t)=>(t===r&&(a.value=String(e)),a))))}}),(0,d.jsx)("button",{onClick:()=>t([...a.slice(0,r),...a.slice(r+1)]),className:"gf-form-label query-part","aria-label":"Remove tag",children:s||(s=(0,d.jsx)(c.Icon,{name:"times"}))}),r===a.length-1?(0,d.jsx)("button",{onClick:()=>t([...a,{key:"",value:""}]),className:"gf-form-label query-part","aria-label":"Add tag",children:n||(n=(0,d.jsx)(c.Icon,{name:"plus"}))}):null]},r))):(0,d.jsx)("button",{onClick:()=>t([...a,{key:"",value:""}]),className:"gf-form-label query-part","aria-label":"Add tag",children:r||(r=(0,d.jsx)(c.Icon,{name:"plus"}))})})},p=e=>({wrapper:i.css`
    display: flex;
    flex-direction: column;
    gap: ${e.spacing.xs} 0;
  `,pair:i.css`
    display: flex;
    justify-content: start;
    align-items: center;
  `,operator:i.css`
    color: ${e.palette.orange};
  `});var h;function g(e){var a,t,s,n,r,p,g,v,b,y,j,f,x,T,D;let{options:w,onOptionsChange:S}=e;const I=(0,c.useStyles)(m);return(0,d.jsxs)("div",{className:(0,i.css)({width:"100%"}),children:[h||(h=(0,d.jsx)("h3",{className:"page-heading",children:"Trace to logs"})),(0,d.jsx)("div",{className:I.infoText,children:"Trace to logs lets you navigate from a trace span to the selected data source's log."}),(0,d.jsx)(c.InlineFieldRow,{children:(0,d.jsx)(c.InlineField,{tooltip:"The data source the trace is going to navigate to",label:"Data source",labelWidth:26,children:(0,d.jsx)(l.DataSourcePicker,{inputId:"trace-to-logs-data-source-picker",pluginId:"loki",current:null===(a=w.jsonData.tracesToLogs)||void 0===a?void 0:a.datasourceUid,noDefault:!0,width:40,onChange:e=>{var a;return(0,o.updateDatasourcePluginJsonDataOption)({onOptionsChange:S,options:w},"tracesToLogs",{datasourceUid:e.uid,tags:null===(a=w.jsonData.tracesToLogs)||void 0===a?void 0:a.tags})}})})}),null!==(t=w.jsonData.tracesToLogs)&&void 0!==t&&t.mapTagNamesEnabled?(0,d.jsx)(c.InlineFieldRow,{children:(0,d.jsx)(c.InlineField,{tooltip:"Tags that will be used in the Loki query. Default tags: 'cluster', 'hostname', 'namespace', 'pod'",label:"Tags",labelWidth:26,children:(0,d.jsx)(u,{keyPlaceholder:"Tag",values:null!==(s=null!==(n=null===(r=w.jsonData.tracesToLogs)||void 0===r?void 0:r.mappedTags)&&void 0!==n?n:null===(p=w.jsonData.tracesToLogs)||void 0===p||null===(g=p.tags)||void 0===g?void 0:g.map((e=>({key:e}))))&&void 0!==s?s:[],onChange:e=>(0,o.updateDatasourcePluginJsonDataOption)({onOptionsChange:S,options:w},"tracesToLogs",Object.assign({},w.jsonData.tracesToLogs,{mappedTags:e}))})})}):(0,d.jsx)(c.InlineFieldRow,{children:(0,d.jsx)(c.InlineField,{tooltip:"Tags that will be used in the Loki query. Default tags: 'cluster', 'hostname', 'namespace', 'pod'",label:"Tags",labelWidth:26,children:(0,d.jsx)(c.TagsInput,{tags:null===(v=w.jsonData.tracesToLogs)||void 0===v?void 0:v.tags,width:40,onChange:e=>(0,o.updateDatasourcePluginJsonDataOption)({onOptionsChange:S,options:w},"tracesToLogs",Object.assign({},w.jsonData.tracesToLogs,{tags:e}))})})}),(0,d.jsx)(c.InlineFieldRow,{children:(0,d.jsx)(c.InlineField,{label:"Map tag names",labelWidth:26,grow:!0,tooltip:"Map trace tag names to log label names. Ex: k8s.pod.name -> pod",children:(0,d.jsx)(c.InlineSwitch,{id:"mapTagNames",value:null!==(b=null===(y=w.jsonData.tracesToLogs)||void 0===y?void 0:y.mapTagNamesEnabled)&&void 0!==b&&b,onChange:e=>(0,o.updateDatasourcePluginJsonDataOption)({onOptionsChange:S,options:w},"tracesToLogs",Object.assign({},w.jsonData.tracesToLogs,{mapTagNamesEnabled:e.currentTarget.checked}))})})}),(0,d.jsx)(c.InlineFieldRow,{children:(0,d.jsx)(c.InlineField,{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)",children:(0,d.jsx)(c.Input,{type:"text",placeholder:"1h",width:40,onChange:e=>(0,o.updateDatasourcePluginJsonDataOption)({onOptionsChange:S,options:w},"tracesToLogs",Object.assign({},w.jsonData.tracesToLogs,{spanStartTimeShift:e.currentTarget.value})),value:(null===(j=w.jsonData.tracesToLogs)||void 0===j?void 0:j.spanStartTimeShift)||""})})}),(0,d.jsx)(c.InlineFieldRow,{children:(0,d.jsx)(c.InlineField,{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",children:(0,d.jsx)(c.Input,{type:"text",placeholder:"1h",width:40,onChange:e=>(0,o.updateDatasourcePluginJsonDataOption)({onOptionsChange:S,options:w},"tracesToLogs",Object.assign({},w.jsonData.tracesToLogs,{spanEndTimeShift:e.currentTarget.value})),value:(null===(f=w.jsonData.tracesToLogs)||void 0===f?void 0:f.spanEndTimeShift)||""})})}),(0,d.jsx)(c.InlineFieldRow,{children:(0,d.jsx)(c.InlineField,{label:"Filter by Trace ID",labelWidth:26,grow:!0,tooltip:"Filters logs by Trace ID. Appends '|=<trace id>' to the query.",children:(0,d.jsx)(c.InlineSwitch,{id:"filterByTraceID",value:null===(x=w.jsonData.tracesToLogs)||void 0===x?void 0:x.filterByTraceID,onChange:e=>(0,o.updateDatasourcePluginJsonDataOption)({onOptionsChange:S,options:w},"tracesToLogs",Object.assign({},w.jsonData.tracesToLogs,{filterByTraceID:e.currentTarget.checked}))})})}),(0,d.jsx)(c.InlineFieldRow,{children:(0,d.jsx)(c.InlineField,{label:"Filter by Span ID",labelWidth:26,grow:!0,tooltip:"Filters logs by Span ID. Appends '|=<span id>' to the query.",children:(0,d.jsx)(c.InlineSwitch,{id:"filterBySpanID",value:null===(T=w.jsonData.tracesToLogs)||void 0===T?void 0:T.filterBySpanID,onChange:e=>(0,o.updateDatasourcePluginJsonDataOption)({onOptionsChange:S,options:w},"tracesToLogs",Object.assign({},w.jsonData.tracesToLogs,{filterBySpanID:e.currentTarget.checked}))})})}),(0,d.jsx)(c.InlineFieldRow,{children:(0,d.jsx)(c.InlineField,{label:"Loki Search",labelWidth:26,grow:!0,tooltip:"Use this logs data source to search for traces.",children:(0,d.jsx)(c.InlineSwitch,{id:"lokiSearch",defaultChecked:!0,value:null===(D=w.jsonData.tracesToLogs)||void 0===D?void 0:D.lokiSearch,onChange:e=>(0,o.updateDatasourcePluginJsonDataOption)({onOptionsChange:S,options:w},"tracesToLogs",Object.assign({},w.jsonData.tracesToLogs,{lokiSearch:e.currentTarget.checked}))})})})]})}const m=e=>({infoText:i.css`
    padding-bottom: ${e.spacing.md};
    color: ${e.colors.textSemiWeak};
  `})},"./public/app/core/utils/tracing.ts":(e,a,t)=>{t.d(a,{et:()=>n,nO:()=>r,fy:()=>i,np:()=>l});var s=t("./packages/grafana-data/src/index.ts");function n(e){e.sort(((e,a)=>e[0]-a[0]));return e.reduce(((e,a)=>{if(!e.length)return[a];const t=e.slice(-1)[0],[s,n]=t,[r,i]=a;return i<n?e:r>n?[...e,a]:[...e.slice(0,-1),[s,i]]}),[]).reduce(((e,a)=>e+(a[1]-a[0])),0)}function r(e){const a={};let t;for(let s=0;t=e(s),t;s++){a[t.id]?a[t.id].span=t.span:a[t.id]={span:t.span,children:[]};for(const e of t.parentIds)e&&(a[e]?a[e].children.push(t.id):a[e]={span:void 0,children:[t.id]})}return a}function i(e,a,t){return{main:`${o(e)}ms (${o(e/a*100)}%)`,secondary:`${o(t)}ms (${o(t/e*100)}%)`}}function o(e){return parseFloat(e.toFixed(2))}function l(){return[new s.MutableDataFrame({fields:[{name:s.NodeGraphDataFrameFieldNames.id,type:s.FieldType.string},{name:s.NodeGraphDataFrameFieldNames.title,type:s.FieldType.string},{name:s.NodeGraphDataFrameFieldNames.subTitle,type:s.FieldType.string},{name:s.NodeGraphDataFrameFieldNames.mainStat,type:s.FieldType.string,config:{displayName:"Total time (% of trace)"}},{name:s.NodeGraphDataFrameFieldNames.secondaryStat,type:s.FieldType.string,config:{displayName:"Self time (% of total)"}},{name:s.NodeGraphDataFrameFieldNames.color,type:s.FieldType.number,config:{color:{mode:"continuous-GrYlRd"},displayName:"Self time / Trace duration"}}],meta:{preferredVisualisationType:"nodeGraph"}}),new s.MutableDataFrame({fields:[{name:s.NodeGraphDataFrameFieldNames.id,type:s.FieldType.string},{name:s.NodeGraphDataFrameFieldNames.target,type:s.FieldType.string},{name:s.NodeGraphDataFrameFieldNames.source,type:s.FieldType.string}],meta:{preferredVisualisationType:"nodeGraph"}})]}},"./public/app/plugins/datasource/tempo/module.ts":(e,a,t)=>{t.r(a),t.d(a,{plugin:()=>le});var s,n=t("./packages/grafana-data/src/index.ts"),r=t("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/index.js"),i=t("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/jsx-runtime.js");var o,l=t("./packages/grafana-ui/src/index.ts"),c=t("./public/app/core/components/TraceToLogs/TraceToLogsSettings.tsx"),d=t("./.yarn/__virtual__/@emotion-css-virtual-72c314ddb1/3/opt/drone/yarncache/@emotion-css-npm-11.7.1-25ff8755a7-ac1f56656f.zip/node_modules/@emotion/css/dist/emotion-css.esm.js"),u=t("./packages/grafana-runtime/src/index.ts");function p(e){var a;let{options:t,onOptionsChange:s}=e;const r=(0,l.useStyles)(h);return(0,i.jsxs)("div",{className:(0,d.css)({width:"100%"}),children:[o||(o=(0,i.jsx)("h3",{className:"page-heading",children:"Service Graph"})),(0,i.jsx)("div",{className:r.infoText,children:"To allow querying service graph data you have to select a Prometheus instance where the data is stored."}),(0,i.jsxs)(l.InlineFieldRow,{className:r.row,children:[(0,i.jsx)(l.InlineField,{tooltip:"The Prometheus data source with the service graph data",label:"Data source",labelWidth:26,children:(0,i.jsx)(u.DataSourcePicker,{inputId:"service-graph-data-source-picker",pluginId:"prometheus",current:null===(a=t.jsonData.serviceMap)||void 0===a?void 0:a.datasourceUid,noDefault:!0,width:40,onChange:e=>(0,n.updateDatasourcePluginJsonDataOption)({onOptionsChange:s,options:t},"serviceMap",{datasourceUid:e.uid})})}),(0,i.jsx)(l.Button,{type:"button",variant:"secondary",size:"sm",fill:"text",onClick:()=>{(0,n.updateDatasourcePluginJsonDataOption)({onOptionsChange:s,options:t},"serviceMap",{datasourceUid:void 0})},children:"Clear"})]})]})}const h=e=>({infoText:d.css`
    label: infoText;
    padding-bottom: ${e.spacing.md};
    color: ${e.colors.textSemiWeak};
  `,row:d.css`
    label: row;
    align-items: baseline;
  `});var g;function m(e){var a;let{options:t,onOptionsChange:s}=e;const r=(0,l.useStyles)(v);return(0,i.jsxs)("div",{className:r.container,children:[g||(g=(0,i.jsx)("h3",{className:"page-heading",children:"Search"})),(0,i.jsx)(l.InlineFieldRow,{className:r.row,children:(0,i.jsx)(l.InlineField,{tooltip:"Removes the Search tab from the Tempo query editor.",label:"Hide search",labelWidth:26,children:(0,i.jsx)(l.InlineSwitch,{id:"hideSearch",value:null===(a=t.jsonData.search)||void 0===a?void 0:a.hide,onChange:e=>(0,n.updateDatasourcePluginJsonDataOption)({onOptionsChange:s,options:t},"search",Object.assign({},t.jsonData.search,{hide:e.currentTarget.checked}))})})})]})}const v=e=>({container:d.css`
    label: container;
    width: 100%;
  `,row:d.css`
    label: row;
    align-items: baseline;
  `});var b=t("./public/app/core/components/NodeGraphSettings.tsx");var y=t("../../opt/drone/yarncache/rxjs-npm-7.5.1-ce59cbb6a3-78e3eecb16.zip/node_modules/rxjs/dist/esm5/internal/observable/of.js"),j=t("../../opt/drone/yarncache/rxjs-npm-7.5.1-ce59cbb6a3-78e3eecb16.zip/node_modules/rxjs/dist/esm5/internal/observable/from.js"),f=t("../../opt/drone/yarncache/rxjs-npm-7.5.1-ce59cbb6a3-78e3eecb16.zip/node_modules/rxjs/dist/esm5/internal/observable/throwError.js"),x=t("../../opt/drone/yarncache/rxjs-npm-7.5.1-ce59cbb6a3-78e3eecb16.zip/node_modules/rxjs/dist/esm5/internal/observable/merge.js"),T=t("../../opt/drone/yarncache/rxjs-npm-7.5.1-ce59cbb6a3-78e3eecb16.zip/node_modules/rxjs/dist/esm5/internal/observable/empty.js"),D=t("../../opt/drone/yarncache/rxjs-npm-7.5.1-ce59cbb6a3-78e3eecb16.zip/node_modules/rxjs/dist/esm5/internal/operators/mergeMap.js"),w=t("../../opt/drone/yarncache/rxjs-npm-7.5.1-ce59cbb6a3-78e3eecb16.zip/node_modules/rxjs/dist/esm5/internal/operators/map.js"),S=t("../../opt/drone/yarncache/rxjs-npm-7.5.1-ce59cbb6a3-78e3eecb16.zip/node_modules/rxjs/dist/esm5/internal/operators/catchError.js"),I=t("../../opt/drone/yarncache/rxjs-npm-7.5.1-ce59cbb6a3-78e3eecb16.zip/node_modules/rxjs/dist/esm5/internal/operators/toArray.js"),k=t("./public/app/core/utils/fetch.ts"),O=t("./public/app/features/plugins/datasource_srv.ts"),F=t("../../opt/drone/yarncache/lodash-npm-4.17.21-6382451519-eb835a2e51.zip/node_modules/lodash/lodash.js"),N=t("./public/app/plugins/datasource/tempo/graphTransform.ts"),C=t("./public/app/plugins/datasource/tempo/resultTransformer.ts");function _(e,a,t){return a in e?Object.defineProperty(e,a,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[a]=t,e}class L extends u.DataSourceWithBackend{constructor(e){super(e),_(this,"tracesToLogs",void 0),_(this,"serviceMap",void 0),_(this,"search",void 0),_(this,"nodeGraph",void 0),_(this,"uploadedJson",null),this.instanceSettings=e,this.tracesToLogs=e.jsonData.tracesToLogs,this.serviceMap=e.jsonData.serviceMap,this.search=e.jsonData.search,this.nodeGraph=e.jsonData.nodeGraph}query(e){var a,t,s,r,i,o,l;const c=[],d=e.targets.filter((e=>!e.hide)),p=(0,F.groupBy)(d,(e=>e.queryType||"traceId"));if(p.clear)return(0,y.of)({data:[],state:n.LoadingState.Done});if(null!==(a=this.tracesToLogs)&&void 0!==a&&a.datasourceUid&&(null===(t=p.search)||void 0===t?void 0:t.length)>0){const a=(0,O.ak)();c.push((0,j.D)(a.get(this.tracesToLogs.datasourceUid)).pipe((0,D.z)((a=>{var t;const s=Object.assign({},e,{targets:p.search.map((e=>e.linkedQuery))}),n=(null===(t=a.instanceSettings.jsonData.derivedFields)||void 0===t?void 0:t.filter((e=>e.datasourceUid===this.uid&&e.matcherRegex)).map((e=>e.matcherRegex)))||[];return n&&0!==n.length?a.query(s).pipe((0,w.U)((e=>e.error?e:(0,C.RY)(e,this.uid,this.name,n)))):(0,f._)((()=>new Error("No Loki datasource configured for search. Set up Derived Fields for traces in a Loki datasource settings and link it to this Tempo datasource.")))}))))}if(null!==(s=p.nativeSearch)&&void 0!==s&&s.length)try{const a=u.config.featureToggles.tempoBackendSearch?{startTime:e.range.from.unix(),endTime:e.range.to.unix()}:void 0,t=this.buildSearchQuery(p.nativeSearch[0],a);c.push(this._request("/api/search",t).pipe((0,w.U)((e=>({data:[(0,C.n4)(e.data.traces,this.instanceSettings)]}))),(0,S.K)((e=>(0,y.of)({error:{message:e.data.message},data:[]})))))}catch(e){return(0,y.of)({error:{message:e.message},data:[]})}if(null!==(r=p.upload)&&void 0!==r&&r.length)if(this.uploadedJson){const e=JSON.parse(this.uploadedJson);var h;if(e.batches)c.push((0,y.of)((0,C.IM)(e.batches,null===(h=this.nodeGraph)||void 0===h?void 0:h.enabled)));else c.push((0,y.of)({error:{message:"JSON is not valid OpenTelemetry format"},data:[]}))}else c.push((0,y.of)({data:[],state:n.LoadingState.Done}));var g,m;return null!==(i=this.serviceMap)&&void 0!==i&&i.datasourceUid&&(null===(o=p.serviceMap)||void 0===o?void 0:o.length)>0&&c.push((g=e,m=this.serviceMap.datasourceUid,function(e,a){return(0,j.D)((0,O.ak)().get(a)).pipe((0,D.z)((a=>a.query(e))))}(function(e){return Object.assign({},e,{targets:N.t3.map((a=>({refId:a,expr:`delta(${a}${e.targets[0].serviceMapQuery||""}[$__range])`,instant:!0})))})}(g),m).pipe((0,I.q)(),(0,w.U)((e=>{const a=e.find((e=>!!e.error));if(a)throw new Error(a.error.message);const{nodes:t,edges:s}=(0,N.BC)(e,g.range);return t.fields[0].config={links:[q("Request rate",`rate(${N.Yt}{server="\${__data.fields.id}"}[$__rate_interval])`,m),q("Request histogram",`histogram_quantile(0.9, sum(rate(${N.NZ}{server="\${__data.fields.id}"}[$__rate_interval])) by (le, client, server))`,m),q("Failed request rate",`rate(${N.yf}{server="\${__data.fields.id}"}[$__rate_interval])`,m)]},{data:[t,s],state:n.LoadingState.Done}}))))),(null===(l=p.traceId)||void 0===l?void 0:l.length)>0&&c.push(this.handleTraceIdQuery(e,p.traceId)),(0,x.T)(...c)}handleTraceIdQuery(e,a){const t=a.filter((e=>e.query));if(!t.length)return T.E;const s=Object.assign({},e,{targets:t});return super.query(s).pipe((0,w.U)((e=>{var a;return e.error?e:(0,C.Jk)(e,null===(a=this.nodeGraph)||void 0===a?void 0:a.enabled)})))}async metadataRequest(e){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return await this._request(e,a,{method:"GET",hideFromInspector:!0}).toPromise()}_request(e,a,t){const s=a?(0,k.tW)(a):"",n=`${this.instanceSettings.url}${e}${s.length?`?${s}`:""}`,r=Object.assign({},t,{url:n});return(0,u.getBackendSrv)().fetch(r)}async testDatasource(){const e={headers:{},method:"GET",url:`${this.instanceSettings.url}/api/echo`},a=await(0,u.getBackendSrv)().fetch(e).toPromise();if(null!=a&&a.ok)return{status:"success",message:"Data source is working"}}getQueryDisplayText(e){if("nativeSearch"===e.queryType){let a=[];for(const t of["serviceName","spanName","search","minDuration","maxDuration","limit"])e.hasOwnProperty(t)&&e[t]&&a.push(`${(0,F.startCase)(t)}: ${e[t]}`);return a.join(", ")}return e.query}buildSearchQuery(e,a){var t;let s=null!==(t=e.search)&&void 0!==t?t:"",r=(0,F.pick)(e,["minDuration","maxDuration","limit"]);if(r=(0,F.pickBy)(r,F.identity),e.serviceName&&(s+=` service.name="${e.serviceName}"`),e.spanName&&(s+=` name="${e.spanName}"`),r.limit||(r.limit=20),r.minDuration){if(!(0,n.isValidGoDuration)(r.minDuration))throw new Error("Please enter a valid min duration.");r.minDuration=r.minDuration.replace(/\s/g,"")}if(r.maxDuration){if(!(0,n.isValidGoDuration)(r.maxDuration))throw new Error("Please enter a valid max duration.");r.maxDuration=r.maxDuration.replace(/\s/g,"")}if(!Number.isInteger(r.limit)||r.limit<=0)throw new Error("Please enter a valid limit.");let i=Object.assign({tags:s},r);return a&&(i.start=a.startTime,i.end=a.endTime),i}async getServiceGraphLabels(){return(await(0,O.ak)().get(this.serviceMap.datasourceUid)).getTagKeys()}async getServiceGraphLabelValues(e){return(await(0,O.ak)().get(this.serviceMap.datasourceUid)).getTagValues({key:e})}}function q(e,a,t){return{url:"",title:e,internal:{query:{expr:a},datasourceUid:t,datasourceName:"Prometheus"}}}var R=t("./public/app/plugins/datasource/loki/components/LokiQueryField.tsx"),$=t("./.yarn/__virtual__/react-use-virtual-00326e70ba/3/opt/drone/yarncache/react-use-npm-17.3.2-a032cbeb01-7379460f51.zip/node_modules/react-use/lib/useAsync.js");var P=t("../../opt/drone/yarncache/prismjs-npm-1.26.0-15be1ab06b-6de058930c.zip/node_modules/prismjs/prism.js"),G=t.n(P);function M(e,a,t){return a in e?Object.defineProperty(e,a,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[a]=t,e}class Q extends n.LanguageProvider{constructor(e,a){var t;super(),t=this,M(this,"datasource",void 0),M(this,"tags",void 0),M(this,"request",(async function(e){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=await t.datasource.metadataRequest(e,a);return null==s?void 0:s.data})),M(this,"start",(async()=>(await this.fetchTags(),[]))),M(this,"provideCompletionItems",(async function(e){let{prefix:a,text:s,value:n,labelKey:r,wrapperClasses:i}=e;const o={suggestions:[]};if(!n)return o;const l=n.endText.getText(),c="="===l[l.indexOf(s)-1];return c||"="===s?t.getTagValueCompletionItems(n):t.getTagsCompletionItems()})),M(this,"getTagsCompletionItems",(()=>{const{tags:e}=this,a=[];return null!=e&&e.length&&a.push({label:"Tag",items:e.map((e=>({label:e})))}),{suggestions:a}})),this.datasource=e,Object.assign(this,a)}async fetchTags(){const e=await this.request("/api/search/tags",[]);this.tags=e.tagNames}async getTagValueCompletionItems(e){var a;const t=e.endText.getText().split(" ");let s=null!==(a=t[t.length-1])&&void 0!==a?a:"";s=s.split("=")[0];const n=await this.request(`/api/search/tag/${s}/values`,[]),r=[];return n&&n.tagValues&&r.push({label:"Tag Values",items:n.tagValues.map((e=>({label:e})))}),{suggestions:r}}async getOptions(e){const a=await this.request(`/api/search/tag/${e}/values`);let t=[];return a&&a.tagValues&&(t=a.tagValues.map((e=>({value:e,label:e})))),t}}var U=t("./public/app/store/store.ts"),B=t("./public/app/core/actions/index.ts"),E=t("./public/app/core/copy/appNotification.ts");const W="tempo",z="e.g. 1.2s, 100ms",J=[(0,l.BracesPlugin)(),(0,l.SlatePrism)({onlyIn:e=>"block"===e.object&&"code_block"===e.type,getSyntax:()=>W})];G().languages.tempo={key:{pattern:/[^\s]+(?==)/,alias:"attr-name"},operator:/[=]/,value:[{pattern:/"(.+)"/},{pattern:/[^\s]+/}]};const V=e=>{let{datasource:a,query:t,onChange:s,onBlur:o,onRunQuery:c}=e;const d=(0,l.useStyles2)(K),u=(0,r.useMemo)((()=>new Q(a)),[a]),[p,h]=(0,r.useState)(!1),[g,m]=(0,r.useState)({value:""}),[v,b]=(0,r.useState)({value:""}),[y,j]=(0,r.useState)(null),[f,x]=(0,r.useState)({}),[T,D]=(0,r.useState)({serviceName:!1,spanName:!1});async function w(e,a){try{const t=await a.getOptions("serviceName"===e?"service.name":"name");return D((a=>Object.assign({},a,{[e]:!1}))),t}catch(a){return 404===(null==a?void 0:a.status)?D((a=>Object.assign({},a,{[e]:!1}))):((0,U.WI)((0,B.$l)((0,E.t_)("Error",a))),D((a=>Object.assign({},a,{[e]:!1})))),j(a),[]}}const S=(0,r.useCallback)((e=>(D((a=>Object.assign({},a,{[e]:!0}))),w(e,u))),[u]),I=(0,r.useCallback)((e=>(0,F.debounce)((()=>S(e)),500,{leading:!0,trailing:!0})),[S]);(0,r.useEffect)((()=>{(async()=>{try{await u.start(),w("serviceName",u),w("spanName",u),h(!0)}catch(e){404===(null==e?void 0:e.status)?j(e):(0,U.WI)((0,B.$l)((0,E.t_)("Error",e))),h(!0)}})()}),[u,I]);const k=e=>{"Enter"===e.key&&(e.shiftKey||e.ctrlKey)&&c()};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("div",{className:d.container,children:[(0,i.jsx)(l.InlineFieldRow,{children:(0,i.jsx)(l.InlineField,{label:"Service Name",labelWidth:14,grow:!0,children:(0,i.jsx)(l.AsyncSelect,{inputId:"service",menuShouldPortal:!0,cacheOptions:!1,loadOptions:I("serviceName"),onOpenMenu:I("serviceName"),isLoading:T.serviceName,value:g.value,onChange:e=>{m({value:e}),s(Object.assign({},t,{serviceName:(null==e?void 0:e.value)||void 0}))},placeholder:"Select a service",isClearable:!0,defaultOptions:!0,onKeyDown:k,"aria-label":"select-service-name"})})}),(0,i.jsx)(l.InlineFieldRow,{children:(0,i.jsx)(l.InlineField,{label:"Span Name",labelWidth:14,grow:!0,children:(0,i.jsx)(l.AsyncSelect,{inputId:"spanName",menuShouldPortal:!0,cacheOptions:!1,loadOptions:I("spanName"),onOpenMenu:I("spanName"),isLoading:T.spanName,value:v.value,onChange:e=>{b({value:e}),s(Object.assign({},t,{spanName:(null==e?void 0:e.value)||void 0}))},placeholder:"Select a span",isClearable:!0,defaultOptions:!0,onKeyDown:k,"aria-label":"select-span-name"})})}),(0,i.jsx)(l.InlineFieldRow,{children:(0,i.jsx)(l.InlineField,{label:"Tags",labelWidth:14,grow:!0,tooltip:"Values should be in the logfmt format.",children:(0,i.jsx)(l.QueryField,{additionalPlugins:J,query:t.search,onTypeahead:async e=>await u.provideCompletionItems(e),onBlur:o,onChange:e=>{s(Object.assign({},t,{search:e}))},placeholder:"http.status_code=200 error=true",cleanText:e=>{const a=e.split(/\s+(?=([^"]*"[^"]*")*[^"]*$)/g);return a.length>1?a[a.length-1]:e},onRunQuery:c,syntaxLoaded:p,portalOrigin:"tempo"})})}),(0,i.jsx)(l.InlineFieldRow,{children:(0,i.jsx)(l.InlineField,{label:"Min Duration",invalid:!!f.minDuration,labelWidth:14,grow:!0,children:(0,i.jsx)(l.Input,{id:"minDuration",value:t.minDuration||"",placeholder:z,onBlur:()=>{t.minDuration&&!(0,n.isValidGoDuration)(t.minDuration)?x(Object.assign({},f,{minDuration:!0})):x(Object.assign({},f,{minDuration:!1}))},onChange:e=>s(Object.assign({},t,{minDuration:e.currentTarget.value})),onKeyDown:k})})}),(0,i.jsx)(l.InlineFieldRow,{children:(0,i.jsx)(l.InlineField,{label:"Max Duration",invalid:!!f.maxDuration,labelWidth:14,grow:!0,children:(0,i.jsx)(l.Input,{id:"maxDuration",value:t.maxDuration||"",placeholder:z,onBlur:()=>{t.maxDuration&&!(0,n.isValidGoDuration)(t.maxDuration)?x(Object.assign({},f,{maxDuration:!0})):x(Object.assign({},f,{maxDuration:!1}))},onChange:e=>s(Object.assign({},t,{maxDuration:e.currentTarget.value})),onKeyDown:k})})}),(0,i.jsx)(l.InlineFieldRow,{children:(0,i.jsx)(l.InlineField,{label:"Limit",invalid:!!f.limit,labelWidth:14,grow:!0,tooltip:"Maximum numbers of returned results",children:(0,i.jsx)(l.Input,{id:"limit",value:t.limit||"",type:"number",onChange:e=>{let a=e.currentTarget.value?parseInt(e.currentTarget.value,10):void 0;a&&(!Number.isInteger(a)||a<=0)?x(Object.assign({},f,{limit:!0})):x(Object.assign({},f,{limit:!1})),s(Object.assign({},t,{limit:e.currentTarget.value?parseInt(e.currentTarget.value,10):void 0}))},onKeyDown:k})})})]}),y?(0,i.jsxs)(l.Alert,{title:"Unable to connect to Tempo search",severity:"info",className:d.alert,children:["Please ensure that Tempo is configured with search enabled. If you would like to hide this tab, you can configure it in the ",(0,i.jsx)("a",{href:`/datasources/edit/${a.uid}`,children:"datasource settings"}),"."]}):null]})},K=e=>({container:d.css`
    max-width: 500px;
  `,alert:d.css`
    max-width: 75ch;
    margin-top: ${e.spacing(2)};
  `});async function A(e){if(!e)return;const a=(0,u.getDataSourceSrv)();try{return await a.get(e)}catch(e){return void console.error("Failed to load data source",e)}}var H,Z,Y,X,ee,ae=t("./public/app/features/variables/adhoc/picker/AdHocFilter.tsx");function te(e){let{graphDatasourceUid:a,query:t,onChange:s}=e;const n=(0,$.Z)((()=>A(a)),[a]);if(n.loading)return null;const r=n.value;if(!a)return H||(H=(0,i.jsx)("div",{className:"text-warning",children:"Please set up a service graph datasource in the datasource settings."}));if(a&&!r)return Z||(Z=(0,i.jsx)("div",{className:"text-warning",children:"Service graph datasource is configured but the data source no longer exists. Please configure existing data source to use the service graph functionality."}));const o=function(e){let a,t=[];const s=/([\w_]+)(=|!=|<|>|=~|!~)"(.*?)"/g;for(;null!==(a=s.exec(e));)t.push({key:a[1],operator:a[2],value:a[3],condition:""});return t}(t.serviceMapQuery||"");return(0,i.jsx)("div",{children:(0,i.jsx)(l.InlineFieldRow,{children:(0,i.jsx)(l.InlineField,{label:"Filter",labelWidth:14,grow:!0,children:(0,i.jsx)(ae.F,{datasource:{uid:a},filters:o,getTagKeysOptions:{series:["traces_service_graph_request_server_seconds_sum","traces_service_graph_request_total","traces_service_graph_request_failed_total"]},addFilter:e=>{s(Object.assign({},t,{serviceMapQuery:se([...o,e])}))},removeFilter:e=>{const a=[...o];a.splice(e,1),s(Object.assign({},t,{serviceMapQuery:se(a)}))},changeFilter:(e,a)=>{const n=[...o];n.splice(e,1,a),s(Object.assign({},t,{serviceMapQuery:se(n)}))}})})})})}function se(e){return`{${e.map((e=>`${e.key}${e.operator}"${e.value}"`)).join(",")}}`}function ne(e,a,t){return a in e?Object.defineProperty(e,a,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[a]=t,e}class re extends r.PureComponent{constructor(e){super(e),ne(this,"state",{linkedDatasourceUid:void 0,linkedDatasource:void 0,serviceMapDatasourceUid:void 0,serviceMapDatasource:void 0}),ne(this,"onChangeLinkedQuery",(e=>{const{query:a,onChange:t}=this.props;t(Object.assign({},a,{linkedQuery:Object.assign({},e,{refId:"linked"})}))})),ne(this,"onRunLinkedQuery",(()=>{this.props.onRunQuery()})),ne(this,"onClearResults",(()=>{const{onChange:e,query:a,onRunQuery:t}=this.props;e(Object.assign({},a,{queryType:"clear"})),t()}))}async componentDidMount(){var e;const{datasource:a}=this.props,t=(a.tracesToLogs||{}).datasourceUid,s=null===(e=a.serviceMap)||void 0===e?void 0:e.datasourceUid,[n,r]=await Promise.all([A(t),A(s)]);this.setState({linkedDatasourceUid:t,linkedDatasource:n,serviceMapDatasourceUid:s,serviceMapDatasource:r}),this.props.query.queryType||this.props.onChange(Object.assign({},this.props.query,{queryType:"traceId"}))}render(){var e,a;const{query:t,onChange:s,datasource:n}=this.props,r=n.tracesToLogs||{},o=r.datasourceUid,c=null===(e=n.serviceMap)||void 0===e?void 0:e.datasourceUid,p=[{value:"traceId",label:"TraceID"},{value:"upload",label:"JSON file"}];return u.config.featureToggles.tempoServiceGraph&&p.push({value:"serviceMap",label:"Service Graph"}),!u.config.featureToggles.tempoSearch||null!=n&&null!==(a=n.search)&&void 0!==a&&a.hide||p.unshift({value:"nativeSearch",label:"Search - Beta"}),o&&!1!==(null==r?void 0:r.lokiSearch)&&(u.config.featureToggles.tempoSearch?p.push({value:"search",label:"Loki Search"}):p.unshift({value:"search",label:"Search"})),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(l.InlineFieldRow,{children:(0,i.jsx)(l.InlineField,{label:"Query type",children:(0,i.jsx)(l.RadioButtonGroup,{options:p,value:t.queryType,onChange:e=>{this.onClearResults(),s(Object.assign({},t,{queryType:e}))},size:"md"})})}),"nativeSearch"===t.queryType&&(0,i.jsxs)("p",{style:{maxWidth:"65ch"},children:[Y||(Y=(0,i.jsx)(l.Badge,{icon:"rocket",text:"Beta",color:"blue"})),u.config.featureToggles.tempoBackendSearch?(0,i.jsx)(i.Fragment,{children:" Tempo search is currently in beta."}):(0,i.jsx)(i.Fragment,{children:" Tempo search is currently in beta and is designed to return recent traces only. It ignores the time range picker. We are actively working on full backend search. Look for improvements in the near future!"})]}),"search"===t.queryType&&(0,i.jsx)(ie,{linkedDatasourceUid:o,query:t,onRunQuery:this.onRunLinkedQuery,onChange:this.onChangeLinkedQuery}),"nativeSearch"===t.queryType&&(0,i.jsx)(V,{datasource:this.props.datasource,query:t,onChange:s,onBlur:this.props.onBlur,onRunQuery:this.props.onRunQuery}),"upload"===t.queryType&&(0,i.jsx)("div",{className:(0,d.css)({padding:this.props.theme.spacing(2)}),children:(0,i.jsx)(l.FileDropzone,{options:{multiple:!1},onLoad:e=>{this.props.datasource.uploadedJson=e,this.props.onRunQuery()}})}),"traceId"===t.queryType&&(0,i.jsx)(l.InlineFieldRow,{children:(0,i.jsx)(l.InlineField,{label:"Trace ID",labelWidth:14,grow:!0,children:(0,i.jsx)(l.QueryField,{query:t.query,onChange:e=>{s(Object.assign({},t,{query:e,queryType:"traceId",linkedQuery:void 0}))},onBlur:this.props.onBlur,onRunQuery:this.props.onRunQuery,placeholder:"Enter a Trace ID (run with Shift+Enter)",portalOrigin:"tempo"})})}),"serviceMap"===t.queryType&&(0,i.jsx)(te,{graphDatasourceUid:c,query:t,onChange:s})]})}}function ie(e){let{linkedDatasourceUid:a,onChange:t,onRunQuery:s,query:n}=e;const r=(0,$.Z)((()=>A(a)),[a]);if(r.loading)return null;const o=r.value;var c;return o?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(l.InlineLabel,{children:["Tempo uses ",o.name," to find traces."]}),(0,i.jsx)(R.n,{datasource:o,onChange:t,onRunQuery:s,query:null!==(c=n.linkedQuery)&&void 0!==c?c:{refId:"linked"},history:[]})]}):a?a&&!o?ee||(ee=(0,i.jsx)("div",{className:"text-warning",children:"Traces-to-logs datasource is configured but the data source no longer exists. Please configure existing data source to use the search."})):null:X||(X=(0,i.jsx)("div",{className:"text-warning",children:"Please set up a Traces-to-logs datasource in the datasource settings."}))}const oe=(0,l.withTheme2)(re),le=new n.DataSourcePlugin(L).setQueryEditor(oe).setConfigEditor((e=>{let{options:a,onOptionsChange:t}=e;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(l.DataSourceHttpSettings,{defaultUrl:"http://tempo",dataSourceConfig:a,showAccessOptions:!1,onChange:t}),(0,i.jsx)("div",{className:"gf-form-group",children:(0,i.jsx)(c.Z,{options:a,onOptionsChange:t})}),u.config.featureToggles.tempoServiceGraph&&(0,i.jsx)("div",{className:"gf-form-group",children:(0,i.jsx)(p,{options:a,onOptionsChange:t})}),u.config.featureToggles.tempoSearch&&(0,i.jsx)("div",{className:"gf-form-group",children:(0,i.jsx)(m,{options:a,onOptionsChange:t})}),(0,i.jsx)("div",{className:"gf-form-group",children:(0,i.jsx)(b.n,{options:a,onOptionsChange:t})})]})})).setQueryEditorHelp((function(){return s||(s=(0,i.jsxs)("div",{children:[(0,i.jsx)("h2",{id:"tempo-cheat-sheet",children:"Tempo Cheat Sheet"}),(0,i.jsx)("p",{children:"Tempo is a trace id lookup store. Enter a trace id in the above field and hit “Run Query” to retrieve your trace. Tempo is generally paired with other datasources such as Loki or Prometheus to find traces."}),(0,i.jsxs)("p",{children:["Here are some"," ",(0,i.jsx)("a",{href:"https://grafana.com/docs/tempo/latest/guides/instrumentation/",target:"blank",children:"instrumentation examples"})," ","to get you started with trace discovery through logs and metrics (exemplars)."]})]}))}))}}]);
//# sourceMappingURL=tempoPlugin.cd4ada1146b53ad3284f.js.map