Skip to content

Commit

Permalink
Ensure all XRay Sampler functionality is under ParentBased logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jj22ee committed Oct 4, 2024
1 parent 64a1336 commit e9f234f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions samplers/aws/xray/remote_sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions samplers/aws/xray/remote_sampler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
package xray

import (
"context"
"net/url"
"testing"
"time"

"github.com/stretchr/testify/assert"
)
Expand All @@ -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)
}

0 comments on commit e9f234f

Please sign in to comment.