Class: Datadog::PrioritySampler
- Inherits:
-
Object
- Object
- Datadog::PrioritySampler
- Extended by:
- Forwardable
- Defined in:
- lib/ddtrace/sampler.rb
Overview
PrioritySampler
Constant Summary collapse
- SAMPLE_RATE_METRIC_KEY =
'_sample_rate'.freeze
Instance Attribute Summary collapse
-
#pre_sampler ⇒ Object
readonly
Returns the value of attribute pre_sampler.
-
#priority_sampler ⇒ Object
readonly
Returns the value of attribute priority_sampler.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ PrioritySampler
constructor
A new instance of PrioritySampler.
- #sample!(span) ⇒ Object
- #sample?(span) ⇒ Boolean
Constructor Details
#initialize(opts = {}) ⇒ PrioritySampler
Returns a new instance of PrioritySampler.
200 201 202 203 |
# File 'lib/ddtrace/sampler.rb', line 200 def initialize(opts = {}) @pre_sampler = opts[:base_sampler] || AllSampler.new @priority_sampler = opts[:post_sampler] || RateByServiceSampler.new end |
Instance Attribute Details
#pre_sampler ⇒ Object (readonly)
Returns the value of attribute pre_sampler.
196 197 198 |
# File 'lib/ddtrace/sampler.rb', line 196 def pre_sampler @pre_sampler end |
#priority_sampler ⇒ Object (readonly)
Returns the value of attribute priority_sampler.
196 197 198 |
# File 'lib/ddtrace/sampler.rb', line 196 def priority_sampler @priority_sampler end |
Instance Method Details
#sample!(span) ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/ddtrace/sampler.rb', line 209 def sample!(span) # If pre-sampling is configured, do it first. (By default, this will sample at 100%.) # NOTE: Pre-sampling at rates < 100% may result in partial traces; not recommended. span.sampled = pre_sample?(span) ? @pre_sampler.sample!(span) : true if span.sampled # If priority sampling has already been applied upstream, use that, otherwise... unless priority_assigned_upstream?(span) # Roll the dice and determine whether how we set the priority. priority = priority_sample!(span) ? Datadog::Ext::Priority::AUTO_KEEP : Datadog::Ext::Priority::AUTO_REJECT assign_priority!(span, priority) end else # If discarded by pre-sampling, set "reject" priority, so other # services for the same trace don't sample needlessly. assign_priority!(span, Datadog::Ext::Priority::AUTO_REJECT) end span.sampled end |
#sample?(span) ⇒ Boolean
205 206 207 |
# File 'lib/ddtrace/sampler.rb', line 205 def sample?(span) @pre_sampler.sample?(span) end |