ddtrace 0.26.1 → 0.27.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +153 -77
- data/.circleci/images/primary/{Dockerfile-1.9.3 → Dockerfile-2.5.6} +8 -8
- data/.circleci/images/primary/Dockerfile-2.6.4 +73 -0
- data/.github/CODEOWNERS +1 -0
- data/Appraisals +201 -94
- data/CHANGELOG.md +25 -8
- data/Rakefile +153 -47
- data/ddtrace.gemspec +1 -1
- data/docker-compose.yml +56 -26
- data/docs/GettingStarted.md +117 -14
- data/lib/ddtrace.rb +4 -0
- data/lib/ddtrace/analytics.rb +9 -39
- data/lib/ddtrace/configuration.rb +0 -19
- data/lib/ddtrace/contrib/action_pack/action_controller/instrumentation.rb +144 -0
- data/lib/ddtrace/contrib/action_pack/action_controller/patcher.rb +37 -0
- data/lib/ddtrace/contrib/action_pack/configuration/settings.rb +25 -0
- data/lib/ddtrace/contrib/action_pack/ext.rb +16 -0
- data/lib/ddtrace/contrib/action_pack/integration.rb +36 -0
- data/lib/ddtrace/contrib/action_pack/patcher.rb +29 -0
- data/lib/ddtrace/contrib/action_pack/utils.rb +36 -0
- data/lib/ddtrace/contrib/action_view/configuration/settings.rb +24 -0
- data/lib/ddtrace/contrib/action_view/ext.rb +17 -0
- data/lib/ddtrace/contrib/action_view/instrumentation.rb +192 -0
- data/lib/ddtrace/contrib/action_view/integration.rb +43 -0
- data/lib/ddtrace/contrib/action_view/patcher.rb +47 -0
- data/lib/ddtrace/contrib/action_view/utils.rb +32 -0
- data/lib/ddtrace/contrib/active_support/cache/instrumentation.rb +157 -0
- data/lib/ddtrace/contrib/active_support/cache/patcher.rb +62 -0
- data/lib/ddtrace/contrib/active_support/cache/redis.rb +47 -0
- data/lib/ddtrace/contrib/active_support/configuration/settings.rb +23 -0
- data/lib/ddtrace/contrib/active_support/ext.rb +21 -0
- data/lib/ddtrace/contrib/active_support/integration.rb +38 -0
- data/lib/ddtrace/contrib/active_support/patcher.rb +29 -0
- data/lib/ddtrace/contrib/ethon/configuration/settings.rb +24 -0
- data/lib/ddtrace/contrib/ethon/easy_patch.rb +139 -0
- data/lib/ddtrace/contrib/ethon/ext.rb +15 -0
- data/lib/ddtrace/contrib/ethon/integration.rb +35 -0
- data/lib/ddtrace/contrib/ethon/multi_patch.rb +80 -0
- data/lib/ddtrace/contrib/ethon/patcher.rb +27 -0
- data/lib/ddtrace/contrib/patchable.rb +1 -1
- data/lib/ddtrace/contrib/rails/configuration/settings.rb +43 -6
- data/lib/ddtrace/contrib/rails/ext.rb +0 -15
- data/lib/ddtrace/contrib/rails/framework.rb +37 -6
- data/lib/ddtrace/contrib/rails/middlewares.rb +2 -1
- data/lib/ddtrace/contrib/rails/patcher.rb +0 -8
- data/lib/ddtrace/contrib/rails/utils.rb +0 -46
- data/lib/ddtrace/contrib/redis/patcher.rb +12 -19
- data/lib/ddtrace/correlation.rb +8 -12
- data/lib/ddtrace/forced_tracing.rb +10 -38
- data/lib/ddtrace/sampler.rb +20 -74
- data/lib/ddtrace/span.rb +3 -4
- data/lib/ddtrace/tracer.rb +4 -11
- data/lib/ddtrace/version.rb +2 -2
- metadata +32 -9
- data/lib/ddtrace/contrib/rails/action_controller.rb +0 -100
- data/lib/ddtrace/contrib/rails/action_controller_patch.rb +0 -78
- data/lib/ddtrace/contrib/rails/action_view.rb +0 -19
- data/lib/ddtrace/contrib/rails/active_support.rb +0 -67
- data/lib/ddtrace/contrib/rails/core_extensions.rb +0 -353
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'ddtrace/contrib/patcher'
|
2
|
+
require 'ddtrace/contrib/action_pack/action_controller/instrumentation'
|
3
|
+
|
4
|
+
module Datadog
|
5
|
+
module Contrib
|
6
|
+
module ActionPack
|
7
|
+
module ActionController
|
8
|
+
# Patcher for ActionController components
|
9
|
+
module Patcher
|
10
|
+
include Contrib::Patcher
|
11
|
+
|
12
|
+
module_function
|
13
|
+
|
14
|
+
def patched?
|
15
|
+
done?(:action_controller)
|
16
|
+
end
|
17
|
+
|
18
|
+
def patch
|
19
|
+
do_once(:action_controller) do
|
20
|
+
begin
|
21
|
+
patch_action_controller_metal
|
22
|
+
rescue StandardError => e
|
23
|
+
Datadog::Tracer.log.error("Unable to apply ActionController integration: #{e}")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def patch_action_controller_metal
|
29
|
+
do_once(:patch_action_controller_metal) do
|
30
|
+
::ActionController::Metal.send(:prepend, ActionController::Instrumentation::Metal)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'ddtrace/contrib/configuration/settings'
|
2
|
+
require 'ddtrace/contrib/action_pack/ext'
|
3
|
+
|
4
|
+
module Datadog
|
5
|
+
module Contrib
|
6
|
+
module ActionPack
|
7
|
+
module Configuration
|
8
|
+
# Custom settings for the ActionPack integration
|
9
|
+
class Settings < Contrib::Configuration::Settings
|
10
|
+
option :analytics_enabled,
|
11
|
+
default: -> { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, nil) },
|
12
|
+
lazy: true
|
13
|
+
|
14
|
+
option :analytics_sample_rate,
|
15
|
+
default: -> { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) },
|
16
|
+
lazy: true
|
17
|
+
|
18
|
+
option :controller_service
|
19
|
+
option :exception_controller, default: nil
|
20
|
+
option :service_name, default: Ext::SERVICE_NAME
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Datadog
|
2
|
+
module Contrib
|
3
|
+
module ActionPack
|
4
|
+
# ActionPack integration constants
|
5
|
+
module Ext
|
6
|
+
APP = 'action_pack'.freeze
|
7
|
+
ENV_ANALYTICS_ENABLED = 'DD_ACTION_PACK_ANALYTICS_ENABLED'.freeze
|
8
|
+
ENV_ANALYTICS_SAMPLE_RATE = 'DD_ACTION_PACK_ANALYTICS_SAMPLE_RATE'.freeze
|
9
|
+
SERVICE_NAME = 'action_pack'.freeze
|
10
|
+
SPAN_ACTION_CONTROLLER = 'rails.action_controller'.freeze
|
11
|
+
TAG_ROUTE_ACTION = 'rails.route.action'.freeze
|
12
|
+
TAG_ROUTE_CONTROLLER = 'rails.route.controller'.freeze
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'ddtrace/contrib/integration'
|
2
|
+
require 'ddtrace/contrib/action_pack/configuration/settings'
|
3
|
+
require 'ddtrace/contrib/action_pack/patcher'
|
4
|
+
|
5
|
+
module Datadog
|
6
|
+
module Contrib
|
7
|
+
module ActionPack
|
8
|
+
# Describes the ActionPack integration
|
9
|
+
class Integration
|
10
|
+
include Contrib::Integration
|
11
|
+
|
12
|
+
register_as :action_pack, auto_patch: false
|
13
|
+
|
14
|
+
def self.version
|
15
|
+
Gem.loaded_specs['actionpack'] && Gem.loaded_specs['actionpack'].version
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.present?
|
19
|
+
super && defined?(::ActionPack)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.compatible?
|
23
|
+
super && version >= Gem::Version.new('3.0')
|
24
|
+
end
|
25
|
+
|
26
|
+
def default_configuration
|
27
|
+
Configuration::Settings.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def patcher
|
31
|
+
ActionPack::Patcher
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'ddtrace/contrib/patcher'
|
2
|
+
require 'ddtrace/contrib/action_pack/action_controller/patcher'
|
3
|
+
|
4
|
+
module Datadog
|
5
|
+
module Contrib
|
6
|
+
module ActionPack
|
7
|
+
# Patcher enables patching of 'action_pack' module.
|
8
|
+
module Patcher
|
9
|
+
include Contrib::Patcher
|
10
|
+
|
11
|
+
module_function
|
12
|
+
|
13
|
+
def patched?
|
14
|
+
done?(:action_pack)
|
15
|
+
end
|
16
|
+
|
17
|
+
def patch
|
18
|
+
do_once(:action_pack) do
|
19
|
+
begin
|
20
|
+
ActionController::Patcher.patch
|
21
|
+
rescue StandardError => e
|
22
|
+
Datadog::Tracer.log.error("Unable to apply ActionPack integration: #{e}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'ddtrace/contrib/analytics'
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module Contrib
|
5
|
+
module ActionPack
|
6
|
+
# Common utilities for ActionPack
|
7
|
+
module Utils
|
8
|
+
def self.exception_is_error?(exception)
|
9
|
+
if defined?(::ActionDispatch::ExceptionWrapper)
|
10
|
+
# Gets the equivalent status code for the exception (not all are 5XX)
|
11
|
+
# You can add custom errors via `config.action_dispatch.rescue_responses`
|
12
|
+
status = ::ActionDispatch::ExceptionWrapper.status_code_for_exception(exception.class.name)
|
13
|
+
# Only 5XX exceptions are actually errors (e.g. don't flag 404s)
|
14
|
+
status.to_s.starts_with?('5')
|
15
|
+
else
|
16
|
+
true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.set_analytics_sample_rate(span)
|
21
|
+
if Contrib::Analytics.enabled?(datadog_configuration[:analytics_enabled])
|
22
|
+
Contrib::Analytics.set_sample_rate(span, datadog_configuration[:analytics_sample_rate])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class << self
|
27
|
+
private
|
28
|
+
|
29
|
+
def datadog_configuration
|
30
|
+
Datadog.configuration[:action_pack]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'ddtrace/contrib/configuration/settings'
|
2
|
+
require 'ddtrace/contrib/action_view/ext'
|
3
|
+
|
4
|
+
module Datadog
|
5
|
+
module Contrib
|
6
|
+
module ActionView
|
7
|
+
module Configuration
|
8
|
+
# Custom settings for the ActionView integration
|
9
|
+
class Settings < Contrib::Configuration::Settings
|
10
|
+
option :analytics_enabled,
|
11
|
+
default: -> { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) },
|
12
|
+
lazy: true
|
13
|
+
|
14
|
+
option :analytics_sample_rate,
|
15
|
+
default: -> { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) },
|
16
|
+
lazy: true
|
17
|
+
|
18
|
+
option :service_name, default: Ext::SERVICE_NAME
|
19
|
+
option :template_base_path, default: 'views/'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Datadog
|
2
|
+
module Contrib
|
3
|
+
module ActionView
|
4
|
+
# ActionView integration constants
|
5
|
+
module Ext
|
6
|
+
APP = 'action_view'.freeze
|
7
|
+
ENV_ANALYTICS_ENABLED = 'DD_ACTION_VIEW_ANALYTICS_ENABLED'.freeze
|
8
|
+
ENV_ANALYTICS_SAMPLE_RATE = 'DD_ACTION_VIEW_ANALYTICS_SAMPLE_RATE'.freeze
|
9
|
+
SERVICE_NAME = 'action_view'.freeze
|
10
|
+
SPAN_RENDER_PARTIAL = 'rails.render_partial'.freeze
|
11
|
+
SPAN_RENDER_TEMPLATE = 'rails.render_template'.freeze
|
12
|
+
TAG_LAYOUT = 'rails.layout'.freeze
|
13
|
+
TAG_TEMPLATE_NAME = 'rails.template_name'.freeze
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
require 'ddtrace/contrib/action_view/ext'
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module Contrib
|
5
|
+
module ActionView
|
6
|
+
# Defines instrumentation for ActionView
|
7
|
+
module Instrumentation
|
8
|
+
# Instrumentation for template rendering
|
9
|
+
module TemplateRenderer
|
10
|
+
# Rails < 3.1 template rendering
|
11
|
+
module Rails30
|
12
|
+
# rubocop:disable Metrics/MethodLength
|
13
|
+
def self.prepended(base)
|
14
|
+
# rubocop:disable Metrics/BlockLength
|
15
|
+
base.class_eval do
|
16
|
+
def render_with_datadog(*args, &block)
|
17
|
+
# NOTE: This check exists purely for Rails 3.0 compatibility.
|
18
|
+
# The 'if' part can be removed when support for Rails 3.0 is removed.
|
19
|
+
if active_datadog_span
|
20
|
+
render_without_datadog(*args, &block)
|
21
|
+
else
|
22
|
+
datadog_tracer.trace(
|
23
|
+
Ext::SPAN_RENDER_TEMPLATE,
|
24
|
+
span_type: Datadog::Ext::HTTP::TEMPLATE
|
25
|
+
) do |span|
|
26
|
+
with_datadog_span(span) { render_without_datadog(*args, &block) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def render_template_with_datadog(*args)
|
32
|
+
begin
|
33
|
+
template = args[0]
|
34
|
+
layout_name = args[1]
|
35
|
+
|
36
|
+
# update the tracing context with computed values before the rendering
|
37
|
+
template_name = template.try('identifier')
|
38
|
+
template_name = Utils.normalize_template_name(template_name)
|
39
|
+
|
40
|
+
if template_name
|
41
|
+
active_datadog_span.set_tag(
|
42
|
+
Ext::TAG_TEMPLATE_NAME,
|
43
|
+
template_name
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
if layout_name
|
48
|
+
active_datadog_span.set_tag(
|
49
|
+
Ext::TAG_LAYOUT,
|
50
|
+
layout_name
|
51
|
+
)
|
52
|
+
end
|
53
|
+
rescue StandardError => e
|
54
|
+
Datadog::Tracer.log.debug(e.message)
|
55
|
+
end
|
56
|
+
|
57
|
+
# execute the original function anyway
|
58
|
+
render_template_without_datadog(*args)
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
attr_accessor :active_datadog_span
|
64
|
+
|
65
|
+
def datadog_tracer
|
66
|
+
Datadog.configuration[:action_view][:tracer]
|
67
|
+
end
|
68
|
+
|
69
|
+
def with_datadog_span(span)
|
70
|
+
self.active_datadog_span = span
|
71
|
+
yield
|
72
|
+
ensure
|
73
|
+
self.active_datadog_span = nil
|
74
|
+
end
|
75
|
+
|
76
|
+
# method aliasing to patch the class
|
77
|
+
alias_method :render_without_datadog, :render
|
78
|
+
alias_method :render, :render_with_datadog
|
79
|
+
|
80
|
+
alias_method :render_template_without_datadog, :_render_template
|
81
|
+
alias_method :_render_template, :render_template_with_datadog
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Rails >= 3.1 template rendering
|
87
|
+
module Rails31Plus
|
88
|
+
def render(*args, &block)
|
89
|
+
datadog_tracer.trace(
|
90
|
+
Ext::SPAN_RENDER_TEMPLATE,
|
91
|
+
span_type: Datadog::Ext::HTTP::TEMPLATE
|
92
|
+
) do |span|
|
93
|
+
with_datadog_span(span) { super(*args, &block) }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def render_template(*args)
|
98
|
+
begin
|
99
|
+
# arguments based on render_template signature (stable since Rails 3.2)
|
100
|
+
template = args[0]
|
101
|
+
layout_name = args[1]
|
102
|
+
|
103
|
+
# update the tracing context with computed values before the rendering
|
104
|
+
template_name = template.try('identifier')
|
105
|
+
template_name = Utils.normalize_template_name(template_name)
|
106
|
+
layout = layout_name.try(:[], 'virtual_path')
|
107
|
+
|
108
|
+
if template_name
|
109
|
+
active_datadog_span.set_tag(
|
110
|
+
Ext::TAG_TEMPLATE_NAME,
|
111
|
+
template_name
|
112
|
+
)
|
113
|
+
end
|
114
|
+
|
115
|
+
if layout
|
116
|
+
active_datadog_span.set_tag(
|
117
|
+
Ext::TAG_LAYOUT,
|
118
|
+
layout
|
119
|
+
)
|
120
|
+
end
|
121
|
+
rescue StandardError => e
|
122
|
+
Datadog::Tracer.log.debug(e.message)
|
123
|
+
end
|
124
|
+
|
125
|
+
# execute the original function anyway
|
126
|
+
super(*args)
|
127
|
+
end
|
128
|
+
|
129
|
+
private
|
130
|
+
|
131
|
+
attr_accessor :active_datadog_span
|
132
|
+
|
133
|
+
def datadog_tracer
|
134
|
+
Datadog.configuration[:action_view][:tracer]
|
135
|
+
end
|
136
|
+
|
137
|
+
def with_datadog_span(span)
|
138
|
+
self.active_datadog_span = span
|
139
|
+
yield
|
140
|
+
ensure
|
141
|
+
self.active_datadog_span = nil
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# Instrumentation for partial rendering
|
147
|
+
module PartialRenderer
|
148
|
+
def render(*args, &block)
|
149
|
+
datadog_tracer.trace(
|
150
|
+
Ext::SPAN_RENDER_PARTIAL,
|
151
|
+
span_type: Datadog::Ext::HTTP::TEMPLATE
|
152
|
+
) do |span|
|
153
|
+
with_datadog_span(span) { super(*args) }
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def render_partial(*args)
|
158
|
+
begin
|
159
|
+
template_name = Utils.normalize_template_name(@template.try('identifier'))
|
160
|
+
if template_name
|
161
|
+
active_datadog_span.set_tag(
|
162
|
+
Ext::TAG_TEMPLATE_NAME,
|
163
|
+
template_name
|
164
|
+
)
|
165
|
+
end
|
166
|
+
rescue StandardError => e
|
167
|
+
Datadog::Tracer.log.debug(e.message)
|
168
|
+
end
|
169
|
+
|
170
|
+
# execute the original function anyway
|
171
|
+
super(*args)
|
172
|
+
end
|
173
|
+
|
174
|
+
private
|
175
|
+
|
176
|
+
attr_accessor :active_datadog_span
|
177
|
+
|
178
|
+
def datadog_tracer
|
179
|
+
Datadog.configuration[:action_view][:tracer]
|
180
|
+
end
|
181
|
+
|
182
|
+
def with_datadog_span(span)
|
183
|
+
self.active_datadog_span = span
|
184
|
+
yield
|
185
|
+
ensure
|
186
|
+
self.active_datadog_span = nil
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'ddtrace/contrib/integration'
|
2
|
+
require 'ddtrace/contrib/action_view/configuration/settings'
|
3
|
+
require 'ddtrace/contrib/action_view/patcher'
|
4
|
+
|
5
|
+
module Datadog
|
6
|
+
module Contrib
|
7
|
+
module ActionView
|
8
|
+
# Describes the ActionView integration
|
9
|
+
class Integration
|
10
|
+
include Contrib::Integration
|
11
|
+
|
12
|
+
register_as :action_view, auto_patch: false
|
13
|
+
|
14
|
+
def self.version
|
15
|
+
# ActionView is its own gem in Rails 4.1+
|
16
|
+
if Gem.loaded_specs['actionview']
|
17
|
+
Gem.loaded_specs['actionview'].version
|
18
|
+
# ActionView is embedded in ActionPack in versions < 4.1
|
19
|
+
elsif Gem.loaded_specs['actionpack']
|
20
|
+
action_pack_version = Gem.loaded_specs['actionpack'].version
|
21
|
+
action_pack_version unless action_pack_version >= Gem::Version.new('4.1')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.present?
|
26
|
+
super && defined?(::ActionView)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.compatible?
|
30
|
+
super && version >= Gem::Version.new('3.0')
|
31
|
+
end
|
32
|
+
|
33
|
+
def default_configuration
|
34
|
+
Configuration::Settings.new
|
35
|
+
end
|
36
|
+
|
37
|
+
def patcher
|
38
|
+
ActionView::Patcher
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|