Tempo: Fix span metrics query when filtered by prefixed service graph labels (#103773)

fix span metrics queries for sevice graph explore when filtered with client_ or server_ prefix
This commit is contained in:
Domas
2025-04-14 09:47:24 +03:00
committed by GitHub
parent 9aca2606c7
commit 90f82cf1af
2 changed files with 20 additions and 1 deletions
@@ -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<TempoQuery>;
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', () => {
@@ -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