Skip to content

Commit

Permalink
[exporter/elasticsearch] Add test case for de-dotting log documents (o…
Browse files Browse the repository at this point in the history
…pen-telemetry#32134)

This PR adds a test case to ensure that log documents are de-dotted
correctly when `dedot: true` is set.
  • Loading branch information
ycombinator committed Apr 3, 2024
1 parent 1c95073 commit 7c9bb8b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions exporter/elasticsearchexporter/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var expectedSpanBody = `{"@timestamp":"2023-04-19T03:04:05.000000006Z","Attribut
var expectedLogBody = `{"@timestamp":"2023-04-19T03:04:05.000000006Z","Attributes.log-attr1":"value1","Body":"log-body","Resource.key1":"value1","Scope.name":"","Scope.version":"","SeverityNumber":0,"TraceFlags":0}`

var expectedLogBodyWithEmptyTimestamp = `{"@timestamp":"1970-01-01T00:00:00.000000000Z","Attributes.log-attr1":"value1","Body":"log-body","Resource.key1":"value1","Scope.name":"","Scope.version":"","SeverityNumber":0,"TraceFlags":0}`
var expectedLogBodyDeDottedWithEmptyTimestamp = `{"@timestamp":"1970-01-01T00:00:00.000000000Z","Attributes":{"log-attr1":"value1"},"Body":"log-body","Resource":{"foo":{"bar":"baz"},"key1":"value1"},"Scope":{"name":"","version":""},"SeverityNumber":0,"TraceFlags":0}`

func TestEncodeSpan(t *testing.T) {
model := &encodeModel{dedup: true, dedot: false}
Expand All @@ -49,6 +50,15 @@ func TestEncodeLog(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, expectedLogBodyWithEmptyTimestamp, string(logByte))
})

t.Run("dedot true", func(t *testing.T) {
model := &encodeModel{dedup: true, dedot: true}
td := mockResourceLogs()
td.Resource().Attributes().PutStr("foo.bar", "baz")
logByte, err := model.encodeLog(td.Resource(), td.ScopeLogs().At(0).LogRecords().At(0), td.ScopeLogs().At(0).Scope())
require.NoError(t, err)
require.Equal(t, expectedLogBodyDeDottedWithEmptyTimestamp, string(logByte))
})
}

func mockResourceSpans() ptrace.Traces {
Expand Down

0 comments on commit 7c9bb8b

Please sign in to comment.