Skip to content
Open
7 changes: 1 addition & 6 deletions exporter/awsxrayexporter/awsxray.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@ func newTracesExporter(ctx context.Context, cfg *Config, set exporter.Settings,
documents := extractResourceSpans(cfg, logger, td)

for offset := 0; offset < len(documents); offset += maxSegmentsPerPut {
var nextOffset int
if offset+maxSegmentsPerPut > len(documents) {
nextOffset = len(documents)
} else {
nextOffset = offset + maxSegmentsPerPut
}
nextOffset := min(offset+maxSegmentsPerPut, len(documents))
input := &xray.PutTraceSegmentsInput{TraceSegmentDocuments: documents[offset:nextOffset]}
logger.Debug("request: " + fmt.Sprintf("%+v", input))
output, localErr := xrayClient.PutTraceSegments(ctx, input)
Expand Down
4 changes: 3 additions & 1 deletion exporter/awsxrayexporter/awsxray_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ func TestXrayAndW3CSpanTraceExport(t *testing.T) {
}

func TestXrayAndW3CSpanTraceResourceExtraction(t *testing.T) {
setSkipTimestampValidation(t, true)
td := constructXrayAndW3CSpanData()
logger, _ := zap.NewProduction()
assert.Len(t, extractResourceSpans(generateConfig(t), logger, td), 4, "4 spans have xray/w3c trace id")
}

func TestW3CSpanTraceResourceExtraction(t *testing.T) {
setSkipTimestampValidation(t, true)
td := constructW3CSpanData()
logger, _ := zap.NewProduction()
assert.Len(t, extractResourceSpans(generateConfig(t), logger, td), 2, "2 spans have w3c trace id")
Expand Down Expand Up @@ -95,7 +97,7 @@ func TestTelemetryEnabled(t *testing.T) {

func BenchmarkForTracesExporter(b *testing.B) {
traceExporter := initializeTracesExporter(b, generateConfig(b), telemetrytest.NewNopRegistry())
for i := 0; i < b.N; i++ {
for b.Loop() {
b.StopTimer()
ctx := b.Context()
td := constructSpanData()
Expand Down
10 changes: 10 additions & 0 deletions exporter/awsxrayexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil"
)

func setSkipTimestampValidation(tb testing.TB, value bool) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this test failing intermittently before? not sure i understand why the refactor in this PR would have caused the tests to fail where they hadn't before 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failure was not caused by this PR. I can reproduce it locally directly from the main branch. 🤔

I ran gotestsum as make run-changed-tests was doing nothing.

❯ ../../.tools/gotestsum --packages="./..." -- -race -timeout 900s -parallel 4 -count=3
∅  internal/metadata
✓  internal/translator (1.647s)
✖  . (3.537s)

=== Failed
=== FAIL: . TestXrayAndW3CSpanTraceResourceExtraction (0.00s)
    awsxray_test.go:58:
        	Error Trace:	/repos/opentelemetry-collector-contrib/exporter/awsxrayexporter/awsxray_test.go:58
        	Error:      	"[{"name":"/users/junit","id":"0d226912b0c77a4f","start_time":1760650419,"service":{"version":"v1"},"trace_id":"1-68f1650c-ebf18704c6a03c6866925d7d","end_time":1760650509,"http":{"request":{"method":"GET","url":"https://api.example.com/users/junit"},"response":{"status":200,"content_length":0}},"fault":false,"error":false,"throttle":false,"aws":{"xray":{"auto_instrumentation":false},"account_id":"999999998"},"namespace":"remote","parent_id":"1153bc3dcdac2878","type":"subsegment"}
        	            	 {"name":"signup_aggregator","id":"a1cce7188fd5b544","start_time":1760650419,"service":{"version":"v1"},"trace_id":"1-68f1650c-f848e39bd59de27743b1dea3","end_time":1760650509,"http":{"request":{"x_forwarded_for":true,"method":"GET","url":"https://api.example.com/users/junit","client_ip":"192.168.15.32"},"response":{"status":200,"content_length":0}},"fault":false,"error":false,"throttle":false,"aws":{"xray":{"auto_instrumentation":false},"account_id":"999999998"},"metadata":{"default":{"otel.resource.cloud.account.id":"999999998","otel.resource.cloud.availability_zone":"us-west-1b","otel.resource.cloud.provider":"aws","otel.resource.cloud.region":"us-west-2","otel.resource.container.image.name":"otel/signupaggregator","otel.resource.container.image.tag":"v1","otel.resource.container.name":"signup_aggregator","otel.resource.service.name":"signup_aggregator"}},"parent_id":"f7b0b80664736000"}
        	            	]" should have 4 item(s), but has 2
        	Test:       	TestXrayAndW3CSpanTraceResourceExtraction
        	Messages:   	4 spans have xray/w3c trace id

=== FAIL: . TestW3CSpanTraceResourceExtraction (0.00s)
    awsxray_test.go:64:
        	Error Trace:	/repos/opentelemetry-collector-contrib/exporter/awsxrayexporter/awsxray_test.go:64
        	Error:      	"[]" should have 2 item(s), but has 0
        	Test:       	TestW3CSpanTraceResourceExtraction
        	Messages:   	2 spans have w3c trace id

=== FAIL: . TestCreateDefaultConfig (0.00s)
    factory_test.go:25:
        	Error Trace:	/repos/opentelemetry-collector-contrib/exporter/awsxrayexporter/factory_test.go:25
        	Error:      	Not equal:
        	            	expected: &awsxrayexporter.Config{AWSSessionSettings:awsutil.AWSSessionSettings{NumberOfWorkers:8, Endpoint:"", RequestTimeoutSeconds:30, MaxRetries:2, NoVerifySSL:false, ProxyAddress:"", Region:"", LocalMode:false, ResourceARN:"", RoleARN:"", ExternalID:""}, IndexedAttributes:[]string(nil), IndexAllAttributes:false, LogGroupNames:[]string(nil), TelemetryConfig:telemetry.Config{Enabled:false, IncludeMetadata:false, Contributors:[]component.ID(nil), Hostname:"", InstanceID:"", ResourceARN:""}, skipTimestampValidation:true}
        	            	actual  : &awsxrayexporter.Config{AWSSessionSettings:awsutil.AWSSessionSettings{NumberOfWorkers:8, Endpoint:"", RequestTimeoutSeconds:30, MaxRetries:2, NoVerifySSL:false, ProxyAddress:"", Region:"", LocalMode:false, ResourceARN:"", RoleARN:"", ExternalID:""}, IndexedAttributes:[]string(nil), IndexAllAttributes:false, LogGroupNames:[]string(nil), TelemetryConfig:telemetry.Config{Enabled:false, IncludeMetadata:false, Contributors:[]component.ID(nil), Hostname:"", InstanceID:"", ResourceARN:""}, skipTimestampValidation:false}

        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -25,3 +25,3 @@
        	            	  },
        	            	- skipTimestampValidation: (bool) true
        	            	+ skipTimestampValidation: (bool) false
        	            	 })
        	Test:       	TestCreateDefaultConfig
        	Messages:   	failed to create default config

=== FAIL: . TestXrayAndW3CSpanTraceResourceExtraction (0.00s)
    awsxray_test.go:58:
        	Error Trace:	/repos/opentelemetry-collector-contrib/exporter/awsxrayexporter/awsxray_test.go:58
        	Error:      	"[{"name":"/users/junit","id":"b236dfe5ad9cdf1a","start_time":1760650420,"service":{"version":"v1"},"trace_id":"1-68f1650d-fbafea511c2afcd12d12db97","end_time":1760650510,"http":{"request":{"method":"GET","url":"https://api.example.com/users/junit"},"response":{"status":200,"content_length":0}},"fault":false,"error":false,"throttle":false,"aws":{"xray":{"auto_instrumentation":false},"account_id":"999999998"},"namespace":"remote","parent_id":"0774bff62361e3c1","type":"subsegment"}
        	            	 {"name":"signup_aggregator","id":"a6d7b4df40b42490","start_time":1760650420,"service":{"version":"v1"},"trace_id":"1-68f1650d-421f8106364c110886bab0d2","end_time":1760650510,"http":{"request":{"x_forwarded_for":true,"method":"GET","url":"https://api.example.com/users/junit","client_ip":"192.168.15.32"},"response":{"status":200,"content_length":0}},"fault":false,"error":false,"throttle":false,"aws":{"xray":{"auto_instrumentation":false},"account_id":"999999998"},"metadata":{"default":{"otel.resource.cloud.account.id":"999999998","otel.resource.cloud.availability_zone":"us-west-1b","otel.resource.cloud.provider":"aws","otel.resource.cloud.region":"us-west-2","otel.resource.container.image.name":"otel/signupaggregator","otel.resource.container.image.tag":"v1","otel.resource.container.name":"signup_aggregator","otel.resource.service.name":"signup_aggregator"}},"parent_id":"5b2ae7c011354d24"}
        	            	]" should have 4 item(s), but has 2
        	Test:       	TestXrayAndW3CSpanTraceResourceExtraction
        	Messages:   	4 spans have xray/w3c trace id

=== FAIL: . TestW3CSpanTraceResourceExtraction (0.00s)
    awsxray_test.go:64:
        	Error Trace:	/repos/opentelemetry-collector-contrib/exporter/awsxrayexporter/awsxray_test.go:64
        	Error:      	"[]" should have 2 item(s), but has 0
        	Test:       	TestW3CSpanTraceResourceExtraction
        	Messages:   	2 spans have w3c trace id

=== FAIL: . TestCreateDefaultConfig (0.00s)
    factory_test.go:25:
        	Error Trace:	/repos/opentelemetry-collector-contrib/exporter/awsxrayexporter/factory_test.go:25
        	Error:      	Not equal:
        	            	expected: &awsxrayexporter.Config{AWSSessionSettings:awsutil.AWSSessionSettings{NumberOfWorkers:8, Endpoint:"", RequestTimeoutSeconds:30, MaxRetries:2, NoVerifySSL:false, ProxyAddress:"", Region:"", LocalMode:false, ResourceARN:"", RoleARN:"", ExternalID:""}, IndexedAttributes:[]string(nil), IndexAllAttributes:false, LogGroupNames:[]string(nil), TelemetryConfig:telemetry.Config{Enabled:false, IncludeMetadata:false, Contributors:[]component.ID(nil), Hostname:"", InstanceID:"", ResourceARN:""}, skipTimestampValidation:true}
        	            	actual  : &awsxrayexporter.Config{AWSSessionSettings:awsutil.AWSSessionSettings{NumberOfWorkers:8, Endpoint:"", RequestTimeoutSeconds:30, MaxRetries:2, NoVerifySSL:false, ProxyAddress:"", Region:"", LocalMode:false, ResourceARN:"", RoleARN:"", ExternalID:""}, IndexedAttributes:[]string(nil), IndexAllAttributes:false, LogGroupNames:[]string(nil), TelemetryConfig:telemetry.Config{Enabled:false, IncludeMetadata:false, Contributors:[]component.ID(nil), Hostname:"", InstanceID:"", ResourceARN:""}, skipTimestampValidation:false}

        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -25,3 +25,3 @@
        	            	  },
        	            	- skipTimestampValidation: (bool) true
        	            	+ skipTimestampValidation: (bool) false
        	            	 })
        	Test:       	TestCreateDefaultConfig
        	Messages:   	failed to create default config

DONE 594 tests, 6 failures in 3.537s

tb.Helper()
prev := skipTimestampValidationFeatureGate.IsEnabled()
require.NoError(tb, featuregate.GlobalRegistry().Set(skipTimestampValidationFeatureGate.ID(), value))
tb.Cleanup(func() {
require.NoError(tb, featuregate.GlobalRegistry().Set(skipTimestampValidationFeatureGate.ID(), prev))
})
}

func TestCreateDefaultConfig(t *testing.T) {
setSkipTimestampValidation(t, true)
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.Equal(t, &Config{
Expand Down
13 changes: 6 additions & 7 deletions exporter/awsxrayexporter/internal/translator/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"maps"
"net/url"
"regexp"
"strings"
Expand Down Expand Up @@ -684,9 +685,7 @@ func makeXRayAttributes(attributes map[string]pcommon.Value, resource pcommon.Re
// if unable to unmarshal, keep the original key/value
defaultMetadata[key] = value.Str()
case strings.EqualFold(namespace, defaultMetadataNamespace):
for k, v := range metaVal {
defaultMetadata[k] = v
}
maps.Copy(defaultMetadata, metaVal)
default:
metadata[namespace] = metaVal
}
Expand Down Expand Up @@ -758,10 +757,10 @@ func fixAnnotationKey(key string) string {

func trimAwsSdkPrefix(name string, span ptrace.Span) string {
if isAwsSdkSpan(span) {
if strings.HasPrefix(name, "AWS.SDK.") {
return strings.TrimPrefix(name, "AWS.SDK.")
} else if strings.HasPrefix(name, "AWS::") {
return strings.TrimPrefix(name, "AWS::")
if after, ok := strings.CutPrefix(name, "AWS.SDK."); ok {
return after
} else if after, ok := strings.CutPrefix(name, "AWS::"); ok {
return after
}
}
return name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestWriterPoolBasic(t *testing.T) {

func BenchmarkWithoutPool(b *testing.B) {
logger := zap.NewNop()
for i := 0; i < b.N; i++ {
for b.Loop() {
b.StopTimer()
span := constructWriterPoolSpan()
b.StartTimer()
Expand All @@ -53,7 +53,7 @@ func BenchmarkWithoutPool(b *testing.B) {
func BenchmarkWithPool(b *testing.B) {
logger := zap.NewNop()
wp := newWriterPool(2048)
for i := 0; i < b.N; i++ {
for b.Loop() {
b.StopTimer()
span := constructWriterPoolSpan()
b.StartTimer()
Expand Down