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.

Constant Summary

Constants inherited from Rule

Rule::PROVENANCE_LOCAL, Rule::PROVENANCE_REMOTE_DYNAMIC, Rule::PROVENANCE_REMOTE_USER

Instance Attribute Summary

Attributes inherited from Rule

#matcher, #provenance, #sampler

Instance Method Summary collapse

Methods inherited from Rule

#match?, #sample!, #sample_rate

Constructor Details

#initialize(name: SimpleMatcher::MATCH_ALL_PATTERN, service: SimpleMatcher::MATCH_ALL_PATTERN, resource: SimpleMatcher::MATCH_ALL_PATTERN, tags: {}, provenance: Rule::PROVENANCE_LOCAL, sample_rate: 1.0) ⇒ SimpleRule

Returns a new instance of SimpleRule.

Parameters:

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

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

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

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

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

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

  • sample_rate (Float) (defaults to: 1.0)

    Sampling rate between [0,1]



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/datadog/tracing/sampling/rule.rb', line 64

def initialize(
  name: SimpleMatcher::MATCH_ALL_PATTERN, service: SimpleMatcher::MATCH_ALL_PATTERN,
  resource: SimpleMatcher::MATCH_ALL_PATTERN, tags: {},
  provenance: Rule::PROVENANCE_LOCAL,
  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, provenance)
end