Skip to content

Commit

Permalink
elasticapm: Default log.level:error for errors
Browse files Browse the repository at this point in the history
Updates the decoder to set the default log.level to error for errors. It
only applies to the Elastic APM Intake protocol.

Signed-off-by: Marc Lopez Rubio <[email protected]>
  • Loading branch information
marclop committed Sep 9, 2024
1 parent 2f0f99a commit 81e4689
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion input/elasticapm/internal/modeldecoder/rumv3/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func mapToErrorModel(from *errorEvent, event *modelpb.APMEvent) {
out.Id = from.ID.Val
}
if from.Log.IsSet() {
log := modelpb.ErrorLog{}
log := modelpb.ErrorLog{Level: "error"}
if from.Log.Level.IsSet() {
log.Level = from.Log.Level.Val
}
Expand Down
10 changes: 10 additions & 0 deletions input/elasticapm/internal/modeldecoder/rumv3/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestDecodeNestedError(t *testing.T) {
assert.Empty(t, cmp.Diff(&modelpb.Error{
Id: "a-b-c",
Log: &modelpb.ErrorLog{
Level: "error",
Message: "abc",
LoggerName: "default",
},
Expand Down Expand Up @@ -191,6 +192,15 @@ func TestDecodeMapToErrorModel(t *testing.T) {
assert.Equal(t, "default", out.Error.Log.LoggerName)
})

t.Run("logLevel", func(t *testing.T) {
var input errorEvent
input.Log.Level.Set("warn")
var out modelpb.APMEvent
mapToErrorModel(&input, &out)
require.NotNil(t, out.Error.Log.Level)
assert.Equal(t, "warn", out.Error.Log.Level)
})

t.Run("http-headers", func(t *testing.T) {
var input errorEvent
input.Context.Request.Headers.Set(http.Header{"a": []string{"b"}, "c": []string{"d", "e"}})
Expand Down
2 changes: 1 addition & 1 deletion input/elasticapm/internal/modeldecoder/v2/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func mapToErrorModel(from *errorEvent, event *modelpb.APMEvent) {
out.Id = from.ID.Val
}
if from.Log.IsSet() {
log := modelpb.ErrorLog{}
log := modelpb.ErrorLog{Level: "error"}
if from.Log.Level.IsSet() {
log.Level = from.Log.Level.Val
}
Expand Down
11 changes: 10 additions & 1 deletion input/elasticapm/internal/modeldecoder/v2/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestDecodeNestedError(t *testing.T) {
assert.Equal(t, modelpb.FromTime(time.Unix(1599996822, 281000000)), batch[0].Timestamp)
assert.Empty(t, cmp.Diff(&modelpb.Error{
Id: "a-b-c",
Log: &modelpb.ErrorLog{Message: "abc"},
Log: &modelpb.ErrorLog{Level: "error", Message: "abc"},
}, batch[0].Error, protocmp.Transform()))

str = `{"error":{"id":"a-b-c","log":{"message":"abc"},"context":{"experimental":"exp"}}}`
Expand Down Expand Up @@ -245,4 +245,13 @@ func TestDecodeMapToErrorModel(t *testing.T) {
assert.Equal(t, "1234", out.Transaction.Id)
assert.Equal(t, "1234", out.Span.Id)
})

t.Run("log.level", func(t *testing.T) {
var input errorEvent
input.Log.Level.Set("warn")
var out modelpb.APMEvent
mapToErrorModel(&input, &out)
require.NotNil(t, out.Error.Log.Level)
assert.Equal(t, "warn", out.Error.Log.Level)
})
}

0 comments on commit 81e4689

Please sign in to comment.