Skip to content

Commit 5e06550

Browse files
committed
Include explicitly sampled in spans
1 parent ef4b7d9 commit 5e06550

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

o11y/honeycomb/sampler.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ type TraceSampler struct {
1818

1919
// Hook implements beeline.Config.Samplerhook
2020
func (s *TraceSampler) Hook(fields map[string]interface{}) (sample bool, rate int) {
21+
// Always sample in spans that have been set to do so via the `SetSpanSampledIn` function
22+
if v, ok := fields["meta.keep.span"]; ok {
23+
if keep, ok := v.(bool); ok && keep {
24+
return true, 1
25+
}
26+
}
27+
2128
key := s.KeyFunc(fields)
2229
rate = s.Sampler.GetSampleRate(key)
2330
if shouldSample(fmt.Sprintf("%v", fields["trace.trace_id"]), rate) {

o11y/honeycomb/sampler_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ var samplerTests = []struct {
3535
},
3636
false, 0,
3737
},
38+
{
39+
"sampled in via meta field",
40+
map[string]interface{}{
41+
"trace.trace_id": "ede23f67-2048-491b-ba71-749a8a00444f",
42+
"app.server_name": "admin",
43+
"request.path": "/ready",
44+
"response.status_code": 200,
45+
"meta.keep.span": true,
46+
},
47+
true, 1,
48+
},
3849
{
3950
"ready-check with no problems but trace hits sample rate",
4051
map[string]interface{}{

o11y/otel/sampler.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ func (s deterministicSampler) shouldSample(p sdktrace.ReadOnlySpan) (bool, uint)
1818
for _, attr := range p.Attributes() {
1919
fields[string(attr.Key)] = attr.Value.AsInterface()
2020
}
21+
22+
// Always sample in spans that have been set to do so via the `SetSpanSampledIn` function
23+
if v, ok := fields["meta.keep.span"]; ok {
24+
if keep, ok := v.(bool); ok && keep {
25+
return true, 1
26+
}
27+
}
28+
2129
// fields used in the existing sample key func
2230
fields["duration_ms"] = int(p.EndTime().Sub(p.StartTime()).Milliseconds())
2331
fields["name"] = p.Name()

0 commit comments

Comments
 (0)