Skip to content

Commit

Permalink
Change the time used for X-Ray exception events to microsecond precision
Browse files Browse the repository at this point in the history
- This matches X-Ray guidance for timestamps - "Microsecond reoslution is recommended when available" https://docs.aws.amazon.com/xray/latest/devguide/xray-api-segmentdocuments.html#api-segmentdocuments-fields
  • Loading branch information
jknollmeyer committed Oct 12, 2023
1 parent 7a8d8a6 commit bfbafbe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions exporter/awsxrayexporter/internal/translator/cause.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ 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 {
eventEpochTime := event.Timestamp().AsTime().Unix()
strs := []string{errorCode.AsString(), strconv.FormatUint(uint64(eventEpochTime), 10), errorMessage.Str()}
eventEpochTime := event.Timestamp().AsTime().UnixMicro()
strs := []string{
errorCode.AsString(),
strconv.FormatFloat(float64(eventEpochTime)/1_000_000, 'f', 6, 64),
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.Unix(1696954760, 0))
timestamp := pcommon.NewTimestampFromTime(time.UnixMicro(1696954761000001))
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, "1696954760", messageParts[1])
assert.Equal(t, "1696954761.000001", messageParts[1])
assert.Equal(t, "service is temporarily unavailable", messageParts[2])
}

Expand Down

0 comments on commit bfbafbe

Please sign in to comment.