From e9f234f8bbfb739fcdc8f700fc86eb12feb57bf4 Mon Sep 17 00:00:00 2001 From: jjllee Date: Fri, 4 Oct 2024 15:20:32 -0700 Subject: [PATCH 1/3] Ensure all XRay Sampler functionality is under ParentBased logic --- samplers/aws/xray/remote_sampler.go | 4 ++-- samplers/aws/xray/remote_sampler_test.go | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/samplers/aws/xray/remote_sampler.go b/samplers/aws/xray/remote_sampler.go index e3c277a5303..01b6da66c4f 100644 --- a/samplers/aws/xray/remote_sampler.go +++ b/samplers/aws/xray/remote_sampler.go @@ -46,7 +46,7 @@ type remoteSampler struct { // Compile time assertion that remoteSampler implements the Sampler interface. var _ sdktrace.Sampler = (*remoteSampler)(nil) -// NewRemoteSampler returns a sampler which decides to sample a given request or not +// NewRemoteSampler returns a ParentBased XRay Sampler which decides to sample a given request or not // based on the sampling rules set by users on AWS X-Ray console. Sampler also periodically polls // sampling rules and sampling targets. // NOTE: ctx passed in NewRemoteSampler API is being used in background go routine. Cancellation to this context can kill the background go routine. @@ -77,7 +77,7 @@ func NewRemoteSampler(ctx context.Context, serviceName string, cloudPlatform str remoteSampler.start(ctx) - return remoteSampler, nil + return sdktrace.ParentBased(remoteSampler), nil } // ShouldSample matches span attributes with retrieved sampling rules and returns a sampling result. diff --git a/samplers/aws/xray/remote_sampler_test.go b/samplers/aws/xray/remote_sampler_test.go index a71020abbe0..21c2a305a47 100644 --- a/samplers/aws/xray/remote_sampler_test.go +++ b/samplers/aws/xray/remote_sampler_test.go @@ -4,7 +4,10 @@ package xray import ( + "context" + "net/url" "testing" + "time" "github.com/stretchr/testify/assert" ) @@ -16,3 +19,11 @@ func TestRemoteSamplerDescription(t *testing.T) { s := rs.Description() assert.Equal(t, "AWSXRayRemoteSampler{remote sampling with AWS X-Ray}", s) } + +func TestNewRemoteSamplerDescription(t *testing.T) { + endpointUrl, _ := url.Parse("http://localhost:2000") + rs, _ := NewRemoteSampler(context.Background(), "otel-test", "", WithEndpoint(*endpointUrl), WithSamplingRulesPollingInterval(300*time.Second)) + + s := rs.Description() + assert.Equal(t, "ParentBased{root:AWSXRayRemoteSampler{remote sampling with AWS X-Ray},remoteParentSampled:AlwaysOnSampler,remoteParentNotSampled:AlwaysOffSampler,localParentSampled:AlwaysOnSampler,localParentNotSampled:AlwaysOffSampler}", s) +} From 54594a5f1ce71ff6a6db41f9c194644b2da2626a Mon Sep 17 00:00:00 2001 From: jjllee Date: Fri, 4 Oct 2024 15:57:40 -0700 Subject: [PATCH 2/3] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7a7bb3da4e..8e6de1aefa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Possible nil dereference panic in `go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace`. (#5965) - Non-200 HTTP status codes when retrieving sampling rules in `go.opentelemetry.io/contrib/samplers/aws/xray` now return an error. (#5718) +- Ensure all AWS XRay Remote Sampler logic is under a ParentBased Sampler in `go.opentelemetry.io/contrib/samplers/aws/xray`. (#6205) ### Removed From 80f4bb021300f65228b3c646d758a76d8ccbcd77 Mon Sep 17 00:00:00 2001 From: jjllee Date: Fri, 4 Oct 2024 16:29:08 -0700 Subject: [PATCH 3/3] update test var name --- samplers/aws/xray/remote_sampler_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samplers/aws/xray/remote_sampler_test.go b/samplers/aws/xray/remote_sampler_test.go index 21c2a305a47..411d38fb50e 100644 --- a/samplers/aws/xray/remote_sampler_test.go +++ b/samplers/aws/xray/remote_sampler_test.go @@ -21,8 +21,8 @@ func TestRemoteSamplerDescription(t *testing.T) { } func TestNewRemoteSamplerDescription(t *testing.T) { - endpointUrl, _ := url.Parse("http://localhost:2000") - rs, _ := NewRemoteSampler(context.Background(), "otel-test", "", WithEndpoint(*endpointUrl), WithSamplingRulesPollingInterval(300*time.Second)) + endpointURL, _ := url.Parse("http://localhost:2000") + rs, _ := NewRemoteSampler(context.Background(), "otel-test", "", WithEndpoint(*endpointURL), WithSamplingRulesPollingInterval(300*time.Second)) s := rs.Description() assert.Equal(t, "ParentBased{root:AWSXRayRemoteSampler{remote sampling with AWS X-Ray},remoteParentSampled:AlwaysOnSampler,remoteParentNotSampled:AlwaysOffSampler,localParentSampled:AlwaysOnSampler,localParentNotSampled:AlwaysOffSampler}", s)