ddtrace 0.29.1 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +18 -1
- data/lib/ddtrace/context.rb +26 -10
- data/lib/ddtrace/contrib/action_pack/action_controller/patcher.rb +3 -15
- data/lib/ddtrace/contrib/action_pack/patcher.rb +3 -9
- data/lib/ddtrace/contrib/action_view/event.rb +39 -0
- data/lib/ddtrace/contrib/action_view/events.rb +30 -0
- data/lib/ddtrace/contrib/action_view/events/render_partial.rb +40 -0
- data/lib/ddtrace/contrib/action_view/events/render_template.rb +43 -0
- data/lib/ddtrace/contrib/action_view/instrumentation/partial_renderer.rb +4 -12
- data/lib/ddtrace/contrib/action_view/instrumentation/template_renderer.rb +6 -14
- data/lib/ddtrace/contrib/action_view/patcher.rb +19 -25
- data/lib/ddtrace/contrib/active_model_serializers/patcher.rb +3 -10
- data/lib/ddtrace/contrib/active_record/patcher.rb +3 -9
- data/lib/ddtrace/contrib/active_support/cache/patcher.rb +10 -24
- data/lib/ddtrace/contrib/active_support/patcher.rb +3 -9
- data/lib/ddtrace/contrib/aws/patcher.rb +7 -13
- data/lib/ddtrace/contrib/concurrent_ruby/patcher.rb +4 -11
- data/lib/ddtrace/contrib/dalli/patcher.rb +4 -10
- data/lib/ddtrace/contrib/delayed_job/patcher.rb +4 -10
- data/lib/ddtrace/contrib/elasticsearch/patcher.rb +8 -14
- data/lib/ddtrace/contrib/ethon/patcher.rb +7 -9
- data/lib/ddtrace/contrib/excon/patcher.rb +4 -11
- data/lib/ddtrace/contrib/faraday/patcher.rb +6 -12
- data/lib/ddtrace/contrib/grape/patcher.rb +7 -13
- data/lib/ddtrace/contrib/graphql/patcher.rb +5 -11
- data/lib/ddtrace/contrib/grpc/patcher.rb +7 -13
- data/lib/ddtrace/contrib/http/patcher.rb +3 -9
- data/lib/ddtrace/contrib/mongodb/patcher.rb +5 -11
- data/lib/ddtrace/contrib/mysql2/patcher.rb +3 -9
- data/lib/ddtrace/contrib/patcher.rb +38 -10
- data/lib/ddtrace/contrib/racecar/patcher.rb +4 -10
- data/lib/ddtrace/contrib/rack/patcher.rb +56 -21
- data/lib/ddtrace/contrib/rails/patcher.rb +4 -8
- data/lib/ddtrace/contrib/rake/patcher.rb +4 -10
- data/lib/ddtrace/contrib/redis/patcher.rb +8 -14
- data/lib/ddtrace/contrib/resque/patcher.rb +4 -10
- data/lib/ddtrace/contrib/rest_client/patcher.rb +5 -7
- data/lib/ddtrace/contrib/sequel/patcher.rb +4 -10
- data/lib/ddtrace/contrib/shoryuken/patcher.rb +4 -10
- data/lib/ddtrace/contrib/sidekiq/patcher.rb +12 -18
- data/lib/ddtrace/contrib/sinatra/patcher.rb +4 -10
- data/lib/ddtrace/contrib/sucker_punch/patcher.rb +7 -13
- data/lib/ddtrace/diagnostics/health.rb +9 -2
- data/lib/ddtrace/ext/diagnostics.rb +6 -0
- data/lib/ddtrace/ext/sampling.rb +13 -0
- data/lib/ddtrace/sampler.rb +49 -8
- data/lib/ddtrace/sampling.rb +2 -0
- data/lib/ddtrace/sampling/matcher.rb +57 -0
- data/lib/ddtrace/sampling/rate_limiter.rb +127 -0
- data/lib/ddtrace/sampling/rule.rb +61 -0
- data/lib/ddtrace/sampling/rule_sampler.rb +111 -0
- data/lib/ddtrace/span.rb +12 -0
- data/lib/ddtrace/tracer.rb +1 -0
- data/lib/ddtrace/version.rb +2 -2
- metadata +27 -4
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
require 'ddtrace/ext/priority'
|
4
|
+
|
5
|
+
require 'ddtrace/ext/sampling'
|
6
|
+
require 'ddtrace/sampler'
|
7
|
+
require 'ddtrace/sampling/rate_limiter'
|
8
|
+
|
9
|
+
module Datadog
|
10
|
+
module Sampling
|
11
|
+
# Span {Sampler} that applies a set of {Rule}s to decide
|
12
|
+
# on sampling outcome. Then, a rate limiter is applied.
|
13
|
+
#
|
14
|
+
# If a span does not conform to any rules, a default
|
15
|
+
# sampling strategy is applied.
|
16
|
+
class RuleSampler
|
17
|
+
extend Forwardable
|
18
|
+
|
19
|
+
attr_reader :rules, :rate_limiter, :default_sampler
|
20
|
+
|
21
|
+
# @param rules [Array<Rule>] ordered list of rules to be applied to a span
|
22
|
+
# @param rate_limit [Float] number of traces per second, defaults to 100
|
23
|
+
# @param rate_limiter [RateLimiter] limiter applied after rule matching
|
24
|
+
# @param default_sample_rate [Float] fallback sample rate when no rules apply to a span,
|
25
|
+
# between +[0,1]+, defaults to +1+
|
26
|
+
# @param default_sampler [Sample] fallback strategy when no rules apply to a span
|
27
|
+
def initialize(rules = [],
|
28
|
+
rate_limit: nil,
|
29
|
+
rate_limiter: nil,
|
30
|
+
default_sample_rate: nil,
|
31
|
+
default_sampler: nil)
|
32
|
+
|
33
|
+
@rules = rules
|
34
|
+
|
35
|
+
@rate_limiter = if rate_limiter
|
36
|
+
rate_limiter
|
37
|
+
elsif rate_limit
|
38
|
+
Datadog::Sampling::TokenBucket.new(rate_limit)
|
39
|
+
else
|
40
|
+
Datadog::Sampling::UnlimitedLimiter.new
|
41
|
+
end
|
42
|
+
|
43
|
+
@default_sampler = if default_sampler
|
44
|
+
default_sampler
|
45
|
+
elsif default_sample_rate
|
46
|
+
# We want to allow 0.0 to drop all traces, but \RateSampler
|
47
|
+
# considers 0.0 an invalid rate and falls back to 100% sampling.
|
48
|
+
#
|
49
|
+
# We address that here by not setting the rate in the constructor,
|
50
|
+
# but using the setter method.
|
51
|
+
#
|
52
|
+
# We don't want to make this change directly to \RateSampler
|
53
|
+
# because it breaks its current contract to existing users.
|
54
|
+
Datadog::RateSampler.new.tap { |s| s.sample_rate = default_sample_rate }
|
55
|
+
else
|
56
|
+
Datadog::AllSampler.new
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# /RuleSampler's components (it's rate limiter, for example) are
|
61
|
+
# not be guaranteed to be size-effect free.
|
62
|
+
# It is not possible to guarantee that a call to {#sample?} will
|
63
|
+
# return the same result as a successive call to {#sample!} with the same span.
|
64
|
+
#
|
65
|
+
# Use {#sample!} instead
|
66
|
+
def sample?(_span)
|
67
|
+
raise 'RuleSampler cannot be evaluated without side-effects'
|
68
|
+
end
|
69
|
+
|
70
|
+
def sample!(span)
|
71
|
+
sampled = sample_span(span) { |s| @default_sampler.sample!(s) }
|
72
|
+
|
73
|
+
sampled.tap do
|
74
|
+
span.sampled = sampled
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def_delegators :@default_sampler, :update
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def sample_span(span)
|
83
|
+
rule = @rules.find { |r| r.match?(span) }
|
84
|
+
|
85
|
+
return yield(span) if rule.nil?
|
86
|
+
|
87
|
+
sampled = rule.sample?(span)
|
88
|
+
sample_rate = rule.sample_rate(span)
|
89
|
+
|
90
|
+
set_rule_metrics(span, sample_rate)
|
91
|
+
|
92
|
+
return false unless sampled
|
93
|
+
|
94
|
+
rate_limiter.allow?(1).tap do
|
95
|
+
set_limiter_metrics(span, rate_limiter.effective_rate)
|
96
|
+
end
|
97
|
+
rescue StandardError => e
|
98
|
+
Datadog::Tracer.log.error("Rule sampling failed. Cause: #{e.message} Source: #{e.backtrace.first}")
|
99
|
+
yield(span)
|
100
|
+
end
|
101
|
+
|
102
|
+
def set_rule_metrics(span, sample_rate)
|
103
|
+
span.set_metric(Ext::Sampling::RULE_SAMPLE_RATE, sample_rate)
|
104
|
+
end
|
105
|
+
|
106
|
+
def set_limiter_metrics(span, limiter_rate)
|
107
|
+
span.set_metric(Ext::Sampling::RATE_LIMITER_RATE, limiter_rate)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/lib/ddtrace/span.rb
CHANGED
@@ -6,6 +6,7 @@ require 'ddtrace/ext/errors'
|
|
6
6
|
require 'ddtrace/ext/priority'
|
7
7
|
require 'ddtrace/analytics'
|
8
8
|
require 'ddtrace/forced_tracing'
|
9
|
+
require 'ddtrace/diagnostics/health'
|
9
10
|
|
10
11
|
module Datadog
|
11
12
|
# Represents a logical unit of work in the system. Each trace consists of one or more spans.
|
@@ -84,6 +85,11 @@ module Datadog
|
|
84
85
|
Datadog::Tracer.log.debug("Unable to set the tag #{key}, ignoring it. Caused by: #{e}")
|
85
86
|
end
|
86
87
|
|
88
|
+
# This method removes a tag for the given key.
|
89
|
+
def clear_tag(key)
|
90
|
+
@meta.delete(key)
|
91
|
+
end
|
92
|
+
|
87
93
|
# Return the tag with the given key, nil if it doesn't exist.
|
88
94
|
def get_tag(key)
|
89
95
|
@meta[key]
|
@@ -99,6 +105,11 @@ module Datadog
|
|
99
105
|
Datadog::Tracer.log.debug("Unable to set the metric #{key}, ignoring it. Caused by: #{e}")
|
100
106
|
end
|
101
107
|
|
108
|
+
# This method removes a metric for the given key. It acts like {#remove_tag}.
|
109
|
+
def clear_metric(key)
|
110
|
+
@metrics.delete(key)
|
111
|
+
end
|
112
|
+
|
102
113
|
# Return the metric with the given key, nil if it doesn't exist.
|
103
114
|
def get_metric(key)
|
104
115
|
@metrics[key]
|
@@ -144,6 +155,7 @@ module Datadog
|
|
144
155
|
@tracer.record(self)
|
145
156
|
rescue StandardError => e
|
146
157
|
Datadog::Tracer.log.debug("error recording finished trace: #{e}")
|
158
|
+
Diagnostics::Health.metrics.error_span_finish(1, tags: ["error:#{e.class.name}"])
|
147
159
|
end
|
148
160
|
self
|
149
161
|
end
|
data/lib/ddtrace/tracer.rb
CHANGED
@@ -10,6 +10,7 @@ require 'ddtrace/provider'
|
|
10
10
|
require 'ddtrace/logger'
|
11
11
|
require 'ddtrace/writer'
|
12
12
|
require 'ddtrace/sampler'
|
13
|
+
require 'ddtrace/sampling'
|
13
14
|
require 'ddtrace/correlation'
|
14
15
|
|
15
16
|
# \Datadog global namespace that includes all tracing functionality for Tracer and Span classes.
|
data/lib/ddtrace/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddtrace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.30.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Datadog, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|
@@ -276,6 +276,20 @@ dependencies:
|
|
276
276
|
- - "~>"
|
277
277
|
- !ruby/object:Gem::Version
|
278
278
|
version: 0.4.9.2
|
279
|
+
- !ruby/object:Gem::Dependency
|
280
|
+
name: warning
|
281
|
+
requirement: !ruby/object:Gem::Requirement
|
282
|
+
requirements:
|
283
|
+
- - ">="
|
284
|
+
- !ruby/object:Gem::Version
|
285
|
+
version: '0'
|
286
|
+
type: :development
|
287
|
+
prerelease: false
|
288
|
+
version_requirements: !ruby/object:Gem::Requirement
|
289
|
+
requirements:
|
290
|
+
- - ">="
|
291
|
+
- !ruby/object:Gem::Version
|
292
|
+
version: '0'
|
279
293
|
description: |
|
280
294
|
ddtrace is Datadog’s tracing client for Ruby. It is used to trace requests
|
281
295
|
as they flow across web servers, databases and microservices so that developers
|
@@ -341,6 +355,10 @@ files:
|
|
341
355
|
- lib/ddtrace/contrib/action_pack/patcher.rb
|
342
356
|
- lib/ddtrace/contrib/action_pack/utils.rb
|
343
357
|
- lib/ddtrace/contrib/action_view/configuration/settings.rb
|
358
|
+
- lib/ddtrace/contrib/action_view/event.rb
|
359
|
+
- lib/ddtrace/contrib/action_view/events.rb
|
360
|
+
- lib/ddtrace/contrib/action_view/events/render_partial.rb
|
361
|
+
- lib/ddtrace/contrib/action_view/events/render_template.rb
|
344
362
|
- lib/ddtrace/contrib/action_view/ext.rb
|
345
363
|
- lib/ddtrace/contrib/action_view/instrumentation/partial_renderer.rb
|
346
364
|
- lib/ddtrace/contrib/action_view/instrumentation/template_renderer.rb
|
@@ -565,6 +583,7 @@ files:
|
|
565
583
|
- lib/ddtrace/ext/net.rb
|
566
584
|
- lib/ddtrace/ext/priority.rb
|
567
585
|
- lib/ddtrace/ext/runtime.rb
|
586
|
+
- lib/ddtrace/ext/sampling.rb
|
568
587
|
- lib/ddtrace/ext/sql.rb
|
569
588
|
- lib/ddtrace/ext/transport.rb
|
570
589
|
- lib/ddtrace/forced_tracing.rb
|
@@ -607,6 +626,11 @@ files:
|
|
607
626
|
- lib/ddtrace/runtime/socket.rb
|
608
627
|
- lib/ddtrace/runtime/thread_count.rb
|
609
628
|
- lib/ddtrace/sampler.rb
|
629
|
+
- lib/ddtrace/sampling.rb
|
630
|
+
- lib/ddtrace/sampling/matcher.rb
|
631
|
+
- lib/ddtrace/sampling/rate_limiter.rb
|
632
|
+
- lib/ddtrace/sampling/rule.rb
|
633
|
+
- lib/ddtrace/sampling/rule_sampler.rb
|
610
634
|
- lib/ddtrace/span.rb
|
611
635
|
- lib/ddtrace/sync_writer.rb
|
612
636
|
- lib/ddtrace/tracer.rb
|
@@ -660,8 +684,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
660
684
|
- !ruby/object:Gem::Version
|
661
685
|
version: '0'
|
662
686
|
requirements: []
|
663
|
-
|
664
|
-
rubygems_version: 2.6.14
|
687
|
+
rubygems_version: 3.0.6
|
665
688
|
signing_key:
|
666
689
|
specification_version: 4
|
667
690
|
summary: Datadog tracing code for your Ruby applications
|