Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elasticapm: Default log.level:error for errors #362

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
}
Loading