tempoPlugin.e6ea62de584e378b96ee.js 27 KB

123456789101112131415161718192021222324252627282930
  1. "use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4156],{86396:(e,a,t)=>{t.r(a),t.d(a,{plugin:()=>ge});var r,i=t(43215),n=t(68404),s=t(45916);var o=t(36636),l=t(90662),c=t(90923),u=t(69783),d=t(11410),h=t(50539),p=t.n(h),g=t(36537),v=t(58257),m=t(56340);function y(e,a,t){return a in e?Object.defineProperty(e,a,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[a]=t,e}class f extends i.LanguageProvider{constructor(e,a){var t;super(),t=this,y(this,"datasource",void 0),y(this,"tags",void 0),y(this,"request",(async function(e){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=await t.datasource.metadataRequest(e,a);return null==r?void 0:r.data})),y(this,"start",(async()=>(await this.fetchTags(),[]))),y(this,"provideCompletionItems",(async function(e){let{prefix:a,text:r,value:i,labelKey:n,wrapperClasses:s}=e;const o={suggestions:[]};if(!i)return o;const l=i.endText.getText(),c="="===l[l.indexOf(r)-1];return c||"="===r?t.getTagValueCompletionItems(i):t.getTagsCompletionItems()})),y(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 r=null!==(a=t[t.length-1])&&void 0!==a?a:"";r=r.split("=")[0];const i=await this.request(`/api/search/tag/${r}/values`,[]),n=[];return i&&i.tagValues&&n.push({label:"Tag Values",items:i.tagValues.map((e=>({label:e})))}),{suggestions:n}}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}}const x="tempo",j="e.g. 1.2s, 100ms",b=[(0,u.BracesPlugin)(),(0,u.SlatePrism)({onlyIn:e=>"block"===e.object&&"code_block"===e.type,getSyntax:()=>x})];p().languages.tempo={key:{pattern:/[^\s]+(?==)/,alias:"attr-name"},operator:/[=]/,value:[{pattern:/"(.+)"/},{pattern:/[^\s]+/}]};const S=e=>{let{datasource:a,query:t,onChange:r,onBlur:o,onRunQuery:l}=e;const d=(0,u.useStyles2)(D),h=(0,n.useMemo)((()=>new f(a)),[a]),[p,y]=(0,n.useState)(!1),[x,S]=(0,n.useState)(),[T,w]=(0,n.useState)(),[k,_]=(0,n.useState)(null),[I,O]=(0,n.useState)({}),[N,q]=(0,n.useState)({serviceName:!1,spanName:!1}),C=(0,n.useCallback)((async function(e){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const t="serviceName"===e?"service.name":"name";q((a=>Object.assign({},a,{[e]:!0})));try{const r=await h.getOptions(t);return r.filter((e=>!!e.value&&(0,u.fuzzyMatch)(e.value,a).found))}catch(e){return 404===(null==e?void 0:e.status)?_(e):(0,m.WI)((0,g.$l)((0,v.t_)("Error",e))),[]}finally{q((a=>Object.assign({},a,{[e]:!1})))}}),[h]);(0,n.useEffect)((()=>{(async()=>{try{const[e,a]=await Promise.all([C("serviceName"),C("spanName")]);t.serviceName&&(0,c.getTemplateSrv)().containsTemplate(t.serviceName)&&e.push((0,i.toOption)(t.serviceName)),S(e),t.spanName&&(0,c.getTemplateSrv)().containsTemplate(t.spanName)&&a.push((0,i.toOption)(t.spanName)),w(a)}catch(e){404===(null==e?void 0:e.status)?_(e):(0,m.WI)((0,g.$l)((0,v.t_)("Error",e)))}})()}),[h,C,t.serviceName,t.spanName]),(0,n.useEffect)((()=>{(async()=>{try{await h.start(),y(!0)}catch(e){(0,m.WI)((0,g.$l)((0,v.t_)("Error",e)))}})()}),[h]);const Q=e=>{"Enter"===e.key&&(e.shiftKey||e.ctrlKey)&&l()},F=(0,c.getTemplateSrv)();return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:d.container,children:[(0,s.jsx)(u.InlineFieldRow,{children:(0,s.jsx)(u.InlineField,{label:"Service Name",labelWidth:14,grow:!0,children:(0,s.jsx)(u.Select,{inputId:"service",options:x,onOpenMenu:()=>{C("serviceName")},isLoading:N.serviceName,value:(null==x?void 0:x.find((e=>(null==e?void 0:e.value)===t.serviceName)))||void 0,onChange:e=>{r(Object.assign({},t,{serviceName:(null==e?void 0:e.value)||void 0}))},placeholder:"Select a service",isClearable:!0,onKeyDown:Q,"aria-label":"select-service-name",allowCustomValue:!0})})}),(0,s.jsx)(u.InlineFieldRow,{children:(0,s.jsx)(u.InlineField,{label:"Span Name",labelWidth:14,grow:!0,children:(0,s.jsx)(u.Select,{inputId:"spanName",options:T,onOpenMenu:()=>{C("spanName")},isLoading:N.spanName,value:(null==T?void 0:T.find((e=>(null==e?void 0:e.value)===t.spanName)))||void 0,onChange:e=>{r(Object.assign({},t,{spanName:(null==e?void 0:e.value)||void 0}))},placeholder:"Select a span",isClearable:!0,onKeyDown:Q,"aria-label":"select-span-name",allowCustomValue:!0})})}),(0,s.jsx)(u.InlineFieldRow,{children:(0,s.jsx)(u.InlineField,{label:"Tags",labelWidth:14,grow:!0,tooltip:"Values should be in the logfmt format.",children:(0,s.jsx)(u.QueryField,{additionalPlugins:b,query:t.search,onTypeahead:async e=>await h.provideCompletionItems(e),onBlur:o,onChange:e=>{r(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:l,syntaxLoaded:p,portalOrigin:"tempo"})})}),(0,s.jsx)(u.InlineFieldRow,{children:(0,s.jsx)(u.InlineField,{label:"Min Duration",invalid:!!I.minDuration,labelWidth:14,grow:!0,children:(0,s.jsx)(u.Input,{id:"minDuration",value:t.minDuration||"",placeholder:j,onBlur:()=>{var e;const a=F.replace(null!==(e=t.minDuration)&&void 0!==e?e:"");t.minDuration&&!(0,i.isValidGoDuration)(a)?O(Object.assign({},I,{minDuration:!0})):O(Object.assign({},I,{minDuration:!1}))},onChange:e=>r(Object.assign({},t,{minDuration:e.currentTarget.value})),onKeyDown:Q})})}),(0,s.jsx)(u.InlineFieldRow,{children:(0,s.jsx)(u.InlineField,{label:"Max Duration",invalid:!!I.maxDuration,labelWidth:14,grow:!0,children:(0,s.jsx)(u.Input,{id:"maxDuration",value:t.maxDuration||"",placeholder:j,onBlur:()=>{var e;const a=F.replace(null!==(e=t.maxDuration)&&void 0!==e?e:"");t.maxDuration&&!(0,i.isValidGoDuration)(a)?O(Object.assign({},I,{maxDuration:!0})):O(Object.assign({},I,{maxDuration:!1}))},onChange:e=>r(Object.assign({},t,{maxDuration:e.currentTarget.value})),onKeyDown:Q})})}),(0,s.jsx)(u.InlineFieldRow,{children:(0,s.jsx)(u.InlineField,{label:"Limit",invalid:!!I.limit,labelWidth:14,grow:!0,tooltip:"Maximum numbers of returned results",children:(0,s.jsx)(u.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)?O(Object.assign({},I,{limit:!0})):O(Object.assign({},I,{limit:!1})),r(Object.assign({},t,{limit:e.currentTarget.value?parseInt(e.currentTarget.value,10):void 0}))},onKeyDown:Q})})})]}),k?(0,s.jsxs)(u.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,s.jsx)("a",{href:`/datasources/edit/${a.uid}`,children:"datasource settings"}),"."]}):null]})},D=e=>({container:o.css`
  2. max-width: 500px;
  3. `,alert:o.css`
  4. max-width: 75ch;
  5. margin-top: ${e.spacing(2)};
  6. `});var T,w,k,_=t(34366);async function I(e){if(!e)return;const a=(0,c.getDataSourceSrv)();try{return await a.get(e)}catch(e){return void console.error("Failed to load data source",e)}}function O(e){let{graphDatasourceUid:a,query:t,onChange:r}=e;const i=(0,u.useStyles2)(q),o=(0,l.Z)((()=>I(a)),[a]),[c,d]=(0,n.useState)(void 0);if((0,n.useEffect)((()=>{!o.loading&&o.value&&async function(e){const a=await e.getTagKeys({series:["traces_service_graph_request_server_seconds_sum","traces_service_graph_request_total","traces_service_graph_request_failed_total"]});d(Boolean(a.length))}(o.value)}),[o]),o.loading)return null;const h=o.value;if(!a)return T||(T=(0,s.jsx)("div",{className:"text-warning",children:"Please set up a service graph datasource in the datasource settings."}));if(a&&!h)return w||(w=(0,s.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 p=function(e){let a,t=[];const r=/([\w_]+)(=|!=|<|>|=~|!~)"(.*?)"/g;for(;null!==(a=r.exec(e));)t.push({key:a[1],operator:a[2],value:a[3],condition:""});return t}(t.serviceMapQuery||"");return(0,s.jsxs)("div",{children:[(0,s.jsx)(u.InlineFieldRow,{children:(0,s.jsx)(u.InlineField,{label:"Filter",labelWidth:14,grow:!0,children:(0,s.jsx)(_.F,{datasource:{uid:a},filters:p,getTagKeysOptions:{series:["traces_service_graph_request_server_seconds_sum","traces_service_graph_request_total","traces_service_graph_request_failed_total"]},addFilter:e=>{r(Object.assign({},t,{serviceMapQuery:N([...p,e])}))},removeFilter:e=>{const a=[...p];a.splice(e,1),r(Object.assign({},t,{serviceMapQuery:N(a)}))},changeFilter:(e,a)=>{const i=[...p];i.splice(e,1,a),r(Object.assign({},t,{serviceMapQuery:N(i)}))}})})}),!1===c?(0,s.jsxs)(u.Alert,{title:"No service graph data found",severity:"info",className:i.alert,children:["Please ensure that service graph metrics are set up correctly according to the"," ",k||(k=(0,s.jsx)("a",{target:"_blank",rel:"noreferrer noopener",href:"https://grafana.com/docs/tempo/next/grafana-agent/service-graphs/",children:"Tempo documentation"})),"."]}):null]})}function N(e){return`{${e.map((e=>`${e.key}${e.operator}"${e.value}"`)).join(",")}}`}const q=e=>({alert:o.css`
  7. max-width: 75ch;
  8. margin-top: ${e.spacing(2)};
  9. `});var C,Q,F;function R(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 n.PureComponent{constructor(e){super(e),R(this,"onChangeLinkedQuery",(e=>{const{query:a,onChange:t}=this.props;t(Object.assign({},a,{linkedQuery:Object.assign({},e,{refId:"linked"})}))})),R(this,"onRunLinkedQuery",(()=>{this.props.onRunQuery()})),R(this,"onClearResults",(()=>{const{onChange:e,query:a,onRunQuery:t}=this.props;e(Object.assign({},a,{queryType:"clear"})),t()}))}async componentDidMount(){this.props.query.queryType||this.props.onChange(Object.assign({},this.props.query,{queryType:"traceId"}))}render(){var e,a;const{query:t,onChange:r,datasource:i,app:n}=this.props,l=i.getLokiSearchDS(),d=null===(e=i.serviceMap)||void 0===e?void 0:e.datasourceUid,h=[{value:"traceId",label:"TraceID"},{value:"upload",label:"JSON file"},{value:"serviceMap",label:"Service Graph"}];return!c.config.featureToggles.tempoSearch||null!=i&&null!==(a=i.search)&&void 0!==a&&a.hide||h.unshift({value:"nativeSearch",label:"Search - Beta"}),l&&(c.config.featureToggles.tempoSearch?h.push({value:"search",label:"Loki Search"}):h.unshift({value:"search",label:"Search"})),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(u.InlineFieldRow,{children:(0,s.jsx)(u.InlineField,{label:"Query type",children:(0,s.jsx)(u.RadioButtonGroup,{options:h,value:t.queryType,onChange:e=>{var a;(0,c.reportInteraction)("grafana_traces_query_type_changed",{datasourceType:"tempo",app:null!=n?n:"",newQueryType:e,previousQueryType:null!==(a=t.queryType)&&void 0!==a?a:""}),this.onClearResults(),r(Object.assign({},t,{queryType:e}))},size:"md"})})}),"nativeSearch"===t.queryType&&(0,s.jsxs)("div",{style:{maxWidth:"65ch"},children:[C||(C=(0,s.jsx)(u.Badge,{icon:"rocket",text:"Beta",color:"blue"})),c.config.featureToggles.tempoBackendSearch?(0,s.jsx)(s.Fragment,{children:" Tempo search is currently in beta."}):(0,s.jsx)(s.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,s.jsx)($,{logsDatasourceUid:l,query:t,onRunQuery:this.onRunLinkedQuery,onChange:this.onChangeLinkedQuery}),"nativeSearch"===t.queryType&&(0,s.jsx)(S,{datasource:this.props.datasource,query:t,onChange:r,onBlur:this.props.onBlur,onRunQuery:this.props.onRunQuery}),"upload"===t.queryType&&(0,s.jsx)("div",{className:(0,o.css)({padding:this.props.theme.spacing(2)}),children:(0,s.jsx)(u.FileDropzone,{options:{multiple:!1},onLoad:e=>{this.props.datasource.uploadedJson=e,this.props.onRunQuery()}})}),"traceId"===t.queryType&&(0,s.jsx)(u.InlineFieldRow,{children:(0,s.jsx)(u.InlineField,{label:"Trace ID",labelWidth:14,grow:!0,children:(0,s.jsx)(u.QueryField,{query:t.query,onChange:e=>{r(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,s.jsx)(O,{graphDatasourceUid:d,query:t,onChange:r})]})}}function $(e){let{logsDatasourceUid:a,onChange:t,onRunQuery:r,query:i}=e;const n=(0,l.Z)((()=>I(a)),[a]);if(n.loading)return null;const o=n.value;var c;return o?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(u.InlineLabel,{children:["Tempo uses ",o.name," to find traces."]}),(0,s.jsx)(d.n,{datasource:o,onChange:t,onRunQuery:r,query:null!==(c=i.linkedQuery)&&void 0!==c?c:{refId:"linked"},history:[]})]}):a?a&&!o?F||(F=(0,s.jsx)("div",{className:"text-warning",children:"Loki search datasource is configured but the data source no longer exists. Please configure existing data source to use the search."})):null:Q||(Q=(0,s.jsx)("div",{className:"text-warning",children:"Please set up a Loki search datasource in the datasource settings."}))}const P=(0,u.withTheme2)(L);var M,U=t(28239),B=t(76038),V=t(67211);function E(e){var a,t,r,n;let{options:l,onOptionsChange:d}=e;const h=(0,u.useStyles)(W),p=!1!==(null===(a=l.jsonData.tracesToLogs)||void 0===a?void 0:a.lokiSearch)?null===(t=l.jsonData.tracesToLogs)||void 0===t?void 0:t.datasourceUid:void 0;return p&&void 0===l.jsonData.lokiSearch&&(0,i.updateDatasourcePluginJsonDataOption)({onOptionsChange:d,options:l},"lokiSearch",{datasourceUid:p}),(0,s.jsxs)("div",{className:(0,o.css)({width:"100%"}),children:[M||(M=(0,s.jsx)("h3",{className:"page-heading",children:"Loki Search"})),(0,s.jsx)("div",{className:h.infoText,children:"Select a Loki datasource to search for traces. Derived fields must be configured in the Loki data source."}),(0,s.jsxs)(u.InlineFieldRow,{className:h.row,children:[(0,s.jsx)(u.InlineField,{tooltip:"The Loki data source with the service graph data",label:"Data source",labelWidth:26,children:(0,s.jsx)(c.DataSourcePicker,{inputId:"loki-search-data-source-picker",pluginId:"loki",current:null===(r=l.jsonData.lokiSearch)||void 0===r?void 0:r.datasourceUid,noDefault:!0,width:40,onChange:e=>(0,i.updateDatasourcePluginJsonDataOption)({onOptionsChange:d,options:l},"lokiSearch",{datasourceUid:e.uid})})}),null!==(n=l.jsonData.lokiSearch)&&void 0!==n&&n.datasourceUid?(0,s.jsx)(u.Button,{type:"button",variant:"secondary",size:"sm",fill:"text",onClick:()=>{(0,i.updateDatasourcePluginJsonDataOption)({onOptionsChange:d,options:l},"lokiSearch",{datasourceUid:void 0})},children:"Clear"}):null]})]})}const W=e=>({infoText:o.css`
  10. label: infoText;
  11. padding-bottom: ${e.spacing.md};
  12. color: ${e.colors.textSemiWeak};
  13. `,row:o.css`
  14. label: row;
  15. align-items: baseline;
  16. `});var G;function J(e){var a;let{options:t,onOptionsChange:r}=e;const n=(0,u.useStyles)(K);return(0,s.jsxs)("div",{className:n.container,children:[G||(G=(0,s.jsx)("h3",{className:"page-heading",children:"Search"})),(0,s.jsx)(u.InlineFieldRow,{className:n.row,children:(0,s.jsx)(u.InlineField,{tooltip:"Removes the Search tab from the Tempo query editor.",label:"Hide search",labelWidth:26,children:(0,s.jsx)(u.InlineSwitch,{id:"hideSearch",value:null===(a=t.jsonData.search)||void 0===a?void 0:a.hide,onChange:e=>(0,i.updateDatasourcePluginJsonDataOption)({onOptionsChange:r,options:t},"search",Object.assign({},t.jsonData.search,{hide:e.currentTarget.checked}))})})})]})}const K=e=>({container:o.css`
  17. label: container;
  18. width: 100%;
  19. `,row:o.css`
  20. label: row;
  21. align-items: baseline;
  22. `});var z;function H(e){var a,t;let{options:r,onOptionsChange:n}=e;const l=(0,u.useStyles)(Z);return(0,s.jsxs)("div",{className:(0,o.css)({width:"100%"}),children:[z||(z=(0,s.jsx)("h3",{className:"page-heading",children:"Service Graph"})),(0,s.jsx)("div",{className:l.infoText,children:"To allow querying service graph data you have to select a Prometheus instance where the data is stored."}),(0,s.jsxs)(u.InlineFieldRow,{className:l.row,children:[(0,s.jsx)(u.InlineField,{tooltip:"The Prometheus data source with the service graph data",label:"Data source",labelWidth:26,children:(0,s.jsx)(c.DataSourcePicker,{inputId:"service-graph-data-source-picker",pluginId:"prometheus",current:null===(a=r.jsonData.serviceMap)||void 0===a?void 0:a.datasourceUid,noDefault:!0,width:40,onChange:e=>(0,i.updateDatasourcePluginJsonDataOption)({onOptionsChange:n,options:r},"serviceMap",{datasourceUid:e.uid})})}),null!==(t=r.jsonData.serviceMap)&&void 0!==t&&t.datasourceUid?(0,s.jsx)(u.Button,{type:"button",variant:"secondary",size:"sm",fill:"text",onClick:()=>{(0,i.updateDatasourcePluginJsonDataOption)({onOptionsChange:n,options:r},"serviceMap",{datasourceUid:void 0})},children:"Clear"}):null]})]})}const Z=e=>({infoText:o.css`
  23. label: infoText;
  24. padding-bottom: ${e.spacing.md};
  25. color: ${e.colors.textSemiWeak};
  26. `,row:o.css`
  27. label: row;
  28. align-items: baseline;
  29. `});var A=t(82897),Y=t(2937),X=t(80890),ee=t(26702),ae=t(73296),te=t(37413),re=t(44998),ie=t(10010),ne=t(76913),se=t(57892),oe=t(25857),le=t(67436),ce=t(59465),ue=t(94546);function de(e,a,t){return a in e?Object.defineProperty(e,a,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[a]=t,e}class he extends c.DataSourceWithBackend{constructor(e){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:(0,c.getTemplateSrv)();super(e),de(this,"tracesToLogs",void 0),de(this,"serviceMap",void 0),de(this,"search",void 0),de(this,"nodeGraph",void 0),de(this,"lokiSearch",void 0),de(this,"uploadedJson",null),de(this,"getLokiSearchDS",(()=>{var e,a,t,r;const i=!1!==(null===(e=this.tracesToLogs)||void 0===e?void 0:e.lokiSearch)&&void 0===this.lokiSearch?null===(a=this.tracesToLogs)||void 0===a?void 0:a.datasourceUid:void 0;return null!==(t=null===(r=this.lokiSearch)||void 0===r?void 0:r.datasourceUid)&&void 0!==t?t:i})),this.instanceSettings=e,this.templateSrv=a,this.tracesToLogs=e.jsonData.tracesToLogs,this.serviceMap=e.jsonData.serviceMap,this.search=e.jsonData.search,this.nodeGraph=e.jsonData.nodeGraph,this.lokiSearch=e.jsonData.lokiSearch}query(e){var a,t,r,n,s,o;const l=[],u=e.targets.filter((e=>!e.hide)),d=(0,A.groupBy)(u,(e=>e.queryType||"traceId"));if(d.clear)return(0,Y.of)({data:[],state:i.LoadingState.Done});const h=this.getLokiSearchDS();if(h&&(null===(a=d.search)||void 0===a?void 0:a.length)>0){var p,g,v;(0,c.reportInteraction)("grafana_traces_loki_search_queried",{datasourceType:"tempo",app:null!==(p=e.app)&&void 0!==p?p:"",linkedQueryExpr:null!==(g=null===(v=d.search[0].linkedQuery)||void 0===v?void 0:v.expr)&&void 0!==g?g:""});const a=(0,le.ak)();l.push((0,X.D)(a.get(h)).pipe((0,re.z)((a=>{var t;const r=Object.assign({},e,{targets:d.search.map((e=>e.linkedQuery))}),i=(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 i&&0!==i.length?a.query(r).pipe((0,ie.U)((e=>e.error?e:(0,ue.RY)(e,this.uid,this.name,i)))):(0,ee._)((()=>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!==(t=d.nativeSearch)&&void 0!==t&&t.length)try{var m,y,f,x,j;(0,c.reportInteraction)("grafana_traces_search_queried",{datasourceType:"tempo",app:null!==(m=e.app)&&void 0!==m?m:"",serviceName:null!==(y=d.nativeSearch[0].serviceName)&&void 0!==y?y:"",spanName:null!==(f=d.nativeSearch[0].spanName)&&void 0!==f?f:"",resultLimit:null!==(x=d.nativeSearch[0].limit)&&void 0!==x?x:"",search:null!==(j=d.nativeSearch[0].search)&&void 0!==j?j:""});const a=c.config.featureToggles.tempoBackendSearch?{startTime:e.range.from.unix(),endTime:e.range.to.unix()}:void 0,t=this.applyVariables(d.nativeSearch[0],e.scopedVars),r=this.buildSearchQuery(t,a);l.push(this._request("/api/search",r).pipe((0,ie.U)((e=>({data:[(0,ue.n4)(e.data.traces,this.instanceSettings)]}))),(0,ne.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=d.upload)&&void 0!==r&&r.length)if(this.uploadedJson){var b;(0,c.reportInteraction)("grafana_traces_json_file_uploaded",{datasourceType:"tempo",app:null!==(b=e.app)&&void 0!==b?b:""});const a=JSON.parse(this.uploadedJson);var S;if(a.batches)l.push((0,Y.of)((0,ue.IM)(a.batches,null===(S=this.nodeGraph)||void 0===S?void 0:S.enabled)));else l.push((0,Y.of)({error:{message:"JSON is not valid OpenTelemetry format"},data:[]}))}else l.push((0,Y.of)({data:[],state:i.LoadingState.Done}));var D,T,w,k,_,I;null!==(n=this.serviceMap)&&void 0!==n&&n.datasourceUid&&(null===(s=d.serviceMap)||void 0===s?void 0:s.length)>0&&((0,c.reportInteraction)("grafana_traces_service_graph_queried",{datasourceType:"tempo",app:null!==(D=e.app)&&void 0!==D?D:"",serviceMapQuery:null!==(T=d.serviceMap[0].serviceMapQuery)&&void 0!==T?T:""}),l.push((w=e,k=this.serviceMap.datasourceUid,function(e,a){return(0,X.D)((0,le.ak)().get(a)).pipe((0,re.z)((a=>a.query(e))))}(function(e){return Object.assign({},e,{targets:ce.t3.map((a=>({refId:a,expr:`delta(${a}${e.targets[0].serviceMapQuery||""}[$__range])`,instant:!0})))})}(w),k).pipe((0,se.q)(),(0,ie.U)((e=>{const a=e.find((e=>!!e.error));if(a)throw new Error(a.error.message);const{nodes:t,edges:r}=(0,ce.BC)(e,w.range);return t.fields[0].config={links:[pe("Request rate",`rate(${ce.Yt}{server="\${__data.fields.id}"}[$__rate_interval])`,k),pe("Request histogram",`histogram_quantile(0.9, sum(rate(${ce.NZ}{server="\${__data.fields.id}"}[$__rate_interval])) by (le, client, server))`,k),pe("Failed request rate",`rate(${ce.yf}{server="\${__data.fields.id}"}[$__rate_interval])`,k)]},{data:[t,r],state:i.LoadingState.Done}}))))));(null===(o=d.traceId)||void 0===o?void 0:o.length)>0&&((0,c.reportInteraction)("grafana_traces_traceID_queried",{datasourceType:"tempo",app:null!==(_=e.app)&&void 0!==_?_:"",query:null!==(I=d.traceId[0].query)&&void 0!==I?I:""}),l.push(this.handleTraceIdQuery(e,d.traceId)));return(0,ae.T)(...l)}applyTemplateVariables(e,a){return this.applyVariables(e,a)}interpolateVariablesInQueries(e,a){return e&&0!==e.length?e.map((e=>Object.assign({},e,{datasource:this.getRef()},this.applyVariables(e,a)))):[]}applyVariables(e,a){var t,r,i,n,s,o;const l=Object.assign({},e);var c,u;e.linkedQuery&&(l.linkedQuery=Object.assign({},e.linkedQuery,{expr:this.templateSrv.replace(null!==(c=null===(u=e.linkedQuery)||void 0===u?void 0:u.expr)&&void 0!==c?c:"",a)}));return Object.assign({},l,{query:this.templateSrv.replace(null!==(t=e.query)&&void 0!==t?t:"",a),serviceName:this.templateSrv.replace(null!==(r=e.serviceName)&&void 0!==r?r:"",a),spanName:this.templateSrv.replace(null!==(i=e.spanName)&&void 0!==i?i:"",a),search:this.templateSrv.replace(null!==(n=e.search)&&void 0!==n?n:"",a),minDuration:this.templateSrv.replace(null!==(s=e.minDuration)&&void 0!==s?s:"",a),maxDuration:this.templateSrv.replace(null!==(o=e.maxDuration)&&void 0!==o?o:"",a)})}handleTraceIdQuery(e,a){const t=a.filter((e=>e.query)).map((e=>Object.assign({},e,{query:e.query.trim()})));if(!t.length)return te.E;const r=Object.assign({},e,{targets:t});return super.query(r).pipe((0,ie.U)((e=>{var a;return e.error?e:(0,ue.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 r=a?(0,oe.tW)(a):"",i=`${this.instanceSettings.url}${e}${r.length?`?${r}`:""}`,n=Object.assign({},t,{url:i});return(0,c.getBackendSrv)().fetch(n)}async testDatasource(){const e={headers:{},method:"GET",url:`${this.instanceSettings.url}/api/echo`},a=await(0,c.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,A.startCase)(t)}: ${e[t]}`);return a.join(", ")}return e.query}buildSearchQuery(e,a){var t;let r=null!==(t=e.search)&&void 0!==t?t:"",n=(0,A.pick)(e,["minDuration","maxDuration","limit"]);if(n=(0,A.pickBy)(n,A.identity),e.serviceName&&(r+=` service.name="${e.serviceName}"`),e.spanName&&(r+=` name="${e.spanName}"`),n.limit||(n.limit=20),n.minDuration){var s;if(n.minDuration=this.templateSrv.replace(null!==(s=n.minDuration)&&void 0!==s?s:""),!(0,i.isValidGoDuration)(n.minDuration))throw new Error("Please enter a valid min duration.");n.minDuration=n.minDuration.replace(/\s/g,"")}if(n.maxDuration){var o;if(n.maxDuration=this.templateSrv.replace(null!==(o=n.maxDuration)&&void 0!==o?o:""),!(0,i.isValidGoDuration)(n.maxDuration))throw new Error("Please enter a valid max duration.");n.maxDuration=n.maxDuration.replace(/\s/g,"")}if(!Number.isInteger(n.limit)||n.limit<=0)throw new Error("Please enter a valid limit.");let l=Object.assign({tags:r},n);return a&&(l.start=a.startTime,l.end=a.endTime),l}async getServiceGraphLabels(){return(await(0,le.ak)().get(this.serviceMap.datasourceUid)).getTagKeys()}async getServiceGraphLabelValues(e){return(await(0,le.ak)().get(this.serviceMap.datasourceUid)).getTagValues({key:e})}}function pe(e,a,t){return{url:"",title:e,internal:{query:{expr:a},datasourceUid:t,datasourceName:"Prometheus"}}}const ge=new i.DataSourcePlugin(he).setQueryEditor(P).setConfigEditor((e=>{let{options:a,onOptionsChange:t}=e;return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(u.DataSourceHttpSettings,{defaultUrl:"http://tempo",dataSourceConfig:a,showAccessOptions:!1,onChange:t}),(0,s.jsx)("div",{className:"gf-form-group",children:(0,s.jsx)(B.Z,{options:a,onOptionsChange:t})}),c.config.featureToggles.traceToMetrics?(0,s.jsx)("div",{className:"gf-form-group",children:(0,s.jsx)(V.F,{options:a,onOptionsChange:t})}):null,(0,s.jsx)("div",{className:"gf-form-group",children:(0,s.jsx)(H,{options:a,onOptionsChange:t})}),c.config.featureToggles.tempoSearch&&(0,s.jsx)("div",{className:"gf-form-group",children:(0,s.jsx)(J,{options:a,onOptionsChange:t})}),(0,s.jsx)("div",{className:"gf-form-group",children:(0,s.jsx)(U.n,{options:a,onOptionsChange:t})}),(0,s.jsx)("div",{className:"gf-form-group",children:(0,s.jsx)(E,{options:a,onOptionsChange:t})})]})})).setQueryEditorHelp((function(){return r||(r=(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{id:"tempo-cheat-sheet",children:"Tempo Cheat Sheet"}),(0,s.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,s.jsxs)("p",{children:["Here are some"," ",(0,s.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)."]})]}))}))}}]);
  30. //# sourceMappingURL=tempoPlugin.e6ea62de584e378b96ee.js.map