[Synthtrace] Sanitize default value for error grouping key (#210010)

## Summary

Closes #209096
This commit is contained in:
Sergi Romeu 2025-02-07 18:13:11 +01:00 committed by GitHub
parent 9409a4364b
commit ba5ae97569
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 9 deletions

View file

@ -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';
@ -114,7 +113,3 @@ export class Instance extends Entity<ApmFields> {
});
}
}
export function getErrorGroupingKey(content: string) {
return createHash('sha256').update(content).digest('hex');
}

View file

@ -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() {

View file

@ -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';
@ -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}`,
@ -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({