Skip to content

Commit

Permalink
traceIDRatioSampler: use rightmost bits (#3557)
Browse files Browse the repository at this point in the history
* use bottom bits

* add changelog entry

Co-authored-by: Chester Cheung <cheung.zhy.csu@gmail.com>
  • Loading branch information
danielmmetz and hanyuancheung committed Dec 30, 2022
1 parent 69e44a3 commit 9d633d2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add `Producer` interface and `Reader.RegisterProducer(Producer)` to `go.opentelemetry.io/otel/sdk/metric` to enable external metric Producers. (#3524)
- Add `NewMetricProducer` to `go.opentelemetry.io/otel/bridge/opencensus`, which can be used to pass OpenCensus metrics to an OpenTelemetry Reader. (#3541)
- Global logger uses an atomic value instead of a mutex. (#3545)
- `traceIDRatioSampler` (given by `TraceIDRatioBased(float64)`) now uses the rightmost bits for sampling decisions,
fixing random sampling when using ID generators like `xray.IDGenerator`
and increasing parity with other language implementations. (#3557)

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion sdk/trace/sampling.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type traceIDRatioSampler struct {

func (ts traceIDRatioSampler) ShouldSample(p SamplingParameters) SamplingResult {
psc := trace.SpanContextFromContext(p.ParentContext)
x := binary.BigEndian.Uint64(p.TraceID[0:8]) >> 1
x := binary.BigEndian.Uint64(p.TraceID[8:16]) >> 1
if x < ts.traceIDUpperBound {
return SamplingResult{
Decision: RecordAndSample,
Expand Down

0 comments on commit 9d633d2

Please sign in to comment.