Skip to content

Commit 0d5f795

Browse files
authored
Add error.grouping_name field (#4886)
Add an ingest pipeline which adds an "error.grouping_name" field to error documents. This is set based on the value of "error.log.message", or "error.exception[0].message". If an error contains both a log message and an exception, then the log message will win.
1 parent 41c47d1 commit 0d5f795

File tree

25 files changed

+256
-11
lines changed

25 files changed

+256
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"description": "Set error.grouping_name for APM error events",
3+
"processors": [
4+
{
5+
"script": {
6+
"source": "ctx.error.grouping_name = ctx.error.exception[0].message",
7+
"if": "ctx.error?.exception?.length != null && ctx.error?.exception?.length > 0"
8+
}
9+
},
10+
{
11+
"set": {
12+
"field": "error.grouping_name",
13+
"copy_from": "error.log.message",
14+
"if": "ctx.error?.log?.message != null"
15+
}
16+
}
17+
]
18+
}

apmpackage/apm/0.1.0/data_stream/app_metrics/elasticsearch/ingest_pipeline/default.json

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
"pipeline": {
2121
"name": "metrics-apm.app-0.1.0-apm_remove_span_metadata"
2222
}
23+
},
24+
{
25+
"pipeline": {
26+
"name": "metrics-apm.app-0.1.0-apm_error_grouping_name",
27+
"if": "ctx.processor?.event == 'error'"
28+
}
2329
}
2430
]
2531
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"description": "Set error.grouping_name for APM error events",
3+
"processors": [
4+
{
5+
"script": {
6+
"source": "ctx.error.grouping_name = ctx.error.exception[0].message",
7+
"if": "ctx.error?.exception?.length != null && ctx.error?.exception?.length > 0"
8+
}
9+
},
10+
{
11+
"set": {
12+
"field": "error.grouping_name",
13+
"copy_from": "error.log.message",
14+
"if": "ctx.error?.log?.message != null"
15+
}
16+
}
17+
]
18+
}

apmpackage/apm/0.1.0/data_stream/error_logs/elasticsearch/ingest_pipeline/default.json

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
"pipeline": {
2121
"name": "logs-apm.error-0.1.0-apm_remove_span_metadata"
2222
}
23+
},
24+
{
25+
"pipeline": {
26+
"name": "logs-apm.error-0.1.0-apm_error_grouping_name",
27+
"if": "ctx.processor?.event == 'error'"
28+
}
2329
}
2430
]
2531
}

apmpackage/apm/0.1.0/data_stream/error_logs/fields/fields.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
- name: error.grouping_key
2626
type: keyword
2727
description: |
28-
GroupingKey of the logged error for use in grouping.
28+
Hash of select properties of the logged error for grouping purposes.
29+
- name: error.grouping_name
30+
type: keyword
31+
description: |
32+
Name to associate with an error group. Errors belonging to the same group (same grouping_key) may have differing values for grouping_name. Consumers may choose one arbitrarily.
2933
- name: error.log.level
3034
type: keyword
3135
description: The severity of the record.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"description": "Set error.grouping_name for APM error events",
3+
"processors": [
4+
{
5+
"script": {
6+
"source": "ctx.error.grouping_name = ctx.error.exception[0].message",
7+
"if": "ctx.error?.exception?.length != null && ctx.error?.exception?.length > 0"
8+
}
9+
},
10+
{
11+
"set": {
12+
"field": "error.grouping_name",
13+
"copy_from": "error.log.message",
14+
"if": "ctx.error?.log?.message != null"
15+
}
16+
}
17+
]
18+
}

apmpackage/apm/0.1.0/data_stream/internal_metrics/elasticsearch/ingest_pipeline/default.json

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
"pipeline": {
2121
"name": "metrics-apm.internal-0.1.0-apm_remove_span_metadata"
2222
}
23+
},
24+
{
25+
"pipeline": {
26+
"name": "metrics-apm.internal-0.1.0-apm_error_grouping_name",
27+
"if": "ctx.processor?.event == 'error'"
28+
}
2329
}
2430
]
2531
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"description": "Set error.grouping_name for APM error events",
3+
"processors": [
4+
{
5+
"script": {
6+
"source": "ctx.error.grouping_name = ctx.error.exception[0].message",
7+
"if": "ctx.error?.exception?.length != null && ctx.error?.exception?.length > 0"
8+
}
9+
},
10+
{
11+
"set": {
12+
"field": "error.grouping_name",
13+
"copy_from": "error.log.message",
14+
"if": "ctx.error?.log?.message != null"
15+
}
16+
}
17+
]
18+
}

apmpackage/apm/0.1.0/data_stream/profile_metrics/elasticsearch/ingest_pipeline/default.json

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
"pipeline": {
2121
"name": "metrics-apm.profiling-0.1.0-apm_remove_span_metadata"
2222
}
23+
},
24+
{
25+
"pipeline": {
26+
"name": "metrics-apm.profiling-0.1.0-apm_error_grouping_name",
27+
"if": "ctx.processor?.event == 'error'"
28+
}
2329
}
2430
]
2531
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"description": "Set error.grouping_name for APM error events",
3+
"processors": [
4+
{
5+
"script": {
6+
"source": "ctx.error.grouping_name = ctx.error.exception[0].message",
7+
"if": "ctx.error?.exception?.length != null && ctx.error?.exception?.length > 0"
8+
}
9+
},
10+
{
11+
"set": {
12+
"field": "error.grouping_name",
13+
"copy_from": "error.log.message",
14+
"if": "ctx.error?.log?.message != null"
15+
}
16+
}
17+
]
18+
}

apmpackage/apm/0.1.0/data_stream/traces/elasticsearch/ingest_pipeline/default.json

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
"pipeline": {
2121
"name": "traces-apm-0.1.0-apm_remove_span_metadata"
2222
}
23+
},
24+
{
25+
"pipeline": {
26+
"name": "traces-apm-0.1.0-apm_error_grouping_name",
27+
"if": "ctx.processor?.event == 'error'"
28+
}
2329
}
2430
]
2531
}

apmpackage/apm/0.1.0/docs/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,8 @@ Logs are written to `logs-apm.error.*` indices.
575575
|error.exception.message|The original error message.|text| ![](https://doc-icons.s3.us-east-2.amazonaws.com/icon-no.png) |
576576
|error.exception.module|The module namespace of the original error.|keyword| ![](https://doc-icons.s3.us-east-2.amazonaws.com/icon-no.png) |
577577
|error.exception.type|The type of the original error, e.g. the Java exception class name.|keyword| ![](https://doc-icons.s3.us-east-2.amazonaws.com/icon-no.png) |
578-
|error.grouping\_key|GroupingKey of the logged error for use in grouping.|keyword| ![](https://doc-icons.s3.us-east-2.amazonaws.com/icon-no.png) |
578+
|error.grouping\_key|Hash of select properties of the logged error for grouping purposes.|keyword| ![](https://doc-icons.s3.us-east-2.amazonaws.com/icon-no.png) |
579+
|error.grouping\_name|Name to associate with an error group. Errors belonging to the same group (same grouping\_key) may have differing values for grouping\_name. Consumers may choose one arbitrarily.|keyword| ![](https://doc-icons.s3.us-east-2.amazonaws.com/icon-no.png) |
579580
|error.id|The ID of the error.|keyword| ![](https://doc-icons.s3.us-east-2.amazonaws.com/icon-yes.png) |
580581
|error.log.level|The severity of the record.|keyword| ![](https://doc-icons.s3.us-east-2.amazonaws.com/icon-no.png) |
581582
|error.log.logger\_name|The name of the logger instance used.|keyword| ![](https://doc-icons.s3.us-east-2.amazonaws.com/icon-no.png) |
@@ -667,6 +668,7 @@ Logs are written to `logs-apm.error.*` indices.
667668
},
668669
"error": {
669670
"grouping_key": "d6b3f958dfea98dc9ed2b57d5f0c48bb",
671+
"grouping_name": "Cannot read property 'baz' of undefined",
670672
"id": "0f0e9d67c1854d21a6f44673ed561ec8",
671673
"log": {
672674
"level": "custom log level",

changelogs/head.asciidoc

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ https://github.com/elastic/apm-server/compare/7.12\...master[View commits]
1818
* Add metricset.name field to metric docs {pull}4857[4857]
1919
* Add `apm-server.default_service_environment` config {pull}4861[4861]
2020
* Transaction histogram metrics are now recorded by default {pull}4882[4882]
21+
* Add `error.grouping_name` field to speed up error grouping aggregations {pull}4886[4886]
2122

2223
[float]
2324
==== Deprecated

docs/data/elasticsearch/generated/errors.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"error": {
1515
"grouping_key": "d6b3f958dfea98dc9ed2b57d5f0c48bb",
16+
"grouping_name": "Cannot read property 'baz' of undefined",
1617
"id": "0f0e9d67c1854d21a6f44673ed561ec8",
1718
"log": {
1819
"level": "custom log level",
@@ -195,6 +196,7 @@
195196
}
196197
],
197198
"grouping_key": "50f62f37edffc4630c6655ba3ecfcf46",
199+
"grouping_name": "My service could not talk to the database named foobar",
198200
"id": "5f0e9d64c1854d21a6f44673ed561ec8",
199201
"log": {
200202
"level": "warning",
@@ -430,6 +432,7 @@
430432
}
431433
],
432434
"grouping_key": "18f82051862e494727fa20e0adc15711",
435+
"grouping_name": null,
433436
"id": "7f0e9d68c1854d21a6f44673ed561ec8"
434437
},
435438
"event": {
@@ -518,6 +521,7 @@
518521
}
519522
],
520523
"grouping_key": "f6b5a2877d9b00d5b32b44c9db039f11",
524+
"grouping_name": "foo is not defined",
521525
"id": "8f0e9d68c1854d21a6f44673ed561ec8"
522526
},
523527
"event": {
@@ -586,4 +590,4 @@
586590
"us": 1494342245000000
587591
}
588592
}
589-
]
593+
]

docs/fields.asciidoc

+11-1
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,17 @@ type: keyword
11901190
*`error.grouping_key`*::
11911191
+
11921192
--
1193-
GroupingKey of the logged error for use in grouping.
1193+
Hash of select properties of the logged error for grouping purposes.
1194+
1195+
1196+
type: keyword
1197+
1198+
--
1199+
1200+
*`error.grouping_name`*::
1201+
+
1202+
--
1203+
Name to associate with an error group. Errors belonging to the same group (same grouping_key) may have differing values for grouping_name. Consumers may choose one arbitrarily.
11941204
11951205
11961206
type: keyword

include/fields.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ingest/pipeline/definition.json

+27
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
"pipeline": {
2424
"name": "apm_remove_span_metadata"
2525
}
26+
},
27+
{
28+
"pipeline": {
29+
"name": "apm_error_grouping_name",
30+
"if": "ctx.processor?.event == 'error'"
31+
}
2632
}
2733
]
2834
}
@@ -99,5 +105,26 @@
99105
}
100106
]
101107
}
108+
},
109+
{
110+
"id": "apm_error_grouping_name",
111+
"body": {
112+
"description" : "Set error.grouping_name for APM error events",
113+
"processors" : [
114+
{
115+
"script" : {
116+
"source": "ctx.error.grouping_name = ctx.error.exception[0].message",
117+
"if": "ctx.error?.exception?.length != null && ctx.error?.exception?.length > 0"
118+
}
119+
},
120+
{
121+
"set" : {
122+
"field": "error.grouping_name",
123+
"copy_from": "error.log.message",
124+
"if": "ctx.error?.log?.message != null"
125+
}
126+
}
127+
]
128+
}
102129
}
103130
]

model/error/_meta/fields.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,13 @@
769769
- name: grouping_key
770770
type: keyword
771771
description: >
772-
GroupingKey of the logged error for use in grouping.
772+
Hash of select properties of the logged error for grouping purposes.
773+
774+
- name: grouping_name
775+
type: keyword
776+
description: >
777+
Name to associate with an error group.
778+
Errors belonging to the same group (same grouping_key) may have differing values for grouping_name. Consumers may choose one arbitrarily.
773779
774780
- name: exception
775781
type: group

processor/stream/package_tests/error_attrs_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func errorFieldsNotInPayloadAttrs() *tests.Set {
5555
return tests.NewSet(
5656
"view errors", "error id icon",
5757
"host.ip", "transaction.name", "source.ip",
58+
"error.grouping_name", // added by ingest node
5859
tests.Group("event"),
5960
tests.Group("observer"),
6061
tests.Group("user"),
@@ -109,7 +110,8 @@ func errorCondRequiredKeys() map[string]tests.Condition {
109110
func errorKeywordExceptionKeys() *tests.Set {
110111
return tests.NewSet(
111112
"data_stream.type", "data_stream.dataset", "data_stream.namespace",
112-
"processor.event", "processor.name", "error.grouping_key",
113+
"processor.event", "processor.name",
114+
"error.grouping_key", "error.grouping_name",
113115
"context.tags", "transaction.name",
114116
"event.outcome", // not relevant
115117
"view errors", "error id icon",

systemtest/approvals/TestRUMErrorSourcemapping.approved.json

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
}
214214
],
215215
"grouping_key": "89e23da755c2dd759d2d529e37c92b8f",
216+
"grouping_name": "Uncaught Error: log timeout test error",
216217
"id": "aba2688e033848ce9c4e4005f1caa534",
217218
"log": {
218219
"message": "Uncaught Error: log timeout test error",

systemtest/elasticsearch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func newElasticsearchConfig() elasticsearch.Config {
9191
// and deletes the default ILM policy "apm-rollover-30-days".
9292
func CleanupElasticsearch(t testing.TB) {
9393
const (
94-
legacyPrefix = "apm-*"
94+
legacyPrefix = "apm*" // Not "apm-*", as that would not capture the "apm" ingest pipeline.
9595
apmTracesPrefix = "traces-apm*"
9696
apmMetricsPrefix = "metrics-apm*"
9797
apmLogsPrefix = "logs-apm*"

0 commit comments

Comments
 (0)