Class: Datadog::Tracing::Sampling::SimpleRule

Inherits:
Rule
  • Object
show all
Defined in:
lib/datadog/tracing/sampling/rule.rb

Overview

A Rule that matches a trace based on trace name and/or service name and applies a fixed sampling to matching spans.

Instance Attribute Summary

Attributes inherited from Rule

#matcher, #sampler

Instance Method Summary collapse

Methods inherited from Rule

#match?, #sample?, #sample_rate

Constructor Details

#initialize(name: SimpleMatcher::MATCH_ALL, service: SimpleMatcher::MATCH_ALL, resource: SimpleMatcher::MATCH_ALL, tags: {}, sample_rate: 1.0) ⇒ SimpleRule

Returns a new instance of SimpleRule.

Parameters:

  • name (String, Regexp, Proc) (defaults to: SimpleMatcher::MATCH_ALL)

    Matcher for case equality (===) with the trace name, defaults to always match

  • service (String, Regexp, Proc) (defaults to: SimpleMatcher::MATCH_ALL)

    Matcher for case equality (===) with the service name, defaults to always match

  • resource (String, Regexp, Proc) (defaults to: SimpleMatcher::MATCH_ALL)

    Matcher for case equality (===) with the resource name, defaults to always match

  • sample_rate (Float) (defaults to: 1.0)

    Sampling rate between [0,1]



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/datadog/tracing/sampling/rule.rb', line 57

def initialize(
  name: SimpleMatcher::MATCH_ALL, service: SimpleMatcher::MATCH_ALL,
  resource: SimpleMatcher::MATCH_ALL, tags: {}, sample_rate: 1.0
)
  # We want to allow 0.0 to drop all traces, but {Datadog::Tracing::Sampling::RateSampler}
  # considers 0.0 an invalid rate and falls back to 100% sampling.
  #
  # We address that here by not setting the rate in the constructor,
  # but using the setter method.
  #
  # We don't want to make this change directly to {Datadog::Tracing::Sampling::RateSampler}
  # because it breaks its current contract to existing users.
  sampler = RateSampler.new
  sampler.sample_rate = sample_rate

  super(SimpleMatcher.new(name: name, service: service, resource: resource, tags: tags), sampler)
end