[8.x] [APM][OTel] Fix spanlink invalid filter (#215322) (#216608)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[APM][OTel] Fix spanlink invalid filter
(#215322)](https://github.com/elastic/kibana/pull/215322)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Sergi
Romeu","email":"sergi.romeu@elastic.co"},"sourceCommit":{"committedDate":"2025-04-01T09:43:19Z","message":"[APM][OTel]
Fix spanlink invalid filter (#215322)\n\n## Summary\n\nFixes
https://github.com/elastic/kibana/issues/215101\n\nThis PR adds an
optional check for `span.id` (this value is always\npopulated) when
redirecting to an error within a span
link.","sha":"8fc00a088f3be5d0252a18c953444a2518f65f10","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","apm","Team:obs-ux-infra_services","backport:version","v9.1.0","v8.19.0","v8.18.1","v8.17.5"],"title":"[APM][OTel]
Fix spanlink invalid
filter","number":215322,"url":"https://github.com/elastic/kibana/pull/215322","mergeCommit":{"message":"[APM][OTel]
Fix spanlink invalid filter (#215322)\n\n## Summary\n\nFixes
https://github.com/elastic/kibana/issues/215101\n\nThis PR adds an
optional check for `span.id` (this value is always\npopulated) when
redirecting to an error within a span
link.","sha":"8fc00a088f3be5d0252a18c953444a2518f65f10"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.x","8.18","8.17"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/215322","number":215322,"mergeCommit":{"message":"[APM][OTel]
Fix spanlink invalid filter (#215322)\n\n## Summary\n\nFixes
https://github.com/elastic/kibana/issues/215101\n\nThis PR adds an
optional check for `span.id` (this value is always\npopulated) when
redirecting to an error within a span
link.","sha":"8fc00a088f3be5d0252a18c953444a2518f65f10"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.5","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Sergi Romeu <sergi.romeu@elastic.co>
This commit is contained in:
Kibana Machine 2025-04-01 13:35:07 +02:00 committed by GitHub
parent 20425bc726
commit db3250bf8a
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

@ -12,7 +12,7 @@ import React, { useRef, useEffect, useState } from 'react';
import { euiStyled } from '@kbn/kibana-react-plugin/common';
import { useTheme } from '../../../../../../hooks/use_theme';
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';
@ -323,8 +323,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`, {