Skip to content

Commit

Permalink
[otel-plugin] Add aliases for spanevent/logrecord exceptions (elastic…
Browse files Browse the repository at this point in the history
…#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]>
(cherry picked from commit af7c81e)

# Conflicts:
#	x-pack/plugin/otel-data/src/main/resources/resources.yaml
  • Loading branch information
gregkalapos committed Oct 2, 2024
1 parent 0dc0965 commit 97b35bf
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ template:
field: [ "resource.attributes.host.name" ]
mappings:
properties:
attributes:
type: passthrough
dynamic: true
priority: 10
time_series_dimension: true
properties:
exception.type:
type: keyword
ignore_above: 1024
exception.message:
type: keyword
ignore_above: 1024
exception.stacktrace:
type: wildcard
fields:
text:
type: match_only_text
data_stream.type:
type: constant_keyword
value: logs
Expand Down Expand Up @@ -40,3 +57,12 @@ template:
span.id:
type: alias
path: span_id
error.exception.type:
type: alias
path: attributes.exception.type
error.exception.message:
type: alias
path: attributes.exception.message
error.stack_trace:
type: alias
path: attributes.exception.stacktrace
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
version: ${xpack.oteldata.template.version}
_meta:
description: Aliases from OpenTelemetry SemConv fields to ECS (and some non-ECS) fields
description: Aliases from OpenTelemetry SemConv resource attribute fields to ECS (and some non-ECS) fields
managed: true
template:
mappings:
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugin/otel-data/src/main/resources/resources.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# "version" holds the version of the templates and ingest pipelines installed
# by xpack-plugin otel-data. This must be increased whenever an existing template is
# changed, in order for it to be updated on Elasticsearch upgrade.
version: 1

version: 3
component-templates:
- otel@mappings
- logs-otel@mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,22 @@ setup:
- match: { hits.hits.0.fields.resource\.attributes\.host\.ip: ["0.0.0.0", "127.0.0.1"] }
- match: { hits.hits.0.fields.attributes\.foo: [1, 2, 3] }
- match: { hits.hits.0.fields.attributes\.bar: [a, b, c] }
---
"Exception aliases":
- do:
bulk:
index: logs-generic.otel-default
refresh: true
body:
- create: {}
- '{"@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"}'
- is_false: errors
- do:
search:
index: logs-generic.otel-default
body:
fields: ["error.exception.type", "error.exception.message", "error.stack_trace"]
- length: { hits.hits: 1 }
- match: { hits.hits.0.fields.error\.exception\.type: ["MyException"] }
- match: { hits.hits.0.fields.error\.exception\.message: ["foo"] }
- 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 comments on commit 97b35bf

Please sign in to comment.