Skip to content

Commit

Permalink
[8.17] [APM] Make `trace.id` an optional field (#201821) (#…
Browse files Browse the repository at this point in the history
…201939)

# Backport

This will backport the following commits from `main` to `8.17`:
- [[APM] Make `trace.id` an optional field
(#201821)](#201821)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Carlos
Crespo","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-27T10:55:51Z","message":"[APM]
Make `trace.id` an optional field (#201821)\n\nfixes
[#201803](https://github.com/elastic/kibana/issues/201803)\r\n\r\n##
Summary\r\n\r\nThis PR fixes the error sample details function, making
the `trace.id`\r\nan optional field, to prevent the function from
crashing in case this\r\nfield is not in the
docs.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"caea2066e4ca70e913b83a1ae13d3f2cd0d46804","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-infra_services","v8.16.0","backport:version","v8.17.0"],"title":"[APM]
Make `trace.id` an optional
field","number":201821,"url":"https://github.com/elastic/kibana/pull/201821","mergeCommit":{"message":"[APM]
Make `trace.id` an optional field (#201821)\n\nfixes
[#201803](https://github.com/elastic/kibana/issues/201803)\r\n\r\n##
Summary\r\n\r\nThis PR fixes the error sample details function, making
the `trace.id`\r\nan optional field, to prevent the function from
crashing in case this\r\nfield is not in the
docs.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"caea2066e4ca70e913b83a1ae13d3f2cd0d46804"}},"sourceBranch":"main","suggestedTargetBranches":["8.16","8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201821","number":201821,"mergeCommit":{"message":"[APM]
Make `trace.id` an optional field (#201821)\n\nfixes
[#201803](https://github.com/elastic/kibana/issues/201803)\r\n\r\n##
Summary\r\n\r\nThis PR fixes the error sample details function, making
the `trace.id`\r\nan optional field, to prevent the function from
crashing in case this\r\nfield is not in the
docs.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"caea2066e4ca70e913b83a1ae13d3f2cd0d46804"}},{"branch":"8.16","label":"v8.16.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Carlos Crespo <[email protected]>
  • Loading branch information
kibanamachine and crespocarlos authored Nov 27, 2024
1 parent 98d9320 commit 7b10d16
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export async function getErrorSampleDetails({
const requiredFields = asMutableArray([
AGENT_NAME,
PROCESSOR_EVENT,
TRACE_ID,
TIMESTAMP_US,
AT_TIMESTAMP,
SERVICE_NAME,
Expand All @@ -78,6 +77,7 @@ export async function getErrorSampleDetails({
] as const);

const optionalFields = asMutableArray([
TRACE_ID,
TRANSACTION_ID,
SPAN_ID,
AGENT_VERSION,
Expand Down Expand Up @@ -131,7 +131,7 @@ export async function getErrorSampleDetails({
const errorFromFields = unflattenKnownApmEventFields(hit.fields, requiredFields);

const transactionId = errorFromFields.transaction?.id ?? errorFromFields.span?.id;
const traceId = errorFromFields.trace.id;
const traceId = errorFromFields.trace?.id;

let transaction: Transaction | undefined;
if (transactionId && traceId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { apm, timerange } from '@kbn/apm-synthtrace-client';
import { ApmFields, apm, timerange } from '@kbn/apm-synthtrace-client';
import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';

export const config = {
Expand All @@ -25,11 +25,13 @@ export async function generateData({
serviceName,
start,
end,
overrides,
}: {
apmSynthtraceEsClient: ApmSynthtraceEsClient;
serviceName: string;
start: number;
end: number;
overrides?: Partial<ApmFields>;
}) {
const serviceGoProdInstance = apm
.service({ name: serviceName, environment: 'production', agentName: 'go' })
Expand All @@ -40,18 +42,18 @@ export async function generateData({

const documents = [appleTransaction, bananaTransaction].flatMap((transaction, index) => {
return [
interval
.rate(transaction.successRate)
.generator((timestamp) =>
serviceGoProdInstance
.transaction({ transactionName: transaction.name })
.timestamp(timestamp)
.duration(1000)
.success()
),
interval.rate(transaction.successRate).generator((timestamp) =>
serviceGoProdInstance
.transaction({ transactionName: transaction.name })
.overrides(overrides ? overrides : {})
.timestamp(timestamp)
.duration(1000)
.success()
),
interval.rate(transaction.failureRate).generator((timestamp) =>
serviceGoProdInstance
.transaction({ transactionName: transaction.name })
.overrides(overrides ? overrides : {})
.errors(
serviceGoProdInstance
.error({ message: `Error ${index}`, type: transaction.name })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,33 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
});
});

describe('error sample without trace.id', () => {
before(async () => {
await generateData({
serviceName,
start,
end,
apmSynthtraceEsClient,
overrides: {
'trace.id': undefined,
},
});
});

after(() => apmSynthtraceEsClient.clean());

it('returns 200', async () => {
const errorsSamplesResponse = await callErrorGroupSamplesApi({
groupId: '0000000000000000000000000Error 1',
});

const errorId = errorsSamplesResponse.body.errorSampleIds[0];

const response = await callErrorSampleDetailsApi(errorId);
expect(response.status).to.be(200);
});
});

describe('with sampled and unsampled transactions', () => {
let errorGroupSamplesResponse: ErrorGroupSamples;

Expand Down

0 comments on commit 7b10d16

Please sign in to comment.