forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APM] generator: support error events and application metrics (elasti…
- Loading branch information
1 parent
c6be6c0
commit 3cfa21d
Showing
12 changed files
with
273 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { Fields } from './entity'; | ||
import { Serializable } from './serializable'; | ||
import { generateLongId, generateShortId } from './utils/generate_id'; | ||
|
||
export class ApmError extends Serializable { | ||
constructor(fields: Fields) { | ||
super({ | ||
...fields, | ||
'processor.event': 'error', | ||
'processor.name': 'error', | ||
'error.id': generateShortId(), | ||
}); | ||
} | ||
|
||
serialize() { | ||
const [data] = super.serialize(); | ||
data['error.grouping_key'] = generateLongId( | ||
this.fields['error.grouping_name'] || this.fields['error.exception']?.[0]?.message | ||
); | ||
return [data]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/elastic-apm-generator/src/test/scenarios/05_transactions_with_errors.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
import { pick } from 'lodash'; | ||
import { service } from '../../index'; | ||
import { Instance } from '../../lib/instance'; | ||
|
||
describe('transactions with errors', () => { | ||
let instance: Instance; | ||
const timestamp = new Date('2021-01-01T00:00:00.000Z').getTime(); | ||
|
||
beforeEach(() => { | ||
instance = service('opbeans-java', 'production', 'java').instance('instance'); | ||
}); | ||
it('generates error events', () => { | ||
const events = instance | ||
.transaction('GET /api') | ||
.timestamp(timestamp) | ||
.errors(instance.error('test error').timestamp(timestamp)) | ||
.serialize(); | ||
|
||
const errorEvents = events.filter((event) => event['processor.event'] === 'error'); | ||
|
||
expect(errorEvents.length).toEqual(1); | ||
|
||
expect( | ||
pick(errorEvents[0], 'processor.event', 'processor.name', 'error.exception', '@timestamp') | ||
).toEqual({ | ||
'processor.event': 'error', | ||
'processor.name': 'error', | ||
'@timestamp': timestamp, | ||
'error.exception': [{ message: 'test error' }], | ||
}); | ||
}); | ||
|
||
it('sets the transaction and trace id', () => { | ||
const [transaction, error] = instance | ||
.transaction('GET /api') | ||
.timestamp(timestamp) | ||
.errors(instance.error('test error').timestamp(timestamp)) | ||
.serialize(); | ||
|
||
const keys = ['transaction.id', 'trace.id', 'transaction.type']; | ||
|
||
expect(pick(error, keys)).toEqual({ | ||
'transaction.id': transaction['transaction.id'], | ||
'trace.id': transaction['trace.id'], | ||
'transaction.type': 'request', | ||
}); | ||
}); | ||
|
||
it('sets the error grouping key', () => { | ||
const [, error] = instance | ||
.transaction('GET /api') | ||
.timestamp(timestamp) | ||
.errors(instance.error('test error').timestamp(timestamp)) | ||
.serialize(); | ||
|
||
expect(error['error.grouping_name']).toEqual('test error'); | ||
expect(error['error.grouping_key']).toMatchInlineSnapshot(`"8b96fa10a7f85a5d960198627bf50840"`); | ||
}); | ||
}); |
Oops, something went wrong.