"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4156],{"./public/app/core/components/NodeGraphSettings.tsx":(e,a,t)=>{t.d(a,{n:()=>l});t("./node_modules/react/index.js");var s,n=t("./node_modules/@emotion/css/dist/emotion-css.esm.js"),i=t("./packages/grafana-data/src/index.ts"),o=t("./packages/grafana-ui/src/index.ts"),r=t("./node_modules/react/jsx-runtime.js");function l({options:e,onOptionsChange:a}){var t;const n=(0,o.useStyles)(c);return(0,r.jsxs)("div",{className:n.container,children:[s||(s=(0,r.jsx)("h3",{className:"page-heading",children:"Node Graph"})),(0,r.jsx)(o.InlineFieldRow,{className:n.row,children:(0,r.jsx)(o.InlineField,{tooltip:"Enables the Node Graph visualization in the trace viewer.",label:"Enable Node Graph",labelWidth:26,children:(0,r.jsx)(o.InlineSwitch,{value:null===(t=e.jsonData.nodeGraph)||void 0===t?void 0:t.enabled,onChange:t=>(0,i.updateDatasourcePluginJsonDataOption)({onOptionsChange:a,options:e},"nodeGraph",Object.assign({},e.jsonData.nodeGraph,{enabled:t.currentTarget.checked}))})})})]})}const c=e=>({container:n.css`
    label: container;
    width: 100%;
  `,row:n.css`
    label: row;
    align-items: baseline;
  `})},"./public/app/core/components/TraceToLogsSettings.tsx":(e,a,t)=>{t.d(a,{Z:()=>c});var s,n=t("./node_modules/@emotion/css/dist/emotion-css.esm.js"),i=t("./packages/grafana-data/src/index.ts"),o=t("./packages/grafana-runtime/src/index.ts"),r=t("./packages/grafana-ui/src/index.ts"),l=(t("./node_modules/react/index.js"),t("./node_modules/react/jsx-runtime.js"));function c({options:e,onOptionsChange:a}){var t,c,d,p,h,g,m;const v=(0,r.useStyles)(u);return(0,l.jsxs)("div",{className:(0,n.css)({width:"100%"}),children:[s||(s=(0,l.jsx)("h3",{className:"page-heading",children:"Trace to logs"})),(0,l.jsx)("div",{className:v.infoText,children:"Trace to logs let's you navigate from a trace span to the selected data source's log."}),(0,l.jsx)(r.InlineFieldRow,{children:(0,l.jsx)(r.InlineField,{tooltip:"The data source the trace is going to navigate to",label:"Data source",labelWidth:26,children:(0,l.jsx)(o.DataSourcePicker,{pluginId:"loki",current:null===(t=e.jsonData.tracesToLogs)||void 0===t?void 0:t.datasourceUid,noDefault:!0,width:40,onChange:t=>{var s;return(0,i.updateDatasourcePluginJsonDataOption)({onOptionsChange:a,options:e},"tracesToLogs",{datasourceUid:t.uid,tags:null===(s=e.jsonData.tracesToLogs)||void 0===s?void 0:s.tags})}})})}),(0,l.jsx)(r.InlineFieldRow,{children:(0,l.jsx)(r.InlineField,{tooltip:"Tags that will be used in the Loki query. Default tags: 'cluster', 'hostname', 'namespace', 'pod'",label:"Tags",labelWidth:26,children:(0,l.jsx)(r.TagsInput,{tags:null===(c=e.jsonData.tracesToLogs)||void 0===c?void 0:c.tags,width:40,onChange:t=>{var s;return(0,i.updateDatasourcePluginJsonDataOption)({onOptionsChange:a,options:e},"tracesToLogs",{datasourceUid:null===(s=e.jsonData.tracesToLogs)||void 0===s?void 0:s.datasourceUid,tags:t})}})})}),(0,l.jsx)(r.InlineFieldRow,{children:(0,l.jsx)(r.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,l.jsx)(r.Input,{type:"text",placeholder:"1h",width:40,onChange:t=>(0,i.updateDatasourcePluginJsonDataOption)({onOptionsChange:a,options:e},"tracesToLogs",Object.assign({},e.jsonData.tracesToLogs,{spanStartTimeShift:t.currentTarget.value})),value:(null===(d=e.jsonData.tracesToLogs)||void 0===d?void 0:d.spanStartTimeShift)||""})})}),(0,l.jsx)(r.InlineFieldRow,{children:(0,l.jsx)(r.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,l.jsx)(r.Input,{type:"text",placeholder:"1h",width:40,onChange:t=>(0,i.updateDatasourcePluginJsonDataOption)({onOptionsChange:a,options:e},"tracesToLogs",Object.assign({},e.jsonData.tracesToLogs,{spanEndTimeShift:t.currentTarget.value})),value:(null===(p=e.jsonData.tracesToLogs)||void 0===p?void 0:p.spanEndTimeShift)||""})})}),(0,l.jsx)(r.InlineFieldRow,{children:(0,l.jsx)(r.InlineField,{label:"Filter by Trace ID",labelWidth:26,grow:!0,tooltip:"Filters logs by Trace ID. Appends '|=<trace id>' to the query.",children:(0,l.jsx)(r.InlineSwitch,{value:null===(h=e.jsonData.tracesToLogs)||void 0===h?void 0:h.filterByTraceID,onChange:t=>(0,i.updateDatasourcePluginJsonDataOption)({onOptionsChange:a,options:e},"tracesToLogs",Object.assign({},e.jsonData.tracesToLogs,{filterByTraceID:t.currentTarget.checked}))})})}),(0,l.jsx)(r.InlineFieldRow,{children:(0,l.jsx)(r.InlineField,{label:"Filter by Span ID",labelWidth:26,grow:!0,tooltip:"Filters logs by Span ID. Appends '|=<span id>' to the query.",children:(0,l.jsx)(r.InlineSwitch,{value:null===(g=e.jsonData.tracesToLogs)||void 0===g?void 0:g.filterBySpanID,onChange:t=>(0,i.updateDatasourcePluginJsonDataOption)({onOptionsChange:a,options:e},"tracesToLogs",Object.assign({},e.jsonData.tracesToLogs,{filterBySpanID:t.currentTarget.checked}))})})}),(0,l.jsx)(r.InlineFieldRow,{children:(0,l.jsx)(r.InlineField,{label:"Loki Search",labelWidth:26,grow:!0,tooltip:"Use this logs data source to search for traces.",children:(0,l.jsx)(r.InlineSwitch,{defaultChecked:!0,value:null===(m=e.jsonData.tracesToLogs)||void 0===m?void 0:m.lokiSearch,onChange:t=>(0,i.updateDatasourcePluginJsonDataOption)({onOptionsChange:a,options:e},"tracesToLogs",Object.assign({},e.jsonData.tracesToLogs,{lokiSearch:t.currentTarget.checked}))})})})]})}const u=e=>({infoText:n.css`
    padding-bottom: ${e.spacing.md};
    color: ${e.colors.textSemiWeak};
  `})},"./public/app/plugins/datasource/tempo/module.ts":(e,a,t)=>{t.r(a),t.d(a,{plugin:()=>ne});var s,n=t("./packages/grafana-data/src/index.ts"),i=t("./node_modules/react/index.js"),o=t("./node_modules/react/jsx-runtime.js");var r,l=t("./packages/grafana-ui/src/index.ts"),c=t("./public/app/core/components/TraceToLogsSettings.tsx"),u=t("./node_modules/@emotion/css/dist/emotion-css.esm.js"),d=t("./packages/grafana-runtime/src/index.ts");function p({options:e,onOptionsChange:a}){var t;const s=(0,l.useStyles)(h);return(0,o.jsxs)("div",{className:(0,u.css)({width:"100%"}),children:[r||(r=(0,o.jsx)("h3",{className:"page-heading",children:"Service map"})),(0,o.jsx)("div",{className:s.infoText,children:"To allow querying service map data you have to select a Prometheus instance where the data is stored."}),(0,o.jsxs)(l.InlineFieldRow,{className:s.row,children:[(0,o.jsx)(l.InlineField,{tooltip:"The Prometheus data source with the service map data",label:"Data source",labelWidth:26,children:(0,o.jsx)(d.DataSourcePicker,{pluginId:"prometheus",current:null===(t=e.jsonData.serviceMap)||void 0===t?void 0:t.datasourceUid,noDefault:!0,width:40,onChange:t=>(0,n.updateDatasourcePluginJsonDataOption)({onOptionsChange:a,options:e},"serviceMap",{datasourceUid:t.uid})})}),(0,o.jsx)(l.Button,{type:"button",variant:"secondary",size:"sm",fill:"text",onClick:()=>{(0,n.updateDatasourcePluginJsonDataOption)({onOptionsChange:a,options:e},"serviceMap",{datasourceUid:void 0})},children:"Clear"})]})]})}const h=e=>({infoText:u.css`
    label: infoText;
    padding-bottom: ${e.spacing.md};
    color: ${e.colors.textSemiWeak};
  `,row:u.css`
    label: row;
    align-items: baseline;
  `});var g;function m({options:e,onOptionsChange:a}){var t;const s=(0,l.useStyles)(v);return(0,o.jsxs)("div",{className:s.container,children:[g||(g=(0,o.jsx)("h3",{className:"page-heading",children:"Search"})),(0,o.jsx)(l.InlineFieldRow,{className:s.row,children:(0,o.jsx)(l.InlineField,{tooltip:"Removes the Search tab from the Tempo query editor.",label:"Hide search",labelWidth:26,children:(0,o.jsx)(l.InlineSwitch,{value:null===(t=e.jsonData.search)||void 0===t?void 0:t.hide,onChange:t=>(0,n.updateDatasourcePluginJsonDataOption)({onOptionsChange:a,options:e},"search",Object.assign({},e.jsonData.search,{hide:t.currentTarget.checked}))})})})]})}const v=e=>({container:u.css`
    label: container;
    width: 100%;
  `,row:u.css`
    label: row;
    align-items: baseline;
  `});var j=t("./public/app/core/components/NodeGraphSettings.tsx");var x=t("./node_modules/rxjs/dist/esm5/internal/observable/from.js"),b=t("./node_modules/rxjs/dist/esm5/internal/observable/throwError.js"),y=t("./node_modules/rxjs/dist/esm5/internal/observable/of.js"),f=t("./node_modules/rxjs/dist/esm5/internal/observable/merge.js"),D=t("./node_modules/rxjs/dist/esm5/internal/operators/mergeMap.js"),T=t("./node_modules/rxjs/dist/esm5/internal/operators/map.js"),w=t("./node_modules/rxjs/dist/esm5/internal/operators/catchError.js"),S=t("./node_modules/rxjs/dist/esm5/internal/operators/toArray.js"),O=t("./public/app/core/utils/fetch.ts"),I=t("./public/app/features/plugins/datasource_srv.ts"),k=t("./node_modules/lodash/lodash.js"),C=t("./node_modules/prismjs/prism.js"),N=t.n(C),F=t("./public/app/plugins/datasource/tempo/graphTransform.ts"),L=t("./public/app/plugins/datasource/tempo/resultTransformer.ts");const q={key:{pattern:/[^\s]+(?==)/,alias:"attr-name"},operator:/[=]/,value:[{pattern:/"(.+)"/},{pattern:/[^\s]+/}]};function P(e,a,t){return a in e?Object.defineProperty(e,a,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[a]=t,e}class R extends d.DataSourceWithBackend{constructor(e){super(e),P(this,"tracesToLogs",void 0),P(this,"serviceMap",void 0),P(this,"search",void 0),P(this,"nodeGraph",void 0),P(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,i,o,r,l;const c=[],u=e.targets.filter((e=>!e.hide)),d=(0,k.groupBy)(u,(e=>e.queryType||"traceId"));if(null!==(a=this.tracesToLogs)&&void 0!==a&&a.datasourceUid&&(null===(t=d.search)||void 0===t?void 0:t.length)>0){const a=(0,I.ak)();c.push((0,x.Dp)(a.get(this.tracesToLogs.datasourceUid)).pipe((0,D.z)((a=>{var t;const s=Object.assign({},e,{targets:d.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,T.U)((e=>e.error?e:(0,L.RY)(e,this.uid,this.name,n)))):(0,b._)((()=>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=d.nativeSearch)&&void 0!==s&&s.length)try{const e=this.buildSearchQuery(d.nativeSearch[0]);c.push(this._request("/api/search",e).pipe((0,T.U)((e=>({data:[(0,L.n4)(e.data.traces,this.instanceSettings)]}))),(0,w.K)((e=>(0,y.of)({error:{message:e.data.message},data:[]})))))}catch(e){return(0,y.of)({error:{message:e.message},data:[]})}if(null!==(i=d.upload)&&void 0!==i&&i.length)if(this.uploadedJson){const e=JSON.parse(this.uploadedJson);var p;if(e.batches)c.push((0,y.of)((0,L.IM)(e.batches,null===(p=this.nodeGraph)||void 0===p?void 0:p.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 h,g;if(null!==(o=this.serviceMap)&&void 0!==o&&o.datasourceUid&&(null===(r=d.serviceMap)||void 0===r?void 0:r.length)>0&&c.push((h=e,g=this.serviceMap.datasourceUid,function(e,a){return(0,x.Dp)((0,I.ak)().get(a)).pipe((0,D.z)((a=>a.query(e))))}(function(e){return Object.assign({},e,{targets:F.t3.map((e=>({refId:e,expr:`delta(${e}[$__range])`,instant:!0})))})}(h),g).pipe((0,S.q)(),(0,T.U)((e=>({data:(0,F.BC)(e,h.range),state:n.LoadingState.Done})))))),(null===(l=d.traceId)||void 0===l?void 0:l.length)>0){const a=Object.assign({},e,{targets:d.traceId});c.push(super.query(a).pipe((0,T.U)((e=>{var a;return e.error?e:(0,L.Jk)(e,null===(a=this.nodeGraph)||void 0===a?void 0:a.enabled)}))))}return(0,f.T)(...c)}async metadataRequest(e,a={}){return await this._request(e,a,{method:"GET",hideFromInspector:!0}).toPromise()}_request(e,a,t){const s=a?(0,O.tW)(a):"",n=`${this.instanceSettings.url}${e}${s.length?`?${s}`:""}`,i=Object.assign({},t,{url:n});return(0,d.getBackendSrv)().fetch(i)}async testDatasource(){const e={headers:{},method:"GET",url:`${this.instanceSettings.url}/api/echo`},a=await(0,d.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,k.startCase)(t)}: ${e[t]}`);return a.join(", ")}return e.query}buildSearchQuery(e){const a=e.search?N().tokenize(e.search,q):[];let t=[];for(let e=0;e<a.length-1;e++){const s=a[e],n=a[e+2];s&&n&&"string"!=typeof s&&"key"===s.type&&"string"==typeof s.content&&"string"!=typeof n&&"value"===n.type&&"string"==typeof n.content&&t.push({[s.content]:n.content})}let s=(0,k.pick)(e,["minDuration","maxDuration","limit"]);if(s=(0,k.pickBy)(s,k.identity),e.serviceName&&t.push({"service.name":e.serviceName}),e.spanName&&t.push({name:e.spanName}),s.limit||(s.limit=20),s.minDuration){if(!(0,n.isValidGoDuration)(s.minDuration))throw new Error("Please enter a valid min duration.");s.minDuration=s.minDuration.replace(/\s/g,"")}if(s.maxDuration){if(!(0,n.isValidGoDuration)(s.maxDuration))throw new Error("Please enter a valid max duration.");s.maxDuration=s.maxDuration.replace(/\s/g,"")}if(!Number.isInteger(s.limit)||s.limit<=0)throw new Error("Please enter a valid limit.");const i=t.reduce(((e,a)=>Object.assign({},e,a)),{});return Object.assign({},i,s)}}var U=t("./public/app/plugins/datasource/loki/components/LokiQueryField.tsx"),_=t("./node_modules/react-use/lib/useAsync.js");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){super(),M(this,"datasource",void 0),M(this,"tags",void 0),M(this,"request",(async(e,a={})=>{const t=await this.datasource.metadataRequest(e,a);return null==t?void 0:t.data})),M(this,"start",(async()=>(await this.fetchTags(),[]))),M(this,"provideCompletionItems",(async({prefix:e,text:a,value:t,labelKey:s,wrapperClasses:n},i={history:[]})=>{const o={suggestions:[]};return t?"="===a?this.getTagValueCompletionItems(t):this.getTagsCompletionItems():o})),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){const a=e.endText.getText().split(" ");let t=a[0];a.length>1&&(t=a[a.length-1]),t=t.slice(0,-1);const s=await this.request(`/api/search/tag/${t}/values`,[]),n=[];return s&&s.tagValues&&n.push({label:"TagValues",items:s.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}}var B=t("./public/app/store/store.ts"),G=t("./public/app/core/actions/index.ts"),W=t("./public/app/core/copy/appNotification.ts");const E="tempo",J="e.g. 1.2s, 100ms, 500us",$=[(0,l.BracesPlugin)(),(0,l.SlatePrism)({onlyIn:e=>"block"===e.object&&"code_block"===e.type,getSyntax:()=>E})];N().languages.tempo=q;const V=({datasource:e,query:a,onChange:t,onBlur:s,onRunQuery:r})=>{const c=(0,l.useStyles2)(K),u=(0,i.useMemo)((()=>new Q(e)),[e]),[d,p]=(0,i.useState)(!1),[h,g]=(0,i.useState)({serviceNameOptions:[],spanNameOptions:[]}),[m,v]=(0,i.useState)(null),[j,x]=(0,i.useState)({}),b=(0,i.useMemo)((()=>(0,k.debounce)((async()=>{const e=await u.getOptions("service.name");g((a=>Object.assign({},a,{serviceNameOptions:e})))}),500,{leading:!0,trailing:!0})),[u]),y=(0,i.useMemo)((()=>(0,k.debounce)((async()=>{const e=await u.getOptions("name");g((a=>Object.assign({},a,{spanNameOptions:e})))}),500,{leading:!0,trailing:!0})),[u]);(0,i.useEffect)((()=>{(async()=>{try{await u.start();const e=await u.getOptions("service.name"),a=await u.getOptions("name");p(!0),g({serviceNameOptions:e,spanNameOptions:a})}catch(e){404===(null==e?void 0:e.status)?v(e):(0,B.WI)((0,G.$l)((0,W.t_)("Error",e)))}})()}),[u,b,y]);const f=e=>{"Enter"===e.key&&(e.shiftKey||e.ctrlKey)&&r()};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("div",{className:c.container,children:[(0,o.jsx)(l.InlineFieldRow,{children:(0,o.jsx)(l.InlineField,{label:"Service Name",labelWidth:14,grow:!0,children:(0,o.jsx)(l.Select,{menuShouldPortal:!0,options:h.serviceNameOptions,value:a.serviceName||"",onChange:e=>{t(Object.assign({},a,{serviceName:(null==e?void 0:e.value)||void 0}))},placeholder:"Select a service",onOpenMenu:b,isClearable:!0,onKeyDown:f})})}),(0,o.jsx)(l.InlineFieldRow,{children:(0,o.jsx)(l.InlineField,{label:"Span Name",labelWidth:14,grow:!0,children:(0,o.jsx)(l.Select,{menuShouldPortal:!0,options:h.spanNameOptions,value:a.spanName||"",onChange:e=>{t(Object.assign({},a,{spanName:(null==e?void 0:e.value)||void 0}))},placeholder:"Select a span",onOpenMenu:y,isClearable:!0,onKeyDown:f})})}),(0,o.jsx)(l.InlineFieldRow,{children:(0,o.jsx)(l.InlineField,{label:"Tags",labelWidth:14,grow:!0,tooltip:"Values should be in the logfmt format.",children:(0,o.jsx)(l.QueryField,{additionalPlugins:$,query:a.search,onTypeahead:async e=>await u.provideCompletionItems(e),onBlur:s,onChange:e=>{t(Object.assign({},a,{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:r,syntaxLoaded:d,portalOrigin:"tempo"})})}),(0,o.jsx)(l.InlineFieldRow,{children:(0,o.jsx)(l.InlineField,{label:"Min Duration",invalid:!!j.minDuration,labelWidth:14,grow:!0,children:(0,o.jsx)(l.Input,{value:a.minDuration||"",placeholder:J,onBlur:()=>{a.minDuration&&!(0,n.isValidGoDuration)(a.minDuration)?x(Object.assign({},j,{minDuration:!0})):x(Object.assign({},j,{minDuration:!1}))},onChange:e=>t(Object.assign({},a,{minDuration:e.currentTarget.value})),onKeyDown:f})})}),(0,o.jsx)(l.InlineFieldRow,{children:(0,o.jsx)(l.InlineField,{label:"Max Duration",invalid:!!j.maxDuration,labelWidth:14,grow:!0,children:(0,o.jsx)(l.Input,{value:a.maxDuration||"",placeholder:J,onBlur:()=>{a.maxDuration&&!(0,n.isValidGoDuration)(a.maxDuration)?x(Object.assign({},j,{maxDuration:!0})):x(Object.assign({},j,{maxDuration:!1}))},onChange:e=>t(Object.assign({},a,{maxDuration:e.currentTarget.value})),onKeyDown:f})})}),(0,o.jsx)(l.InlineFieldRow,{children:(0,o.jsx)(l.InlineField,{label:"Limit",invalid:!!j.limit,labelWidth:14,grow:!0,tooltip:"Maximum numbers of returned results",children:(0,o.jsx)(l.Input,{value:a.limit||"",type:"number",onChange:e=>{let s=e.currentTarget.value?parseInt(e.currentTarget.value,10):void 0;s&&(!Number.isInteger(s)||s<=0)?x(Object.assign({},j,{limit:!0})):x(Object.assign({},j,{limit:!1})),t(Object.assign({},a,{limit:e.currentTarget.value?parseInt(e.currentTarget.value,10):void 0}))},onKeyDown:f})})})]}),m?(0,o.jsxs)(l.Alert,{title:"Unable to connect to Tempo search",severity:"info",className:c.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,o.jsx)("a",{href:`/datasources/edit/${e.uid}`,children:"datasource settings"}),"."]}):null]})},K=e=>({container:u.css`
    max-width: 500px;
  `,alert:u.css`
    max-width: 75ch;
    margin-top: ${e.spacing(2)};
  `});var z,A,H,Z;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 X extends i.PureComponent{constructor(e){super(e),Y(this,"state",{linkedDatasourceUid:void 0,linkedDatasource:void 0,serviceMapDatasourceUid:void 0,serviceMapDatasource:void 0}),Y(this,"onChangeLinkedQuery",(e=>{const{query:a,onChange:t}=this.props;t(Object.assign({},a,{linkedQuery:Object.assign({},e,{refId:"linked"})}))})),Y(this,"onRunLinkedQuery",(()=>{this.props.onRunQuery()}))}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,i]=await Promise.all([te(t),te(s)]);this.setState({linkedDatasourceUid:t,linkedDatasource:n,serviceMapDatasourceUid:s,serviceMapDatasource:i}),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,i=n.tracesToLogs||{},r=i.datasourceUid,c=null===(e=n.serviceMap)||void 0===e?void 0:e.datasourceUid,p=[{value:"traceId",label:"TraceID"},{value:"upload",label:"JSON file"}];return d.config.featureToggles.tempoServiceGraph&&p.push({value:"serviceMap",label:"Service Map"}),!d.config.featureToggles.tempoSearch||null!=n&&null!==(a=n.search)&&void 0!==a&&a.hide||p.unshift({value:"nativeSearch",label:"Search - Beta"}),r&&!1!==(null==i?void 0:i.lokiSearch)&&(d.config.featureToggles.tempoSearch?p.push({value:"search",label:"Loki Search"}):p.unshift({value:"search",label:"Search"})),(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(l.InlineFieldRow,{children:(0,o.jsx)(l.InlineField,{label:"Query type",children:(0,o.jsx)(l.RadioButtonGroup,{options:p,value:t.queryType,onChange:e=>s(Object.assign({},t,{queryType:e})),size:"md"})})}),"search"===t.queryType&&(0,o.jsx)(ae,{linkedDatasourceUid:r,query:t,onRunQuery:this.onRunLinkedQuery,onChange:this.onChangeLinkedQuery}),"nativeSearch"===t.queryType&&(0,o.jsx)(V,{datasource:this.props.datasource,query:t,onChange:s,onBlur:this.props.onBlur,onRunQuery:this.props.onRunQuery}),"upload"===t.queryType&&(0,o.jsx)("div",{className:(0,u.css)({padding:this.props.theme.spacing(2)}),children:(0,o.jsx)(l.FileDropzone,{options:{multiple:!1},onLoad:e=>{this.props.datasource.uploadedJson=e,this.props.onRunQuery()}})}),"traceId"===t.queryType&&(0,o.jsx)(l.InlineFieldRow,{children:(0,o.jsx)(l.InlineField,{label:"Trace ID",labelWidth:14,grow:!0,children:(0,o.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,o.jsx)(ee,{graphDatasourceUid:c})]})}}function ee({graphDatasourceUid:e}){const a=(0,_.Z)((()=>te(e)),[e]);if(a.loading)return null;const t=a.value;return e?e&&!t?A||(A=(0,o.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."})):null:z||(z=(0,o.jsx)("div",{className:"text-warning",children:"Please set up a service graph datasource in the datasource settings."}))}function ae({linkedDatasourceUid:e,onChange:a,onRunQuery:t,query:s}){const n=(0,_.Z)((()=>te(e)),[e]);if(n.loading)return null;const i=n.value;var r;return i?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(l.InlineLabel,{children:["Tempo uses ",i.name," to find traces."]}),(0,o.jsx)(U.n,{datasource:i,onChange:a,onRunQuery:t,query:null!==(r=s.linkedQuery)&&void 0!==r?r:{refId:"linked"},history:[]})]}):e?e&&!i?Z||(Z=(0,o.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:H||(H=(0,o.jsx)("div",{className:"text-warning",children:"Please set up a Traces-to-logs datasource in the datasource settings."}))}async function te(e){if(!e)return;const a=(0,d.getDataSourceSrv)();try{return await a.get(e)}catch(e){return void console.error("Failed to load data source",e)}}const se=(0,l.withTheme2)(X),ne=new n.DataSourcePlugin(R).setConfigEditor((({options:e,onOptionsChange:a})=>(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(l.DataSourceHttpSettings,{defaultUrl:"http://tempo",dataSourceConfig:e,showAccessOptions:!1,onChange:a}),(0,o.jsx)("div",{className:"gf-form-group",children:(0,o.jsx)(c.Z,{options:e,onOptionsChange:a})}),d.config.featureToggles.tempoServiceGraph&&(0,o.jsx)("div",{className:"gf-form-group",children:(0,o.jsx)(p,{options:e,onOptionsChange:a})}),d.config.featureToggles.tempoSearch&&(0,o.jsx)("div",{className:"gf-form-group",children:(0,o.jsx)(m,{options:e,onOptionsChange:a})}),(0,o.jsx)("div",{className:"gf-form-group",children:(0,o.jsx)(j.n,{options:e,onOptionsChange:a})})]}))).setQueryEditorHelp((function(){return s||(s=(0,o.jsxs)("div",{children:[(0,o.jsx)("h2",{id:"tempo-cheat-sheet",children:"Tempo Cheat Sheet"}),(0,o.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,o.jsxs)("p",{children:["Here are some"," ",(0,o.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)."]})]}))})).setExploreQueryField(se)}}]);
//# sourceMappingURL=tempoPlugin.8128b05ac04b15cbf98d.js.map