Skip to content

Commit

Permalink
Add @timestamp as sort field for logs and traces
Browse files Browse the repository at this point in the history
  • Loading branch information
gregkalapos committed Oct 4, 2024
1 parent 4d59064 commit d11548a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ template:
index:
mode: logsdb
sort:
field: [ "resource.attributes.host.name" ]
field: [ "@timestamp", "resource.attributes.host.name" ]
mappings:
properties:
attributes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ template:
index:
mode: logsdb
sort:
field: [ "resource.attributes.host.name" ]
field: [ "@timestamp", "resource.attributes.host.name" ]
mappings:
_source:
mode: synthetic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,24 @@ setup:
- 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)"] }
---
"@timestamp should be used as sort field":
- do:
bulk:
index: logs-generic.otel-default
refresh: true
body:
- create: {}
- '{"@timestamp":"2024-07-18T14:49:33.467654000Z","data_stream":{"dataset":"generic.otel","namespace":"default"}, "body_text":"error2"}'
- create: {}
- '{"@timestamp":"2024-07-18T14:48:33.467654000Z","data_stream":{"dataset":"generic.otel","namespace":"default"}, "body_text":"error1"}'

- is_false: errors
- do:
search:
index: logs-generic.otel-default
body:
fields: ["body_text"]
- length: { hits.hits: 2 }
- match: { hits.hits.0.fields.body_text: ["error1"] }
- match: { hits.hits.1.fields.body_text: ["error2"] }
Original file line number Diff line number Diff line change
Expand Up @@ -76,44 +76,48 @@ setup:
- match: { hits.hits.0._source.links.1.trace_id: "4aaa9f33312b3dbb8b2c2c62bb7abe1a1" }
- match: { hits.hits.0._source.links.1.span_id: "b3b7d1f1f1b4e1e1" }
---
"Default data_stream.type must be traces":
Conflicting attribute types:
- do:
bulk:
index: traces-generic.otel-default
refresh: true
body:
- create: {}
- '{"@timestamp":"2024-02-18T14:48:33.467654000Z","data_stream":{"dataset":"generic.otel","type":"traces","namespace":"default"},"resource":{"attributes":{"service.name":"OtelSample","telemetry.sdk.language":"dotnet","telemetry.sdk.name":"opentelemetry"}},"name":"foo","trace_id":"7bba9f33312b3dbb8b2c2c62bb7abe2d","span_id":"086e83747d0e381e","kind":"SERVER","status":{"code":"2xx"}}'
- "@timestamp": 2024-10-04T00:00:00
attributes:
http.status_code: 200
- create: {}
- "@timestamp": 2024-10-04T01:00:00
attributes:
http.status_code: "foo"
- is_false: errors
- do:
search:
index: traces-generic.otel-default
body:
fields: ["data_stream.type"]
- length: { hits.hits: 1 }
- match: { hits.hits.0.fields.data_stream\.type: ["traces"] }
fields: ["*"]
"sort" : [ "@timestamp" ]
- length: { hits.hits: 2 }
- match: { hits.hits.0.fields.attributes\.http\.status_code: [200] }
- match: { hits.hits.1._ignored: ["attributes.http.status_code"] }
---
Conflicting attribute types:
"@timestamp should be used as sort field":
- do:
bulk:
index: traces-generic.otel-default
refresh: true
body:
- create: {}
- "@timestamp": 2024-10-04T00:00:00
attributes:
http.status_code: 200
- '{"@timestamp":"2024-07-18T14:49:33.467654000Z","data_stream":{"dataset":"generic.otel","namespace":"default"}, "span_id":"2"}'
- create: {}
- "@timestamp": 2024-10-04T01:00:00
attributes:
http.status_code: "foo"
- '{"@timestamp":"2024-07-18T14:48:33.467654000Z","data_stream":{"dataset":"generic.otel","namespace":"default"}, "span_id":"1"}'

- is_false: errors
- do:
search:
index: traces-generic.otel-default
body:
fields: ["*"]
"sort" : [ "@timestamp" ]
fields: ["span_id"]
- length: { hits.hits: 2 }
- match: { hits.hits.0.fields.attributes\.http\.status_code: [200] }
- match: { hits.hits.1._ignored: ["attributes.http.status_code"] }
- match: { hits.hits.0.fields.span_id: ["1"] }
- match: { hits.hits.1.fields.span_id: ["2"] }

0 comments on commit d11548a

Please sign in to comment.