Skip to content

Commit ba5ae97

Browse files
authored
[Synthtrace] Sanitize default value for error grouping key (#210010)
## Summary Closes #209096
1 parent 9409a43 commit ba5ae97

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

packages/kbn-apm-synthtrace-client/src/lib/apm/instance.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10-
import { createHash } from 'crypto';
1110
import { ApmError } from './apm_error';
1211
import { Entity } from '../entity';
1312
import { Metricset } from './metricset';
@@ -114,7 +113,3 @@ export class Instance extends Entity<ApmFields> {
114113
});
115114
}
116115
}
117-
118-
export function getErrorGroupingKey(content: string) {
119-
return createHash('sha256').update(content).digest('hex');
120-
}

packages/kbn-apm-synthtrace-client/src/lib/utils/generate_id.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ function generateId(length: number = LONG_ID_LENGTH) {
2424
}
2525

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

3033
export function generateShortId() {

x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/e2e/errors/error_details.cy.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* 2.0.
66
*/
77

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

1110
import url from 'url';
@@ -36,7 +35,7 @@ describe('Error details', () => {
3635
});
3736

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

5554
describe('when error has no occurrences', () => {
5655
it('shows zero occurrences', () => {
57-
const errorGroupingKey = getErrorGroupingKey('Error foo bar');
56+
const errorGroupingKey = generateLongIdWithSeed('Error foo bar');
5857

5958
cy.visitKibana(
6059
url.format({

0 commit comments

Comments
 (0)