opentelemetry-go-contrib
opentelemetry-go-contrib copied to clipboard
TraceIDRatioBased doesn't work with xray.NewIDGenerator
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.
This likely relates to the latest revision on IDs in the specification.
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 {