Skip to content

Commit

Permalink
Change the time used for X-Ray exception events to unix epoch time
Browse files Browse the repository at this point in the history
- timestamp.String() generates a string like "2023-10-10 01:58:24.675761 +0000 UTC", which is not a standardized format
- Under the hood, it is just calling AsTime().String() https://github.com/open-telemetry/opentelemetry-collector/blob/pdata/v0.66.0/pdata/pcommon/timestamp.go#L36
- Time.String() has the warning "The returned string is meant for debugging; for a stable serialized representation, use t.MarshalText, t.MarshalBinary, or t.Format with an explicit format string." https://pkg.go.dev/time#Time.String
  • Loading branch information
jknollmeyer committed Oct 10, 2023
1 parent e846069 commit 1c22163
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions exporter/awsxrayexporter/internal/translator/cause.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func makeCause(span ptrace.Span, attributes map[string]pcommon.Value, resource p
errorCode, ok1 := event.Attributes().Get(AwsIndividualHTTPErrorCodeAttr)
errorMessage, ok2 := event.Attributes().Get(AwsIndividualHTTPErrorMsgAttr)
if ok1 && ok2 {
timestamp := event.Timestamp().String()
strs := []string{errorCode.AsString(), timestamp, errorMessage.Str()}
eventEpochTime := event.Timestamp().AsTime().Unix()
strs := []string{errorCode.AsString(), strconv.FormatUint(uint64(eventEpochTime), 10), errorMessage.Str()}
message = strings.Join(strs, "@")
segmentID := newSegmentID()
exception := awsxray.Exception{
Expand Down
4 changes: 2 additions & 2 deletions exporter/awsxrayexporter/internal/translator/cause_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestMakeCauseAwsSdkSpan(t *testing.T) {
event1.SetName(AwsIndividualHTTPEventName)
event1.Attributes().PutStr(AwsIndividualHTTPErrorCodeAttr, "503")
event1.Attributes().PutStr(AwsIndividualHTTPErrorMsgAttr, "service is temporarily unavailable")
timestamp := pcommon.NewTimestampFromTime(time.Now())
timestamp := pcommon.NewTimestampFromTime(time.Unix(1696954760, 0))
event1.SetTimestamp(timestamp)

res := pcommon.NewResource()
Expand All @@ -88,7 +88,7 @@ func TestMakeCauseAwsSdkSpan(t *testing.T) {

messageParts := strings.SplitN(*exception.Message, "@", 3)
assert.Equal(t, "503", messageParts[0])
assert.Equal(t, timestamp.String(), messageParts[1])
assert.Equal(t, "1696954760", messageParts[1])
assert.Equal(t, "service is temporarily unavailable", messageParts[2])
}

Expand Down

0 comments on commit 1c22163

Please sign in to comment.