diff --git a/public/app/plugins/datasource/tempo/datasource.test.ts b/public/app/plugins/datasource/tempo/datasource.test.ts index de5416de26e..f8a7fc57824 100644 --- a/public/app/plugins/datasource/tempo/datasource.test.ts +++ b/public/app/plugins/datasource/tempo/datasource.test.ts @@ -953,12 +953,20 @@ describe('Tempo service graph view', () => { queryType: 'traceqlSearch', refId: 'A', filters: [ + { + id: 'service-namespace', + operator: '=', + scope: 'resource', + tag: 'service.namespace', + value: '${__data.fields.targetNamespace}', + valueType: 'string', + }, { id: 'service-name', operator: '=', scope: 'resource', tag: 'service.name', - value: '${__data.fields.target}', + value: '${__data.fields.targetName}', valueType: 'string', }, ], @@ -1033,8 +1041,8 @@ describe('Tempo service graph view', () => { ]); }); - it('should make tempo link correctly', () => { - const tempoLink = makeTempoLink('Tempo', '', '"${__data.fields[0]}"', 'gdev-tempo'); + it('should make tempo link correctly without namespace', () => { + const tempoLink = makeTempoLink('Tempo', undefined, '', '"${__data.fields[0]}"', 'gdev-tempo'); expect(tempoLink).toEqual({ url: '', title: 'Tempo', @@ -1058,6 +1066,40 @@ describe('Tempo service graph view', () => { }, }); }); + + it('should make tempo link correctly with namespace', () => { + const tempoLink = makeTempoLink('Tempo', '"${__data.fields.subtitle}"', '', '"${__data.fields[0]}"', 'gdev-tempo'); + expect(tempoLink).toEqual({ + url: '', + title: 'Tempo', + internal: { + query: { + queryType: 'traceqlSearch', + refId: 'A', + filters: [ + { + id: 'service-namespace', + operator: '=', + scope: 'resource', + tag: 'service.namespace', + value: '"${__data.fields.subtitle}"', + valueType: 'string', + }, + { + id: 'span-name', + operator: '=', + scope: 'span', + tag: 'name', + value: '"${__data.fields[0]}"', + valueType: 'string', + }, + ], + }, + datasourceUid: 'gdev-tempo', + datasourceName: 'Tempo', + }, + }); + }); }); describe('label names - v2 tags', () => { @@ -1457,7 +1499,7 @@ const serviceGraphLinks = [ operator: '=', scope: 'resource', tag: 'service.name', - value: '${__data.fields[0]}', + value: '${__data.fields.id}', valueType: 'string', }, ], diff --git a/public/app/plugins/datasource/tempo/datasource.ts b/public/app/plugins/datasource/tempo/datasource.ts index 96fcb05b88c..503f4db7899 100644 --- a/public/app/plugins/datasource/tempo/datasource.ts +++ b/public/app/plugins/datasource/tempo/datasource.ts @@ -1128,13 +1128,35 @@ export function getFieldConfig( datasourceUid, false ), - makeTempoLink('View traces', `\${${tempoField}}`, '', tempoDatasourceUid), + makeTempoLink( + 'View traces', + namespaceFields !== undefined ? `\${${namespaceFields.targetNamespace}}` : '', + `\${${targetField}}`, + '', + tempoDatasourceUid + ), ], }; } -export function makeTempoLink(title: string, serviceName: string, spanName: string, datasourceUid: string) { +export function makeTempoLink( + title: string, + serviceNamespace: string | undefined, + serviceName: string, + spanName: string, + datasourceUid: string +) { let query: TempoQuery = { refId: 'A', queryType: 'traceqlSearch', filters: [] }; + if (serviceNamespace !== undefined && serviceNamespace !== '') { + query.filters.push({ + id: 'service-namespace', + scope: TraceqlSearchScope.Resource, + tag: 'service.namespace', + value: serviceNamespace, + operator: '=', + valueType: 'string', + }); + } if (serviceName !== '') { query.filters.push({ id: 'service-name', @@ -1338,7 +1360,7 @@ function getServiceGraphView( return 'Tempo'; }), config: { - links: [makeTempoLink('Tempo', '', `\${__data.fields[0]}`, tempoDatasourceUid)], + links: [makeTempoLink('Tempo', undefined, '', `\${__data.fields[0]}`, tempoDatasourceUid)], }, }); }