opentelemetry-go-contrib icon indicating copy to clipboard operation
opentelemetry-go-contrib copied to clipboard

TraceIDRatioBased doesn't work with xray.NewIDGenerator

Open danilobuerger opened this issue 3 years ago • 1 comments

The first 4 bytes of an xray trace id are time based (https://docs.aws.amazon.com/xray/latest/devguide/xray-api-sendingdata.html#xray-api-traceids):

https://github.com/open-telemetry/opentelemetry-go-contrib/blob/ace6b3cdc1e7aa40f88b737e3a8a1f72d0a8fb60/propagators/aws/xray/idgenerator.go#L57-L59

When using TraceIDRatioBased, it compares the first 8 bytes to see if it should sample:

https://github.com/open-telemetry/opentelemetry-go/blob/569f7430726278f40e562f81e64d21156cc3edb9/sdk/trace/sampling.go#L84-L85

This assumes that the first 8 bytes are random, which they are not. So if the current time is above the upper bound it will never sample.

danilobuerger avatar Sep 07 '22 15:09 danilobuerger

This likely relates to the latest revision on IDs in the specification.

MrAlias avatar Apr 10 '25 17:04 MrAlias

As a fix traceIDRatioSampler could hash x to make it appear random.

x := binary.BigEndian.Uint64(p.TraceID[0:8]) >> 1
if x < ts.traceIDUpperBound {

AlexanderYastrebov avatar Oct 15 '25 14:10 AlexanderYastrebov