datadog 2.1.0 → 2.3.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 +4 -4
- data/CHANGELOG.md +101 -1
- data/ext/datadog_profiling_loader/extconf.rb +15 -15
- data/ext/datadog_profiling_native_extension/clock_id.h +1 -0
- data/ext/datadog_profiling_native_extension/clock_id_from_pthread.c +1 -2
- data/ext/datadog_profiling_native_extension/clock_id_noop.c +1 -2
- data/ext/datadog_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +132 -44
- data/ext/datadog_profiling_native_extension/collectors_discrete_dynamic_sampler.c +49 -26
- data/ext/datadog_profiling_native_extension/collectors_discrete_dynamic_sampler.h +34 -4
- data/ext/datadog_profiling_native_extension/collectors_idle_sampling_helper.c +4 -0
- data/ext/datadog_profiling_native_extension/collectors_stack.c +90 -37
- data/ext/datadog_profiling_native_extension/collectors_stack.h +2 -2
- data/ext/datadog_profiling_native_extension/collectors_thread_context.c +81 -19
- data/ext/datadog_profiling_native_extension/collectors_thread_context.h +1 -0
- data/ext/datadog_profiling_native_extension/datadog_ruby_common.c +110 -0
- data/ext/datadog_profiling_native_extension/datadog_ruby_common.h +57 -0
- data/ext/datadog_profiling_native_extension/extconf.rb +69 -62
- data/ext/datadog_profiling_native_extension/heap_recorder.c +34 -6
- data/ext/datadog_profiling_native_extension/heap_recorder.h +3 -1
- data/ext/datadog_profiling_native_extension/helpers.h +6 -17
- data/ext/datadog_profiling_native_extension/http_transport.c +3 -3
- data/ext/datadog_profiling_native_extension/libdatadog_helpers.c +0 -86
- data/ext/datadog_profiling_native_extension/libdatadog_helpers.h +2 -23
- data/ext/datadog_profiling_native_extension/native_extension_helpers.rb +61 -126
- data/ext/datadog_profiling_native_extension/private_vm_api_access.c +64 -138
- data/ext/datadog_profiling_native_extension/private_vm_api_access.h +17 -11
- data/ext/datadog_profiling_native_extension/profiling.c +0 -2
- data/ext/datadog_profiling_native_extension/ruby_helpers.c +0 -33
- data/ext/datadog_profiling_native_extension/ruby_helpers.h +1 -26
- data/ext/datadog_profiling_native_extension/setup_signal_handler.c +1 -1
- data/ext/datadog_profiling_native_extension/setup_signal_handler.h +1 -0
- data/ext/datadog_profiling_native_extension/stack_recorder.c +27 -8
- data/ext/datadog_profiling_native_extension/stack_recorder.h +2 -0
- data/ext/datadog_profiling_native_extension/time_helpers.c +0 -15
- data/ext/datadog_profiling_native_extension/time_helpers.h +36 -6
- data/ext/{datadog_profiling_native_extension → libdatadog_api}/crashtracker.c +20 -7
- data/ext/libdatadog_api/datadog_ruby_common.c +110 -0
- data/ext/libdatadog_api/datadog_ruby_common.h +57 -0
- data/ext/libdatadog_api/extconf.rb +108 -0
- data/ext/libdatadog_api/macos_development.md +26 -0
- data/ext/libdatadog_extconf_helpers.rb +130 -0
- data/lib/datadog/appsec/contrib/graphql/appsec_trace.rb +49 -0
- data/lib/datadog/appsec/contrib/graphql/gateway/multiplex.rb +73 -0
- data/lib/datadog/appsec/contrib/graphql/gateway/watcher.rb +68 -0
- data/lib/datadog/appsec/contrib/graphql/integration.rb +41 -0
- data/lib/datadog/appsec/contrib/graphql/patcher.rb +37 -0
- data/lib/datadog/appsec/contrib/graphql/reactive/multiplex.rb +59 -0
- data/lib/datadog/appsec/contrib/rack/gateway/request.rb +1 -1
- data/lib/datadog/appsec/contrib/sinatra/patcher.rb +1 -1
- data/lib/datadog/appsec/extensions.rb +1 -0
- data/lib/datadog/appsec/processor/actions.rb +1 -1
- data/lib/datadog/appsec/response.rb +15 -1
- data/lib/datadog/appsec.rb +1 -0
- data/lib/datadog/core/configuration/components.rb +17 -12
- data/lib/datadog/core/configuration/settings.rb +93 -7
- data/lib/datadog/core/configuration.rb +3 -17
- data/lib/datadog/core/crashtracking/agent_base_url.rb +21 -0
- data/lib/datadog/core/crashtracking/component.rb +111 -0
- data/lib/datadog/core/crashtracking/tag_builder.rb +39 -0
- data/lib/datadog/core/deprecations.rb +58 -0
- data/lib/datadog/core/diagnostics/environment_logger.rb +8 -11
- data/lib/datadog/core/environment/yjit.rb +5 -0
- data/lib/datadog/core/runtime/ext.rb +1 -0
- data/lib/datadog/core/runtime/metrics.rb +6 -0
- data/lib/datadog/core/telemetry/component.rb +154 -0
- data/lib/datadog/core/telemetry/emitter.rb +9 -11
- data/lib/datadog/core/telemetry/event.rb +132 -26
- data/lib/datadog/core/telemetry/ext.rb +3 -0
- data/lib/datadog/core/telemetry/http/adapters/net.rb +11 -13
- data/lib/datadog/core/telemetry/http/ext.rb +3 -0
- data/lib/datadog/core/telemetry/http/transport.rb +38 -9
- data/lib/datadog/core/telemetry/logging.rb +35 -0
- data/lib/datadog/core/telemetry/metric.rb +167 -0
- data/lib/datadog/core/telemetry/metrics_collection.rb +81 -0
- data/lib/datadog/core/telemetry/metrics_manager.rb +81 -0
- data/lib/datadog/core/telemetry/request.rb +1 -1
- data/lib/datadog/core/telemetry/worker.rb +173 -0
- data/lib/datadog/core/utils/at_fork_monkey_patch.rb +102 -0
- data/lib/datadog/core/utils/only_once_successful.rb +76 -0
- data/lib/datadog/core.rb +2 -19
- data/lib/datadog/kit/appsec/events.rb +2 -4
- data/lib/datadog/opentelemetry/sdk/propagator.rb +5 -10
- data/lib/datadog/opentelemetry/sdk/span_processor.rb +15 -2
- data/lib/datadog/opentelemetry/sdk/trace/span.rb +23 -0
- data/lib/datadog/profiling/collectors/code_provenance.rb +24 -11
- data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +17 -17
- data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +11 -13
- data/lib/datadog/profiling/collectors/info.rb +3 -3
- data/lib/datadog/profiling/collectors/thread_context.rb +4 -2
- data/lib/datadog/profiling/component.rb +85 -90
- data/lib/datadog/profiling/exporter.rb +3 -3
- data/lib/datadog/profiling/ext/dir_monkey_patches.rb +410 -0
- data/lib/datadog/profiling/ext.rb +21 -21
- data/lib/datadog/profiling/flush.rb +1 -1
- data/lib/datadog/profiling/http_transport.rb +8 -6
- data/lib/datadog/profiling/load_native_extension.rb +5 -5
- data/lib/datadog/profiling/preload.rb +1 -1
- data/lib/datadog/profiling/profiler.rb +5 -8
- data/lib/datadog/profiling/scheduler.rb +31 -25
- data/lib/datadog/profiling/tag_builder.rb +2 -2
- data/lib/datadog/profiling/tasks/exec.rb +5 -5
- data/lib/datadog/profiling/tasks/setup.rb +16 -35
- data/lib/datadog/profiling.rb +5 -5
- data/lib/datadog/tracing/contrib/action_cable/event.rb +1 -1
- data/lib/datadog/tracing/contrib/action_cable/events/broadcast.rb +1 -1
- data/lib/datadog/tracing/contrib/action_cable/events/perform_action.rb +1 -1
- data/lib/datadog/tracing/contrib/action_cable/events/transmit.rb +1 -1
- data/lib/datadog/tracing/contrib/action_mailer/event.rb +4 -6
- data/lib/datadog/tracing/contrib/action_mailer/events/deliver.rb +9 -4
- data/lib/datadog/tracing/contrib/action_mailer/events/process.rb +3 -2
- data/lib/datadog/tracing/contrib/action_view/events/render_partial.rb +1 -5
- data/lib/datadog/tracing/contrib/action_view/events/render_template.rb +1 -1
- data/lib/datadog/tracing/contrib/active_job/events/discard.rb +1 -1
- data/lib/datadog/tracing/contrib/active_job/events/enqueue.rb +1 -1
- data/lib/datadog/tracing/contrib/active_job/events/enqueue_at.rb +1 -1
- data/lib/datadog/tracing/contrib/active_job/events/enqueue_retry.rb +1 -1
- data/lib/datadog/tracing/contrib/active_job/events/perform.rb +1 -1
- data/lib/datadog/tracing/contrib/active_job/events/retry_stopped.rb +1 -1
- data/lib/datadog/tracing/contrib/active_model_serializers/events/render.rb +1 -1
- data/lib/datadog/tracing/contrib/active_model_serializers/events/serialize.rb +1 -1
- data/lib/datadog/tracing/contrib/active_record/events/instantiation.rb +1 -1
- data/lib/datadog/tracing/contrib/active_record/events/sql.rb +2 -1
- data/lib/datadog/tracing/contrib/active_support/cache/event.rb +32 -0
- data/lib/datadog/tracing/contrib/active_support/cache/events/cache.rb +156 -0
- data/lib/datadog/tracing/contrib/active_support/cache/events.rb +34 -0
- data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +45 -41
- data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +17 -40
- data/lib/datadog/tracing/contrib/active_support/cache/redis.rb +4 -1
- data/lib/datadog/tracing/contrib/active_support/notifications/event.rb +29 -6
- data/lib/datadog/tracing/contrib/active_support/notifications/subscriber.rb +16 -4
- data/lib/datadog/tracing/contrib/active_support/notifications/subscription.rb +33 -29
- data/lib/datadog/tracing/contrib/analytics.rb +5 -0
- data/lib/datadog/tracing/contrib/ext.rb +14 -0
- data/lib/datadog/tracing/contrib/graphql/configuration/settings.rb +5 -0
- data/lib/datadog/tracing/contrib/graphql/patcher.rb +8 -2
- data/lib/datadog/tracing/contrib/graphql/unified_trace.rb +166 -0
- data/lib/datadog/tracing/contrib/graphql/unified_trace_patcher.rb +28 -0
- data/lib/datadog/tracing/contrib/kafka/consumer_event.rb +1 -1
- data/lib/datadog/tracing/contrib/kafka/consumer_group_event.rb +1 -1
- data/lib/datadog/tracing/contrib/kafka/event.rb +1 -1
- data/lib/datadog/tracing/contrib/kafka/events/connection/request.rb +3 -3
- data/lib/datadog/tracing/contrib/kafka/events/consumer/process_batch.rb +3 -3
- data/lib/datadog/tracing/contrib/kafka/events/consumer/process_message.rb +3 -3
- data/lib/datadog/tracing/contrib/kafka/events/consumer_group/heartbeat.rb +3 -3
- data/lib/datadog/tracing/contrib/kafka/events/produce_operation/send_messages.rb +3 -3
- data/lib/datadog/tracing/contrib/kafka/events/producer/deliver_messages.rb +3 -3
- data/lib/datadog/tracing/contrib/lograge/patcher.rb +16 -0
- data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +5 -0
- data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +17 -13
- data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +5 -0
- data/lib/datadog/tracing/contrib/pg/instrumentation.rb +4 -1
- data/lib/datadog/tracing/contrib/propagation/sql_comment/ext.rb +28 -0
- data/lib/datadog/tracing/contrib/propagation/sql_comment/mode.rb +5 -1
- data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +22 -10
- data/lib/datadog/tracing/contrib/racecar/event.rb +2 -2
- data/lib/datadog/tracing/contrib/rails/ext.rb +9 -0
- data/lib/datadog/tracing/contrib/rails/patcher.rb +7 -0
- data/lib/datadog/tracing/contrib/rails/runner.rb +95 -0
- data/lib/datadog/tracing/contrib/trilogy/configuration/settings.rb +5 -0
- data/lib/datadog/tracing/contrib/trilogy/instrumentation.rb +4 -1
- data/lib/datadog/tracing/diagnostics/environment_logger.rb +14 -16
- data/lib/datadog/tracing/distributed/b3_multi.rb +1 -1
- data/lib/datadog/tracing/distributed/b3_single.rb +3 -1
- data/lib/datadog/tracing/distributed/datadog.rb +2 -2
- data/lib/datadog/tracing/distributed/propagation.rb +9 -2
- data/lib/datadog/tracing/distributed/trace_context.rb +3 -2
- data/lib/datadog/tracing/metadata/errors.rb +9 -1
- data/lib/datadog/tracing/metadata/ext.rb +4 -0
- data/lib/datadog/tracing/pipeline/span_filter.rb +2 -2
- data/lib/datadog/tracing/span.rb +9 -2
- data/lib/datadog/tracing/span_event.rb +41 -0
- data/lib/datadog/tracing/span_operation.rb +9 -4
- data/lib/datadog/tracing/trace_operation.rb +7 -3
- data/lib/datadog/tracing/trace_segment.rb +4 -1
- data/lib/datadog/tracing/tracer.rb +9 -2
- data/lib/datadog/tracing/transport/serializable_trace.rb +3 -0
- data/lib/datadog/tracing.rb +5 -1
- data/lib/datadog/version.rb +2 -2
- metadata +43 -12
- data/lib/datadog/core/telemetry/client.rb +0 -95
- data/lib/datadog/core/telemetry/heartbeat.rb +0 -33
- data/lib/datadog/profiling/crashtracker.rb +0 -91
- data/lib/datadog/profiling/ext/forking.rb +0 -98
@@ -0,0 +1,410 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module Profiling
|
5
|
+
# Monkey patches needed for profiler features and compatibility
|
6
|
+
module Ext
|
7
|
+
# All Ruby versions as of this writing have bugs in the dir class implementation, causing issues such as
|
8
|
+
# https://github.com/DataDog/dd-trace-rb/issues/3450 .
|
9
|
+
# See also https://bugs.ruby-lang.org/issues/20586 for more details.
|
10
|
+
#
|
11
|
+
# This monkey patch for the Ruby `Dir` class works around these bugs for affected Ruby versions by temporarily
|
12
|
+
# blocking the profiler from interrupting system calls.
|
13
|
+
#
|
14
|
+
# A lot of these APIs do very similar things -- they're provided by Ruby as helpers so users don't need to keep
|
15
|
+
# reimplementing them but share the same underlying buggy code. And so our monkey patches are a bit repetitive
|
16
|
+
# as well.
|
17
|
+
# We don't DRY out this file to have minimal overhead.
|
18
|
+
#
|
19
|
+
# These monkey patches are applied by the profiler when the "dir_interruption_workaround_enabled" setting is
|
20
|
+
# enabled. See the profiling settings for more detail.
|
21
|
+
module DirMonkeyPatches
|
22
|
+
def self.apply!
|
23
|
+
::Dir.singleton_class.prepend(Datadog::Profiling::Ext::DirClassMonkeyPatches)
|
24
|
+
::Dir.prepend(Datadog::Profiling::Ext::DirInstanceMonkeyPatches)
|
25
|
+
|
26
|
+
true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
if RUBY_VERSION.start_with?("2.")
|
31
|
+
# Monkey patches for Dir.singleton_class (Ruby 2 version). See DirMonkeyPatches above for more details.
|
32
|
+
module DirClassMonkeyPatches
|
33
|
+
def [](*args, &block)
|
34
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
35
|
+
super
|
36
|
+
ensure
|
37
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
38
|
+
end
|
39
|
+
|
40
|
+
def children(*args, &block)
|
41
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
42
|
+
super
|
43
|
+
ensure
|
44
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
45
|
+
end
|
46
|
+
|
47
|
+
# NOTE: When wrapping methods that yield, it's OK if the `yield` raises an exception while signals are
|
48
|
+
# enabled. This is because:
|
49
|
+
# * We can call `_native_resume_signals` many times in a row, both because it's idempotent, as well as it's
|
50
|
+
# very low overhead (see benchmarks/profiler_hold_resume_interruptions.rb)
|
51
|
+
# * When an exception is being raised, the iteration will stop anyway, so there's no longer a concern of a
|
52
|
+
# signal causing Ruby to return an incorrect value
|
53
|
+
def each_child(*args, &block)
|
54
|
+
if block
|
55
|
+
begin
|
56
|
+
# <-- Begin critical region
|
57
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
58
|
+
super do |entry_name|
|
59
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
60
|
+
# <-- We're safe now while running customer code
|
61
|
+
yield entry_name
|
62
|
+
# <-- We'll go back to the Dir internals, critical region again
|
63
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
64
|
+
end
|
65
|
+
ensure
|
66
|
+
# <-- End critical region
|
67
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
68
|
+
end
|
69
|
+
else
|
70
|
+
# This returns an enumerator. We don't want/need to intercede here, the enumerator will eventually call the
|
71
|
+
# other branch once it gets going.
|
72
|
+
super
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def empty?(*args, &block)
|
77
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
78
|
+
super
|
79
|
+
ensure
|
80
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
81
|
+
end
|
82
|
+
|
83
|
+
def entries(*args, &block)
|
84
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
85
|
+
super
|
86
|
+
ensure
|
87
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
88
|
+
end
|
89
|
+
|
90
|
+
# See note on methods that yield above.
|
91
|
+
def foreach(*args, &block)
|
92
|
+
if block
|
93
|
+
begin
|
94
|
+
# <-- Begin critical region
|
95
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
96
|
+
super do |entry_name|
|
97
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
98
|
+
# <-- We're safe now while running customer code
|
99
|
+
yield entry_name
|
100
|
+
# <-- We'll go back to the Dir internals, critical region again
|
101
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
102
|
+
end
|
103
|
+
ensure
|
104
|
+
# <-- End critical region
|
105
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
106
|
+
end
|
107
|
+
else
|
108
|
+
# This returns an enumerator. We don't want/need to intercede here, the enumerator will eventually call the
|
109
|
+
# other branch once it gets going.
|
110
|
+
super
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# See note on methods that yield above.
|
115
|
+
def glob(*args, &block)
|
116
|
+
if block
|
117
|
+
begin
|
118
|
+
# <-- Begin critical region
|
119
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
120
|
+
super do |entry_name|
|
121
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
122
|
+
# <-- We're safe now while running customer code
|
123
|
+
yield entry_name
|
124
|
+
# <-- We'll go back to the Dir internals, critical region again
|
125
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
126
|
+
end
|
127
|
+
ensure
|
128
|
+
# <-- End critical region
|
129
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
130
|
+
end
|
131
|
+
else
|
132
|
+
begin
|
133
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
134
|
+
super
|
135
|
+
ensure
|
136
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def home(*args, &block)
|
142
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
143
|
+
super
|
144
|
+
ensure
|
145
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
146
|
+
end
|
147
|
+
end
|
148
|
+
else
|
149
|
+
# Monkey patches for Dir.singleton_class (Ruby 3 version). See DirMonkeyPatches above for more details.
|
150
|
+
module DirClassMonkeyPatches
|
151
|
+
def [](*args, **kwargs, &block)
|
152
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
153
|
+
super
|
154
|
+
ensure
|
155
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
156
|
+
end
|
157
|
+
|
158
|
+
def children(*args, **kwargs, &block)
|
159
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
160
|
+
super
|
161
|
+
ensure
|
162
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
163
|
+
end
|
164
|
+
|
165
|
+
# See note on methods that yield above.
|
166
|
+
def each_child(*args, **kwargs, &block)
|
167
|
+
if block
|
168
|
+
begin
|
169
|
+
# <-- Begin critical region
|
170
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
171
|
+
super do |entry_name|
|
172
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
173
|
+
# <-- We're safe now while running customer code
|
174
|
+
yield entry_name
|
175
|
+
# <-- We'll go back to the Dir internals, critical region again
|
176
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
177
|
+
end
|
178
|
+
ensure
|
179
|
+
# <-- End critical region
|
180
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
181
|
+
end
|
182
|
+
else
|
183
|
+
# This returns an enumerator. We don't want/need to intercede here, the enumerator will eventually call the
|
184
|
+
# other branch once it gets going.
|
185
|
+
super
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def empty?(*args, **kwargs, &block)
|
190
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
191
|
+
super
|
192
|
+
ensure
|
193
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
194
|
+
end
|
195
|
+
|
196
|
+
def entries(*args, **kwargs, &block)
|
197
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
198
|
+
super
|
199
|
+
ensure
|
200
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
201
|
+
end
|
202
|
+
|
203
|
+
# See note on methods that yield above.
|
204
|
+
def foreach(*args, **kwargs, &block)
|
205
|
+
if block
|
206
|
+
begin
|
207
|
+
# <-- Begin critical region
|
208
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
209
|
+
super do |entry_name|
|
210
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
211
|
+
# <-- We're safe now while running customer code
|
212
|
+
yield entry_name
|
213
|
+
# <-- We'll go back to the Dir internals, critical region again
|
214
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
215
|
+
end
|
216
|
+
ensure
|
217
|
+
# <-- End critical region
|
218
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
219
|
+
end
|
220
|
+
else
|
221
|
+
# This returns an enumerator. We don't want/need to intercede here, the enumerator will eventually call the
|
222
|
+
# other branch once it gets going.
|
223
|
+
super
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
# See note on methods that yield above.
|
228
|
+
def glob(*args, **kwargs, &block)
|
229
|
+
if block
|
230
|
+
begin
|
231
|
+
# <-- Begin critical region
|
232
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
233
|
+
super do |entry_name|
|
234
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
235
|
+
# <-- We're safe now while running customer code
|
236
|
+
yield entry_name
|
237
|
+
# <-- We'll go back to the Dir internals, critical region again
|
238
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
239
|
+
end
|
240
|
+
ensure
|
241
|
+
# <-- End critical region
|
242
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
243
|
+
end
|
244
|
+
else
|
245
|
+
begin
|
246
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
247
|
+
super
|
248
|
+
ensure
|
249
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
def home(*args, **kwargs, &block)
|
255
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
256
|
+
super
|
257
|
+
ensure
|
258
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
if RUBY_VERSION.start_with?("2.")
|
264
|
+
# Monkey patches for Dir (Ruby 2 version). See DirMonkeyPatches above for more details.
|
265
|
+
module DirInstanceMonkeyPatches
|
266
|
+
# See note on methods that yield above.
|
267
|
+
def each(*args, &block)
|
268
|
+
if block
|
269
|
+
begin
|
270
|
+
# <-- Begin critical region
|
271
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
272
|
+
super do |entry_name|
|
273
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
274
|
+
# <-- We're safe now while running customer code
|
275
|
+
yield entry_name
|
276
|
+
# <-- We'll go back to the Dir internals, critical region again
|
277
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
278
|
+
end
|
279
|
+
ensure
|
280
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals # <-- End critical region
|
281
|
+
end
|
282
|
+
else
|
283
|
+
# This returns an enumerator. We don't want/need to intercede here, the enumerator will eventually call the
|
284
|
+
# other branch once it gets going.
|
285
|
+
super
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
unless RUBY_VERSION.start_with?("2.5.") # This is Ruby 2.6+
|
290
|
+
# See note on methods that yield above.
|
291
|
+
def each_child(*args, &block)
|
292
|
+
if block
|
293
|
+
begin
|
294
|
+
# <-- Begin critical region
|
295
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
296
|
+
super do |entry_name|
|
297
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
298
|
+
# <-- We're safe now while running customer code
|
299
|
+
yield entry_name
|
300
|
+
# <-- We'll go back to the Dir internals, critical region again
|
301
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
302
|
+
end
|
303
|
+
ensure
|
304
|
+
# <-- End critical region
|
305
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
306
|
+
end
|
307
|
+
else
|
308
|
+
# This returns an enumerator. We don't want/need to intercede here, the enumerator will eventually call the
|
309
|
+
# other branch once it gets going.
|
310
|
+
super
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
def children(*args, &block)
|
315
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
316
|
+
super
|
317
|
+
ensure
|
318
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
def tell(*args, &block)
|
323
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
324
|
+
super
|
325
|
+
ensure
|
326
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
327
|
+
end
|
328
|
+
|
329
|
+
def pos(*args, &block)
|
330
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
331
|
+
super
|
332
|
+
ensure
|
333
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
334
|
+
end
|
335
|
+
end
|
336
|
+
else
|
337
|
+
# Monkey patches for Dir (Ruby 3 version). See DirMonkeyPatches above for more details.
|
338
|
+
module DirInstanceMonkeyPatches
|
339
|
+
# See note on methods that yield above.
|
340
|
+
def each(*args, **kwargs, &block)
|
341
|
+
if block
|
342
|
+
begin
|
343
|
+
# <-- Begin critical region
|
344
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
345
|
+
super do |entry_name|
|
346
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
347
|
+
# <-- We're safe now while running customer code
|
348
|
+
yield entry_name
|
349
|
+
# <-- We'll go back to the Dir internals, critical region again
|
350
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
351
|
+
end
|
352
|
+
ensure
|
353
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals # <-- End critical region
|
354
|
+
end
|
355
|
+
else
|
356
|
+
# This returns an enumerator. We don't want/need to intercede here, the enumerator will eventually call the
|
357
|
+
# other branch once it gets going.
|
358
|
+
super
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
# See note on methods that yield above.
|
363
|
+
def each_child(*args, **kwargs, &block)
|
364
|
+
if block
|
365
|
+
begin
|
366
|
+
# <-- Begin critical region
|
367
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
368
|
+
super do |entry_name|
|
369
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
370
|
+
# <-- We're safe now while running customer code
|
371
|
+
yield entry_name
|
372
|
+
# <-- We'll go back to the Dir internals, critical region again
|
373
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
374
|
+
end
|
375
|
+
ensure
|
376
|
+
# <-- End critical region
|
377
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
378
|
+
end
|
379
|
+
else
|
380
|
+
# This returns an enumerator. We don't want/need to intercede here, the enumerator will eventually call the
|
381
|
+
# other branch once it gets going.
|
382
|
+
super
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
386
|
+
def children(*args, **kwargs, &block)
|
387
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
388
|
+
super
|
389
|
+
ensure
|
390
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
391
|
+
end
|
392
|
+
|
393
|
+
def tell(*args, **kwargs, &block)
|
394
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
395
|
+
super
|
396
|
+
ensure
|
397
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
398
|
+
end
|
399
|
+
|
400
|
+
def pos(*args, **kwargs, &block)
|
401
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
|
402
|
+
super
|
403
|
+
ensure
|
404
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
|
405
|
+
end
|
406
|
+
end
|
407
|
+
end
|
408
|
+
end
|
409
|
+
end
|
410
|
+
end
|
@@ -3,31 +3,31 @@
|
|
3
3
|
module Datadog
|
4
4
|
module Profiling
|
5
5
|
module Ext
|
6
|
-
ENV_ENABLED =
|
7
|
-
ENV_UPLOAD_TIMEOUT =
|
8
|
-
ENV_MAX_FRAMES =
|
9
|
-
ENV_AGENTLESS =
|
10
|
-
ENV_ENDPOINT_COLLECTION_ENABLED =
|
6
|
+
ENV_ENABLED = "DD_PROFILING_ENABLED"
|
7
|
+
ENV_UPLOAD_TIMEOUT = "DD_PROFILING_UPLOAD_TIMEOUT"
|
8
|
+
ENV_MAX_FRAMES = "DD_PROFILING_MAX_FRAMES"
|
9
|
+
ENV_AGENTLESS = "DD_PROFILING_AGENTLESS"
|
10
|
+
ENV_ENDPOINT_COLLECTION_ENABLED = "DD_PROFILING_ENDPOINT_COLLECTION_ENABLED"
|
11
11
|
|
12
12
|
module Transport
|
13
13
|
module HTTP
|
14
|
-
FORM_FIELD_TAG_ENV =
|
15
|
-
FORM_FIELD_TAG_HOST =
|
16
|
-
FORM_FIELD_TAG_LANGUAGE =
|
17
|
-
FORM_FIELD_TAG_PID =
|
18
|
-
FORM_FIELD_TAG_PROFILER_VERSION =
|
19
|
-
FORM_FIELD_TAG_RUNTIME =
|
20
|
-
FORM_FIELD_TAG_RUNTIME_ENGINE =
|
21
|
-
FORM_FIELD_TAG_RUNTIME_ID =
|
22
|
-
FORM_FIELD_TAG_RUNTIME_PLATFORM =
|
23
|
-
FORM_FIELD_TAG_RUNTIME_VERSION =
|
24
|
-
FORM_FIELD_TAG_SERVICE =
|
25
|
-
FORM_FIELD_TAG_VERSION =
|
26
|
-
TAG_GIT_REPOSITORY_URL =
|
27
|
-
TAG_GIT_COMMIT_SHA =
|
14
|
+
FORM_FIELD_TAG_ENV = "env"
|
15
|
+
FORM_FIELD_TAG_HOST = "host"
|
16
|
+
FORM_FIELD_TAG_LANGUAGE = "language"
|
17
|
+
FORM_FIELD_TAG_PID = "process_id"
|
18
|
+
FORM_FIELD_TAG_PROFILER_VERSION = "profiler_version"
|
19
|
+
FORM_FIELD_TAG_RUNTIME = "runtime"
|
20
|
+
FORM_FIELD_TAG_RUNTIME_ENGINE = "runtime_engine"
|
21
|
+
FORM_FIELD_TAG_RUNTIME_ID = "runtime-id"
|
22
|
+
FORM_FIELD_TAG_RUNTIME_PLATFORM = "runtime_platform"
|
23
|
+
FORM_FIELD_TAG_RUNTIME_VERSION = "runtime_version"
|
24
|
+
FORM_FIELD_TAG_SERVICE = "service"
|
25
|
+
FORM_FIELD_TAG_VERSION = "version"
|
26
|
+
TAG_GIT_REPOSITORY_URL = "git.repository_url"
|
27
|
+
TAG_GIT_COMMIT_SHA = "git.commit.sha"
|
28
28
|
|
29
|
-
PPROF_DEFAULT_FILENAME =
|
30
|
-
CODE_PROVENANCE_FILENAME =
|
29
|
+
PPROF_DEFAULT_FILENAME = "rubyprofile.pprof"
|
30
|
+
CODE_PROVENANCE_FILENAME = "code-provenance.json"
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "../core/transport/ext"
|
4
4
|
|
5
5
|
module Datadog
|
6
6
|
module Profiling
|
@@ -53,7 +53,7 @@ module Datadog
|
|
53
53
|
|
54
54
|
if status == :ok
|
55
55
|
if (200..299).cover?(result)
|
56
|
-
Datadog.logger.debug(
|
56
|
+
Datadog.logger.debug("Successfully reported profiling data")
|
57
57
|
true
|
58
58
|
else
|
59
59
|
Datadog.logger.error(
|
@@ -73,7 +73,7 @@ module Datadog
|
|
73
73
|
def base_url_from(agent_settings)
|
74
74
|
case agent_settings.adapter
|
75
75
|
when Datadog::Core::Configuration::Ext::Agent::HTTP::ADAPTER
|
76
|
-
"#{agent_settings.ssl ?
|
76
|
+
"#{agent_settings.ssl ? "https" : "http"}://#{agent_settings.hostname}:#{agent_settings.port}/"
|
77
77
|
when Datadog::Core::Configuration::Ext::Agent::UnixSocket::ADAPTER
|
78
78
|
"unix://#{agent_settings.uds_path}"
|
79
79
|
else
|
@@ -82,12 +82,14 @@ module Datadog
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def validate_agent_settings(agent_settings)
|
85
|
-
supported_adapters = [
|
86
|
-
|
85
|
+
supported_adapters = [
|
86
|
+
Datadog::Core::Configuration::Ext::Agent::UnixSocket::ADAPTER,
|
87
|
+
Datadog::Core::Configuration::Ext::Agent::HTTP::ADAPTER
|
88
|
+
]
|
87
89
|
unless supported_adapters.include?(agent_settings.adapter)
|
88
90
|
raise ArgumentError,
|
89
91
|
"Unsupported transport configuration for profiling: Adapter #{agent_settings.adapter} " \
|
90
|
-
|
92
|
+
" is not supported"
|
91
93
|
end
|
92
94
|
end
|
93
95
|
|
@@ -15,26 +15,26 @@ begin
|
|
15
15
|
require "datadog_profiling_loader.#{RUBY_VERSION}_#{RUBY_PLATFORM}"
|
16
16
|
rescue LoadError => e
|
17
17
|
raise LoadError,
|
18
|
-
|
18
|
+
"Failed to load the profiling loader extension. To fix this, please remove and then reinstall datadog " \
|
19
19
|
"(Details: #{e.message})"
|
20
20
|
end
|
21
21
|
|
22
22
|
extension_name = "datadog_profiling_native_extension.#{RUBY_VERSION}_#{RUBY_PLATFORM}"
|
23
|
-
file_name = "#{extension_name}.#{RbConfig::CONFIG[
|
23
|
+
file_name = "#{extension_name}.#{RbConfig::CONFIG["DLEXT"]}"
|
24
24
|
full_file_path = "#{__dir__}/../../#{file_name}"
|
25
25
|
|
26
26
|
unless File.exist?(full_file_path)
|
27
|
-
extension_dir = Gem.loaded_specs[
|
27
|
+
extension_dir = Gem.loaded_specs["datadog"].extension_dir
|
28
28
|
candidate_path = "#{extension_dir}/#{file_name}"
|
29
29
|
if File.exist?(candidate_path)
|
30
30
|
full_file_path = candidate_path
|
31
|
-
else
|
31
|
+
else
|
32
32
|
# We found none of the files. This is unexpected. Let's go ahead anyway, the error is going to be reported further
|
33
33
|
# down anyway.
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
init_function_name = "Init_#{extension_name.split(
|
37
|
+
init_function_name = "Init_#{extension_name.split(".").first}"
|
38
38
|
|
39
39
|
status, result = Datadog::Profiling::Loader._native_load(full_file_path, init_function_name)
|
40
40
|
|
@@ -8,34 +8,30 @@ module Datadog
|
|
8
8
|
|
9
9
|
private
|
10
10
|
|
11
|
-
attr_reader :worker, :scheduler
|
11
|
+
attr_reader :worker, :scheduler
|
12
12
|
|
13
13
|
public
|
14
14
|
|
15
|
-
def initialize(worker:, scheduler
|
15
|
+
def initialize(worker:, scheduler:)
|
16
16
|
@worker = worker
|
17
17
|
@scheduler = scheduler
|
18
|
-
@optional_crashtracker = optional_crashtracker
|
19
18
|
end
|
20
19
|
|
21
20
|
def start
|
22
21
|
after_fork! do
|
23
|
-
optional_crashtracker.reset_after_fork if optional_crashtracker
|
24
22
|
worker.reset_after_fork
|
25
23
|
scheduler.reset_after_fork
|
26
24
|
end
|
27
25
|
|
28
|
-
optional_crashtracker.start if optional_crashtracker
|
29
26
|
worker.start(on_failure_proc: proc { component_failed(:worker) })
|
30
27
|
scheduler.start(on_failure_proc: proc { component_failed(:scheduler) })
|
31
28
|
end
|
32
29
|
|
33
30
|
def shutdown!
|
34
|
-
Datadog.logger.debug(
|
31
|
+
Datadog.logger.debug("Shutting down profiler")
|
35
32
|
|
36
33
|
stop_worker
|
37
34
|
stop_scheduler
|
38
|
-
optional_crashtracker.stop if optional_crashtracker
|
39
35
|
end
|
40
36
|
|
41
37
|
private
|
@@ -52,13 +48,14 @@ module Datadog
|
|
52
48
|
def component_failed(failed_component)
|
53
49
|
Datadog.logger.warn(
|
54
50
|
"Detected issue with profiler (#{failed_component} component), stopping profiling. " \
|
55
|
-
|
51
|
+
"See previous log messages for details."
|
56
52
|
)
|
57
53
|
|
58
54
|
# We explicitly not stop the crash tracker in this situation, under the assumption that, if a component failed,
|
59
55
|
# we're operating in a degraded state and crash tracking may still be helpful.
|
60
56
|
|
61
57
|
if failed_component == :worker
|
58
|
+
scheduler.mark_profiler_failed
|
62
59
|
stop_scheduler
|
63
60
|
elsif failed_component == :scheduler
|
64
61
|
stop_worker
|