From 3551e6074cfd113a7fb04dd989d949e64f36e4c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Jamr=C3=B3z?= Date: Thu, 10 Apr 2025 21:07:49 +0200 Subject: [PATCH] TraceView: Handle External correlation links correctly (#103594) * TraceView: Handle External correlation links correctly * Improve handling URLs --- .../SpanDetail/SpanDetailLinkButtons.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/public/app/features/explore/TraceView/components/TraceTimelineViewer/SpanDetail/SpanDetailLinkButtons.tsx b/public/app/features/explore/TraceView/components/TraceTimelineViewer/SpanDetail/SpanDetailLinkButtons.tsx index 73f650ee3c0..d3e272e9cc7 100644 --- a/public/app/features/explore/TraceView/components/TraceTimelineViewer/SpanDetail/SpanDetailLinkButtons.tsx +++ b/public/app/features/explore/TraceView/components/TraceTimelineViewer/SpanDetail/SpanDetailLinkButtons.tsx @@ -49,6 +49,8 @@ const LINKS_ORDER = [ */ const MAX_LINKS = 3; +const ABSOLUTE_LINK_PATTERN = /^https?:\/\//i; + export const getSpanDetailLinkButtons = (props: Props) => { const { span, createSpanLink, traceToProfilesOptions, timeRange, datasourceType, app } = props; @@ -212,7 +214,22 @@ const createLinkModel = ( if (link.onClick) { link.onClick?.(event); } else { - locationService.push(link.href); + // TODO: Replace with https://github.com/grafana/grafana/issues/103593 + // We need to handle absolute and relative URLs correctly because when + // there are multiple links we group them into a dropdown and not use + // the grafana/ui DataLinkButton component which handles relative and + // absolute URLs nicely. A nice solution would be to have a separate + // component that handles this for us and not pass the onClick in the + // SpanLinkModel when link.href is defined (removing the need of having + // if (link.onClick) in here. + + // if it's an absolute URL - open it in a new window + if (!ABSOLUTE_LINK_PATTERN.test(link.href)) { + // handle relative URLs by changing current URL: + locationService.push(link.href); + } else { + window.open(link.href, '_blank', 'noopener,noreferrer'); + } } }, },