ddtrace 0.52.0 → 0.54.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +174 -11
- data/ddtrace.gemspec +6 -3
- data/docs/DevelopmentGuide.md +1 -6
- data/docs/GettingStarted.md +109 -18
- data/docs/ProfilingDevelopment.md +2 -2
- data/ext/ddtrace_profiling_native_extension/NativeExtensionDesign.md +86 -0
- data/ext/ddtrace_profiling_native_extension/clock_id.h +4 -0
- data/ext/ddtrace_profiling_native_extension/clock_id_from_pthread.c +52 -0
- data/ext/ddtrace_profiling_native_extension/clock_id_noop.c +14 -0
- data/ext/ddtrace_profiling_native_extension/extconf.rb +177 -8
- data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +35 -0
- data/ext/ddtrace_profiling_native_extension/private_vm_api_access.h +3 -0
- data/ext/ddtrace_profiling_native_extension/profiling.c +6 -1
- data/lib/datadog/ci/contrib/cucumber/formatter.rb +1 -0
- data/lib/datadog/ci/contrib/rspec/example.rb +1 -0
- data/lib/datadog/ci/contrib/rspec/integration.rb +2 -2
- data/lib/datadog/ci/ext/environment.rb +64 -22
- data/lib/datadog/ci/ext/test.rb +1 -0
- data/lib/datadog/ci/test.rb +5 -1
- data/lib/datadog/contrib.rb +2 -0
- data/lib/datadog/core/environment/vm_cache.rb +46 -0
- data/lib/ddtrace/buffer.rb +28 -16
- data/lib/ddtrace/configuration/agent_settings_resolver.rb +131 -53
- data/lib/ddtrace/configuration/components.rb +1 -1
- data/lib/ddtrace/configuration/settings.rb +13 -3
- data/lib/ddtrace/context.rb +10 -2
- data/lib/ddtrace/contrib/action_cable/instrumentation.rb +46 -0
- data/lib/ddtrace/contrib/action_cable/patcher.rb +1 -0
- data/lib/ddtrace/contrib/action_mailer/configuration/settings.rb +32 -0
- data/lib/ddtrace/contrib/action_mailer/event.rb +50 -0
- data/lib/ddtrace/contrib/action_mailer/events/deliver.rb +54 -0
- data/lib/ddtrace/contrib/action_mailer/events/process.rb +41 -0
- data/lib/ddtrace/contrib/action_mailer/events.rb +31 -0
- data/lib/ddtrace/contrib/action_mailer/ext.rb +32 -0
- data/lib/ddtrace/contrib/action_mailer/integration.rb +45 -0
- data/lib/ddtrace/contrib/action_mailer/patcher.rb +27 -0
- data/lib/ddtrace/contrib/active_job/configuration/settings.rb +33 -0
- data/lib/ddtrace/contrib/active_job/event.rb +54 -0
- data/lib/ddtrace/contrib/active_job/events/discard.rb +46 -0
- data/lib/ddtrace/contrib/active_job/events/enqueue.rb +45 -0
- data/lib/ddtrace/contrib/active_job/events/enqueue_at.rb +45 -0
- data/lib/ddtrace/contrib/active_job/events/enqueue_retry.rb +47 -0
- data/lib/ddtrace/contrib/active_job/events/perform.rb +45 -0
- data/lib/ddtrace/contrib/active_job/events/retry_stopped.rb +46 -0
- data/lib/ddtrace/contrib/active_job/events.rb +39 -0
- data/lib/ddtrace/contrib/active_job/ext.rb +32 -0
- data/lib/ddtrace/contrib/active_job/integration.rb +46 -0
- data/lib/ddtrace/contrib/active_job/log_injection.rb +21 -0
- data/lib/ddtrace/contrib/active_job/patcher.rb +33 -0
- data/lib/ddtrace/contrib/auto_instrument.rb +0 -1
- data/lib/ddtrace/contrib/delayed_job/plugin.rb +2 -2
- data/lib/ddtrace/contrib/mongodb/instrumentation.rb +1 -1
- data/lib/ddtrace/contrib/mongodb/integration.rb +5 -0
- data/lib/ddtrace/contrib/rails/auto_instrument_railtie.rb +0 -1
- data/lib/ddtrace/contrib/rails/configuration/settings.rb +7 -0
- data/lib/ddtrace/contrib/rails/framework.rb +24 -1
- data/lib/ddtrace/contrib/rails/patcher.rb +19 -10
- data/lib/ddtrace/contrib/redis/instrumentation.rb +90 -0
- data/lib/ddtrace/contrib/redis/patcher.rb +2 -84
- data/lib/ddtrace/contrib/registerable.rb +0 -1
- data/lib/ddtrace/contrib/resque/integration.rb +1 -5
- data/lib/ddtrace/contrib/sidekiq/ext.rb +3 -0
- data/lib/ddtrace/contrib/sidekiq/integration.rb +10 -0
- data/lib/ddtrace/contrib/sidekiq/patcher.rb +26 -0
- data/lib/ddtrace/contrib/sidekiq/server_internal_tracer/heartbeat.rb +30 -0
- data/lib/ddtrace/contrib/sidekiq/server_internal_tracer/job_fetch.rb +30 -0
- data/lib/ddtrace/contrib/sidekiq/server_internal_tracer/scheduled_push.rb +29 -0
- data/lib/ddtrace/contrib/sinatra/env.rb +2 -1
- data/lib/ddtrace/contrib/sinatra/tracer.rb +15 -2
- data/lib/ddtrace/ext/git.rb +12 -0
- data/lib/ddtrace/ext/priority.rb +6 -4
- data/lib/ddtrace/ext/profiling.rb +8 -11
- data/lib/ddtrace/ext/runtime.rb +3 -0
- data/lib/ddtrace/ext/transport.rb +11 -0
- data/lib/ddtrace/metrics.rb +2 -2
- data/lib/ddtrace/profiling/collectors/stack.rb +112 -72
- data/lib/ddtrace/profiling/encoding/profile.rb +10 -2
- data/lib/ddtrace/profiling/events/stack.rb +13 -13
- data/lib/ddtrace/profiling/native_extension.rb +23 -1
- data/lib/ddtrace/profiling/pprof/builder.rb +8 -2
- data/lib/ddtrace/profiling/pprof/converter.rb +22 -9
- data/lib/ddtrace/profiling/pprof/stack_sample.rb +32 -9
- data/lib/ddtrace/profiling/pprof/template.rb +2 -2
- data/lib/ddtrace/profiling/scheduler.rb +20 -4
- data/lib/ddtrace/profiling/tasks/setup.rb +21 -13
- data/lib/ddtrace/profiling/trace_identifiers/ddtrace.rb +10 -9
- data/lib/ddtrace/profiling/trace_identifiers/helper.rb +5 -5
- data/lib/ddtrace/profiling/transport/http/api/endpoint.rb +8 -15
- data/lib/ddtrace/profiling/transport/http.rb +8 -17
- data/lib/ddtrace/profiling.rb +0 -2
- data/lib/ddtrace/runtime/metrics.rb +14 -0
- data/lib/ddtrace/sampler.rb +18 -8
- data/lib/ddtrace/sampling/rule_sampler.rb +13 -1
- data/lib/ddtrace/span.rb +7 -19
- data/lib/ddtrace/tracer.rb +1 -1
- data/lib/ddtrace/transport/http/adapters/net.rb +13 -3
- data/lib/ddtrace/transport/http/adapters/test.rb +4 -2
- data/lib/ddtrace/transport/http/adapters/unix_socket.rb +23 -12
- data/lib/ddtrace/transport/http/builder.rb +13 -6
- data/lib/ddtrace/transport/http.rb +5 -11
- data/lib/ddtrace/utils/time.rb +11 -6
- data/lib/ddtrace/version.rb +2 -2
- data/lib/ddtrace/workers/{loop.rb → interval_loop.rb} +0 -16
- data/lib/ddtrace/workers/polling.rb +1 -1
- metadata +40 -10
- data/lib/ddtrace/profiling/ext/cpu.rb +0 -67
- data/lib/ddtrace/profiling/ext/cthread.rb +0 -156
@@ -0,0 +1,41 @@
|
|
1
|
+
# typed: false
|
2
|
+
require 'ddtrace/contrib/action_mailer/ext'
|
3
|
+
require 'ddtrace/contrib/action_mailer/event'
|
4
|
+
|
5
|
+
module Datadog
|
6
|
+
module Contrib
|
7
|
+
module ActionMailer
|
8
|
+
module Events
|
9
|
+
# Defines instrumentation for process.action_mailer event
|
10
|
+
module Process
|
11
|
+
include ActionMailer::Event
|
12
|
+
|
13
|
+
EVENT_NAME = 'process.action_mailer'.freeze
|
14
|
+
|
15
|
+
module_function
|
16
|
+
|
17
|
+
def event_name
|
18
|
+
self::EVENT_NAME
|
19
|
+
end
|
20
|
+
|
21
|
+
def span_name
|
22
|
+
Ext::SPAN_PROCESS
|
23
|
+
end
|
24
|
+
|
25
|
+
def span_type
|
26
|
+
# process.action_mailer processes email and renders partial templates
|
27
|
+
Datadog::Ext::HTTP::TEMPLATE
|
28
|
+
end
|
29
|
+
|
30
|
+
def process(span, event, _id, payload)
|
31
|
+
super
|
32
|
+
|
33
|
+
span.span_type = span_type
|
34
|
+
span.set_tag(Ext::TAG_ACTION, payload[:action])
|
35
|
+
span.set_tag(Ext::TAG_MAILER, payload[:mailer])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# typed: false
|
2
|
+
require 'ddtrace/contrib/action_mailer/events/process'
|
3
|
+
require 'ddtrace/contrib/action_mailer/events/deliver'
|
4
|
+
|
5
|
+
module Datadog
|
6
|
+
module Contrib
|
7
|
+
module ActionMailer
|
8
|
+
# Defines collection of instrumented ActionMailer events
|
9
|
+
module Events
|
10
|
+
ALL = [
|
11
|
+
Events::Process,
|
12
|
+
Events::Deliver
|
13
|
+
].freeze
|
14
|
+
|
15
|
+
module_function
|
16
|
+
|
17
|
+
def all
|
18
|
+
self::ALL
|
19
|
+
end
|
20
|
+
|
21
|
+
def subscriptions
|
22
|
+
all.collect(&:subscriptions).collect(&:to_a).flatten
|
23
|
+
end
|
24
|
+
|
25
|
+
def subscribe!
|
26
|
+
all.each(&:subscribe!)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# typed: true
|
2
|
+
module Datadog
|
3
|
+
module Contrib
|
4
|
+
module ActionMailer
|
5
|
+
# ActionMailer integration constants
|
6
|
+
module Ext
|
7
|
+
APP = 'action_mailer'.freeze
|
8
|
+
ENV_ENABLED = 'DD_TRACE_ACTION_MAILER_ENABLED'.freeze
|
9
|
+
ENV_ANALYTICS_ENABLED = 'DD_TRACE_ACTION_MAILER_ANALYTICS_ENABLED'.freeze
|
10
|
+
ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_ACTION_MAILER_ANALYTICS_SAMPLE_RATE'.freeze
|
11
|
+
|
12
|
+
ENV_ANALYTICS_ENABLED_OLD = 'DD_ACTION_MAILER_ANALYTICS_ENABLED'.freeze
|
13
|
+
|
14
|
+
ENV_ANALYTICS_SAMPLE_RATE_OLD = 'DD_ACTION_MAILER_ANALYTICS_SAMPLE_RATE'.freeze
|
15
|
+
SERVICE_NAME = 'action_mailer'.freeze
|
16
|
+
SPAN_PROCESS = 'action_mailer.process'.freeze
|
17
|
+
SPAN_DELIVER = 'action_mailer.deliver'.freeze
|
18
|
+
TAG_ACTION = 'action_mailer.action'.freeze
|
19
|
+
TAG_MAILER = 'action_mailer.mailer'.freeze
|
20
|
+
TAG_MSG_ID = 'action_mailer.message_id'.freeze
|
21
|
+
|
22
|
+
TAG_SUBJECT = 'action_mailer.subject'.freeze
|
23
|
+
TAG_TO = 'action_mailer.to'.freeze
|
24
|
+
TAG_FROM = 'action_mailer.from'.freeze
|
25
|
+
TAG_BCC = 'action_mailer.bcc'.freeze
|
26
|
+
TAG_CC = 'action_mailer.cc'.freeze
|
27
|
+
TAG_DATE = 'action_mailer.date'.freeze
|
28
|
+
TAG_PERFORM_DELIVERIES = 'action_mailer.perform_deliveries'.freeze
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# typed: false
|
2
|
+
require 'ddtrace/contrib/integration'
|
3
|
+
require 'ddtrace/contrib/action_mailer/configuration/settings'
|
4
|
+
require 'ddtrace/contrib/action_mailer/patcher'
|
5
|
+
|
6
|
+
module Datadog
|
7
|
+
module Contrib
|
8
|
+
module ActionMailer
|
9
|
+
# Description of ActionMailer integration
|
10
|
+
class Integration
|
11
|
+
include Contrib::Integration
|
12
|
+
|
13
|
+
MINIMUM_VERSION = Gem::Version.new('5.0.0')
|
14
|
+
|
15
|
+
register_as :action_mailer, auto_patch: false
|
16
|
+
|
17
|
+
def self.version
|
18
|
+
Gem.loaded_specs['actionmailer'] && Gem.loaded_specs['actionmailer'].version
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.loaded?
|
22
|
+
!defined?(::ActionMailer).nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.compatible?
|
26
|
+
super && version >= MINIMUM_VERSION && !defined?(::ActiveSupport::Notifications).nil?
|
27
|
+
end
|
28
|
+
|
29
|
+
# enabled by rails integration so should only auto instrument
|
30
|
+
# if detected that it is being used without rails
|
31
|
+
def auto_instrument?
|
32
|
+
!Datadog::Contrib::Rails::Utils.railtie_supported?
|
33
|
+
end
|
34
|
+
|
35
|
+
def default_configuration
|
36
|
+
Configuration::Settings.new
|
37
|
+
end
|
38
|
+
|
39
|
+
def patcher
|
40
|
+
ActionMailer::Patcher
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# typed: true
|
2
|
+
require 'ddtrace/contrib/patcher'
|
3
|
+
require 'ddtrace/ext/app_types'
|
4
|
+
require 'ddtrace/contrib/action_mailer/ext'
|
5
|
+
require 'ddtrace/contrib/action_mailer/events'
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
module Contrib
|
9
|
+
module ActionMailer
|
10
|
+
# Patcher enables patching of 'action_mailer' module.
|
11
|
+
module Patcher
|
12
|
+
include Contrib::Patcher
|
13
|
+
|
14
|
+
module_function
|
15
|
+
|
16
|
+
def target_version
|
17
|
+
Integration.version
|
18
|
+
end
|
19
|
+
|
20
|
+
def patch
|
21
|
+
# Subscribe to ActionMailer events
|
22
|
+
Events.subscribe!
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# typed: false
|
2
|
+
require 'ddtrace/contrib/configuration/settings'
|
3
|
+
require 'ddtrace/contrib/active_job/ext'
|
4
|
+
|
5
|
+
module Datadog
|
6
|
+
module Contrib
|
7
|
+
module ActiveJob
|
8
|
+
module Configuration
|
9
|
+
# Custom settings for the DelayedJob integration
|
10
|
+
class Settings < Contrib::Configuration::Settings
|
11
|
+
option :enabled do |o|
|
12
|
+
o.default { env_to_bool(Ext::ENV_ENABLED, true) }
|
13
|
+
o.lazy
|
14
|
+
end
|
15
|
+
|
16
|
+
option :analytics_enabled do |o|
|
17
|
+
o.default { env_to_bool([Ext::ENV_ANALYTICS_ENABLED, Ext::ENV_ANALYTICS_ENABLED_OLD], false) }
|
18
|
+
o.lazy
|
19
|
+
end
|
20
|
+
|
21
|
+
option :analytics_sample_rate do |o|
|
22
|
+
o.default { env_to_float([Ext::ENV_ANALYTICS_SAMPLE_RATE, Ext::ENV_ANALYTICS_SAMPLE_RATE_OLD], 1.0) }
|
23
|
+
o.lazy
|
24
|
+
end
|
25
|
+
|
26
|
+
option :service_name, default: Ext::SERVICE_NAME
|
27
|
+
option :error_handler, default: Datadog::Tracer::DEFAULT_ON_ERROR
|
28
|
+
option :log_injection, default: false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# typed: true
|
2
|
+
require 'ddtrace/contrib/active_support/notifications/event'
|
3
|
+
require 'ddtrace/contrib/active_job/ext'
|
4
|
+
|
5
|
+
module Datadog
|
6
|
+
module Contrib
|
7
|
+
module ActiveJob
|
8
|
+
# Defines basic behaviors for an ActiveJob event.
|
9
|
+
module Event
|
10
|
+
def self.included(base)
|
11
|
+
base.include(ActiveSupport::Notifications::Event)
|
12
|
+
base.extend(ClassMethods)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Class methods for ActiveJob events.
|
16
|
+
module ClassMethods
|
17
|
+
def span_options
|
18
|
+
{ service: configuration[:service_name] }
|
19
|
+
end
|
20
|
+
|
21
|
+
def tracer
|
22
|
+
-> { configuration[:tracer] }
|
23
|
+
end
|
24
|
+
|
25
|
+
def configuration
|
26
|
+
Datadog.configuration[:active_job]
|
27
|
+
end
|
28
|
+
|
29
|
+
def set_common_tags(span, payload)
|
30
|
+
adapter_name = if payload[:adapter].is_a?(Class)
|
31
|
+
payload[:adapter].name
|
32
|
+
else
|
33
|
+
payload[:adapter].class.name
|
34
|
+
end
|
35
|
+
span.set_tag(Ext::TAG_ADAPTER, adapter_name)
|
36
|
+
|
37
|
+
job = payload[:job]
|
38
|
+
span.set_tag(Ext::TAG_JOB_ID, job.job_id)
|
39
|
+
span.set_tag(Ext::TAG_JOB_QUEUE, job.queue_name)
|
40
|
+
span.set_tag(Ext::TAG_JOB_PRIORITY, job.priority) if job.respond_to?(:priority)
|
41
|
+
span.set_tag(Ext::TAG_JOB_EXECUTIONS, job.executions) if job.respond_to?(:executions)
|
42
|
+
|
43
|
+
job_scheduled_at = if job.respond_to?(:scheduled_at)
|
44
|
+
job.scheduled_at
|
45
|
+
elsif job.respond_to?(:enqueued_at)
|
46
|
+
job.enqueued_at
|
47
|
+
end
|
48
|
+
span.set_tag(Ext::TAG_JOB_SCHEDULED_AT, Time.at(job_scheduled_at)) if job_scheduled_at
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# typed: false
|
2
|
+
require 'ddtrace/ext/integration'
|
3
|
+
require 'ddtrace/contrib/analytics'
|
4
|
+
require 'ddtrace/contrib/active_job/ext'
|
5
|
+
require 'ddtrace/contrib/active_job/event'
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
module Contrib
|
9
|
+
module ActiveJob
|
10
|
+
module Events
|
11
|
+
# Defines instrumentation for enqueue.active_job event
|
12
|
+
module Discard
|
13
|
+
include ActiveJob::Event
|
14
|
+
|
15
|
+
EVENT_NAME = 'discard.active_job'.freeze
|
16
|
+
|
17
|
+
module_function
|
18
|
+
|
19
|
+
def event_name
|
20
|
+
self::EVENT_NAME
|
21
|
+
end
|
22
|
+
|
23
|
+
def span_name
|
24
|
+
Ext::SPAN_DISCARD
|
25
|
+
end
|
26
|
+
|
27
|
+
def process(span, event, _id, payload)
|
28
|
+
span.name = span_name
|
29
|
+
span.service = configuration[:service_name]
|
30
|
+
span.resource = payload[:job].class.name
|
31
|
+
|
32
|
+
# Set analytics sample rate
|
33
|
+
if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
|
34
|
+
Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate])
|
35
|
+
end
|
36
|
+
|
37
|
+
set_common_tags(span, payload)
|
38
|
+
span.set_tag(Ext::TAG_JOB_ERROR, payload[:error])
|
39
|
+
rescue StandardError => e
|
40
|
+
Datadog.logger.debug(e.message)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# typed: false
|
2
|
+
require 'ddtrace/ext/integration'
|
3
|
+
require 'ddtrace/contrib/analytics'
|
4
|
+
require 'ddtrace/contrib/active_job/ext'
|
5
|
+
require 'ddtrace/contrib/active_job/event'
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
module Contrib
|
9
|
+
module ActiveJob
|
10
|
+
module Events
|
11
|
+
# Defines instrumentation for enqueue.active_job event
|
12
|
+
module Enqueue
|
13
|
+
include ActiveJob::Event
|
14
|
+
|
15
|
+
EVENT_NAME = 'enqueue.active_job'.freeze
|
16
|
+
|
17
|
+
module_function
|
18
|
+
|
19
|
+
def event_name
|
20
|
+
self::EVENT_NAME
|
21
|
+
end
|
22
|
+
|
23
|
+
def span_name
|
24
|
+
Ext::SPAN_ENQUEUE
|
25
|
+
end
|
26
|
+
|
27
|
+
def process(span, event, _id, payload)
|
28
|
+
span.name = span_name
|
29
|
+
span.service = configuration[:service_name]
|
30
|
+
span.resource = payload[:job].class.name
|
31
|
+
|
32
|
+
# Set analytics sample rate
|
33
|
+
if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
|
34
|
+
Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate])
|
35
|
+
end
|
36
|
+
|
37
|
+
set_common_tags(span, payload)
|
38
|
+
rescue StandardError => e
|
39
|
+
Datadog.logger.debug(e.message)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# typed: false
|
2
|
+
require 'ddtrace/ext/integration'
|
3
|
+
require 'ddtrace/contrib/analytics'
|
4
|
+
require 'ddtrace/contrib/active_job/ext'
|
5
|
+
require 'ddtrace/contrib/active_job/event'
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
module Contrib
|
9
|
+
module ActiveJob
|
10
|
+
module Events
|
11
|
+
# Defines instrumentation for enqueue.active_job event
|
12
|
+
module EnqueueAt
|
13
|
+
include ActiveJob::Event
|
14
|
+
|
15
|
+
EVENT_NAME = 'enqueue_at.active_job'.freeze
|
16
|
+
|
17
|
+
module_function
|
18
|
+
|
19
|
+
def event_name
|
20
|
+
self::EVENT_NAME
|
21
|
+
end
|
22
|
+
|
23
|
+
def span_name
|
24
|
+
Ext::SPAN_ENQUEUE
|
25
|
+
end
|
26
|
+
|
27
|
+
def process(span, event, _id, payload)
|
28
|
+
span.name = span_name
|
29
|
+
span.service = configuration[:service_name]
|
30
|
+
span.resource = payload[:job].class.name
|
31
|
+
|
32
|
+
# Set analytics sample rate
|
33
|
+
if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
|
34
|
+
Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate])
|
35
|
+
end
|
36
|
+
|
37
|
+
set_common_tags(span, payload)
|
38
|
+
rescue StandardError => e
|
39
|
+
Datadog.logger.debug(e.message)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# typed: false
|
2
|
+
require 'ddtrace/ext/integration'
|
3
|
+
require 'ddtrace/contrib/analytics'
|
4
|
+
require 'ddtrace/contrib/active_job/ext'
|
5
|
+
require 'ddtrace/contrib/active_job/event'
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
module Contrib
|
9
|
+
module ActiveJob
|
10
|
+
module Events
|
11
|
+
# Defines instrumentation for enqueue.active_job event
|
12
|
+
module EnqueueRetry
|
13
|
+
include ActiveJob::Event
|
14
|
+
|
15
|
+
EVENT_NAME = 'enqueue_retry.active_job'.freeze
|
16
|
+
|
17
|
+
module_function
|
18
|
+
|
19
|
+
def event_name
|
20
|
+
self::EVENT_NAME
|
21
|
+
end
|
22
|
+
|
23
|
+
def span_name
|
24
|
+
Ext::SPAN_ENQUEUE_RETRY
|
25
|
+
end
|
26
|
+
|
27
|
+
def process(span, event, _id, payload)
|
28
|
+
span.name = span_name
|
29
|
+
span.service = configuration[:service_name]
|
30
|
+
span.resource = payload[:job].class.name
|
31
|
+
|
32
|
+
# Set analytics sample rate
|
33
|
+
if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
|
34
|
+
Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate])
|
35
|
+
end
|
36
|
+
|
37
|
+
set_common_tags(span, payload)
|
38
|
+
span.set_tag(Ext::TAG_JOB_ERROR, payload[:error])
|
39
|
+
span.set_tag(Ext::TAG_JOB_RETRY_WAIT, payload[:wait])
|
40
|
+
rescue StandardError => e
|
41
|
+
Datadog.logger.debug(e.message)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# typed: false
|
2
|
+
require 'ddtrace/ext/integration'
|
3
|
+
require 'ddtrace/contrib/analytics'
|
4
|
+
require 'ddtrace/contrib/active_job/ext'
|
5
|
+
require 'ddtrace/contrib/active_job/event'
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
module Contrib
|
9
|
+
module ActiveJob
|
10
|
+
module Events
|
11
|
+
# Defines instrumentation for perform.active_job event
|
12
|
+
module Perform
|
13
|
+
include ActiveJob::Event
|
14
|
+
|
15
|
+
EVENT_NAME = 'perform.active_job'.freeze
|
16
|
+
|
17
|
+
module_function
|
18
|
+
|
19
|
+
def event_name
|
20
|
+
self::EVENT_NAME
|
21
|
+
end
|
22
|
+
|
23
|
+
def span_name
|
24
|
+
Ext::SPAN_PERFORM
|
25
|
+
end
|
26
|
+
|
27
|
+
def process(span, event, _id, payload)
|
28
|
+
span.name = span_name
|
29
|
+
span.service = configuration[:service_name]
|
30
|
+
span.resource = payload[:job].class.name
|
31
|
+
|
32
|
+
# Set analytics sample rate
|
33
|
+
if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
|
34
|
+
Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate])
|
35
|
+
end
|
36
|
+
|
37
|
+
set_common_tags(span, payload)
|
38
|
+
rescue StandardError => e
|
39
|
+
Datadog.logger.debug(e.message)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# typed: false
|
2
|
+
require 'ddtrace/ext/integration'
|
3
|
+
require 'ddtrace/contrib/analytics'
|
4
|
+
require 'ddtrace/contrib/active_job/ext'
|
5
|
+
require 'ddtrace/contrib/active_job/event'
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
module Contrib
|
9
|
+
module ActiveJob
|
10
|
+
module Events
|
11
|
+
# Defines instrumentation for enqueue.active_job event
|
12
|
+
module RetryStopped
|
13
|
+
include ActiveJob::Event
|
14
|
+
|
15
|
+
EVENT_NAME = 'retry_stopped.active_job'.freeze
|
16
|
+
|
17
|
+
module_function
|
18
|
+
|
19
|
+
def event_name
|
20
|
+
self::EVENT_NAME
|
21
|
+
end
|
22
|
+
|
23
|
+
def span_name
|
24
|
+
Ext::SPAN_RETRY_STOPPED
|
25
|
+
end
|
26
|
+
|
27
|
+
def process(span, event, _id, payload)
|
28
|
+
span.name = span_name
|
29
|
+
span.service = configuration[:service_name]
|
30
|
+
span.resource = payload[:job].class.name
|
31
|
+
|
32
|
+
# Set analytics sample rate
|
33
|
+
if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
|
34
|
+
Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate])
|
35
|
+
end
|
36
|
+
|
37
|
+
set_common_tags(span, payload)
|
38
|
+
span.set_tag(Ext::TAG_JOB_ERROR, payload[:error])
|
39
|
+
rescue StandardError => e
|
40
|
+
Datadog.logger.debug(e.message)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# typed: false
|
2
|
+
require 'ddtrace/contrib/active_job/events/discard'
|
3
|
+
require 'ddtrace/contrib/active_job/events/enqueue'
|
4
|
+
require 'ddtrace/contrib/active_job/events/enqueue_at'
|
5
|
+
require 'ddtrace/contrib/active_job/events/enqueue_retry'
|
6
|
+
require 'ddtrace/contrib/active_job/events/perform'
|
7
|
+
require 'ddtrace/contrib/active_job/events/retry_stopped'
|
8
|
+
|
9
|
+
module Datadog
|
10
|
+
module Contrib
|
11
|
+
module ActiveJob
|
12
|
+
# Defines collection of instrumented ActiveJob events
|
13
|
+
module Events
|
14
|
+
ALL = [
|
15
|
+
Events::Discard,
|
16
|
+
Events::Enqueue,
|
17
|
+
Events::EnqueueAt,
|
18
|
+
Events::EnqueueRetry,
|
19
|
+
Events::Perform,
|
20
|
+
Events::RetryStopped,
|
21
|
+
].freeze
|
22
|
+
|
23
|
+
module_function
|
24
|
+
|
25
|
+
def all
|
26
|
+
self::ALL
|
27
|
+
end
|
28
|
+
|
29
|
+
def subscriptions
|
30
|
+
all.collect(&:subscriptions).collect(&:to_a).flatten
|
31
|
+
end
|
32
|
+
|
33
|
+
def subscribe!
|
34
|
+
all.each(&:subscribe!)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# typed: true
|
2
|
+
module Datadog
|
3
|
+
module Contrib
|
4
|
+
module ActiveJob
|
5
|
+
module Ext
|
6
|
+
APP = 'active_job'.freeze
|
7
|
+
SERVICE_NAME = 'active_job'.freeze
|
8
|
+
|
9
|
+
ENV_ENABLED = 'DD_TRACE_ACTIVE_JOB_ENABLED'.freeze
|
10
|
+
ENV_ANALYTICS_ENABLED = 'DD_TRACE_ACTIVE_JOB_ANALYTICS_ENABLED'.freeze
|
11
|
+
ENV_ANALYTICS_ENABLED_OLD = 'DD_ACTIVE_JOB_ANALYTICS_ENABLED'.freeze
|
12
|
+
ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_ACTIVE_JOB_ANALYTICS_SAMPLE_RATE'.freeze
|
13
|
+
ENV_ANALYTICS_SAMPLE_RATE_OLD = 'DD_ACTIVE_JOB_ANALYTICS_SAMPLE_RATE'.freeze
|
14
|
+
|
15
|
+
SPAN_DISCARD = 'active_job.discard'.freeze
|
16
|
+
SPAN_ENQUEUE = 'active_job.enqueue'.freeze
|
17
|
+
SPAN_ENQUEUE_RETRY = 'active_job.enqueue_retry'.freeze
|
18
|
+
SPAN_PERFORM = 'active_job.perform'.freeze
|
19
|
+
SPAN_RETRY_STOPPED = 'active_job.retry_stopped'.freeze
|
20
|
+
|
21
|
+
TAG_ADAPTER = 'active_job.adapter'.freeze
|
22
|
+
TAG_JOB_ERROR = 'active_job.job.error'.freeze
|
23
|
+
TAG_JOB_EXECUTIONS = 'active_job.job.executions'.freeze
|
24
|
+
TAG_JOB_ID = 'active_job.job.id'.freeze
|
25
|
+
TAG_JOB_PRIORITY = 'active_job.job.priority'.freeze
|
26
|
+
TAG_JOB_QUEUE = 'active_job.job.queue'.freeze
|
27
|
+
TAG_JOB_RETRY_WAIT = 'active_job.job.retry_wait'.freeze
|
28
|
+
TAG_JOB_SCHEDULED_AT = 'active_job.job.scheduled_at'.freeze
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# typed: false
|
2
|
+
require 'ddtrace/contrib/integration'
|
3
|
+
require 'ddtrace/contrib/active_job/configuration/settings'
|
4
|
+
require 'ddtrace/contrib/active_job/patcher'
|
5
|
+
require 'ddtrace/contrib/rails/utils'
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
module Contrib
|
9
|
+
module ActiveJob
|
10
|
+
# Describes the ActiveJob integration
|
11
|
+
class Integration
|
12
|
+
include Contrib::Integration
|
13
|
+
|
14
|
+
MINIMUM_VERSION = Gem::Version.new('4.2')
|
15
|
+
|
16
|
+
register_as :active_job, auto_patch: false
|
17
|
+
|
18
|
+
def self.version
|
19
|
+
Gem.loaded_specs['activejob'] && Gem.loaded_specs['activejob'].version
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.loaded?
|
23
|
+
!defined?(::ActiveJob).nil?
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.compatible?
|
27
|
+
super && version >= MINIMUM_VERSION
|
28
|
+
end
|
29
|
+
|
30
|
+
# enabled by rails integration so should only auto instrument
|
31
|
+
# if detected that it is being used without rails
|
32
|
+
def auto_instrument?
|
33
|
+
!Datadog::Contrib::Rails::Utils.railtie_supported?
|
34
|
+
end
|
35
|
+
|
36
|
+
def default_configuration
|
37
|
+
Configuration::Settings.new
|
38
|
+
end
|
39
|
+
|
40
|
+
def patcher
|
41
|
+
ActiveJob::Patcher
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# typed: false
|
2
|
+
module Datadog
|
3
|
+
module Contrib
|
4
|
+
module ActiveJob
|
5
|
+
# Active Job log injection wrapped around job execution
|
6
|
+
module LogInjection
|
7
|
+
def self.included(base)
|
8
|
+
base.class_eval do
|
9
|
+
around_perform do |_, block|
|
10
|
+
if logger.respond_to?(:tagged)
|
11
|
+
logger.tagged(Datadog.tracer.active_correlation.to_s, &block)
|
12
|
+
else
|
13
|
+
block.call
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|