From 157ded7c3fc13f8bcb25c5fc2a7ee89807d40928 Mon Sep 17 00:00:00 2001 From: Sven Grossmann Date: Fri, 27 Sep 2024 18:11:09 +0200 Subject: [PATCH] Tempo: Create trace to logs links with traces in structured metadata (#93923) --- .../app/features/explore/TraceView/createSpanLink.test.ts | 2 +- public/app/features/explore/TraceView/createSpanLink.tsx | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/public/app/features/explore/TraceView/createSpanLink.test.ts b/public/app/features/explore/TraceView/createSpanLink.test.ts index 18cf81ecb6d..6d2ee26d684 100644 --- a/public/app/features/explore/TraceView/createSpanLink.test.ts +++ b/public/app/features/explore/TraceView/createSpanLink.test.ts @@ -200,7 +200,7 @@ describe('createSpanLinkFactory', () => { datasource: 'loki1_uid', queries: [ { - expr: '{cluster="cluster1", hostname="hostname1", service_namespace="namespace1"} |="7946b05c2e2e4e5a" |="6605c7b08e715d6c"', + expr: '{cluster="cluster1", hostname="hostname1", service_namespace="namespace1"} | label_format log_line_contains_trace_id=`{{ contains "7946b05c2e2e4e5a" __line__ }}` | log_line_contains_trace_id="true" OR trace_id="7946b05c2e2e4e5a" | label_format log_line_contains_span_id=`{{ contains "6605c7b08e715d6c" __line__ }}` | log_line_contains_span_id="true" OR span_id="6605c7b08e715d6c"', refId: '', }, ], diff --git a/public/app/features/explore/TraceView/createSpanLink.tsx b/public/app/features/explore/TraceView/createSpanLink.tsx index 15cb385e178..43024dd7cd7 100644 --- a/public/app/features/explore/TraceView/createSpanLink.tsx +++ b/public/app/features/explore/TraceView/createSpanLink.tsx @@ -384,10 +384,12 @@ function getQueryForLoki( let expr = '{${__tags}}'; if (filterByTraceID && span.traceID) { - expr += ' |="${__span.traceId}"'; + expr += + ' | label_format log_line_contains_trace_id=`{{ contains "${__span.traceId}" __line__ }}` | log_line_contains_trace_id="true" OR trace_id="${__span.traceId}"'; } if (filterBySpanID && span.spanID) { - expr += ' |="${__span.spanId}"'; + expr += + ' | label_format log_line_contains_span_id=`{{ contains "${__span.spanId}" __line__ }}` | log_line_contains_span_id="true" OR span_id="${__span.spanId}"'; } return {