diff --git a/.chloggen/main.yaml b/.chloggen/main.yaml new file mode 100644 index 00000000..a393f7bb --- /dev/null +++ b/.chloggen/main.yaml @@ -0,0 +1,11 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component (e.g. pkg/quantile) +component: pkg/otlp/logs + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: DataDog log timestamp (ie. '@timestamp') now includes milliseconds. + +# The PR related to this change +issues: [152] diff --git a/pkg/otlp/logs/logs_translator.go b/pkg/otlp/logs/logs_translator.go index d4ce845a..0d9f12a1 100644 --- a/pkg/otlp/logs/logs_translator.go +++ b/pkg/otlp/logs/logs_translator.go @@ -19,7 +19,6 @@ import ( "encoding/hex" "strconv" "strings" - "time" "github.com/DataDog/datadog-api-client-go/v2/api/datadog" "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" @@ -159,7 +158,7 @@ func Transform(lr plog.LogRecord, res pcommon.Resource, logger *zap.Logger) data if lr.Timestamp() != 0 { // we are retaining the nano second precision in this property l.AdditionalProperties[otelTimestamp] = strconv.FormatInt(lr.Timestamp().AsTime().UnixNano(), 10) - l.AdditionalProperties[ddTimestamp] = lr.Timestamp().AsTime().Format(time.RFC3339) + l.AdditionalProperties[ddTimestamp] = lr.Timestamp().AsTime().Format("2006-01-02T15:04:05.000Z07:00") } if l.Message == "" { // set the Message to the Body in case it wasn't already parsed as part of the attributes diff --git a/pkg/otlp/logs/logs_translator_test.go b/pkg/otlp/logs/logs_translator_test.go index e81f7387..751aaea2 100644 --- a/pkg/otlp/logs/logs_translator_test.go +++ b/pkg/otlp/logs/logs_translator_test.go @@ -554,6 +554,31 @@ func TestTransform(t *testing.T) { }, }, }, + { + name: "Timestamps are formatted properly", + args: args{ + lr: func() plog.LogRecord { + l := plog.NewLogRecord() + l.SetTimestamp(pcommon.Timestamp(uint64(1700499303397000000))) + l.SetSeverityNumber(5) + return l + }(), + res: func() pcommon.Resource { + r := pcommon.NewResource() + return r + }(), + }, + want: datadogV2.HTTPLogItem{ + Ddtags: datadog.PtrString(""), + Message: *datadog.PtrString(""), + AdditionalProperties: map[string]string{ + "status": "debug", + otelSeverityNumber: "5", + ddTimestamp: "2023-11-20T16:55:03.397Z", + otelTimestamp: "1700499303397000000", + }, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {