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 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..411d38fb50e 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) +}