Skip to content

Commit 31a50af

Browse files
committed
Include explicitly sampled in spans
1 parent 0d8448a commit 31a50af

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (s deterministicSampler) shouldSample(p sdktrace.ReadOnlySpan) (bool, uint)
1919
fields[string(attr.Key)] = attr.Value.AsInterface()
2020
}
2121

22-
// Always sample in spans that have the `meta.keep.span` field set to `true`
22+
// Always sample in spans that have been set to do so via the `SetSpanSampledIn` function
2323
if v, ok := fields["meta.keep.span"]; ok {
2424
if keep, ok := v.(bool); ok && keep {
2525
return true, 1

0 commit comments

Comments
 (0)