[APM][OTel] Fix spanlink invalid filter (#215322)

## Summary

Fixes https://github.com/elastic/kibana/issues/215101

This PR adds an optional check for `span.id` (this value is always
populated) when redirecting to an error within a span link.
This commit is contained in:
Sergi Romeu 2025-04-01 11:43:19 +02:00 committed by GitHub
parent f8b3e93573
commit 8fc00a088f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

View file

@ -33,6 +33,7 @@ export interface WaterfallTransaction {
coldstart?: boolean;
};
span?: {
id?: string;
links?: SpanLink[];
};
}

View file

@ -11,7 +11,7 @@ import type { ReactNode } from 'react';
import React, { useRef, useEffect, useState } from 'react';
import styled from '@emotion/styled';
import { isMobileAgentName, isRumAgentName } from '../../../../../../../common/agent_name';
import { TRACE_ID, TRANSACTION_ID } from '../../../../../../../common/es_fields/apm';
import { SPAN_ID, TRACE_ID, TRANSACTION_ID } from '../../../../../../../common/es_fields/apm';
import { asDuration } from '../../../../../../../common/utils/formatters';
import type { Margins } from '../../../../../shared/charts/timeline';
import { TruncateWithTooltip } from '../../../../../shared/truncate_with_tooltip';
@ -333,8 +333,13 @@ function RelatedErrors({
);
let kuery = `${TRACE_ID} : "${item.doc.trace.id}"`;
if (item.doc.transaction?.id) {
kuery += ` and ${TRANSACTION_ID} : "${item.doc.transaction?.id}"`;
const transactionId = item.doc.transaction?.id;
const spanId = item.doc.span?.id;
if (item.docType === 'transaction' && spanId) {
kuery += ` and ${SPAN_ID} : "${spanId}"`;
} else if (transactionId) {
kuery += ` and ${TRANSACTION_ID} : "${transactionId}"`;
}
const mobileHref = apmRouter.link(`/mobile-services/{serviceName}/errors-and-crashes`, {