Skip to content

Commit

Permalink
[Synthtrace] Sanitize default value for error grouping key (elastic#2…
Browse files Browse the repository at this point in the history
…10010)

## Summary

Closes elastic#209096
  • Loading branch information
rmyz authored Feb 7, 2025
1 parent 9409a43 commit ba5ae97
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
5 changes: 0 additions & 5 deletions packages/kbn-apm-synthtrace-client/src/lib/apm/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { createHash } from 'crypto';
import { ApmError } from './apm_error';
import { Entity } from '../entity';
import { Metricset } from './metricset';
Expand Down Expand Up @@ -114,7 +113,3 @@ export class Instance extends Entity<ApmFields> {
});
}
}

export function getErrorGroupingKey(content: string) {
return createHash('sha256').update(content).digest('hex');
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ function generateId(length: number = LONG_ID_LENGTH) {
}

function generateIdWithSeed(seed: string, length: number = LONG_ID_LENGTH) {
return seed?.padStart(length, '0');
// this is needed to sanitize errors like "No handler for /order/{id}",
// as encodeURIComponent is not enough and can cause errors in the client
const encodedSeed = seed.replace(/[/]/g, '_').replace(/[{}]/g, '');
return encodedSeed?.padStart(length, '0');
}

export function generateShortId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { getErrorGroupingKey } from '@kbn/apm-synthtrace-client/src/lib/apm/instance';
import { generateLongIdWithSeed } from '@kbn/apm-synthtrace-client/src/lib/utils/generate_id';

import url from 'url';
Expand Down Expand Up @@ -36,7 +35,7 @@ describe('Error details', () => {
});

it('has no detectable a11y violations on load', () => {
const errorGroupingKey = getErrorGroupingKey('Error 1');
const errorGroupingKey = generateLongIdWithSeed('Error 1');
const errorGroupingKeyShort = errorGroupingKey.slice(0, 5);
const errorDetailsPageHref = url.format({
pathname: `/app/apm/services/opbeans-java/errors/${errorGroupingKey}`,
Expand All @@ -54,7 +53,7 @@ describe('Error details', () => {

describe('when error has no occurrences', () => {
it('shows zero occurrences', () => {
const errorGroupingKey = getErrorGroupingKey('Error foo bar');
const errorGroupingKey = generateLongIdWithSeed('Error foo bar');

cy.visitKibana(
url.format({
Expand Down

0 comments on commit ba5ae97

Please sign in to comment.