diff --git a/input/elasticapm/internal/modeldecoder/rumv3/decoder.go b/input/elasticapm/internal/modeldecoder/rumv3/decoder.go index d4b40197..ac71ca57 100644 --- a/input/elasticapm/internal/modeldecoder/rumv3/decoder.go +++ b/input/elasticapm/internal/modeldecoder/rumv3/decoder.go @@ -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 } diff --git a/input/elasticapm/internal/modeldecoder/rumv3/error_test.go b/input/elasticapm/internal/modeldecoder/rumv3/error_test.go index 4e23ead8..4ae77f3c 100644 --- a/input/elasticapm/internal/modeldecoder/rumv3/error_test.go +++ b/input/elasticapm/internal/modeldecoder/rumv3/error_test.go @@ -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", }, @@ -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"}}) diff --git a/input/elasticapm/internal/modeldecoder/v2/decoder.go b/input/elasticapm/internal/modeldecoder/v2/decoder.go index b3a3faad..88d947f8 100644 --- a/input/elasticapm/internal/modeldecoder/v2/decoder.go +++ b/input/elasticapm/internal/modeldecoder/v2/decoder.go @@ -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 } diff --git a/input/elasticapm/internal/modeldecoder/v2/error_test.go b/input/elasticapm/internal/modeldecoder/v2/error_test.go index a65273b1..a9dca271 100644 --- a/input/elasticapm/internal/modeldecoder/v2/error_test.go +++ b/input/elasticapm/internal/modeldecoder/v2/error_test.go @@ -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"}}}` @@ -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) + }) }