Skip to content

Commit af7c81e

Browse files
[otel-plugin] Add aliases for spanevent/logrecord exceptions (#113636)
* Add tests for exceptions * Adapt aliases and move into a separate file * Clarify description in alias files * Handling stacktrace * Move error aliases to [email protected] * Update resources.yaml --------- Co-authored-by: Elastic Machine <[email protected]>
1 parent 9a65282 commit af7c81e

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

x-pack/plugin/otel-data/src/main/resources/component-templates/[email protected]

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,23 @@ template:
1111
field: [ "resource.attributes.host.name" ]
1212
mappings:
1313
properties:
14+
attributes:
15+
type: passthrough
16+
dynamic: true
17+
priority: 10
18+
time_series_dimension: true
19+
properties:
20+
exception.type:
21+
type: keyword
22+
ignore_above: 1024
23+
exception.message:
24+
type: keyword
25+
ignore_above: 1024
26+
exception.stacktrace:
27+
type: wildcard
28+
fields:
29+
text:
30+
type: match_only_text
1431
data_stream.type:
1532
type: constant_keyword
1633
value: logs
@@ -40,3 +57,12 @@ template:
4057
span.id:
4158
type: alias
4259
path: span_id
60+
error.exception.type:
61+
type: alias
62+
path: attributes.exception.type
63+
error.exception.message:
64+
type: alias
65+
path: attributes.exception.message
66+
error.stack_trace:
67+
type: alias
68+
path: attributes.exception.stacktrace

x-pack/plugin/otel-data/src/main/resources/component-templates/[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
version: ${xpack.oteldata.template.version}
33
_meta:
4-
description: Aliases from OpenTelemetry SemConv fields to ECS (and some non-ECS) fields
4+
description: Aliases from OpenTelemetry SemConv resource attribute fields to ECS (and some non-ECS) fields
55
managed: true
66
template:
77
mappings:

x-pack/plugin/otel-data/src/main/resources/resources.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# "version" holds the version of the templates and ingest pipelines installed
22
# by xpack-plugin otel-data. This must be increased whenever an existing template is
33
# changed, in order for it to be updated on Elasticsearch upgrade.
4-
version: 2
4+
version: 3
55

66
component-templates:
77
- otel@mappings

x-pack/plugin/otel-data/src/yamlRestTest/resources/rest-api-spec/test/20_logs_tests.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,22 @@ setup:
5151
- match: { hits.hits.0.fields.resource\.attributes\.host\.ip: ["0.0.0.0", "127.0.0.1"] }
5252
- match: { hits.hits.0.fields.attributes\.foo: [1, 2, 3] }
5353
- match: { hits.hits.0.fields.attributes\.bar: [a, b, c] }
54+
---
55+
"Exception aliases":
56+
- do:
57+
bulk:
58+
index: logs-generic.otel-default
59+
refresh: true
60+
body:
61+
- create: {}
62+
- '{"@timestamp":"2024-07-18T14:48:33.467654000Z","data_stream":{"dataset":"generic.otel","namespace":"default"}, "attributes": { "exception.type": "MyException", "exception.message": "foo", "exception.stacktrace": "Exception in thread \"main\" java.lang.RuntimeException: Test exception\n at com.example.GenerateTrace.methodB(GenerateTrace.java:13)\n at com.example.GenerateTrace.methodA(GenerateTrace.java:9)\n at com.example.GenerateTrace.main(GenerateTrace.java:5)" },"trace_id":"abc123xyz456def789ghi012jkl345"}'
63+
- is_false: errors
64+
- do:
65+
search:
66+
index: logs-generic.otel-default
67+
body:
68+
fields: ["error.exception.type", "error.exception.message", "error.stack_trace"]
69+
- length: { hits.hits: 1 }
70+
- match: { hits.hits.0.fields.error\.exception\.type: ["MyException"] }
71+
- match: { hits.hits.0.fields.error\.exception\.message: ["foo"] }
72+
- match: { hits.hits.0.fields.error\.stack_trace: ["Exception in thread \"main\" java.lang.RuntimeException: Test exception\n at com.example.GenerateTrace.methodB(GenerateTrace.java:13)\n at com.example.GenerateTrace.methodA(GenerateTrace.java:9)\n at com.example.GenerateTrace.main(GenerateTrace.java:5)"] }

0 commit comments

Comments
 (0)