-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a67c6d
commit 8abcea7
Showing
6 changed files
with
63 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM golang:alpine as builder | ||
FROM golang:1.21-alpine as builder | ||
|
||
WORKDIR /build | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package tracing | ||
|
||
import ( | ||
"encoding/binary" | ||
"go.opentelemetry.io/otel/sdk/trace" | ||
trace2 "go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
type GuGoTikSampler struct { | ||
traceIDUpperBound uint64 | ||
} | ||
|
||
func GetGuGoTikSampler(fraction float64) trace.Sampler { | ||
if fraction >= 1 { | ||
return trace.AlwaysSample() | ||
} | ||
|
||
if fraction <= 0 { | ||
fraction = 0 | ||
} | ||
|
||
return &GuGoTikSampler{ | ||
traceIDUpperBound: uint64(fraction * (1 << 63)), | ||
} | ||
} | ||
|
||
func (cs *GuGoTikSampler) ShouldSample(p trace.SamplingParameters) trace.SamplingResult { | ||
psc := trace2.SpanContextFromContext(p.ParentContext) | ||
|
||
for _, attribute := range p.Attributes { | ||
if attribute.Key == "error" { | ||
return trace.SamplingResult{ | ||
Decision: trace.RecordAndSample, | ||
Tracestate: psc.TraceState(), | ||
} | ||
} | ||
} | ||
|
||
x := binary.BigEndian.Uint64(p.TraceID[8:16]) >> 1 | ||
if x < cs.traceIDUpperBound { | ||
return trace.SamplingResult{ | ||
Decision: trace.RecordAndSample, | ||
Tracestate: psc.TraceState(), | ||
} | ||
} | ||
|
||
return trace.SamplingResult{ | ||
Decision: trace.Drop, | ||
Tracestate: psc.TraceState(), | ||
} | ||
} | ||
|
||
func (cs *GuGoTikSampler) Description() string { | ||
return "GuGoTikSampler" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters