datadog 2.35.0 → 2.36.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 (83) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -1
  3. data/ext/datadog_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +68 -31
  4. data/ext/datadog_profiling_native_extension/collectors_discrete_dynamic_sampler.c +1 -1
  5. data/ext/datadog_profiling_native_extension/collectors_idle_sampling_helper.c +1 -1
  6. data/ext/datadog_profiling_native_extension/collectors_stack.c +37 -18
  7. data/ext/datadog_profiling_native_extension/collectors_stack.h +8 -2
  8. data/ext/datadog_profiling_native_extension/collectors_thread_context.c +434 -300
  9. data/ext/datadog_profiling_native_extension/collectors_thread_context.h +9 -7
  10. data/ext/datadog_profiling_native_extension/datadog_ruby_common.c +7 -8
  11. data/ext/datadog_profiling_native_extension/datadog_ruby_common.h +0 -12
  12. data/ext/datadog_profiling_native_extension/extconf.rb +2 -2
  13. data/ext/datadog_profiling_native_extension/gvl_profiling_helper.c +4 -43
  14. data/ext/datadog_profiling_native_extension/gvl_profiling_helper.h +15 -47
  15. data/ext/datadog_profiling_native_extension/heap_recorder.c +44 -26
  16. data/ext/datadog_profiling_native_extension/private_vm_api_access.c +14 -35
  17. data/ext/datadog_profiling_native_extension/profiling.c +41 -4
  18. data/ext/datadog_profiling_native_extension/ruby_helpers.c +33 -34
  19. data/ext/datadog_profiling_native_extension/stack_recorder.c +24 -3
  20. data/ext/datadog_profiling_native_extension/stack_recorder.h +1 -0
  21. data/ext/datadog_profiling_native_extension/unsafe_api_calls_check.h +4 -2
  22. data/ext/libdatadog_api/datadog_ruby_common.c +7 -8
  23. data/ext/libdatadog_api/datadog_ruby_common.h +0 -12
  24. data/ext/libdatadog_extconf_helpers.rb +1 -1
  25. data/lib/datadog/appsec/api_security/route_extractor.rb +6 -0
  26. data/lib/datadog/appsec/component.rb +1 -1
  27. data/lib/datadog/appsec/configuration.rb +7 -0
  28. data/lib/datadog/appsec/contrib/aws_lambda/waf_addresses.rb +37 -4
  29. data/lib/datadog/appsec/contrib/graphql/gateway/multiplex.rb +64 -19
  30. data/lib/datadog/appsec/contrib/graphql/integration.rb +1 -0
  31. data/lib/datadog/appsec/contrib/rack/buffered_input.rb +83 -0
  32. data/lib/datadog/appsec/contrib/rack/gateway/request.rb +41 -3
  33. data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +20 -7
  34. data/lib/datadog/appsec/contrib/rack/input_peeker.rb +92 -0
  35. data/lib/datadog/appsec/contrib/rails/gateway/request.rb +33 -0
  36. data/lib/datadog/appsec/contrib/rails/gateway/watcher.rb +17 -1
  37. data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +20 -3
  38. data/lib/datadog/appsec/default_header_tags.rb +10 -6
  39. data/lib/datadog/core/configuration/components.rb +1 -0
  40. data/lib/datadog/core/configuration/settings.rb +1 -2
  41. data/lib/datadog/core/configuration/supported_configurations.rb +2 -0
  42. data/lib/datadog/core/remote/component.rb +1 -1
  43. data/lib/datadog/core/telemetry/event/app_started.rb +0 -21
  44. data/lib/datadog/core/utils/at_fork_monkey_patch.rb +1 -1
  45. data/lib/datadog/core/utils/forking.rb +3 -1
  46. data/lib/datadog/core/utils/spawn_monkey_patch.rb +3 -1
  47. data/lib/datadog/core.rb +3 -0
  48. data/lib/datadog/di/base.rb +4 -1
  49. data/lib/datadog/di/component.rb +1 -1
  50. data/lib/datadog/error_tracking/collector.rb +2 -1
  51. data/lib/datadog/error_tracking/component.rb +2 -2
  52. data/lib/datadog/kit/tracing/method_tracer.rb +4 -1
  53. data/lib/datadog/opentelemetry/sdk/propagator.rb +9 -3
  54. data/lib/datadog/opentelemetry/sdk/span_processor.rb +4 -1
  55. data/lib/datadog/profiling/collectors/thread_context.rb +1 -0
  56. data/lib/datadog/profiling/component.rb +13 -15
  57. data/lib/datadog/profiling/ext/dir_monkey_patches.rb +3 -3
  58. data/lib/datadog/ruby_version.rb +25 -0
  59. data/lib/datadog/symbol_database/component.rb +306 -98
  60. data/lib/datadog/symbol_database/extractor.rb +223 -84
  61. data/lib/datadog/tracing/configuration/ext.rb +13 -0
  62. data/lib/datadog/tracing/configuration/settings.rb +17 -0
  63. data/lib/datadog/tracing/contrib/configuration/resolver.rb +7 -0
  64. data/lib/datadog/tracing/contrib/grpc/distributed/propagation.rb +2 -0
  65. data/lib/datadog/tracing/contrib/grpc.rb +1 -0
  66. data/lib/datadog/tracing/contrib/http/distributed/propagation.rb +2 -0
  67. data/lib/datadog/tracing/contrib/http.rb +1 -0
  68. data/lib/datadog/tracing/contrib/karafka/distributed/propagation.rb +2 -0
  69. data/lib/datadog/tracing/contrib/karafka.rb +1 -0
  70. data/lib/datadog/tracing/contrib/rack/middlewares.rb +3 -1
  71. data/lib/datadog/tracing/contrib/rack/route_inference.rb +3 -1
  72. data/lib/datadog/tracing/contrib/sidekiq/distributed/propagation.rb +2 -0
  73. data/lib/datadog/tracing/contrib/sidekiq.rb +1 -0
  74. data/lib/datadog/tracing/contrib/waterdrop/distributed/propagation.rb +2 -0
  75. data/lib/datadog/tracing/contrib/waterdrop.rb +1 -0
  76. data/lib/datadog/tracing/distributed/propagation.rb +33 -1
  77. data/lib/datadog/tracing/distributed/trace_context.rb +11 -2
  78. data/lib/datadog/tracing/trace_digest.rb +7 -0
  79. data/lib/datadog/tracing/trace_operation.rb +4 -1
  80. data/lib/datadog/tracing/tracer.rb +1 -0
  81. data/lib/datadog/version.rb +1 -1
  82. data/lib/datadog.rb +4 -1
  83. metadata +8 -5
@@ -141,15 +141,14 @@ module Datadog
141
141
  # that causes a segmentation fault during garbage collection of Ractors
142
142
  # (https://bugs.ruby-lang.org/issues/18464). We don't allow enabling gc profiling on such Rubies.
143
143
  # This bug is fixed on Ruby versions 3.1.4, 3.2.3 and 3.3.0.
144
- if RUBY_VERSION.start_with?("3.0.") ||
145
- (RUBY_VERSION.start_with?("3.1.") && RUBY_VERSION < "3.1.4") ||
146
- (RUBY_VERSION.start_with?("3.2.") && RUBY_VERSION < "3.2.3")
144
+ if RubyVersion.is?(">= 3", "< 3.1.4") ||
145
+ RubyVersion.is?(">= 3.2", "< 3.2.3")
147
146
  logger.warn(
148
147
  "Current Ruby version (#{RUBY_VERSION}) has a VM bug where enabling GC profiling would cause " \
149
148
  "crashes (https://bugs.ruby-lang.org/issues/18464). GC profiling has been disabled."
150
149
  )
151
150
  return false
152
- elsif RUBY_VERSION.start_with?("3.")
151
+ elsif RubyVersion.is?(">= 3", "< 4")
153
152
  logger.debug(
154
153
  "Using Ractors may result in GC profiling unexpectedly " \
155
154
  "stopping (https://bugs.ruby-lang.org/issues/19112). Note that this stop has no impact in your " \
@@ -177,7 +176,7 @@ module Datadog
177
176
  # Ruby 3.2.0 to 3.2.2 have a bug in the newobj tracepoint (https://bugs.ruby-lang.org/issues/19482,
178
177
  # https://github.com/ruby/ruby/pull/7464) that makes this crash in any configuration. This bug is
179
178
  # fixed on Ruby versions 3.2.3 and 3.3.0.
180
- if RUBY_VERSION.start_with?("3.2.") && RUBY_VERSION < "3.2.3"
179
+ if RubyVersion.is?(">= 3.2", "< 3.2.3")
181
180
  logger.warn(
182
181
  "Allocation profiling is not supported in Ruby versions 3.2.0, 3.2.1 and 3.2.2 and will be forcibly " \
183
182
  "disabled. This is due to a VM bug that can lead to crashes (https://bugs.ruby-lang.org/issues/19482). " \
@@ -191,9 +190,8 @@ module Datadog
191
190
  # that causes a segmentation fault during garbage collection of Ractors
192
191
  # (https://bugs.ruby-lang.org/issues/18464). We don't recommend using this feature on such Rubies.
193
192
  # This bug is fixed on Ruby versions 3.1.4, 3.2.3 and 3.3.0.
194
- if RUBY_VERSION.start_with?("3.0.") ||
195
- (RUBY_VERSION.start_with?("3.1.") && RUBY_VERSION < "3.1.4") ||
196
- (RUBY_VERSION.start_with?("3.2.") && RUBY_VERSION < "3.2.3")
193
+ if RubyVersion.is?(">= 3", "< 3.1.4") ||
194
+ RubyVersion.is?(">= 3.2", "< 3.2.3")
197
195
  logger.warn(
198
196
  "Current Ruby version (#{RUBY_VERSION}) has a VM bug where enabling allocation profiling while using " \
199
197
  "Ractors may cause unexpected issues, including crashes (https://bugs.ruby-lang.org/issues/18464). " \
@@ -202,7 +200,7 @@ module Datadog
202
200
  # ANNOYANCE - Only with Ractors
203
201
  # On all known versions of Ruby 3.x, due to https://bugs.ruby-lang.org/issues/19112, when a ractor gets
204
202
  # garbage collected, Ruby will disable all active tracepoints, which this feature internally relies on.
205
- elsif RUBY_VERSION.start_with?("3.")
203
+ elsif RubyVersion.is?(">= 3", "< 4")
206
204
  logger.debug(
207
205
  "Using Ractors may result in allocation profiling " \
208
206
  "stopping (https://bugs.ruby-lang.org/issues/19112). Note that this stop has no impact in your " \
@@ -220,7 +218,7 @@ module Datadog
220
218
 
221
219
  return false unless heap_profiling_enabled
222
220
 
223
- if RUBY_VERSION < "3.1"
221
+ if RubyVersion.is?("< 3.1")
224
222
  logger.warn(
225
223
  "Current Ruby version (#{RUBY_VERSION}) cannot support heap profiling due to VM limitations. " \
226
224
  "Please upgrade to Ruby >= 3.1 in order to use this feature. Heap profiling has been disabled."
@@ -262,7 +260,7 @@ module Datadog
262
260
  end
263
261
 
264
262
  if setting_value == false
265
- if RUBY_VERSION.start_with?("2.5.")
263
+ if RubyVersion.is?("< 2.6")
266
264
  logger.warn(
267
265
  'The profiling "no signals" workaround has been disabled via configuration on Ruby 2.5. ' \
268
266
  "This is not recommended " \
@@ -288,7 +286,7 @@ module Datadog
288
286
  # Setting is in auto mode. Let's probe to see if we should enable it:
289
287
 
290
288
  # We don't warn users in this situation because "upgrade your Ruby" is not a great warning
291
- return true if RUBY_VERSION.start_with?("2.5.")
289
+ return true if RubyVersion.is?("< 2.6")
292
290
 
293
291
  if Gem.loaded_specs["mysql2"] && incompatible_libmysqlclient_version?(settings, logger)
294
292
  logger.warn(
@@ -450,13 +448,13 @@ module Datadog
450
448
  end
451
449
 
452
450
  private_class_method def self.dir_interruption_workaround_enabled?(settings, no_signals_workaround_enabled)
453
- return false if no_signals_workaround_enabled || RUBY_VERSION >= "3.4"
451
+ return false if no_signals_workaround_enabled || RubyVersion.is?(">= 3.4")
454
452
 
455
453
  settings.profiling.advanced.dir_interruption_workaround_enabled
456
454
  end
457
455
 
458
456
  private_class_method def self.can_apply_exec_monkey_patch?(settings)
459
- return false if RUBY_VERSION < "2.7"
457
+ return false if RubyVersion.is?("< 2.7")
460
458
 
461
459
  # This file is 2.7+ only so we only require it here once we've checked the Ruby version
462
460
  require "datadog/profiling/ext/exec_monkey_patch"
@@ -465,7 +463,7 @@ module Datadog
465
463
  end
466
464
 
467
465
  private_class_method def self.enable_gvl_profiling?(settings, logger)
468
- RUBY_VERSION >= "3.2" && settings.profiling.advanced.gvl_enabled
466
+ RubyVersion.is?(">= 3.2") && settings.profiling.advanced.gvl_enabled
469
467
  end
470
468
  end
471
469
  end
@@ -28,7 +28,7 @@ module Datadog
28
28
  end
29
29
  end
30
30
 
31
- if RUBY_VERSION.start_with?("2.")
31
+ if RubyVersion.is?("< 3")
32
32
  # Monkey patches for Dir.singleton_class (Ruby 2 version). See DirMonkeyPatches above for more details.
33
33
  module DirClassMonkeyPatches
34
34
  # Steep: Workaround that defines args and block only for Ruby 2.x.
@@ -270,7 +270,7 @@ module Datadog
270
270
  end
271
271
  end
272
272
 
273
- if RUBY_VERSION.start_with?("2.")
273
+ if RubyVersion.is?("< 3")
274
274
  # Monkey patches for Dir (Ruby 2 version). See DirMonkeyPatches above for more details.
275
275
  module DirInstanceMonkeyPatches
276
276
  # Steep: Workaround that defines args and block only for Ruby 2.x.
@@ -300,7 +300,7 @@ module Datadog
300
300
  end
301
301
  end
302
302
 
303
- unless RUBY_VERSION.start_with?("2.5.") # This is Ruby 2.6+
303
+ if RubyVersion.is?(">= 2.6.0") # This method is Ruby 2.6+
304
304
  # See note on methods that yield above.
305
305
  def each_child(*args, &block)
306
306
  if block
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datadog
4
+ # Compares the running Ruby against version requirements.
5
+ #
6
+ # Lexical comparisons against `RUBY_VERSION` are subtly wrong: `RUBY_VERSION < "3.2.3"` is also
7
+ # `true` on 3.2.10 and 3.2.11, since those sort *before* "3.2.3" as strings.
8
+ #
9
+ # @example
10
+ # RubyVersion.is?(">= 3.2", "< 3.2.3") # => true on Ruby 3.2.0, 3.2.1, 3.2.2 (NOT 3.2.3+, NOT 3.2.10+)
11
+ module RubyVersion
12
+ extend RubyVersion # steep currently needs this (instead of extend self or def self.is?) for the inline rbs to work
13
+
14
+ CURRENT_RUBY_VERSION = Gem::Version.new(RUBY_VERSION) #: ::Gem::Version
15
+ private_constant :CURRENT_RUBY_VERSION
16
+
17
+ # Returns `true` when the running Ruby satisfies ALL of the given requirements. Each uses the
18
+ # same syntax as a gem dependency (e.g. `">= 3.1"`, `">= 3.2"`, `"< 3.2.3"`).
19
+ #
20
+ # @rbs (*String requirements, ?ruby_version: ::Gem::Version) -> bool
21
+ def is?(*requirements, ruby_version: CURRENT_RUBY_VERSION)
22
+ Gem::Requirement.new(*requirements).satisfied_by?(ruby_version)
23
+ end
24
+ end
25
+ end