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

Include milliseconds in DataDog timestamp format [Refs #152] #202

Merged
merged 6 commits into from
Dec 5, 2023
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
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
Loading