Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions o11y/honeycomb/sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ type TraceSampler struct {

// Hook implements beeline.Config.Samplerhook
func (s *TraceSampler) Hook(fields map[string]interface{}) (sample bool, rate int) {
// Always sample in spans that have been set to do so via the `SetSpanSampledIn` function
if v, ok := fields["meta.keep.span"]; ok {
if keep, ok := v.(bool); ok && keep {
return true, 1
}
}

key := s.KeyFunc(fields)
rate = s.Sampler.GetSampleRate(key)
if shouldSample(fmt.Sprintf("%v", fields["trace.trace_id"]), rate) {
Expand Down
11 changes: 11 additions & 0 deletions o11y/honeycomb/sampler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ var samplerTests = []struct {
},
false, 0,
},
{
"sampled in via meta field",
map[string]interface{}{
"trace.trace_id": "ede23f67-2048-491b-ba71-749a8a00444f",
"app.server_name": "admin",
"request.path": "/ready",
"response.status_code": 200,
"meta.keep.span": true,
},
true, 1,
},
{
"ready-check with no problems but trace hits sample rate",
map[string]interface{}{
Expand Down
8 changes: 8 additions & 0 deletions o11y/otel/sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ func (s deterministicSampler) shouldSample(p sdktrace.ReadOnlySpan) (bool, uint)
for _, attr := range p.Attributes() {
fields[string(attr.Key)] = attr.Value.AsInterface()
}

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

// fields used in the existing sample key func
fields["duration_ms"] = int(p.EndTime().Sub(p.StartTime()).Milliseconds())
fields["name"] = p.Name()
Expand Down