From bfbafbee303bc1e4c11259a6b2f9f74d50ad0fa6 Mon Sep 17 00:00:00 2001 From: John Knollmeyer Date: Wed, 11 Oct 2023 17:19:23 -0700 Subject: [PATCH] Change the time used for X-Ray exception events to microsecond precision - 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 --- exporter/awsxrayexporter/internal/translator/cause.go | 8 ++++++-- .../awsxrayexporter/internal/translator/cause_test.go | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/exporter/awsxrayexporter/internal/translator/cause.go b/exporter/awsxrayexporter/internal/translator/cause.go index 074c07f8f0e3..36edb287c3b0 100644 --- a/exporter/awsxrayexporter/internal/translator/cause.go +++ b/exporter/awsxrayexporter/internal/translator/cause.go @@ -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{ diff --git a/exporter/awsxrayexporter/internal/translator/cause_test.go b/exporter/awsxrayexporter/internal/translator/cause_test.go index 47dfd866ff6a..0d9d4388ef7f 100644 --- a/exporter/awsxrayexporter/internal/translator/cause_test.go +++ b/exporter/awsxrayexporter/internal/translator/cause_test.go @@ -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() @@ -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]) }