datadog 2.16.0 → 2.18.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 (164) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +72 -1
  3. data/ext/datadog_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +12 -46
  4. data/ext/datadog_profiling_native_extension/collectors_stack.c +227 -49
  5. data/ext/datadog_profiling_native_extension/collectors_stack.h +19 -3
  6. data/ext/datadog_profiling_native_extension/collectors_thread_context.c +63 -12
  7. data/ext/datadog_profiling_native_extension/collectors_thread_context.h +1 -0
  8. data/ext/datadog_profiling_native_extension/encoded_profile.c +22 -12
  9. data/ext/datadog_profiling_native_extension/encoded_profile.h +1 -0
  10. data/ext/datadog_profiling_native_extension/extconf.rb +7 -0
  11. data/ext/datadog_profiling_native_extension/heap_recorder.c +239 -363
  12. data/ext/datadog_profiling_native_extension/heap_recorder.h +4 -6
  13. data/ext/datadog_profiling_native_extension/http_transport.c +45 -72
  14. data/ext/datadog_profiling_native_extension/libdatadog_helpers.c +22 -0
  15. data/ext/datadog_profiling_native_extension/libdatadog_helpers.h +8 -5
  16. data/ext/datadog_profiling_native_extension/private_vm_api_access.c +1 -0
  17. data/ext/datadog_profiling_native_extension/private_vm_api_access.h +6 -3
  18. data/ext/datadog_profiling_native_extension/ruby_helpers.c +1 -13
  19. data/ext/datadog_profiling_native_extension/ruby_helpers.h +2 -10
  20. data/ext/datadog_profiling_native_extension/stack_recorder.c +156 -60
  21. data/ext/libdatadog_api/crashtracker.c +10 -3
  22. data/ext/libdatadog_api/extconf.rb +2 -2
  23. data/ext/libdatadog_api/library_config.c +54 -12
  24. data/ext/libdatadog_api/library_config.h +6 -0
  25. data/ext/libdatadog_api/macos_development.md +3 -3
  26. data/ext/libdatadog_api/process_discovery.c +2 -7
  27. data/ext/libdatadog_extconf_helpers.rb +2 -2
  28. data/lib/datadog/appsec/api_security/lru_cache.rb +56 -0
  29. data/lib/datadog/appsec/api_security/route_extractor.rb +65 -0
  30. data/lib/datadog/appsec/api_security/sampler.rb +59 -0
  31. data/lib/datadog/appsec/api_security.rb +23 -0
  32. data/lib/datadog/appsec/assets/waf_rules/recommended.json +257 -85
  33. data/lib/datadog/appsec/assets/waf_rules/strict.json +10 -78
  34. data/lib/datadog/appsec/component.rb +30 -54
  35. data/lib/datadog/appsec/configuration/settings.rb +60 -2
  36. data/lib/datadog/appsec/context.rb +6 -6
  37. data/lib/datadog/appsec/contrib/devise/tracking_middleware.rb +1 -1
  38. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +27 -16
  39. data/lib/datadog/appsec/processor/rule_loader.rb +5 -6
  40. data/lib/datadog/appsec/remote.rb +15 -55
  41. data/lib/datadog/appsec/security_engine/engine.rb +194 -0
  42. data/lib/datadog/appsec/security_engine/runner.rb +10 -11
  43. data/lib/datadog/appsec.rb +4 -7
  44. data/lib/datadog/core/buffer/random.rb +18 -2
  45. data/lib/datadog/core/configuration/agent_settings.rb +52 -0
  46. data/lib/datadog/core/configuration/agent_settings_resolver.rb +4 -46
  47. data/lib/datadog/core/configuration/components.rb +31 -24
  48. data/lib/datadog/core/configuration/components_state.rb +23 -0
  49. data/lib/datadog/core/configuration/option.rb +27 -27
  50. data/lib/datadog/core/configuration/option_definition.rb +4 -4
  51. data/lib/datadog/core/configuration/options.rb +1 -1
  52. data/lib/datadog/core/configuration/settings.rb +32 -20
  53. data/lib/datadog/core/configuration/stable_config.rb +1 -2
  54. data/lib/datadog/core/configuration.rb +16 -16
  55. data/lib/datadog/core/crashtracking/component.rb +2 -1
  56. data/lib/datadog/core/crashtracking/tag_builder.rb +4 -22
  57. data/lib/datadog/core/encoding.rb +1 -1
  58. data/lib/datadog/core/environment/cgroup.rb +10 -12
  59. data/lib/datadog/core/environment/container.rb +38 -40
  60. data/lib/datadog/core/environment/ext.rb +6 -6
  61. data/lib/datadog/core/environment/identity.rb +3 -3
  62. data/lib/datadog/core/environment/platform.rb +3 -3
  63. data/lib/datadog/core/error.rb +11 -9
  64. data/lib/datadog/core/logger.rb +2 -2
  65. data/lib/datadog/core/metrics/client.rb +12 -14
  66. data/lib/datadog/core/metrics/logging.rb +5 -5
  67. data/lib/datadog/core/process_discovery/tracer_memfd.rb +15 -0
  68. data/lib/datadog/core/process_discovery.rb +5 -1
  69. data/lib/datadog/core/rate_limiter.rb +4 -2
  70. data/lib/datadog/core/remote/client.rb +32 -31
  71. data/lib/datadog/core/remote/component.rb +3 -3
  72. data/lib/datadog/core/remote/configuration/digest.rb +7 -7
  73. data/lib/datadog/core/remote/configuration/path.rb +1 -1
  74. data/lib/datadog/core/remote/configuration/repository.rb +12 -0
  75. data/lib/datadog/core/remote/transport/http/client.rb +1 -1
  76. data/lib/datadog/core/remote/transport/http/config.rb +21 -5
  77. data/lib/datadog/core/remote/transport/http/negotiation.rb +1 -1
  78. data/lib/datadog/core/runtime/metrics.rb +3 -3
  79. data/lib/datadog/core/tag_builder.rb +56 -0
  80. data/lib/datadog/core/telemetry/component.rb +39 -24
  81. data/lib/datadog/core/telemetry/emitter.rb +7 -1
  82. data/lib/datadog/core/telemetry/event/app_client_configuration_change.rb +66 -0
  83. data/lib/datadog/core/telemetry/event/app_closing.rb +18 -0
  84. data/lib/datadog/core/telemetry/event/app_dependencies_loaded.rb +33 -0
  85. data/lib/datadog/core/telemetry/event/app_heartbeat.rb +18 -0
  86. data/lib/datadog/core/telemetry/event/app_integrations_change.rb +58 -0
  87. data/lib/datadog/core/telemetry/event/app_started.rb +269 -0
  88. data/lib/datadog/core/telemetry/event/base.rb +40 -0
  89. data/lib/datadog/core/telemetry/event/distributions.rb +18 -0
  90. data/lib/datadog/core/telemetry/event/generate_metrics.rb +43 -0
  91. data/lib/datadog/core/telemetry/event/log.rb +76 -0
  92. data/lib/datadog/core/telemetry/event/message_batch.rb +42 -0
  93. data/lib/datadog/core/telemetry/event/synth_app_client_configuration_change.rb +43 -0
  94. data/lib/datadog/core/telemetry/event.rb +17 -475
  95. data/lib/datadog/core/telemetry/logger.rb +5 -4
  96. data/lib/datadog/core/telemetry/logging.rb +11 -5
  97. data/lib/datadog/core/telemetry/metric.rb +3 -3
  98. data/lib/datadog/core/telemetry/transport/http/telemetry.rb +2 -2
  99. data/lib/datadog/core/telemetry/transport/telemetry.rb +0 -1
  100. data/lib/datadog/core/telemetry/worker.rb +48 -27
  101. data/lib/datadog/core/transport/http/adapters/net.rb +17 -2
  102. data/lib/datadog/core/transport/http/adapters/test.rb +2 -1
  103. data/lib/datadog/core/transport/http/builder.rb +14 -14
  104. data/lib/datadog/core/transport/http/env.rb +8 -0
  105. data/lib/datadog/core/utils/at_fork_monkey_patch.rb +6 -6
  106. data/lib/datadog/core/utils/duration.rb +32 -32
  107. data/lib/datadog/core/utils/forking.rb +2 -2
  108. data/lib/datadog/core/utils/network.rb +6 -6
  109. data/lib/datadog/core/utils/only_once_successful.rb +16 -5
  110. data/lib/datadog/core/utils/time.rb +10 -2
  111. data/lib/datadog/core/utils/truncation.rb +21 -0
  112. data/lib/datadog/core/utils.rb +7 -0
  113. data/lib/datadog/core/vendor/multipart-post/multipart/post/composite_read_io.rb +1 -1
  114. data/lib/datadog/core/vendor/multipart-post/multipart/post/multipartable.rb +8 -8
  115. data/lib/datadog/core/vendor/multipart-post/multipart/post/parts.rb +7 -7
  116. data/lib/datadog/core/worker.rb +1 -1
  117. data/lib/datadog/core/workers/async.rb +9 -10
  118. data/lib/datadog/di/instrumenter.rb +52 -2
  119. data/lib/datadog/di/probe_notification_builder.rb +31 -41
  120. data/lib/datadog/di/probe_notifier_worker.rb +9 -1
  121. data/lib/datadog/di/serializer.rb +6 -2
  122. data/lib/datadog/di/transport/http/input.rb +10 -0
  123. data/lib/datadog/di/transport/input.rb +10 -2
  124. data/lib/datadog/error_tracking/component.rb +2 -2
  125. data/lib/datadog/profiling/collectors/code_provenance.rb +18 -9
  126. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +4 -0
  127. data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +1 -0
  128. data/lib/datadog/profiling/collectors/thread_context.rb +16 -1
  129. data/lib/datadog/profiling/component.rb +7 -9
  130. data/lib/datadog/profiling/ext.rb +0 -13
  131. data/lib/datadog/profiling/flush.rb +1 -1
  132. data/lib/datadog/profiling/http_transport.rb +3 -8
  133. data/lib/datadog/profiling/profiler.rb +2 -0
  134. data/lib/datadog/profiling/scheduler.rb +10 -2
  135. data/lib/datadog/profiling/stack_recorder.rb +5 -5
  136. data/lib/datadog/profiling/tag_builder.rb +5 -41
  137. data/lib/datadog/profiling/tasks/setup.rb +2 -0
  138. data/lib/datadog/tracing/contrib/action_pack/action_controller/instrumentation.rb +15 -0
  139. data/lib/datadog/tracing/contrib/action_pack/action_dispatch/instrumentation.rb +19 -12
  140. data/lib/datadog/tracing/contrib/action_pack/ext.rb +2 -0
  141. data/lib/datadog/tracing/contrib/active_support/cache/events/cache.rb +4 -1
  142. data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +33 -0
  143. data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +4 -0
  144. data/lib/datadog/tracing/contrib/active_support/cache/redis.rb +2 -4
  145. data/lib/datadog/tracing/contrib/aws/instrumentation.rb +10 -0
  146. data/lib/datadog/tracing/contrib/aws/parsed_context.rb +5 -1
  147. data/lib/datadog/tracing/contrib/http/instrumentation.rb +1 -5
  148. data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +1 -5
  149. data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +1 -5
  150. data/lib/datadog/tracing/contrib/lograge/patcher.rb +4 -2
  151. data/lib/datadog/tracing/contrib/patcher.rb +5 -2
  152. data/lib/datadog/tracing/contrib/sidekiq/ext.rb +1 -0
  153. data/lib/datadog/tracing/contrib/sidekiq/server_tracer.rb +5 -2
  154. data/lib/datadog/tracing/contrib/support.rb +28 -0
  155. data/lib/datadog/tracing/metadata/errors.rb +4 -4
  156. data/lib/datadog/tracing/sync_writer.rb +1 -1
  157. data/lib/datadog/tracing/trace_operation.rb +12 -4
  158. data/lib/datadog/tracing/tracer.rb +6 -2
  159. data/lib/datadog/version.rb +1 -1
  160. metadata +31 -12
  161. data/lib/datadog/appsec/assets/waf_rules/processors.json +0 -321
  162. data/lib/datadog/appsec/assets/waf_rules/scanners.json +0 -1023
  163. data/lib/datadog/appsec/processor/rule_merger.rb +0 -171
  164. data/lib/datadog/appsec/processor.rb +0 -107
@@ -22,7 +22,7 @@ module Datadog
22
22
  # Represents an Option precedence level.
23
23
  # Each precedence has a `numeric` value; higher values means higher precedence.
24
24
  # `name` is for inspection purposes only.
25
- Value = Struct.new(:numeric, :name) do
25
+ Value = Struct.new(:numeric, :name, :origin) do
26
26
  include Comparable
27
27
 
28
28
  def <=>(other)
@@ -33,22 +33,22 @@ module Datadog
33
33
  end
34
34
 
35
35
  # Remote configuration provided through the Datadog app.
36
- REMOTE_CONFIGURATION = Value.new(5, :remote_configuration).freeze
36
+ REMOTE_CONFIGURATION = Value.new(5, :remote_configuration, 'remote_config').freeze
37
37
 
38
38
  # Configuration provided in Ruby code, in this same process
39
- PROGRAMMATIC = Value.new(4, :programmatic).freeze
39
+ PROGRAMMATIC = Value.new(4, :programmatic, 'code').freeze
40
40
 
41
41
  # Configuration provided by fleet managed stable config
42
- FLEET_STABLE = Value.new(3, :fleet_stable).freeze
42
+ FLEET_STABLE = Value.new(3, :fleet_stable, 'fleet_stable_config').freeze
43
43
 
44
44
  # Configuration provided via environment variable
45
- ENVIRONMENT = Value.new(2, :environment).freeze
45
+ ENVIRONMENT = Value.new(2, :environment, 'env_var').freeze
46
46
 
47
47
  # Configuration provided by local stable config file
48
- LOCAL_STABLE = Value.new(1, :local_stable).freeze
48
+ LOCAL_STABLE = Value.new(1, :local_stable, 'local_stable_config').freeze
49
49
 
50
50
  # Configuration that comes from default values
51
- DEFAULT = Value.new(0, :default).freeze
51
+ DEFAULT = Value.new(0, :default, 'default').freeze
52
52
 
53
53
  # All precedences, sorted from highest to lowest
54
54
  LIST = [REMOTE_CONFIGURATION, PROGRAMMATIC, FLEET_STABLE, ENVIRONMENT, LOCAL_STABLE, DEFAULT].sort.reverse.freeze
@@ -142,14 +142,14 @@ module Datadog
142
142
 
143
143
  def reset
144
144
  @value = if definition.resetter
145
- # Don't change @is_set to false; custom resetters are
146
- # responsible for changing @value back to a good state.
147
- # Setting @is_set = false would cause a default to be applied.
148
- context_exec(@value, &definition.resetter)
149
- else
150
- @is_set = false
151
- nil
152
- end
145
+ # Don't change @is_set to false; custom resetters are
146
+ # responsible for changing @value back to a good state.
147
+ # Setting @is_set = false would cause a default to be applied.
148
+ context_exec(@value, &definition.resetter)
149
+ else
150
+ @is_set = false
151
+ nil
152
+ end
153
153
 
154
154
  # Reset back to the lowest precedence, to allow all `set`s to succeed right after a reset.
155
155
  @precedence_set = Precedence::DEFAULT
@@ -227,20 +227,20 @@ module Datadog
227
227
 
228
228
  unless valid_type
229
229
  raise_error = if @definition.type_options[:nilable]
230
- !value.is_a?(NilClass)
231
- else
232
- true
233
- end
230
+ !value.is_a?(NilClass)
231
+ else
232
+ true
233
+ end
234
234
  end
235
235
 
236
236
  if raise_error
237
237
  error_msg = if @definition.type_options[:nilable]
238
- "The setting `#{@definition.name}` inside your app's `Datadog.configure` block expects a "\
239
- "#{@definition.type} or `nil`, but a `#{value.class}` was provided (#{value.inspect})."\
240
- else
241
- "The setting `#{@definition.name}` inside your app's `Datadog.configure` block expects a "\
242
- "#{@definition.type}, but a `#{value.class}` was provided (#{value.inspect})."\
243
- end
238
+ "The setting `#{@definition.name}` inside your app's `Datadog.configure` block expects a " \
239
+ "#{@definition.type} or `nil`, but a `#{value.class}` was provided (#{value.inspect})." \
240
+ else
241
+ "The setting `#{@definition.name}` inside your app's `Datadog.configure` block expects a " \
242
+ "#{@definition.type}, but a `#{value.class}` was provided (#{value.inspect})." \
243
+ end
244
244
 
245
245
  error_msg = "#{error_msg} Please update your `configure` block. "
246
246
 
@@ -309,7 +309,7 @@ module Datadog
309
309
  end
310
310
 
311
311
  def set_customer_stable_config_value
312
- customer_config = StableConfig.configuration[:local]
312
+ customer_config = StableConfig.configuration.dig(:local, :config)
313
313
  return if customer_config.nil?
314
314
 
315
315
  value, resolved_env = get_value_and_resolved_env_from(customer_config, source: 'local stable config')
@@ -317,7 +317,7 @@ module Datadog
317
317
  end
318
318
 
319
319
  def set_fleet_stable_config_value
320
- fleet_config = StableConfig.configuration[:fleet]
320
+ fleet_config = StableConfig.configuration.dig(:fleet, :config)
321
321
  return if fleet_config.nil?
322
322
 
323
323
  value, resolved_env = get_value_and_resolved_env_from(fleet_config, source: 'fleet stable config')
@@ -71,11 +71,11 @@ module Datadog
71
71
  validate_options!
72
72
  end
73
73
 
74
- def env(value)
74
+ def env(value) # standard:disable Style/TrivialAccessors
75
75
  @env = value
76
76
  end
77
77
 
78
- def deprecated_env(value)
78
+ def deprecated_env(value) # standard:disable Style/TrivialAccessors
79
79
  @deprecated_env = value
80
80
  end
81
81
 
@@ -111,7 +111,7 @@ module Datadog
111
111
 
112
112
  def type(value, nilable: false)
113
113
  @type = value
114
- @type_options = { nilable: nilable }
114
+ @type_options = {nilable: nilable}
115
115
 
116
116
  value
117
117
  end
@@ -156,7 +156,7 @@ module Datadog
156
156
  if !@default.nil? && @default_proc
157
157
  raise InvalidOptionError,
158
158
  'Using `default` and `default_proc` is not allowed. Please use one or the other.' \
159
- 'If you want to store a block as the default value use `default_proc`'\
159
+ 'If you want to store a block as the default value use `default_proc`' \
160
160
  ' otherwise use `default`'
161
161
  end
162
162
  end
@@ -18,7 +18,7 @@ module Datadog
18
18
  module ClassMethods
19
19
  def options
20
20
  # Allows for class inheritance of option definitions
21
- @options ||= superclass <= Options ? superclass.options.dup : {}
21
+ @options ||= (superclass <= Options) ? superclass.options.dup : {}
22
22
  end
23
23
 
24
24
  protected
@@ -18,7 +18,7 @@ module Datadog
18
18
  module Configuration
19
19
  # Global configuration settings for the Datadog library.
20
20
  # @public_api
21
- # rubocop:disable Metrics/BlockLength
21
+ # standard:disable Metrics/BlockLength
22
22
  class Settings
23
23
  include Base
24
24
 
@@ -123,7 +123,7 @@ module Datadog
123
123
  # @return [Boolean]
124
124
  option :debug do |o|
125
125
  o.env [Datadog::Core::Configuration::Ext::Diagnostics::ENV_DEBUG_ENABLED,
126
- Datadog::Core::Configuration::Ext::Diagnostics::ENV_OTEL_LOG_LEVEL]
126
+ Datadog::Core::Configuration::Ext::Diagnostics::ENV_OTEL_LOG_LEVEL]
127
127
  o.default false
128
128
  o.type :bool
129
129
  o.env_parser do |value|
@@ -137,7 +137,7 @@ module Datadog
137
137
  o.after_set do |enabled|
138
138
  # Enable rich debug print statements.
139
139
  # We do not need to unnecessarily load 'pp' unless in debugging mode.
140
- require 'pp' if enabled
140
+ require 'pp' if enabled # standard:disable Lint/RedundantRequireStatement
141
141
  end
142
142
  end
143
143
 
@@ -313,7 +313,7 @@ module Datadog
313
313
 
314
314
  # Can be used to enable/disable the collection of heap profiles.
315
315
  #
316
- # This feature is alpha and disabled by default
316
+ # This feature is in preview and disabled by default. Requires Ruby 3.1+.
317
317
  #
318
318
  # @warn To enable heap profiling you are required to also enable allocation profiling.
319
319
  #
@@ -326,12 +326,12 @@ module Datadog
326
326
 
327
327
  # Can be used to enable/disable the collection of heap size profiles.
328
328
  #
329
- # This feature is alpha and enabled by default when heap profiling is enabled.
329
+ # This feature is in preview and by default is enabled whenever heap profiling is enabled.
330
330
  #
331
- # @warn To enable heap size profiling you are required to also enable allocation and heap profiling.
331
+ # @warn Heap size profiling depends on allocation and heap profiling, so they must be enabled as well.
332
332
  #
333
- # @default `DD_PROFILING_EXPERIMENTAL_HEAP_SIZE_ENABLED` environment variable as a boolean, otherwise
334
- # whatever the value of DD_PROFILING_EXPERIMENTAL_HEAP_ENABLED is.
333
+ # @default `DD_PROFILING_EXPERIMENTAL_HEAP_SIZE_ENABLED` environment variable as a boolean, otherwise it
334
+ # follows the value of `experimental_heap_enabled`.
335
335
  option :experimental_heap_size_enabled do |o|
336
336
  o.type :bool
337
337
  o.env 'DD_PROFILING_EXPERIMENTAL_HEAP_SIZE_ENABLED'
@@ -341,17 +341,19 @@ module Datadog
341
341
  # Can be used to configure the heap sampling rate: a heap sample will be collected for every x allocation
342
342
  # samples.
343
343
  #
344
- # The lower the value, the more accuracy in heap tracking but the bigger the overhead. In particular, a
345
- # value of 1 will track ALL allocations samples for heap profiles.
344
+ # The higher the value, the less accuracy in heap tracking but the smaller the overhead.
345
+ #
346
+ # If you needed to tweak this, please tell us why on <https://github.com/DataDog/dd-trace-rb/issues/new>,
347
+ # so we can fix it!
346
348
  #
347
349
  # The effective heap sampling rate in terms of allocations (not allocation samples) can be calculated via
348
350
  # effective_heap_sample_rate = allocation_sample_rate * heap_sample_rate.
349
351
  #
350
- # @default `DD_PROFILING_EXPERIMENTAL_HEAP_SAMPLE_RATE` environment variable, otherwise `10`.
352
+ # @default `DD_PROFILING_EXPERIMENTAL_HEAP_SAMPLE_RATE` environment variable, otherwise `1`.
351
353
  option :experimental_heap_sample_rate do |o|
352
354
  o.type :int
353
355
  o.env 'DD_PROFILING_EXPERIMENTAL_HEAP_SAMPLE_RATE'
354
- o.default 10
356
+ o.default 1
355
357
  end
356
358
 
357
359
  # Can be used to disable checking which version of `libmysqlclient` is being used by the `mysql2` gem.
@@ -454,7 +456,7 @@ module Datadog
454
456
  o.after_set do |_, _, precedence|
455
457
  unless precedence == Datadog::Core::Configuration::Option::Precedence::DEFAULT
456
458
  Core.log_deprecation(key: :experimental_crash_tracking_enabled) do
457
- 'The profiling.advanced.experimental_crash_tracking_enabled setting has been deprecated for removal '\
459
+ 'The profiling.advanced.experimental_crash_tracking_enabled setting has been deprecated for removal ' \
458
460
  'and no longer does anything. Please remove it from your Datadog.configure block.'
459
461
  end
460
462
  end
@@ -542,6 +544,16 @@ module Datadog
542
544
  o.env 'DD_PROFILING_HEAP_CLEAN_AFTER_GC_ENABLED'
543
545
  o.default true
544
546
  end
547
+
548
+ # Controls if the profiler should use native filenames for frames in stack traces for functions implemented using
549
+ # native code. Setting to `false` will make the profiler fall back to default Ruby stack trace behavior (only show .rb files).
550
+ #
551
+ # @default true
552
+ option :native_filenames_enabled do |o|
553
+ o.type :bool
554
+ o.env 'DD_PROFILING_NATIVE_FILENAMES_ENABLED'
555
+ o.default true
556
+ end
545
557
  end
546
558
 
547
559
  # @public_api
@@ -572,7 +584,7 @@ module Datadog
572
584
 
573
585
  option :experimental_runtime_id_enabled do |o|
574
586
  o.type :bool
575
- o.env 'DD_TRACE_EXPERIMENTAL_RUNTIME_ID_ENABLED'
587
+ o.env ['DD_TRACE_EXPERIMENTAL_RUNTIME_ID_ENABLED', 'DD_RUNTIME_METRICS_RUNTIME_ID_ENABLED']
576
588
  o.default false
577
589
  end
578
590
 
@@ -641,11 +653,11 @@ module Datadog
641
653
  val ||= ''
642
654
  # maps OpenTelemetry semantic attributes to Datadog tags
643
655
  key = case key.downcase
644
- when 'deployment.environment' then 'env'
645
- when 'service.version' then 'version'
646
- when 'service.name' then 'service'
647
- else key
648
- end
656
+ when 'deployment.environment' then 'env'
657
+ when 'service.version' then 'version'
658
+ when 'service.name' then 'service'
659
+ else key
660
+ end
649
661
  result[key] = val unless key.empty?
650
662
  end
651
663
  end
@@ -995,7 +1007,7 @@ module Datadog
995
1007
  # Keep this extension here for now to keep things working.
996
1008
  extend Datadog::Tracing::Configuration::Settings
997
1009
  end
998
- # rubocop:enable Metrics/BlockLength
1010
+ # standard:enable Metrics/BlockLength
999
1011
  end
1000
1012
  end
1001
1013
  end
@@ -14,8 +14,7 @@ module Datadog
14
14
  end
15
15
 
16
16
  def self.configuration
17
- # @configuration ||= StableConfig.extract_configuration # TODO: After libdatadog 17.1 release, uncomment this line
18
- @configuration ||= {} # TODO: After libdatadog 17.1 release, delete this line
17
+ @configuration ||= StableConfig.extract_configuration
19
18
  end
20
19
  end
21
20
  end
@@ -235,16 +235,14 @@ module Datadog
235
235
  end
236
236
 
237
237
  COMPONENTS_WRITE_LOCK.synchronize do
238
- begin
239
- yield write_components
240
- rescue ThreadError => e
241
- logger_without_components.error(
242
- 'Detected deadlock during datadog initialization. ' \
243
- 'Please report this at https://github.com/datadog/dd-trace-rb/blob/master/CONTRIBUTING.md#found-a-bug' \
244
- "\n\tSource:\n\t#{Array(e.backtrace).join("\n\t")}"
245
- )
246
- nil
247
- end
238
+ yield write_components
239
+ rescue ThreadError => e
240
+ logger_without_components.error(
241
+ 'Detected deadlock during datadog initialization. ' \
242
+ 'Please report this at https://github.com/datadog/dd-trace-rb/blob/master/CONTRIBUTING.md#found-a-bug' \
243
+ "\n\tSource:\n\t#{Array(e.backtrace).join("\n\t")}"
244
+ )
245
+ nil
248
246
  end
249
247
  end
250
248
 
@@ -267,12 +265,14 @@ module Datadog
267
265
  components = Components.new(settings)
268
266
 
269
267
  # Carry over state from existing components to the new ones.
270
- # Currently, if we already started the remote component (which
271
- # happens after a request goes through installed Rack middleware),
272
- # we will start the new remote component as well.
273
- old_state = {
274
- remote_started: old.remote&.started?,
275
- }
268
+ # Currently:
269
+ # 1. If we already started the remote component (which
270
+ # happens after a request goes through installed Rack middleware),
271
+ # we will start the new remote component as well.
272
+ # 2. If telemetry has been enabled and is enabled in the new
273
+ # component tree, we send AppConfigurationChange event instead
274
+ # of AppStarted event.
275
+ old_state = old.state
276
276
 
277
277
  old.shutdown!(components)
278
278
  components.startup!(settings, old_state: old_state)
@@ -92,7 +92,8 @@ module Datadog
92
92
  path_to_crashtracking_receiver_binary: path_to_crashtracking_receiver_binary,
93
93
  ld_library_path: ld_library_path,
94
94
  tags_as_array: tags.to_a,
95
- upload_timeout_seconds: 1
95
+ # @ivoanjo: On my machine this needs to be > 5 seconds, and seems to work with 10; the extra 15 is extra margin
96
+ upload_timeout_seconds: 15,
96
97
  )
97
98
  logger.debug("Crash tracking action: #{action} successful")
98
99
  rescue => e
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../tag_builder'
3
4
  require_relative '../utils'
4
- require_relative '../environment/socket'
5
- require_relative '../environment/identity'
6
- require_relative '../environment/git'
7
5
 
8
6
  module Datadog
9
7
  module Core
@@ -11,27 +9,11 @@ module Datadog
11
9
  # This module builds a hash of tags
12
10
  module TagBuilder
13
11
  def self.call(settings)
14
- hash = {
15
- 'host' => Environment::Socket.hostname,
16
- 'process_id' => Process.pid.to_s,
17
- 'runtime_engine' => Environment::Identity.lang_engine,
18
- 'runtime-id' => Environment::Identity.id,
19
- 'runtime_platform' => Environment::Identity.lang_platform,
20
- 'runtime_version' => Environment::Identity.lang_version,
21
- 'env' => settings.env,
22
- 'service' => settings.service,
23
- 'version' => settings.version,
24
- 'git.repository_url' => Environment::Git.git_repository_url,
25
- 'git.commit.sha' => Environment::Git.git_commit_sha,
12
+ hash = Core::TagBuilder.tags(settings).merge(
26
13
  'is_crash' => 'true',
27
- 'language' => 'ruby',
28
- 'library_version' => Core::Environment::Identity.gem_datadog_version,
29
- }.compact
14
+ )
30
15
 
31
- # Make sure everything is an utf-8 string, to avoid encoding issues in downstream
32
- settings.tags.merge(hash).each_with_object({}) do |(key, value), h|
33
- h[Utils.utf8_encode(key)] = Utils.utf8_encode(value)
34
- end
16
+ Utils.encode_tags(hash)
35
17
  end
36
18
  end
37
19
  end
@@ -54,7 +54,7 @@ module Datadog
54
54
  end
55
55
 
56
56
  def join(encoded_data)
57
- "[#{encoded_data.join(',')}]"
57
+ "[#{encoded_data.join(",")}]"
58
58
  end
59
59
  end
60
60
 
@@ -23,20 +23,18 @@ module Datadog
23
23
 
24
24
  def descriptors(process = 'self')
25
25
  [].tap do |descriptors|
26
- begin
27
- filepath = "/proc/#{process}/cgroup"
28
-
29
- if File.exist?(filepath)
30
- File.foreach("/proc/#{process}/cgroup") do |line|
31
- line = line.strip
32
- descriptors << parse(line) unless line.empty?
33
- end
26
+ filepath = "/proc/#{process}/cgroup"
27
+
28
+ if File.exist?(filepath)
29
+ File.foreach("/proc/#{process}/cgroup") do |line|
30
+ line = line.strip
31
+ descriptors << parse(line) unless line.empty?
34
32
  end
35
- rescue StandardError => e
36
- Datadog.logger.error(
37
- "Error while parsing cgroup. Cause: #{e.class.name} #{e.message} Location: #{Array(e.backtrace).first}"
38
- )
39
33
  end
34
+ rescue => e
35
+ Datadog.logger.error(
36
+ "Error while parsing cgroup. Cause: #{e.class.name} #{e.message} Location: #{Array(e.backtrace).first}"
37
+ )
40
38
  end
41
39
  end
42
40
 
@@ -37,52 +37,50 @@ module Datadog
37
37
 
38
38
  def descriptor
39
39
  @descriptor ||= Descriptor.new.tap do |descriptor|
40
- begin
41
- Cgroup.descriptors.each do |cgroup_descriptor|
42
- # Parse container data from cgroup descriptor
43
- path = cgroup_descriptor.path
44
- next if path.nil?
45
-
46
- # Split path into parts
47
- parts = path.split('/')
48
- parts.shift # Remove leading empty part
49
-
50
- # Read info from path
51
- next if parts.empty?
52
-
53
- platform = parts[0][PLATFORM_REGEX, :platform]
54
- container_id, task_uid = nil
55
-
56
- case parts.length
57
- when 0..1
58
- next
59
- when 2
60
- container_id = parts[-1][CONTAINER_REGEX, :container] \
61
- || parts[-1][FARGATE_14_CONTAINER_REGEX, :container]
40
+ Cgroup.descriptors.each do |cgroup_descriptor|
41
+ # Parse container data from cgroup descriptor
42
+ path = cgroup_descriptor.path
43
+ next if path.nil?
44
+
45
+ # Split path into parts
46
+ parts = path.split('/')
47
+ parts.shift # Remove leading empty part
48
+
49
+ # Read info from path
50
+ next if parts.empty?
51
+
52
+ platform = parts[0][PLATFORM_REGEX, :platform]
53
+ container_id, task_uid = nil
54
+
55
+ case parts.length
56
+ when 0..1
57
+ next
58
+ when 2
59
+ container_id = parts[-1][CONTAINER_REGEX, :container] \
60
+ || parts[-1][FARGATE_14_CONTAINER_REGEX, :container]
61
+ else
62
+ if (container_id = parts[-1][CONTAINER_REGEX, :container])
63
+ task_uid = parts[-2][POD_REGEX, :pod] || parts[1][POD_REGEX, :pod]
62
64
  else
63
- if (container_id = parts[-1][CONTAINER_REGEX, :container])
64
- task_uid = parts[-2][POD_REGEX, :pod] || parts[1][POD_REGEX, :pod]
65
- else
66
- container_id = parts[-1][FARGATE_14_CONTAINER_REGEX, :container]
67
- end
65
+ container_id = parts[-1][FARGATE_14_CONTAINER_REGEX, :container]
68
66
  end
67
+ end
69
68
 
70
- # If container ID wasn't found, ignore.
71
- # Path might describe a non-container environment.
72
- next if container_id.nil?
69
+ # If container ID wasn't found, ignore.
70
+ # Path might describe a non-container environment.
71
+ next if container_id.nil?
73
72
 
74
- descriptor.platform = platform
75
- descriptor.container_id = container_id
76
- descriptor.task_uid = task_uid
73
+ descriptor.platform = platform
74
+ descriptor.container_id = container_id
75
+ descriptor.task_uid = task_uid
77
76
 
78
- break
79
- end
80
- rescue StandardError => e
81
- Datadog.logger.error(
82
- "Error while parsing container info. Cause: #{e.class.name} #{e.message} " \
83
- "Location: #{Array(e.backtrace).first}"
84
- )
77
+ break
85
78
  end
79
+ rescue => e
80
+ Datadog.logger.error(
81
+ "Error while parsing container info. Cause: #{e.class.name} #{e.message} " \
82
+ "Location: #{Array(e.backtrace).first}"
83
+ )
86
84
  end
87
85
  end
88
86
  end
@@ -9,11 +9,11 @@ module Datadog
9
9
  module Ext
10
10
  # e.g for CRuby '3.0.1', for JRuby '9.2.19.0', for TruffleRuby '21.1.0'
11
11
  ENGINE_VERSION = if defined?(RUBY_ENGINE_VERSION)
12
- RUBY_ENGINE_VERSION
13
- else
14
- # CRuby < 2.3 doesn't support RUBY_ENGINE_VERSION
15
- RUBY_VERSION
16
- end
12
+ RUBY_ENGINE_VERSION
13
+ else
14
+ # CRuby < 2.3 doesn't support RUBY_ENGINE_VERSION
15
+ RUBY_VERSION
16
+ end
17
17
 
18
18
  ENV_API_KEY = 'DD_API_KEY'
19
19
  ENV_ENVIRONMENT = 'DD_ENV'
@@ -26,7 +26,7 @@ module Datadog
26
26
  FALLBACK_SERVICE_NAME =
27
27
  begin
28
28
  File.basename($PROGRAM_NAME, '.*')
29
- rescue StandardError
29
+ rescue
30
30
  'ruby'
31
31
  end.freeze
32
32
 
@@ -67,12 +67,12 @@ module Datadog
67
67
 
68
68
  rest.split('.').tap do |segments|
69
69
  if segments.length >= 4
70
- pre = "-#{segments.shift}"
71
- build = "+#{segments.join('.')}"
70
+ pre = "-#{segments.shift}"
71
+ build = "+#{segments.join(".")}"
72
72
  elsif segments.length == 1
73
73
  pre = "-#{segments.shift}"
74
74
  else
75
- build = "+#{segments.join('.')}"
75
+ build = "+#{segments.join(".")}"
76
76
  end
77
77
  end
78
78
 
@@ -13,18 +13,18 @@ module Datadog
13
13
 
14
14
  # @return [String] ISA of host; `uname -m`
15
15
  def architecture
16
- Identity.lang_version >= '2.2' ? Etc.uname[:machine] : Gem::Platform.local.cpu
16
+ (Identity.lang_version >= '2.2') ? Etc.uname[:machine] : Gem::Platform.local.cpu
17
17
  end
18
18
 
19
19
  # @return [String] name of host; `uname -n`
20
20
  def hostname
21
- Identity.lang_version >= '2.2' ? Etc.uname[:nodename] : nil
21
+ (Identity.lang_version >= '2.2') ? Etc.uname[:nodename] : nil
22
22
  end
23
23
 
24
24
  # System name, normally `Linux` or `Darwin` (but 'Mac OS X' on JRuby);
25
25
  # @return [String] name of kernel; `uname -s`.
26
26
  def kernel_name
27
- Identity.lang_version >= '2.2' ? Etc.uname[:sysname] : Gem::Platform.local.os.capitalize
27
+ (Identity.lang_version >= '2.2') ? Etc.uname[:sysname] : Gem::Platform.local.os.capitalize
28
28
  end
29
29
 
30
30
  # @return [String] kernel release; `uname -r`
@@ -11,12 +11,17 @@ module Datadog
11
11
  class << self
12
12
  def build_from(value)
13
13
  case value
14
- when Error then value
15
- when Array then new(*value)
14
+ # A Ruby {Exception} is the most common parameter type.
16
15
  when Exception then new(value.class, value.message, full_backtrace(value))
17
- when ContainsMessage then new(value.class, value.message)
16
+ # steep:ignore:start
17
+ # Steep doesn't like an array with up to 3 elements to be passed here: it thinks the array is unbounded.
18
+ when Array then new(*value)
19
+ # Steep can not follow the logic inside the lambda, thus it doesn't know `value` responds to `:message`.
20
+ when ->(v) { v.respond_to?(:message) } then new(value.class, value.message)
21
+ # steep:ignore:end
18
22
  when String then new(nil, value)
19
- else BlankError
23
+ when Error then value
24
+ else Error.new # Blank error
20
25
  end
21
26
  end
22
27
 
@@ -34,7 +39,7 @@ module Datadog
34
39
  # but it's around 3x faster in our benchmark test
35
40
  # at `error_spec.rb`.
36
41
  def full_backtrace(ex)
37
- backtrace = String.new
42
+ backtrace = +''
38
43
  backtrace_for(ex, backtrace)
39
44
 
40
45
  # Avoid circular causes
@@ -75,7 +80,7 @@ module Datadog
75
80
  if trace[1]
76
81
  # Ident stack trace for caller lines, to separate
77
82
  # them from the main error lines.
78
- trace[1..-1].each do |line|
83
+ trace[1..-1]&.each do |line|
79
84
  backtrace << "\n\tfrom "
80
85
  backtrace << line
81
86
  end
@@ -92,9 +97,6 @@ module Datadog
92
97
  @message = Utils.utf8_encode(message)
93
98
  @backtrace = Utils.utf8_encode(backtrace)
94
99
  end
95
-
96
- BlankError = Error.new
97
- ContainsMessage = ->(v) { v.respond_to?(:message) }
98
100
  end
99
101
  end
100
102
  end