ddtrace 0.17.3 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env +2 -2
- data/Appraisals +4 -0
- data/CHANGELOG.md +21 -2
- data/Rakefile +31 -29
- data/docker-compose.yml +7 -7
- data/docs/GettingStarted.md +26 -2
- data/lib/ddtrace.rb +4 -0
- data/lib/ddtrace/augmentation.rb +13 -0
- data/lib/ddtrace/augmentation/method_wrapper.rb +20 -0
- data/lib/ddtrace/augmentation/method_wrapping.rb +38 -0
- data/lib/ddtrace/augmentation/shim.rb +102 -0
- data/lib/ddtrace/contrib/active_record/events/sql.rb +6 -2
- data/lib/ddtrace/contrib/active_record/patcher.rb +2 -0
- data/lib/ddtrace/contrib/active_record/patches/abstract_adapter.rb +72 -0
- data/lib/ddtrace/contrib/active_record/utils.rb +8 -18
- data/lib/ddtrace/contrib/aws/instrumentation.rb +15 -11
- data/lib/ddtrace/contrib/aws/patcher.rb +0 -11
- data/lib/ddtrace/contrib/configurable.rb +13 -9
- data/lib/ddtrace/contrib/rack/request_queue.rb +5 -1
- data/lib/ddtrace/contrib/shoryuken/configuration/settings.rb +14 -0
- data/lib/ddtrace/contrib/shoryuken/ext.rb +18 -0
- data/lib/ddtrace/contrib/shoryuken/integration.rb +35 -0
- data/lib/ddtrace/contrib/shoryuken/patcher.rb +30 -0
- data/lib/ddtrace/contrib/shoryuken/tracer.rb +37 -0
- data/lib/ddtrace/contrib/sidekiq/client_tracer.rb +35 -0
- data/lib/ddtrace/contrib/sidekiq/configuration/settings.rb +1 -0
- data/lib/ddtrace/contrib/sidekiq/ext.rb +2 -0
- data/lib/ddtrace/contrib/sidekiq/patcher.rb +9 -2
- data/lib/ddtrace/contrib/sidekiq/server_tracer.rb +50 -0
- data/lib/ddtrace/contrib/sidekiq/tracing.rb +38 -0
- data/lib/ddtrace/sync_writer.rb +2 -1
- data/lib/ddtrace/transport.rb +6 -3
- data/lib/ddtrace/utils/database.rb +7 -3
- data/lib/ddtrace/version.rb +2 -2
- data/lib/ddtrace/writer.rb +1 -4
- metadata +15 -3
- data/lib/ddtrace/contrib/sidekiq/tracer.rb +0 -72
@@ -18,9 +18,13 @@ module Datadog
|
|
18
18
|
time_string = header.split('t=')[1]
|
19
19
|
return if time_string.nil?
|
20
20
|
|
21
|
+
# Return nil if the time is clearly invalid
|
22
|
+
time_value = time_string.to_f
|
23
|
+
return if time_value.zero?
|
24
|
+
|
21
25
|
# return the request_start only if it's lesser than
|
22
26
|
# current time, to avoid significant clock skew
|
23
|
-
request_start = Time.at(
|
27
|
+
request_start = Time.at(time_value)
|
24
28
|
request_start.utc > now ? nil : request_start
|
25
29
|
rescue StandardError => e
|
26
30
|
# in case of an Exception we don't create a
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'ddtrace/contrib/configuration/settings'
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module Contrib
|
5
|
+
module Shoryuken
|
6
|
+
module Configuration
|
7
|
+
# Default settings for the Shoryuken integration
|
8
|
+
class Settings < Contrib::Configuration::Settings
|
9
|
+
option :service_name, default: Ext::SERVICE_NAME
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Datadog
|
2
|
+
module Contrib
|
3
|
+
module Shoryuken
|
4
|
+
# Shoryuken integration constants
|
5
|
+
module Ext
|
6
|
+
APP = 'shoryuken'.freeze
|
7
|
+
SERVICE_NAME = 'shoryuken'.freeze
|
8
|
+
|
9
|
+
SPAN_JOB = 'shoryuken.job'.freeze
|
10
|
+
|
11
|
+
TAG_JOB_ID = 'shoryuken.id'.freeze
|
12
|
+
TAG_JOB_QUEUE = 'shoryuken.queue'.freeze
|
13
|
+
TAG_JOB_ATTRIBUTES = 'shoryuken.attributes'.freeze
|
14
|
+
TAG_JOB_BODY = 'shoryuken.body'.freeze
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'ddtrace/contrib/integration'
|
2
|
+
require 'ddtrace/contrib/shoryuken/ext'
|
3
|
+
require 'ddtrace/contrib/shoryuken/configuration/settings'
|
4
|
+
require 'ddtrace/contrib/shoryuken/patcher'
|
5
|
+
|
6
|
+
module Datadog
|
7
|
+
module Contrib
|
8
|
+
module Shoryuken
|
9
|
+
# Description of Shoryuken integration
|
10
|
+
class Integration
|
11
|
+
include Contrib::Integration
|
12
|
+
|
13
|
+
register_as :shoryuken
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def version
|
17
|
+
Gem.loaded_specs['shoryuken'] && Gem.loaded_specs['shoryuken'].version
|
18
|
+
end
|
19
|
+
|
20
|
+
def present?
|
21
|
+
super && defined?(::Shoryuken)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def default_configuration
|
26
|
+
Configuration::Settings.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def patcher
|
30
|
+
Patcher
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'ddtrace/contrib/shoryuken/tracer'
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module Contrib
|
5
|
+
module Shoryuken
|
6
|
+
# Patcher enables patching of 'shoryuken' module.
|
7
|
+
module Patcher
|
8
|
+
include Contrib::Patcher
|
9
|
+
|
10
|
+
module_function
|
11
|
+
|
12
|
+
def patched?
|
13
|
+
done?(:shoryuken)
|
14
|
+
end
|
15
|
+
|
16
|
+
def patch
|
17
|
+
do_once(:shoryuken) do
|
18
|
+
begin
|
19
|
+
::Shoryuken.server_middleware do |chain|
|
20
|
+
chain.add Shoryuken::Tracer
|
21
|
+
end
|
22
|
+
rescue StandardError => e
|
23
|
+
Datadog::Tracer.log.error("Unable to apply Shoryuken integration: #{e}")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Datadog
|
2
|
+
module Contrib
|
3
|
+
module Shoryuken
|
4
|
+
# Tracer is a Shoryuken server-side middleware which traces executed jobs
|
5
|
+
class Tracer
|
6
|
+
def initialize(options = {})
|
7
|
+
@tracer = options[:tracer] || Datadog.configuration[:shoryuken][:tracer]
|
8
|
+
@shoryuken_service = options[:service_name] || Datadog.configuration[:shoryuken][:service_name]
|
9
|
+
set_service_info(@shoryuken_service)
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(worker_instance, queue, sqs_msg, body)
|
13
|
+
@tracer.trace(Ext::SPAN_JOB, service: @shoryuken_service, span_type: Datadog::Ext::AppTypes::WORKER) do |span|
|
14
|
+
span.resource = worker_instance.class.name
|
15
|
+
span.set_tag(Ext::TAG_JOB_ID, sqs_msg.message_id)
|
16
|
+
span.set_tag(Ext::TAG_JOB_QUEUE, queue)
|
17
|
+
span.set_tag(Ext::TAG_JOB_ATTRIBUTES, sqs_msg.attributes) if sqs_msg.respond_to?(:attributes)
|
18
|
+
span.set_tag(Ext::TAG_JOB_BODY, body)
|
19
|
+
|
20
|
+
yield
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def set_service_info(service)
|
27
|
+
return if @tracer.services[service]
|
28
|
+
@tracer.set_service_info(
|
29
|
+
service,
|
30
|
+
Ext::APP,
|
31
|
+
Datadog::Ext::AppTypes::WORKER
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'ddtrace/contrib/sidekiq/tracing'
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module Contrib
|
5
|
+
module Sidekiq
|
6
|
+
# Tracer is a Sidekiq client-side middleware which traces job enqueues/pushes
|
7
|
+
class ClientTracer
|
8
|
+
include Tracing
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
super
|
12
|
+
@sidekiq_service = options[:client_service_name] || Datadog.configuration[:sidekiq][:client_service_name]
|
13
|
+
end
|
14
|
+
|
15
|
+
# Client middleware arguments are documented here:
|
16
|
+
# https://github.com/mperham/sidekiq/wiki/Middleware#client-middleware
|
17
|
+
def call(worker_class, job, queue, redis_pool)
|
18
|
+
service = @sidekiq_service
|
19
|
+
set_service_info(service)
|
20
|
+
|
21
|
+
resource = job_resource(job)
|
22
|
+
|
23
|
+
@tracer.trace(Ext::SPAN_PUSH, service: service) do |span|
|
24
|
+
span.resource = resource
|
25
|
+
span.set_tag(Ext::TAG_JOB_ID, job['jid'])
|
26
|
+
span.set_tag(Ext::TAG_JOB_QUEUE, job['queue'])
|
27
|
+
span.set_tag(Ext::TAG_JOB_WRAPPER, job['class']) if job['wrapped']
|
28
|
+
|
29
|
+
yield
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -16,10 +16,17 @@ module Datadog
|
|
16
16
|
def patch
|
17
17
|
do_once(:sidekiq) do
|
18
18
|
begin
|
19
|
-
require 'ddtrace/contrib/sidekiq/
|
19
|
+
require 'ddtrace/contrib/sidekiq/client_tracer'
|
20
|
+
::Sidekiq.configure_client do |config|
|
21
|
+
config.client_middleware do |chain|
|
22
|
+
chain.add(Sidekiq::ClientTracer)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'ddtrace/contrib/sidekiq/server_tracer'
|
20
27
|
::Sidekiq.configure_server do |config|
|
21
28
|
config.server_middleware do |chain|
|
22
|
-
chain.add(Sidekiq::
|
29
|
+
chain.add(Sidekiq::ServerTracer)
|
23
30
|
end
|
24
31
|
end
|
25
32
|
rescue StandardError => e
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'ddtrace/contrib/sidekiq/tracing'
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module Contrib
|
5
|
+
module Sidekiq
|
6
|
+
# Tracer is a Sidekiq server-side middleware which traces executed jobs
|
7
|
+
class ServerTracer
|
8
|
+
include Tracing
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
super
|
12
|
+
@sidekiq_service = options[:service_name] || Datadog.configuration[:sidekiq][:service_name]
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(worker, job, queue)
|
16
|
+
resource = job_resource(job)
|
17
|
+
|
18
|
+
service = service_from_worker_config(resource) || @sidekiq_service
|
19
|
+
set_service_info(service)
|
20
|
+
|
21
|
+
@tracer.trace(Ext::SPAN_JOB, service: service, span_type: Datadog::Ext::AppTypes::WORKER) do |span|
|
22
|
+
span.resource = resource
|
23
|
+
span.set_tag(Ext::TAG_JOB_ID, job['jid'])
|
24
|
+
span.set_tag(Ext::TAG_JOB_RETRY, job['retry'])
|
25
|
+
span.set_tag(Ext::TAG_JOB_QUEUE, job['queue'])
|
26
|
+
span.set_tag(Ext::TAG_JOB_WRAPPER, job['class']) if job['wrapped']
|
27
|
+
span.set_tag(Ext::TAG_JOB_DELAY, 1000.0 * (Time.now.utc.to_f - job['enqueued_at'].to_f))
|
28
|
+
|
29
|
+
yield
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def service_from_worker_config(resource)
|
36
|
+
# Try to get the Ruby class from the resource name.
|
37
|
+
worker_klass = begin
|
38
|
+
Object.const_get(resource)
|
39
|
+
rescue NameError
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
|
43
|
+
if worker_klass.respond_to?(:datadog_tracer_config)
|
44
|
+
worker_klass.datadog_tracer_config[:service_name]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'ddtrace/ext/app_types'
|
2
|
+
require 'ddtrace/contrib/sidekiq/ext'
|
3
|
+
|
4
|
+
module Datadog
|
5
|
+
module Contrib
|
6
|
+
module Sidekiq
|
7
|
+
# Common functionality used by both client-side and server-side tracers.
|
8
|
+
module Tracing
|
9
|
+
def initialize(options = {})
|
10
|
+
@tracer = options[:tracer] || Datadog.configuration[:sidekiq][:tracer]
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
# If class is wrapping something else, the interesting resource info
|
16
|
+
# is the underlying, wrapped class, and not the wrapper. This is
|
17
|
+
# primarily to support `ActiveJob`.
|
18
|
+
def job_resource(job)
|
19
|
+
if job['wrapped']
|
20
|
+
job['wrapped']
|
21
|
+
else
|
22
|
+
job['class']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_service_info(service)
|
27
|
+
# Ensure the tracer knows about this service.
|
28
|
+
return if @tracer.services[service]
|
29
|
+
@tracer.set_service_info(
|
30
|
+
service,
|
31
|
+
Ext::APP,
|
32
|
+
Datadog::Ext::AppTypes::WORKER
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/ddtrace/sync_writer.rb
CHANGED
data/lib/ddtrace/transport.rb
CHANGED
@@ -13,6 +13,9 @@ module Datadog
|
|
13
13
|
attr_accessor :hostname, :port
|
14
14
|
attr_reader :traces_endpoint, :services_endpoint
|
15
15
|
|
16
|
+
DEFAULT_AGENT_HOST = '127.0.0.1'.freeze
|
17
|
+
DEFAULT_TRACE_AGENT_PORT = '8126'.freeze
|
18
|
+
|
16
19
|
# seconds before the transport timeout
|
17
20
|
TIMEOUT = 1
|
18
21
|
|
@@ -45,11 +48,11 @@ module Datadog
|
|
45
48
|
|
46
49
|
private_constant :API
|
47
50
|
|
48
|
-
def initialize(
|
51
|
+
def initialize(options = {})
|
49
52
|
api_version = options.fetch(:api_version, V3)
|
50
53
|
|
51
|
-
@hostname = hostname
|
52
|
-
@port = port
|
54
|
+
@hostname = options[:hostname] || ENV['DD_AGENT_HOST'] || DEFAULT_AGENT_HOST
|
55
|
+
@port = options[:port] || ENV['DD_TRACE_AGENT_PORT'] || DEFAULT_TRACE_AGENT_PORT
|
53
56
|
@api = API.fetch(api_version)
|
54
57
|
@encoder = options[:encoder] || @api[:encoder]
|
55
58
|
@response_callback = options[:response_callback]
|
@@ -2,16 +2,20 @@ module Datadog
|
|
2
2
|
module Utils
|
3
3
|
# Common database-related utility functions.
|
4
4
|
module Database
|
5
|
+
VENDOR_DEFAULT = 'defaultdb'.freeze
|
6
|
+
VENDOR_POSTGRES = 'postgres'.freeze
|
7
|
+
VENDOR_SQLITE = 'sqlite'.freeze
|
8
|
+
|
5
9
|
module_function
|
6
10
|
|
7
11
|
def normalize_vendor(vendor)
|
8
12
|
case vendor
|
9
13
|
when nil
|
10
|
-
|
14
|
+
VENDOR_DEFAULT
|
11
15
|
when 'postgresql'
|
12
|
-
|
16
|
+
VENDOR_POSTGRES
|
13
17
|
when 'sqlite3'
|
14
|
-
|
18
|
+
VENDOR_SQLITE
|
15
19
|
else
|
16
20
|
vendor
|
17
21
|
end
|
data/lib/ddtrace/version.rb
CHANGED
data/lib/ddtrace/writer.rb
CHANGED
@@ -7,9 +7,6 @@ module Datadog
|
|
7
7
|
class Writer
|
8
8
|
attr_reader :transport, :worker, :priority_sampler
|
9
9
|
|
10
|
-
HOSTNAME = '127.0.0.1'.freeze
|
11
|
-
PORT = '8126'.freeze
|
12
|
-
|
13
10
|
def initialize(options = {})
|
14
11
|
# writer and transport parameters
|
15
12
|
@buff_size = options.fetch(:buffer_size, 100)
|
@@ -24,7 +21,7 @@ module Datadog
|
|
24
21
|
|
25
22
|
# transport and buffers
|
26
23
|
@transport = options.fetch(:transport) do
|
27
|
-
HTTPTransport.new(
|
24
|
+
HTTPTransport.new(transport_options)
|
28
25
|
end
|
29
26
|
|
30
27
|
@services = {}
|
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.18.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: 2018-
|
11
|
+
date: 2018-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|
@@ -283,6 +283,10 @@ files:
|
|
283
283
|
- docker-compose.yml
|
284
284
|
- docs/GettingStarted.md
|
285
285
|
- lib/ddtrace.rb
|
286
|
+
- lib/ddtrace/augmentation.rb
|
287
|
+
- lib/ddtrace/augmentation/method_wrapper.rb
|
288
|
+
- lib/ddtrace/augmentation/method_wrapping.rb
|
289
|
+
- lib/ddtrace/augmentation/shim.rb
|
286
290
|
- lib/ddtrace/buffer.rb
|
287
291
|
- lib/ddtrace/configurable.rb
|
288
292
|
- lib/ddtrace/configuration.rb
|
@@ -308,6 +312,7 @@ files:
|
|
308
312
|
- lib/ddtrace/contrib/active_record/ext.rb
|
309
313
|
- lib/ddtrace/contrib/active_record/integration.rb
|
310
314
|
- lib/ddtrace/contrib/active_record/patcher.rb
|
315
|
+
- lib/ddtrace/contrib/active_record/patches/abstract_adapter.rb
|
311
316
|
- lib/ddtrace/contrib/active_record/utils.rb
|
312
317
|
- lib/ddtrace/contrib/active_support/notifications/event.rb
|
313
318
|
- lib/ddtrace/contrib/active_support/notifications/subscriber.rb
|
@@ -452,11 +457,18 @@ files:
|
|
452
457
|
- lib/ddtrace/contrib/sequel/integration.rb
|
453
458
|
- lib/ddtrace/contrib/sequel/patcher.rb
|
454
459
|
- lib/ddtrace/contrib/sequel/utils.rb
|
460
|
+
- lib/ddtrace/contrib/shoryuken/configuration/settings.rb
|
461
|
+
- lib/ddtrace/contrib/shoryuken/ext.rb
|
462
|
+
- lib/ddtrace/contrib/shoryuken/integration.rb
|
463
|
+
- lib/ddtrace/contrib/shoryuken/patcher.rb
|
464
|
+
- lib/ddtrace/contrib/shoryuken/tracer.rb
|
465
|
+
- lib/ddtrace/contrib/sidekiq/client_tracer.rb
|
455
466
|
- lib/ddtrace/contrib/sidekiq/configuration/settings.rb
|
456
467
|
- lib/ddtrace/contrib/sidekiq/ext.rb
|
457
468
|
- lib/ddtrace/contrib/sidekiq/integration.rb
|
458
469
|
- lib/ddtrace/contrib/sidekiq/patcher.rb
|
459
|
-
- lib/ddtrace/contrib/sidekiq/
|
470
|
+
- lib/ddtrace/contrib/sidekiq/server_tracer.rb
|
471
|
+
- lib/ddtrace/contrib/sidekiq/tracing.rb
|
460
472
|
- lib/ddtrace/contrib/sinatra/configuration/settings.rb
|
461
473
|
- lib/ddtrace/contrib/sinatra/env.rb
|
462
474
|
- lib/ddtrace/contrib/sinatra/ext.rb
|