ddtrace 1.20.0 → 1.23.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.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +130 -1
  3. data/LICENSE-3rdparty.csv +1 -1
  4. data/bin/ddprofrb +15 -0
  5. data/bin/ddtracerb +3 -1
  6. data/ext/{ddtrace_profiling_loader/ddtrace_profiling_loader.c → datadog_profiling_loader/datadog_profiling_loader.c} +2 -2
  7. data/ext/{ddtrace_profiling_loader → datadog_profiling_loader}/extconf.rb +3 -3
  8. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_cpu_and_wall_time_worker.c +226 -61
  9. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_discrete_dynamic_sampler.c +145 -72
  10. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_discrete_dynamic_sampler.h +17 -5
  11. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_thread_context.c +115 -14
  12. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/extconf.rb +2 -2
  13. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/heap_recorder.c +81 -4
  14. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/heap_recorder.h +12 -1
  15. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/http_transport.c +15 -19
  16. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/native_extension_helpers.rb +4 -4
  17. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/private_vm_api_access.c +14 -0
  18. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/private_vm_api_access.h +4 -0
  19. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/profiling.c +1 -1
  20. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/ruby_helpers.c +10 -0
  21. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/ruby_helpers.h +5 -0
  22. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/stack_recorder.c +161 -62
  23. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +43 -13
  24. data/lib/datadog/appsec/event.rb +1 -1
  25. data/lib/datadog/auto_instrument.rb +3 -0
  26. data/lib/datadog/core/configuration/components.rb +7 -6
  27. data/lib/datadog/core/configuration/option.rb +8 -6
  28. data/lib/datadog/core/configuration/settings.rb +130 -63
  29. data/lib/datadog/core/configuration.rb +20 -4
  30. data/lib/datadog/core/diagnostics/environment_logger.rb +4 -3
  31. data/lib/datadog/core/environment/git.rb +25 -0
  32. data/lib/datadog/core/environment/identity.rb +18 -48
  33. data/lib/datadog/core/environment/platform.rb +7 -1
  34. data/lib/datadog/core/git/ext.rb +2 -23
  35. data/lib/datadog/core/remote/client/capabilities.rb +1 -1
  36. data/lib/datadog/core/remote/negotiation.rb +2 -2
  37. data/lib/datadog/core/remote/transport/http/config.rb +1 -1
  38. data/lib/datadog/core/remote/worker.rb +7 -4
  39. data/lib/datadog/core/telemetry/client.rb +18 -10
  40. data/lib/datadog/core/telemetry/emitter.rb +9 -13
  41. data/lib/datadog/core/telemetry/event.rb +247 -57
  42. data/lib/datadog/core/telemetry/ext.rb +1 -0
  43. data/lib/datadog/core/telemetry/heartbeat.rb +1 -3
  44. data/lib/datadog/core/telemetry/http/ext.rb +4 -1
  45. data/lib/datadog/core/telemetry/http/response.rb +4 -0
  46. data/lib/datadog/core/telemetry/http/transport.rb +9 -4
  47. data/lib/datadog/core/telemetry/request.rb +59 -0
  48. data/lib/datadog/core/transport/ext.rb +2 -0
  49. data/lib/datadog/core/utils/url.rb +25 -0
  50. data/lib/datadog/profiling/collectors/code_provenance.rb +10 -4
  51. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +31 -0
  52. data/lib/datadog/profiling/collectors/info.rb +101 -0
  53. data/lib/datadog/profiling/component.rb +34 -28
  54. data/lib/datadog/profiling/exporter.rb +23 -6
  55. data/lib/datadog/profiling/ext.rb +2 -0
  56. data/lib/datadog/profiling/flush.rb +6 -3
  57. data/lib/datadog/profiling/http_transport.rb +5 -1
  58. data/lib/datadog/profiling/load_native_extension.rb +19 -6
  59. data/lib/datadog/profiling/native_extension.rb +1 -1
  60. data/lib/datadog/profiling/stack_recorder.rb +6 -2
  61. data/lib/datadog/profiling/tag_builder.rb +5 -0
  62. data/lib/datadog/profiling/tasks/exec.rb +3 -3
  63. data/lib/datadog/profiling/tasks/help.rb +3 -3
  64. data/lib/datadog/profiling.rb +13 -2
  65. data/lib/datadog/tracing/contrib/action_mailer/events/deliver.rb +1 -1
  66. data/lib/datadog/tracing/contrib/active_record/configuration/resolver.rb +11 -4
  67. data/lib/datadog/tracing/contrib/concurrent_ruby/async_patch.rb +20 -0
  68. data/lib/datadog/tracing/contrib/concurrent_ruby/patcher.rb +11 -1
  69. data/lib/datadog/tracing/contrib/configurable.rb +1 -1
  70. data/lib/datadog/tracing/contrib/extensions.rb +6 -2
  71. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +11 -4
  72. data/lib/datadog/tracing/sampling/matcher.rb +23 -3
  73. data/lib/datadog/tracing/sampling/rule.rb +7 -2
  74. data/lib/datadog/tracing/sampling/rule_sampler.rb +2 -0
  75. data/lib/datadog/tracing/trace_operation.rb +1 -2
  76. data/lib/datadog/tracing/transport/http.rb +1 -0
  77. data/lib/datadog/tracing/transport/trace_formatter.rb +31 -0
  78. data/lib/ddtrace/version.rb +1 -1
  79. metadata +58 -65
  80. data/ext/ddtrace_profiling_native_extension/pid_controller.c +0 -57
  81. data/ext/ddtrace_profiling_native_extension/pid_controller.h +0 -45
  82. data/lib/datadog/core/telemetry/collector.rb +0 -250
  83. data/lib/datadog/core/telemetry/v1/app_event.rb +0 -59
  84. data/lib/datadog/core/telemetry/v1/application.rb +0 -92
  85. data/lib/datadog/core/telemetry/v1/configuration.rb +0 -25
  86. data/lib/datadog/core/telemetry/v1/dependency.rb +0 -43
  87. data/lib/datadog/core/telemetry/v1/host.rb +0 -59
  88. data/lib/datadog/core/telemetry/v1/install_signature.rb +0 -38
  89. data/lib/datadog/core/telemetry/v1/integration.rb +0 -64
  90. data/lib/datadog/core/telemetry/v1/product.rb +0 -36
  91. data/lib/datadog/core/telemetry/v1/telemetry_request.rb +0 -106
  92. data/lib/datadog/core/telemetry/v2/app_client_configuration_change.rb +0 -41
  93. data/lib/datadog/core/telemetry/v2/request.rb +0 -29
  94. data/lib/datadog/profiling/diagnostics/environment_logger.rb +0 -39
  95. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/NativeExtensionDesign.md +0 -0
  96. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/clock_id.h +0 -0
  97. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/clock_id_from_pthread.c +0 -0
  98. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/clock_id_noop.c +0 -0
  99. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_dynamic_sampling_rate.c +0 -0
  100. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_dynamic_sampling_rate.h +0 -0
  101. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_gc_profiling_helper.c +0 -0
  102. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_gc_profiling_helper.h +0 -0
  103. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_idle_sampling_helper.c +0 -0
  104. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_idle_sampling_helper.h +0 -0
  105. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_stack.c +0 -0
  106. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_stack.h +0 -0
  107. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_thread_context.h +0 -0
  108. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/helpers.h +0 -0
  109. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/libdatadog_helpers.c +0 -0
  110. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/libdatadog_helpers.h +0 -0
  111. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/setup_signal_handler.c +0 -0
  112. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/setup_signal_handler.h +0 -0
  113. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/stack_recorder.h +0 -0
  114. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/time_helpers.c +0 -0
  115. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/time_helpers.h +0 -0
@@ -62,7 +62,8 @@ module Datadog
62
62
 
63
63
  Telemetry::Client.new(
64
64
  enabled: enabled,
65
- heartbeat_interval_seconds: settings.telemetry.heartbeat_interval_seconds
65
+ heartbeat_interval_seconds: settings.telemetry.heartbeat_interval_seconds,
66
+ dependency_collection: settings.telemetry.dependency_collection
66
67
  )
67
68
  end
68
69
  end
@@ -81,6 +82,7 @@ module Datadog
81
82
 
82
83
  def initialize(settings)
83
84
  @logger = self.class.build_logger(settings)
85
+ @environment_logger_extra = {}
84
86
 
85
87
  # This agent_settings is intended for use within Core. If you require
86
88
  # agent_settings within a product outside of core you should extend
@@ -90,11 +92,13 @@ module Datadog
90
92
  @remote = Remote::Component.build(settings, agent_settings)
91
93
  @tracer = self.class.build_tracer(settings, logger: @logger)
92
94
 
93
- @profiler = Datadog::Profiling::Component.build_profiler_component(
95
+ @profiler, profiler_logger_extra = Datadog::Profiling::Component.build_profiler_component(
94
96
  settings: settings,
95
97
  agent_settings: agent_settings,
96
98
  optional_tracer: @tracer,
97
99
  )
100
+ @environment_logger_extra.merge!(profiler_logger_extra) if profiler_logger_extra
101
+
98
102
  @runtime_metrics = self.class.build_runtime_metrics_worker(settings)
99
103
  @health_metrics = self.class.build_health_metrics(settings)
100
104
  @telemetry = self.class.build_telemetry(settings, agent_settings, logger)
@@ -105,18 +109,15 @@ module Datadog
105
109
  def startup!(settings)
106
110
  if settings.profiling.enabled
107
111
  if profiler
108
- @logger.debug('Profiling started')
109
112
  profiler.start
110
113
  else
111
114
  # Display a warning for users who expected profiling to be enabled
112
115
  unsupported_reason = Profiling.unsupported_reason
113
116
  logger.warn("Profiling was requested but is not supported, profiling disabled: #{unsupported_reason}")
114
117
  end
115
- else
116
- @logger.debug('Profiling is disabled')
117
118
  end
118
119
 
119
- Core::Diagnostics::EnvironmentLogger.collect_and_log!
120
+ Core::Diagnostics::EnvironmentLogger.collect_and_log!(@environment_logger_extra)
120
121
  end
121
122
 
122
123
  # Shuts down all the components in use.
@@ -8,7 +8,13 @@ module Datadog
8
8
  # Represents an instance of an integration configuration option
9
9
  # @public_api
10
10
  class Option
11
- attr_reader :definition
11
+ # @!attribute [r] definition
12
+ # The definition object that matches this option.
13
+ # @return [Configuration::OptionDefinition]
14
+ # @!attribute [r] precedence_set
15
+ # When this option was last set, what was the value precedence used?
16
+ # @return [Precedence::Value]
17
+ attr_reader :definition, :precedence_set
12
18
 
13
19
  # Option setting precedence.
14
20
  module Precedence
@@ -264,7 +270,7 @@ module Datadog
264
270
  # when restoring a value from `@value_per_precedence`, and we are only running `definition.setter`
265
271
  # on the original value, not on a valud that has already been processed by `definition.setter`.
266
272
  @value_per_precedence[precedence] = value
267
- context_exec(v, old_value, &definition.after_set) if definition.after_set
273
+ context_exec(v, old_value, precedence, &definition.after_set) if definition.after_set
268
274
  end
269
275
  end
270
276
 
@@ -303,10 +309,6 @@ module Datadog
303
309
  ['true', '1'].include?(ENV.fetch('DD_EXPERIMENTAL_SKIP_CONFIGURATION_VALIDATION', '').strip)
304
310
  end
305
311
 
306
- # Used for testing
307
- attr_reader :precedence_set
308
- private :precedence_set
309
-
310
312
  # Anchor object that represents a value that is not set.
311
313
  # This is necessary because `nil` is a valid value to be set.
312
314
  UNSET = Object.new
@@ -205,6 +205,22 @@ module Datadog
205
205
  option :transport
206
206
  end
207
207
 
208
+ # Can be used to enable/disable collection of allocation profiles.
209
+ #
210
+ # This feature is disabled by default
211
+ #
212
+ # @warn Due to bugs in Ruby we only recommend enabling this feature in
213
+ # Ruby versions 2.x, 3.1.4+, 3.2.3+ and 3.3.0+
214
+ # (more details in {Datadog::Profiling::Component.enable_allocation_profiling?})
215
+ #
216
+ # @default `DD_PROFILING_ALLOCATION_ENABLED` environment variable as a boolean, otherwise `false`
217
+ option :allocation_enabled do |o|
218
+ o.type :bool
219
+ o.deprecated_env 'DD_PROFILING_EXPERIMENTAL_ALLOCATION_ENABLED' # TODO: Remove this for dd-trace-rb 2.0
220
+ o.env 'DD_PROFILING_ALLOCATION_ENABLED'
221
+ o.default false
222
+ end
223
+
208
224
  # @public_api
209
225
  settings :advanced do
210
226
  # @deprecated No longer does anything, and will be removed on dd-trace-rb 2.0.
@@ -212,11 +228,13 @@ module Datadog
212
228
  # This was used prior to the GA of the new CPU Profiling 2.0 profiler. The CPU Profiling 2.0 profiler does not
213
229
  # use or need this setting and thus it doesn't do anything.
214
230
  option :max_events do |o|
215
- o.after_set do
216
- Datadog.logger.warn(
217
- 'The profiling.advanced.max_events setting has been deprecated for removal and no ' \
218
- 'longer does anything. Please remove it from your Datadog.configure block.'
219
- )
231
+ o.after_set do |_, _, precedence|
232
+ unless precedence == Datadog::Core::Configuration::Option::Precedence::DEFAULT
233
+ Datadog.logger.warn(
234
+ 'The profiling.advanced.max_events setting has been deprecated for removal and no ' \
235
+ 'longer does anything. Please remove it from your Datadog.configure block.'
236
+ )
237
+ end
220
238
  end
221
239
  end
222
240
 
@@ -248,18 +266,23 @@ module Datadog
248
266
 
249
267
  # Can be used to disable the gathering of names and versions of gems in use by the service, used to power
250
268
  # grouping and categorization of stack traces.
251
- option :code_provenance_enabled, default: true
269
+ option :code_provenance_enabled do |o|
270
+ o.type :bool
271
+ o.default true
272
+ end
252
273
 
253
274
  # @deprecated No longer does anything, and will be removed on dd-trace-rb 2.0.
254
275
  #
255
276
  # This was added as a temporary support option in case of issues with the new `Profiling::HttpTransport` class
256
277
  # but we're now confident it's working nicely so we've removed the old code path.
257
278
  option :legacy_transport_enabled do |o|
258
- o.after_set do
259
- Datadog.logger.warn(
260
- 'The profiling.advanced.legacy_transport_enabled setting has been deprecated for removal and no ' \
261
- 'longer does anything. Please remove it from your Datadog.configure block.'
262
- )
279
+ o.after_set do |_, _, precedence|
280
+ unless precedence == Datadog::Core::Configuration::Option::Precedence::DEFAULT
281
+ Datadog.logger.warn(
282
+ 'The profiling.advanced.legacy_transport_enabled setting has been deprecated for removal and no ' \
283
+ 'longer does anything. Please remove it from your Datadog.configure block.'
284
+ )
285
+ end
263
286
  end
264
287
  end
265
288
 
@@ -268,11 +291,13 @@ module Datadog
268
291
  # This was used prior to the GA of the new CPU Profiling 2.0 profiler. Using CPU Profiling 2.0 is now the
269
292
  # default and this doesn't do anything.
270
293
  option :force_enable_new_profiler do |o|
271
- o.after_set do
272
- Datadog.logger.warn(
273
- 'The profiling.advanced.force_enable_new_profiler setting has been deprecated for removal and no ' \
274
- 'longer does anything. Please remove it from your Datadog.configure block.'
275
- )
294
+ o.after_set do |_, _, precedence|
295
+ unless precedence == Datadog::Core::Configuration::Option::Precedence::DEFAULT
296
+ Datadog.logger.warn(
297
+ 'The profiling.advanced.force_enable_new_profiler setting has been deprecated for removal and no ' \
298
+ 'longer does anything. Please remove it from your Datadog.configure block.'
299
+ )
300
+ end
276
301
  end
277
302
  end
278
303
 
@@ -281,63 +306,75 @@ module Datadog
281
306
  # This was used prior to the GA of the new CPU Profiling 2.0 profiler. Using CPU Profiling 2.0 is now the
282
307
  # default and this doesn't do anything.
283
308
  option :force_enable_legacy_profiler do |o|
284
- o.after_set do
285
- Datadog.logger.warn(
286
- 'The profiling.advanced.force_enable_legacy_profiler setting has been deprecated for removal and no ' \
287
- 'longer does anything. Please remove it from your Datadog.configure block.'
288
- )
309
+ o.after_set do |_, _, precedence|
310
+ unless precedence == Datadog::Core::Configuration::Option::Precedence::DEFAULT
311
+ Datadog.logger.warn(
312
+ 'The profiling.advanced.force_enable_legacy_profiler setting has been deprecated for removal and no ' \
313
+ 'longer does anything. Please remove it from your Datadog.configure block.'
314
+ )
315
+ end
289
316
  end
290
317
  end
291
318
 
292
- # Forces enabling of profiling of time/resources spent in Garbage Collection.
319
+ # @deprecated No longer does anything, and will be removed on dd-trace-rb 2.0.
293
320
  #
294
- # Note that setting this to "false" (or not setting it) will not prevent the feature from being
295
- # being automatically enabled in the future.
321
+ # GC profiling is now on by default and controlled by {:gc_enabled}.
322
+ option :force_enable_gc_profiling do |o|
323
+ o.after_set do |_, _, precedence|
324
+ unless precedence == Datadog::Core::Configuration::Option::Precedence::DEFAULT
325
+ Datadog.logger.warn(
326
+ 'The profiling.advanced.force_enable_gc_profiling setting has been deprecated for removal and no ' \
327
+ 'longer does anything (the feature is now on by default). ' \
328
+ 'Please remove this setting from your Datadog.configure block.'
329
+ )
330
+ end
331
+ end
332
+ end
333
+
334
+ # Can be used to enable/disable garbage collection profiling.
296
335
  #
297
- # This feature defaults to off for two reasons:
298
- # 1. Currently this feature can add a lot of overhead for GC-heavy workloads.
299
- # 2. Although this feature is safe on Ruby 2.x, on Ruby 3.x it can break in applications that make use of
300
- # Ractors due to two Ruby VM bugs:
301
- # https://bugs.ruby-lang.org/issues/19112 AND https://bugs.ruby-lang.org/issues/18464.
302
- # If you use Ruby 3.x and your application does not use Ractors (or if your Ruby has been patched), the
303
- # feature is fully safe to enable and this toggle can be used to do so.
336
+ # @warn To avoid https://bugs.ruby-lang.org/issues/18464 even when enabled, GC profiling is only started
337
+ # for Ruby versions 2.x, 3.1.4+, 3.2.3+ and 3.3.0+
338
+ # (more details in {Datadog::Profiling::Component.enable_gc_profiling?})
304
339
  #
305
- # We expect the once the above issues are overcome, we'll automatically enable the feature on fixed Ruby
306
- # versions.
340
+ # @warn Due to a VM bug in the Ractor implementation (https://bugs.ruby-lang.org/issues/19112) this feature
341
+ # stops working when Ractors get garbage collected.
307
342
  #
308
- # @default `DD_PROFILING_FORCE_ENABLE_GC` environment variable, otherwise `false`
309
- option :force_enable_gc_profiling do |o|
310
- o.env 'DD_PROFILING_FORCE_ENABLE_GC'
343
+ # @default `DD_PROFILING_GC_ENABLED` environment variable, otherwise `true`
344
+ option :gc_enabled do |o|
311
345
  o.type :bool
312
- o.default false
346
+ o.env 'DD_PROFILING_GC_ENABLED'
347
+ o.default true
313
348
  end
314
349
 
315
350
  # Can be used to enable/disable the Datadog::Profiling.allocation_count feature.
316
351
  #
317
- # This feature is now controlled via {:experimental_allocation_enabled}
352
+ # @deprecated Use {:allocation_enabled} (outside of advanced section) instead.
318
353
  option :allocation_counting_enabled do |o|
319
- o.after_set do
320
- Datadog.logger.warn(
321
- 'The profiling.advanced.allocation_counting_enabled setting has been deprecated for removal and no ' \
322
- 'longer does anything. Please remove it from your Datadog.configure block. ' \
323
- 'Allocation counting is now controlled by the `experimental_allocation_enabled` setting instead.'
324
- )
354
+ o.after_set do |_, _, precedence|
355
+ unless precedence == Datadog::Core::Configuration::Option::Precedence::DEFAULT
356
+ Datadog.logger.warn(
357
+ 'The profiling.advanced.allocation_counting_enabled setting has been deprecated for removal and no ' \
358
+ 'longer does anything. Please remove it from your Datadog.configure block. ' \
359
+ 'Allocation counting is now controlled by the profiling.allocation_enabled setting instead.'
360
+ )
361
+ end
325
362
  end
326
363
  end
327
364
 
328
- # Can be used to enable/disable collection of allocation profiles.
329
- #
330
- # This feature is alpha and disabled by default
331
- #
332
- # @warn This feature is not supported/safe in all Rubies. Details in {Datadog::Profiling::Component} but
333
- # in summary, this should be supported on Ruby 2.x, 3.1.4+, 3.2.3+ and 3.3.0+. Enabling it on
334
- # unsupported Rubies may result in unexpected behaviour, including crashes.
335
- #
336
- # @default `DD_PROFILING_EXPERIMENTAL_ALLOCATION_ENABLED` environment variable as a boolean, otherwise `false`
365
+ # @deprecated Use {:allocation_enabled} (outside of advanced section) instead.
337
366
  option :experimental_allocation_enabled do |o|
338
367
  o.type :bool
339
- o.env 'DD_PROFILING_EXPERIMENTAL_ALLOCATION_ENABLED'
340
368
  o.default false
369
+ o.after_set do |_, _, precedence|
370
+ unless precedence == Datadog::Core::Configuration::Option::Precedence::DEFAULT
371
+ Datadog.logger.warn(
372
+ 'The profiling.advanced.experimental_allocation_enabled setting has been deprecated for removal and ' \
373
+ 'no longer does anything. Please remove it from your Datadog.configure block. ' \
374
+ 'Allocation profiling is now controlled by the profiling.allocation_enabled setting instead.'
375
+ )
376
+ end
377
+ end
341
378
  end
342
379
 
343
380
  # Can be used to enable/disable the collection of heap profiles.
@@ -371,13 +408,15 @@ module Datadog
371
408
  #
372
409
  # This feature is now controlled via {:overhead_target_percentage}
373
410
  option :experimental_allocation_sample_rate do |o|
374
- o.after_set do
375
- Datadog.logger.warn(
376
- 'The profiling.advanced.experimental_allocation_sample_rate setting has been deprecated for removal ' \
377
- 'and no longer does anything. Please remove it from your Datadog.configure block. ' \
378
- 'Allocation sample rate is now handled by a dynamic sampler which will adjust the sampling rate to ' \
379
- 'keep to the configured `profiling.advanced.overhead_target_percentage`.'
380
- )
411
+ o.after_set do |_, _, precedence|
412
+ unless precedence == Datadog::Core::Configuration::Option::Precedence::DEFAULT
413
+ Datadog.logger.warn(
414
+ 'The profiling.advanced.experimental_allocation_sample_rate setting has been deprecated for removal ' \
415
+ 'and no longer does anything. Please remove it from your Datadog.configure block. ' \
416
+ 'Allocation sample rate is now handled by a dynamic sampler which will adjust the sampling rate to ' \
417
+ 'keep to the configured `profiling.advanced.overhead_target_percentage`.'
418
+ )
419
+ end
381
420
  end
382
421
  end
383
422
 
@@ -412,9 +451,27 @@ module Datadog
412
451
  #
413
452
  # @default `DD_PROFILING_EXPERIMENTAL_TIMELINE_ENABLED` environment variable as a boolean, otherwise `false`
414
453
  option :experimental_timeline_enabled do |o|
454
+ o.after_set do |_, _, precedence|
455
+ unless precedence == Datadog::Core::Configuration::Option::Precedence::DEFAULT
456
+ Datadog.logger.warn(
457
+ 'The profiling.advanced.experimental_timeline_enabled setting has been deprecated for removal ' \
458
+ 'and no longer does anything. Please remove it from your Datadog.configure block. ' \
459
+ 'The timeline feature counting is now controlled by the `timeline_enabled` setting instead.'
460
+ )
461
+ end
462
+ end
463
+ end
464
+
465
+ # Controls data collection for the timeline feature.
466
+ #
467
+ # If you needed to disable this, please tell us why on <https://github.com/DataDog/dd-trace-rb/issues/new>,
468
+ # so we can fix it!
469
+ #
470
+ # @default `DD_PROFILING_TIMELINE_ENABLED` environment variable as a boolean, otherwise `true`
471
+ option :timeline_enabled do |o|
415
472
  o.type :bool
416
- o.env 'DD_PROFILING_EXPERIMENTAL_TIMELINE_ENABLED'
417
- o.default false
473
+ o.env 'DD_PROFILING_TIMELINE_ENABLED'
474
+ o.default true
418
475
  end
419
476
 
420
477
  # The profiler gathers data by sending `SIGPROF` unix signals to Ruby application threads.
@@ -641,6 +698,16 @@ module Datadog
641
698
  # Client-side telemetry configuration
642
699
  # @public_api
643
700
  settings :telemetry do
701
+ # Whether the bundled Ruby gems as reported through telemetry.
702
+ #
703
+ # @default `DD_TELEMETRY_DEPENDENCY_COLLECTION_ENABLED` environment variable, otherwise `true`.
704
+ # @return [Boolean]
705
+ option :dependency_collection do |o|
706
+ o.type :bool
707
+ o.env Core::Telemetry::Ext::ENV_DEPENDENCY_COLLECTION
708
+ o.default true
709
+ end
710
+
644
711
  # Enable telemetry collection. This allows telemetry events to be emitted to the telemetry API.
645
712
  #
646
713
  # @default `DD_INSTRUMENTATION_TELEMETRY_ENABLED` environment variable, otherwise `true`.
@@ -81,18 +81,23 @@ module Datadog
81
81
  configuration = self.configuration
82
82
  yield(configuration)
83
83
 
84
- safely_synchronize do |write_components|
84
+ built_components = false
85
+
86
+ components = safely_synchronize do |write_components|
85
87
  write_components.call(
86
88
  if components?
87
89
  replace_components!(configuration, @components)
88
90
  else
89
91
  components = build_components(configuration)
90
- components.telemetry.started!
92
+ built_components = true
91
93
  components
92
94
  end
93
95
  )
94
96
  end
95
97
 
98
+ # Should only be called the first time components are built
99
+ components.telemetry.started! if built_components
100
+
96
101
  configuration
97
102
  end
98
103
 
@@ -192,9 +197,20 @@ module Datadog
192
197
  current_components = COMPONENTS_READ_LOCK.synchronize { defined?(@components) && @components }
193
198
  return current_components if current_components || !allow_initialization
194
199
 
195
- safely_synchronize do |write_components|
196
- (defined?(@components) && @components) || write_components.call(build_components(configuration))
200
+ built_components = false
201
+
202
+ components = safely_synchronize do |write_components|
203
+ if defined?(@components) && @components
204
+ @components
205
+ else
206
+ built_components = true
207
+ write_components.call(build_components(configuration))
208
+ end
197
209
  end
210
+
211
+ # Should only be called the first time components are built
212
+ components.telemetry.started! if built_components && components && components.telemetry
213
+ components
198
214
  end
199
215
 
200
216
  private
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'date'
4
3
  require 'json'
5
4
  require 'rbconfig'
5
+ require 'time'
6
6
 
7
7
  module Datadog
8
8
  module Core
@@ -58,9 +58,10 @@ module Datadog
58
58
  module EnvironmentLogger
59
59
  extend EnvironmentLogging
60
60
 
61
- def self.collect_and_log!
61
+ def self.collect_and_log!(extra_fields = nil)
62
62
  log_once! do
63
63
  data = EnvironmentCollector.collect_config!
64
+ data = data.merge(extra_fields) if extra_fields
64
65
  log_configuration!('CORE', data.to_json)
65
66
  end
66
67
  rescue => e
@@ -91,7 +92,7 @@ module Datadog
91
92
 
92
93
  # @return [String] current time in ISO8601 format
93
94
  def date
94
- DateTime.now.iso8601
95
+ Time.now.utc.iso8601
95
96
  end
96
97
 
97
98
  # Best portable guess of OS information.
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../git/ext'
4
+ require_relative '../utils/url'
5
+
6
+ module Datadog
7
+ module Core
8
+ module Environment
9
+ # Retrieves git repository information from environment variables
10
+ module Git
11
+ def self.git_repository_url
12
+ return @git_repository_url if defined?(@git_repository_url)
13
+
14
+ @git_repository_url = Utils::Url.filter_basic_auth(ENV[Datadog::Core::Git::Ext::ENV_REPOSITORY_URL])
15
+ end
16
+
17
+ def self.git_commit_sha
18
+ return @git_commit_sha if defined?(@git_commit_sha)
19
+
20
+ @git_commit_sha = ENV[Datadog::Core::Git::Ext::ENV_COMMIT_SHA]
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -56,58 +56,28 @@ module Datadog
56
56
 
57
57
  # Returns tracer version, comforming to https://semver.org/spec/v2.0.0.html
58
58
  def tracer_version_semver2
59
- # from ddtrace/version.rb, we have MAJOR.MINOR.PATCH plus optional .PRE and .BUILD
60
- # - transform .PRE to -PRE if present
61
- # - transform .BUILD to +BUILD if present
62
- # - keep triplet segments before that
59
+ major, minor, patch, rest = tracer_version.split('.', 4)
63
60
 
64
- m = SEMVER2_RE.match(tracer_version)
61
+ semver = "#{major}.#{minor}.#{patch}"
65
62
 
66
- pre = "-#{m[:pre]}" if m[:pre]
67
- build = "+gha#{m[:gha_run_id]}.g#{m[:git_sha]}.#{m[:branch].tr('.', '-')}" if m[:build]
63
+ return semver unless rest
68
64
 
69
- "#{m[:major]}.#{m[:minor]}.#{m[:patch]}#{pre}#{build}"
70
- end
65
+ pre = ''
66
+ build = ''
67
+
68
+ rest.split('.').tap do |segments|
69
+ if segments.length >= 4
70
+ pre = "-#{segments.shift}"
71
+ build = "+#{segments.join('.')}"
72
+ elsif segments.length == 1
73
+ pre = "-#{segments.shift}"
74
+ else
75
+ build = "+#{segments.join('.')}"
76
+ end
77
+ end
71
78
 
72
- SEMVER2_RE = /
73
- ^
74
- # mandatory segments
75
- (?<major>\d+)
76
- \.
77
- (?<minor>\d+)
78
- \.
79
- (?<patch>\d+)
80
-
81
- # pre segments start with a value
82
- # - containing at least one alpha
83
- # - that is not part of our build segments expected values
84
- # and stop with a value that is not part of our build segments expected values
85
- (?:
86
- \.
87
- (?<pre>
88
- (?!gha)
89
- [a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*
90
- (?:
91
- \.
92
- (?!gha)
93
- [a-zA-Z0-9]+
94
- )*
95
- )
96
- )?
97
-
98
- # build segments: ours include CI info (`gha`), then git (`g`), then branch name
99
- (?:
100
- \.
101
- (?<build>
102
- gha(?<gha_run_id>\d+)
103
- \.
104
- g(?<git_sha>[a-f0-9]+)
105
- \.
106
- (?<branch>(?:[a-zA-Z0-9.])+)
107
- )
108
- )?
109
- $
110
- /xm.freeze
79
+ semver + pre + build
80
+ end
111
81
  end
112
82
  end
113
83
  end
@@ -9,12 +9,18 @@ module Datadog
9
9
  module Platform
10
10
  module_function
11
11
 
12
+ # @return [String] ISA of host; `uname -m`
13
+ def architecture
14
+ Identity.lang_version >= '2.2' ? Etc.uname[:machine] : Gem::Platform.local.cpu
15
+ end
16
+
12
17
  # @return [String] name of host; `uname -n`
13
18
  def hostname
14
19
  Identity.lang_version >= '2.2' ? Etc.uname[:nodename] : nil
15
20
  end
16
21
 
17
- # @return [String] name of kernel; `uname -s`
22
+ # System name, normally `Linux` or `Darwin` (but 'Mac OS X' on JRuby);
23
+ # @return [String] name of kernel; `uname -s`.
18
24
  def kernel_name
19
25
  Identity.lang_version >= '2.2' ? Etc.uname[:sysname] : Gem::Platform.local.os.capitalize
20
26
  end
@@ -5,32 +5,11 @@ module Datadog
5
5
  module Git
6
6
  # Defines constants for Git tags
7
7
  module Ext
8
- GIT_SHA_LENGTH = 40
9
-
10
- TAG_BRANCH = 'git.branch'
11
- TAG_REPOSITORY_URL = 'git.repository_url'
12
- TAG_TAG = 'git.tag'
13
-
14
- TAG_COMMIT_AUTHOR_DATE = 'git.commit.author.date'
15
- TAG_COMMIT_AUTHOR_EMAIL = 'git.commit.author.email'
16
- TAG_COMMIT_AUTHOR_NAME = 'git.commit.author.name'
17
- TAG_COMMIT_COMMITTER_DATE = 'git.commit.committer.date'
18
- TAG_COMMIT_COMMITTER_EMAIL = 'git.commit.committer.email'
19
- TAG_COMMIT_COMMITTER_NAME = 'git.commit.committer.name'
20
- TAG_COMMIT_MESSAGE = 'git.commit.message'
21
- TAG_COMMIT_SHA = 'git.commit.sha'
8
+ TAG_REPOSITORY_URL = '_dd.git.repository_url'
9
+ TAG_COMMIT_SHA = '_dd.git.commit.sha'
22
10
 
23
11
  ENV_REPOSITORY_URL = 'DD_GIT_REPOSITORY_URL'
24
12
  ENV_COMMIT_SHA = 'DD_GIT_COMMIT_SHA'
25
- ENV_BRANCH = 'DD_GIT_BRANCH'
26
- ENV_TAG = 'DD_GIT_TAG'
27
- ENV_COMMIT_MESSAGE = 'DD_GIT_COMMIT_MESSAGE'
28
- ENV_COMMIT_AUTHOR_NAME = 'DD_GIT_COMMIT_AUTHOR_NAME'
29
- ENV_COMMIT_AUTHOR_EMAIL = 'DD_GIT_COMMIT_AUTHOR_EMAIL'
30
- ENV_COMMIT_AUTHOR_DATE = 'DD_GIT_COMMIT_AUTHOR_DATE'
31
- ENV_COMMIT_COMMITTER_NAME = 'DD_GIT_COMMIT_COMMITTER_NAME'
32
- ENV_COMMIT_COMMITTER_EMAIL = 'DD_GIT_COMMIT_COMMITTER_EMAIL'
33
- ENV_COMMIT_COMMITTER_DATE = 'DD_GIT_COMMIT_COMMITTER_DATE'
34
13
  end
35
14
  end
36
15
  end
@@ -53,7 +53,7 @@ module Datadog
53
53
  cap_to_hexs = capabilities.reduce(:|).to_s(16).tap { |s| s.size.odd? && s.prepend('0') }.scan(/\h\h/)
54
54
  binary = cap_to_hexs.each_with_object([]) { |hex, acc| acc << hex }.map { |e| e.to_i(16) }.pack('C*')
55
55
 
56
- Base64.encode64(binary).chomp
56
+ Base64.strict_encode64(binary)
57
57
  end
58
58
  end
59
59
  end
@@ -7,12 +7,12 @@ module Datadog
7
7
  module Remote
8
8
  # Endpoint negotiation
9
9
  class Negotiation
10
- def initialize(_settings, agent_settings)
10
+ def initialize(_settings, agent_settings, suppress_logging: {})
11
11
  transport_options = {}
12
12
  transport_options[:agent_settings] = agent_settings if agent_settings
13
13
 
14
14
  @transport_root = Datadog::Core::Remote::Transport::HTTP.root(**transport_options.dup)
15
- @logged = {}
15
+ @logged = suppress_logging
16
16
  end
17
17
 
18
18
  def endpoint?(path)
@@ -51,7 +51,7 @@ module Datadog
51
51
 
52
52
  # TODO: these fallbacks should be improved
53
53
  roots = payload[:roots] || []
54
- targets = payload[:targets] || Base64.encode64('{}').chomp
54
+ targets = payload[:targets] || Base64.strict_encode64('{}')
55
55
  target_files = payload[:target_files] || []
56
56
  client_configs = payload[:client_configs] || []
57
57