Skip to content

Commit

Permalink
Include milliseconds in DataDog timestamp format [Refs #152] (#202)
Browse files Browse the repository at this point in the history
* Include milliseconds in DataDog timestamp format [Refs #152]

* Added changelog information [Refs #152]

* Added timezone to format string, fixed changelog. [Refs #152]

* Resolved conflict with new tests. [Refs #152]
  • Loading branch information
ladenedge authored Dec 5, 2023
1 parent 73b8f9d commit 97610b4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
11 changes: 11 additions & 0 deletions .chloggen/main.yaml
Original file line number Diff line number Diff line change
@@ -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]
3 changes: 1 addition & 2 deletions pkg/otlp/logs/logs_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions pkg/otlp/logs/logs_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 97610b4

Please sign in to comment.