diff --git a/public/app/plugins/datasource/tempo/datasource.test.ts b/public/app/plugins/datasource/tempo/datasource.test.ts index 9b715503516..e12b53d7f70 100644 --- a/public/app/plugins/datasource/tempo/datasource.test.ts +++ b/public/app/plugins/datasource/tempo/datasource.test.ts @@ -748,6 +748,20 @@ describe('Tempo service graph view', () => { expect(builtQuery).toBe( 'topk(5, sum(rate(traces_spanmetrics_calls_total{service="${app}",service="$app"}[$__range])) by (span_name))' ); + + targets = { + targets: [ + { queryType: 'serviceMap', serviceMapQuery: '{client="app",client_deployment_environment="production"}' }, + ], + } as DataQueryRequest; + builtQuery = buildExpr( + { expr: 'sum(rate(traces_spanmetrics_calls_total{}[$__range])) by (span_name)', params: [], topk: 5 }, + '', + targets + ); + expect(builtQuery).toBe( + 'topk(5, sum(rate(traces_spanmetrics_calls_total{service="app",deployment_environment="production"}[$__range])) by (span_name))' + ); }); it('should build link expr correctly', () => { diff --git a/public/app/plugins/datasource/tempo/datasource.ts b/public/app/plugins/datasource/tempo/datasource.ts index a0da5493bd5..618f1b642d5 100644 --- a/public/app/plugins/datasource/tempo/datasource.ts +++ b/public/app/plugins/datasource/tempo/datasource.ts @@ -1549,7 +1549,12 @@ export function buildExpr( query = serviceMapQueryMatch[1]; } // map serviceGraph metric tags to serviceGraphView metric tags - query = query.replace('client', 'service').replace('server', 'service'); + query = query + // client_deployment_environment="prod" -> deployment_environment="prod" + .replaceAll('client_', '') + .replaceAll('server_', '') + .replace('client', 'service') // client="fooservice" -> service="fooservice" + .replace('server', 'service'); return query.includes('span_name') ? metric.params.concat(query) : metric.params