ddtrace 1.7.0 → 1.9.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 (182) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +100 -1
  3. data/README.md +2 -2
  4. data/ext/ddtrace_profiling_loader/extconf.rb +4 -1
  5. data/ext/ddtrace_profiling_native_extension/NativeExtensionDesign.md +1 -1
  6. data/ext/ddtrace_profiling_native_extension/clock_id_from_pthread.c +3 -2
  7. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.c +24 -50
  8. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.h +1 -1
  9. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +284 -74
  10. data/ext/ddtrace_profiling_native_extension/collectors_dynamic_sampling_rate.c +142 -0
  11. data/ext/ddtrace_profiling_native_extension/collectors_dynamic_sampling_rate.h +14 -0
  12. data/ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.c +241 -0
  13. data/ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.h +3 -0
  14. data/ext/ddtrace_profiling_native_extension/collectors_stack.c +32 -32
  15. data/ext/ddtrace_profiling_native_extension/collectors_stack.h +2 -2
  16. data/ext/ddtrace_profiling_native_extension/extconf.rb +21 -7
  17. data/ext/ddtrace_profiling_native_extension/helpers.h +5 -0
  18. data/ext/ddtrace_profiling_native_extension/http_transport.c +50 -49
  19. data/ext/ddtrace_profiling_native_extension/libdatadog_helpers.h +5 -1
  20. data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +42 -12
  21. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +116 -22
  22. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.h +9 -0
  23. data/ext/ddtrace_profiling_native_extension/profiling.c +205 -0
  24. data/ext/ddtrace_profiling_native_extension/ruby_helpers.c +86 -0
  25. data/ext/ddtrace_profiling_native_extension/ruby_helpers.h +28 -6
  26. data/ext/ddtrace_profiling_native_extension/setup_signal_handler.c +23 -4
  27. data/ext/ddtrace_profiling_native_extension/setup_signal_handler.h +4 -0
  28. data/ext/ddtrace_profiling_native_extension/stack_recorder.c +47 -50
  29. data/ext/ddtrace_profiling_native_extension/stack_recorder.h +4 -4
  30. data/ext/ddtrace_profiling_native_extension/time_helpers.c +17 -0
  31. data/ext/ddtrace_profiling_native_extension/time_helpers.h +10 -0
  32. data/lib/datadog/appsec/assets/waf_rules/recommended.json +75 -8
  33. data/lib/datadog/appsec/assets/waf_rules/risky.json +1 -1
  34. data/lib/datadog/appsec/assets/waf_rules/strict.json +1 -1
  35. data/lib/datadog/appsec/assets.rb +1 -1
  36. data/lib/datadog/appsec/configuration/settings.rb +35 -22
  37. data/lib/datadog/appsec/configuration.rb +4 -2
  38. data/lib/datadog/appsec/contrib/auto_instrument.rb +1 -1
  39. data/lib/datadog/appsec/contrib/configuration/settings.rb +1 -1
  40. data/lib/datadog/appsec/contrib/integration.rb +1 -1
  41. data/lib/datadog/appsec/contrib/patcher.rb +1 -1
  42. data/lib/datadog/appsec/contrib/rack/configuration/settings.rb +1 -1
  43. data/lib/datadog/appsec/contrib/rack/ext.rb +1 -1
  44. data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +1 -1
  45. data/lib/datadog/appsec/contrib/rack/reactive/request.rb +1 -1
  46. data/lib/datadog/appsec/contrib/rack/reactive/request_body.rb +1 -1
  47. data/lib/datadog/appsec/contrib/rack/reactive/response.rb +1 -1
  48. data/lib/datadog/appsec/contrib/rack/request.rb +1 -1
  49. data/lib/datadog/appsec/contrib/rack/response.rb +1 -1
  50. data/lib/datadog/appsec/contrib/rails/configuration/settings.rb +1 -1
  51. data/lib/datadog/appsec/contrib/rails/ext.rb +1 -1
  52. data/lib/datadog/appsec/contrib/rails/framework.rb +1 -1
  53. data/lib/datadog/appsec/contrib/rails/gateway/watcher.rb +1 -1
  54. data/lib/datadog/appsec/contrib/rails/reactive/action.rb +1 -1
  55. data/lib/datadog/appsec/contrib/rails/request.rb +1 -1
  56. data/lib/datadog/appsec/contrib/rails/request_middleware.rb +1 -1
  57. data/lib/datadog/appsec/contrib/sinatra/configuration/settings.rb +1 -1
  58. data/lib/datadog/appsec/contrib/sinatra/ext.rb +1 -1
  59. data/lib/datadog/appsec/contrib/sinatra/framework.rb +1 -1
  60. data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +1 -1
  61. data/lib/datadog/appsec/contrib/sinatra/reactive/routed.rb +1 -1
  62. data/lib/datadog/appsec/contrib/sinatra/request_middleware.rb +1 -1
  63. data/lib/datadog/appsec/event.rb +1 -1
  64. data/lib/datadog/appsec/extensions.rb +36 -26
  65. data/lib/datadog/appsec/instrumentation/gateway.rb +3 -3
  66. data/lib/datadog/appsec/processor.rb +15 -19
  67. data/lib/datadog/appsec/rate_limiter.rb +1 -1
  68. data/lib/datadog/appsec/reactive/address_hash.rb +1 -1
  69. data/lib/datadog/appsec/reactive/engine.rb +1 -1
  70. data/lib/datadog/appsec/reactive/operation.rb +2 -2
  71. data/lib/datadog/appsec/reactive/subscriber.rb +1 -1
  72. data/lib/datadog/appsec/response.rb +18 -9
  73. data/lib/datadog/appsec/utils/http/media_range.rb +201 -0
  74. data/lib/datadog/appsec/utils/http/media_type.rb +87 -0
  75. data/lib/datadog/appsec/utils/http.rb +9 -0
  76. data/lib/datadog/appsec/utils.rb +7 -0
  77. data/lib/datadog/appsec.rb +1 -1
  78. data/lib/datadog/ci/ext/environment.rb +57 -13
  79. data/lib/datadog/core/configuration/agent_settings_resolver.rb +2 -2
  80. data/lib/datadog/core/configuration/base.rb +3 -0
  81. data/lib/datadog/core/configuration/components.rb +27 -6
  82. data/lib/datadog/core/configuration/ext.rb +26 -0
  83. data/lib/datadog/core/configuration/option_definition.rb +11 -2
  84. data/lib/datadog/core/configuration/settings.rb +16 -341
  85. data/lib/datadog/core/diagnostics/environment_logger.rb +4 -3
  86. data/lib/datadog/core/diagnostics/health.rb +4 -22
  87. data/lib/datadog/core/environment/variable_helpers.rb +58 -10
  88. data/lib/datadog/core/metrics/client.rb +3 -2
  89. data/lib/datadog/core/metrics/ext.rb +0 -2
  90. data/lib/datadog/core/telemetry/collector.rb +1 -0
  91. data/lib/datadog/core/utils.rb +0 -21
  92. data/lib/datadog/core.rb +21 -1
  93. data/lib/datadog/kit/appsec/events.rb +75 -0
  94. data/lib/datadog/kit/enable_core_dumps.rb +1 -0
  95. data/lib/datadog/kit/identity.rb +8 -7
  96. data/lib/datadog/opentelemetry/api/context.rb +187 -0
  97. data/lib/datadog/opentelemetry/api/trace/span.rb +15 -0
  98. data/lib/datadog/opentelemetry/sdk/configurator.rb +38 -0
  99. data/lib/datadog/opentelemetry/sdk/id_generator.rb +27 -0
  100. data/lib/datadog/opentelemetry/sdk/propagator.rb +91 -0
  101. data/lib/datadog/opentelemetry/sdk/span_processor.rb +92 -0
  102. data/lib/datadog/opentelemetry.rb +48 -0
  103. data/lib/datadog/opentracer/distributed_headers.rb +2 -2
  104. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +16 -5
  105. data/lib/datadog/profiling/collectors/dynamic_sampling_rate.rb +14 -0
  106. data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +68 -0
  107. data/lib/datadog/profiling/stack_recorder.rb +14 -0
  108. data/lib/datadog/profiling.rb +2 -0
  109. data/lib/datadog/tracing/configuration/ext.rb +33 -4
  110. data/lib/datadog/tracing/configuration/settings.rb +433 -0
  111. data/lib/datadog/tracing/contrib/aws/configuration/settings.rb +4 -1
  112. data/lib/datadog/tracing/contrib/aws/ext.rb +1 -0
  113. data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +4 -1
  114. data/lib/datadog/tracing/contrib/dalli/ext.rb +1 -0
  115. data/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +5 -1
  116. data/lib/datadog/tracing/contrib/elasticsearch/ext.rb +1 -0
  117. data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +6 -1
  118. data/lib/datadog/tracing/contrib/ethon/ext.rb +1 -0
  119. data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +5 -1
  120. data/lib/datadog/tracing/contrib/excon/ext.rb +1 -0
  121. data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +5 -1
  122. data/lib/datadog/tracing/contrib/faraday/ext.rb +1 -0
  123. data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +6 -1
  124. data/lib/datadog/tracing/contrib/grpc/distributed/propagation.rb +9 -4
  125. data/lib/datadog/tracing/contrib/grpc/ext.rb +1 -0
  126. data/lib/datadog/tracing/contrib/http/configuration/settings.rb +11 -1
  127. data/lib/datadog/tracing/contrib/http/distributed/fetcher.rb +10 -3
  128. data/lib/datadog/tracing/contrib/http/distributed/propagation.rb +9 -4
  129. data/lib/datadog/tracing/contrib/http/ext.rb +2 -0
  130. data/lib/datadog/tracing/contrib/http/instrumentation.rb +3 -6
  131. data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +11 -1
  132. data/lib/datadog/tracing/contrib/httpclient/ext.rb +2 -0
  133. data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +3 -4
  134. data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +11 -1
  135. data/lib/datadog/tracing/contrib/httprb/ext.rb +2 -0
  136. data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +3 -4
  137. data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +5 -1
  138. data/lib/datadog/tracing/contrib/mongodb/ext.rb +1 -0
  139. data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +4 -1
  140. data/lib/datadog/tracing/contrib/mysql2/ext.rb +1 -0
  141. data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +2 -2
  142. data/lib/datadog/tracing/contrib/patcher.rb +3 -2
  143. data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +4 -1
  144. data/lib/datadog/tracing/contrib/pg/ext.rb +1 -0
  145. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +56 -33
  146. data/lib/datadog/tracing/contrib/presto/configuration/settings.rb +4 -1
  147. data/lib/datadog/tracing/contrib/presto/ext.rb +1 -0
  148. data/lib/datadog/tracing/contrib/propagation/sql_comment/ext.rb +1 -0
  149. data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +10 -12
  150. data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +4 -1
  151. data/lib/datadog/tracing/contrib/redis/ext.rb +1 -0
  152. data/lib/datadog/tracing/contrib/redis/instrumentation.rb +30 -23
  153. data/lib/datadog/tracing/contrib/redis/integration.rb +34 -2
  154. data/lib/datadog/tracing/contrib/redis/patcher.rb +18 -14
  155. data/lib/datadog/tracing/contrib/redis/quantize.rb +12 -9
  156. data/lib/datadog/tracing/contrib/redis/tags.rb +4 -6
  157. data/lib/datadog/tracing/contrib/redis/trace_middleware.rb +72 -0
  158. data/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +6 -1
  159. data/lib/datadog/tracing/contrib/rest_client/ext.rb +1 -0
  160. data/lib/datadog/tracing/contrib/stripe/configuration/settings.rb +33 -0
  161. data/lib/datadog/tracing/contrib/stripe/ext.rb +26 -0
  162. data/lib/datadog/tracing/contrib/stripe/integration.rb +43 -0
  163. data/lib/datadog/tracing/contrib/stripe/patcher.rb +29 -0
  164. data/lib/datadog/tracing/contrib/stripe/request.rb +67 -0
  165. data/lib/datadog/tracing/contrib.rb +1 -0
  166. data/lib/datadog/{core → tracing}/diagnostics/ext.rb +1 -6
  167. data/lib/datadog/tracing/diagnostics/health.rb +40 -0
  168. data/lib/datadog/tracing/distributed/{b3.rb → b3_multi.rb} +2 -2
  169. data/lib/datadog/tracing/distributed/helpers.rb +2 -1
  170. data/lib/datadog/tracing/distributed/none.rb +19 -0
  171. data/lib/datadog/tracing/distributed/trace_context.rb +378 -0
  172. data/lib/datadog/tracing/metadata/ext.rb +1 -1
  173. data/lib/datadog/tracing/metadata/tagging.rb +6 -0
  174. data/lib/datadog/tracing/sampling/priority_sampler.rb +11 -0
  175. data/lib/datadog/tracing/sampling/rate_sampler.rb +3 -3
  176. data/lib/datadog/tracing/span.rb +3 -19
  177. data/lib/datadog/tracing/span_operation.rb +5 -4
  178. data/lib/datadog/tracing/trace_digest.rb +85 -2
  179. data/lib/datadog/tracing/trace_operation.rb +13 -4
  180. data/lib/datadog/tracing/utils.rb +50 -0
  181. data/lib/ddtrace/version.rb +1 -1
  182. metadata +41 -9
@@ -3,19 +3,20 @@
3
3
  require 'logger'
4
4
 
5
5
  require_relative 'base'
6
+ require_relative 'ext'
6
7
  require_relative '../environment/ext'
7
8
  require_relative '../runtime/ext'
8
9
  require_relative '../telemetry/ext'
9
10
  require_relative '../../profiling/ext'
10
- require_relative '../../tracing/configuration/ext'
11
+
12
+ require_relative '../../tracing/configuration/settings'
11
13
 
12
14
  module Datadog
13
15
  module Core
14
16
  module Configuration
15
- # Global configuration settings for the trace library.
17
+ # Global configuration settings for the Datadog library.
16
18
  # @public_api
17
19
  # rubocop:disable Metrics/BlockLength
18
- # rubocop:disable Layout/LineLength
19
20
  class Settings
20
21
  include Base
21
22
 
@@ -99,7 +100,7 @@ module Datadog
99
100
  # @default `DD_TRACE_DEBUG` environment variable, otherwise `false`
100
101
  # @return [Boolean]
101
102
  option :debug do |o|
102
- o.default { env_to_bool(Datadog::Core::Diagnostics::Ext::DD_TRACE_DEBUG, false) }
103
+ o.default { env_to_bool(Datadog::Core::Configuration::Ext::Diagnostics::ENV_DEBUG_ENABLED, false) }
103
104
  o.lazy
104
105
  o.on_set do |enabled|
105
106
  # Enable rich debug print statements.
@@ -110,7 +111,6 @@ module Datadog
110
111
 
111
112
  # Internal {Datadog::Statsd} metrics collection.
112
113
  #
113
- # The list of metrics collected can be found in {Datadog::Core::Diagnostics::Ext::Health::Metrics}.
114
114
  # @public_api
115
115
  settings :health_metrics do
116
116
  # Enable health metrics collection.
@@ -118,7 +118,7 @@ module Datadog
118
118
  # @default `DD_HEALTH_METRICS_ENABLED` environment variable, otherwise `false`
119
119
  # @return [Boolean]
120
120
  option :enabled do |o|
121
- o.default { env_to_bool(Datadog::Core::Diagnostics::Ext::Health::Metrics::ENV_ENABLED, false) }
121
+ o.default { env_to_bool(Datadog::Core::Configuration::Ext::Diagnostics::ENV_HEALTH_METRICS_ENABLED, false) }
122
122
  o.lazy
123
123
  end
124
124
 
@@ -144,7 +144,7 @@ module Datadog
144
144
  # @return [Boolean,nil]
145
145
  option :enabled do |o|
146
146
  # Defaults to nil as we want to know when the default value is being used
147
- o.default { env_to_bool(Datadog::Core::Diagnostics::Ext::DD_TRACE_STARTUP_LOGS, nil) }
147
+ o.default { env_to_bool(Datadog::Core::Configuration::Ext::Diagnostics::ENV_STARTUP_LOGS_ENABLED, nil) }
148
148
  o.lazy
149
149
  end
150
150
  end
@@ -210,6 +210,8 @@ module Datadog
210
210
 
211
211
  # Controls the maximum number of frames for each thread sampled. Can be tuned to avoid omitted frames in the
212
212
  # produced profiles. Increasing this may increase the overhead of profiling.
213
+ #
214
+ # @default `DD_PROFILING_MAX_FRAMES` environment variable, otherwise 400
213
215
  option :max_frames do |o|
214
216
  o.default { env_to_int(Profiling::Ext::ENV_MAX_FRAMES, 400) }
215
217
  o.lazy
@@ -269,7 +271,9 @@ module Datadog
269
271
  # If you use Ruby 3.x and your application does not use Ractors (or if your Ruby has been patched), the
270
272
  # feature is fully safe to enable and this toggle can be used to do so.
271
273
  #
272
- # We expect that once the above issue is patched, we'll automatically re-enable the feature on fixed Ruby
274
+ # Furthermore, currently this feature can add a lot of overhead for GC-heavy workloads.
275
+ #
276
+ # We expect the once the above issues are overcome, we'll automatically enable the feature on fixed Ruby
273
277
  # versions.
274
278
  option :force_enable_gc_profiling do |o|
275
279
  o.default { env_to_bool('DD_PROFILING_FORCE_ENABLE_GC', false) }
@@ -408,338 +412,6 @@ module Datadog
408
412
  end
409
413
  end
410
414
 
411
- # Tracer specific configurations.
412
- # @public_api
413
- settings :tracing do
414
- # Legacy [App Analytics](https://docs.datadoghq.com/tracing/legacy_app_analytics/) configuration.
415
- #
416
- # @configure_with {Datadog::Tracing}
417
- # @deprecated Use [Trace Retention and Ingestion](https://docs.datadoghq.com/tracing/trace_retention_and_ingestion/)
418
- # controls.
419
- # @public_api
420
- settings :analytics do
421
- # @default `DD_TRACE_ANALYTICS_ENABLED` environment variable, otherwise `nil`
422
- # @return [Boolean,nil]
423
- option :enabled do |o|
424
- o.default { env_to_bool(Tracing::Configuration::Ext::Analytics::ENV_TRACE_ANALYTICS_ENABLED, nil) }
425
- o.lazy
426
- end
427
- end
428
-
429
- # [Distributed Tracing](https://docs.datadoghq.com/tracing/setup_overview/setup/ruby/#distributed-tracing) propagation
430
- # style configuration.
431
- #
432
- # The supported formats are:
433
- # * `Datadog`: Datadog propagation format, described by [Distributed Tracing](https://docs.datadoghq.com/tracing/setup_overview/setup/ruby/#distributed-tracing).
434
- # * `B3`: B3 Propagation using multiple headers, described by [openzipkin/b3-propagation](https://github.com/openzipkin/b3-propagation#multiple-headers).
435
- # * `B3 single header`: B3 Propagation using a single header, described by [openzipkin/b3-propagation](https://github.com/openzipkin/b3-propagation#single-header).
436
- #
437
- # @public_api
438
- settings :distributed_tracing do
439
- # An ordered list of what data propagation styles the tracer will use to extract distributed tracing propagation
440
- # data from incoming requests and messages.
441
- #
442
- # The tracer will try to find distributed headers in the order they are present in the list provided to this option.
443
- # The first format to have valid data present will be used.
444
- #
445
- # @default `DD_PROPAGATION_STYLE_EXTRACT` environment variable (comma-separated list),
446
- # otherwise `['Datadog','B3','B3 single header']`.
447
- # @return [Array<String>]
448
- option :propagation_extract_style do |o|
449
- o.default do
450
- # Look for all headers by default
451
- env_to_list(
452
- Tracing::Configuration::Ext::Distributed::ENV_PROPAGATION_STYLE_EXTRACT,
453
- [
454
- Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_DATADOG,
455
- Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3,
456
- Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_SINGLE_HEADER
457
- ],
458
- comma_separated_only: true
459
- )
460
- end
461
-
462
- o.lazy
463
- end
464
-
465
- # The data propagation styles the tracer will use to inject distributed tracing propagation
466
- # data into outgoing requests and messages.
467
- #
468
- # The tracer will inject data from all styles specified in this option.
469
- #
470
- # @default `DD_PROPAGATION_STYLE_INJECT` environment variable (comma-separated list), otherwise `['Datadog']`.
471
- # @return [Array<String>]
472
- option :propagation_inject_style do |o|
473
- o.default do
474
- env_to_list(
475
- Tracing::Configuration::Ext::Distributed::ENV_PROPAGATION_STYLE_INJECT,
476
- [Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_DATADOG],
477
- comma_separated_only: true # Only inject Datadog headers by default
478
- )
479
- end
480
-
481
- o.lazy
482
- end
483
- end
484
-
485
- # Enable trace collection and span generation.
486
- #
487
- # You can use this option to disable tracing without having to
488
- # remove the library as a whole.
489
- #
490
- # @default `DD_TRACE_ENABLED` environment variable, otherwise `true`
491
- # @return [Boolean]
492
- option :enabled do |o|
493
- o.default { env_to_bool(Datadog::Core::Diagnostics::Ext::DD_TRACE_ENABLED, true) }
494
- o.lazy
495
- end
496
-
497
- # A custom tracer instance.
498
- #
499
- # It must respect the contract of {Datadog::Tracing::Tracer}.
500
- # It's recommended to delegate methods to {Datadog::Tracing::Tracer} to ease the implementation
501
- # of a custom tracer.
502
- #
503
- # This option will not return the live tracer instance: it only holds a custom tracing instance, if any.
504
- #
505
- # For internal use only.
506
- #
507
- # @default `nil`
508
- # @return [Object,nil]
509
- option :instance
510
-
511
- # Automatic correlation between tracing and logging.
512
- # @see https://docs.datadoghq.com/tracing/setup_overview/setup/ruby/#trace-correlation
513
- # @return [Boolean]
514
- option :log_injection do |o|
515
- o.default { env_to_bool(Tracing::Configuration::Ext::Correlation::ENV_LOGS_INJECTION_ENABLED, true) }
516
- o.lazy
517
- end
518
-
519
- # Configures an alternative trace transport behavior, where
520
- # traces can be sent to the agent and backend before all spans
521
- # have finished.
522
- #
523
- # This is useful for long-running jobs or very large traces.
524
- #
525
- # The trace flame graph will display the partial trace as it is received and constantly
526
- # update with new spans as they are flushed.
527
- # @public_api
528
- settings :partial_flush do
529
- # Enable partial trace flushing.
530
- #
531
- # @default `false`
532
- # @return [Boolean]
533
- option :enabled, default: false
534
-
535
- # Minimum number of finished spans required in a single unfinished trace before
536
- # the tracer will consider that trace for partial flushing.
537
- #
538
- # This option helps preserve a minimum amount of batching in the
539
- # flushing process, reducing network overhead.
540
- #
541
- # This threshold only applies to unfinished traces. Traces that have finished
542
- # are always flushed immediately.
543
- #
544
- # @default 500
545
- # @return [Integer]
546
- option :min_spans_threshold, default: 500
547
- end
548
-
549
- # Enables {https://docs.datadoghq.com/tracing/trace_retention_and_ingestion/#datadog-intelligent-retention-filter
550
- # Datadog intelligent retention filter}.
551
- # @default `true`
552
- # @return [Boolean,nil]
553
- option :priority_sampling
554
-
555
- option :report_hostname do |o|
556
- o.default { env_to_bool(Tracing::Configuration::Ext::NET::ENV_REPORT_HOSTNAME, false) }
557
- o.lazy
558
- end
559
-
560
- # A custom sampler instance.
561
- # The object must respect the {Datadog::Tracing::Sampling::Sampler} interface.
562
- # @default `nil`
563
- # @return [Object,nil]
564
- option :sampler
565
-
566
- # Client-side sampling configuration.
567
- # @see https://docs.datadoghq.com/tracing/trace_ingestion/mechanisms/
568
- # @public_api
569
- settings :sampling do
570
- # Default sampling rate for the tracer.
571
- #
572
- # If `nil`, the trace uses an automatic sampling strategy that tries to ensure
573
- # the collection of traces that are considered important (e.g. traces with an error, traces
574
- # for resources not seen recently).
575
- #
576
- # @default `DD_TRACE_SAMPLE_RATE` environment variable, otherwise `nil`.
577
- # @return [Float,nil]
578
- option :default_rate do |o|
579
- o.default { env_to_float(Tracing::Configuration::Ext::Sampling::ENV_SAMPLE_RATE, nil) }
580
- o.lazy
581
- end
582
-
583
- # Rate limit for number of spans per second.
584
- #
585
- # Spans created above the limit will contribute to service metrics, but won't
586
- # have their payload stored.
587
- #
588
- # @default `DD_TRACE_RATE_LIMIT` environment variable, otherwise 100.
589
- # @return [Numeric,nil]
590
- option :rate_limit do |o|
591
- o.default { env_to_float(Tracing::Configuration::Ext::Sampling::ENV_RATE_LIMIT, 100) }
592
- o.lazy
593
- end
594
-
595
- # Single span sampling rules.
596
- # These rules allow a span to be kept when its encompassing trace is dropped.
597
- #
598
- # The syntax for single span sampling rules can be found here:
599
- # TODO: <Single Span Sampling documentation URL here>
600
- #
601
- # @default `DD_SPAN_SAMPLING_RULES` environment variable.
602
- # Otherwise, `ENV_SPAN_SAMPLING_RULES_FILE` environment variable.
603
- # Otherwise `nil`.
604
- # @return [String,nil]
605
- # @public_api
606
- option :span_rules do |o|
607
- o.default do
608
- rules = ENV[Tracing::Configuration::Ext::Sampling::Span::ENV_SPAN_SAMPLING_RULES]
609
- rules_file = ENV[Tracing::Configuration::Ext::Sampling::Span::ENV_SPAN_SAMPLING_RULES_FILE]
610
-
611
- if rules
612
- if rules_file
613
- Datadog.logger.warn(
614
- 'Both DD_SPAN_SAMPLING_RULES and DD_SPAN_SAMPLING_RULES_FILE were provided: only ' \
615
- 'DD_SPAN_SAMPLING_RULES will be used. Please do not provide DD_SPAN_SAMPLING_RULES_FILE when ' \
616
- 'also providing DD_SPAN_SAMPLING_RULES as their configuration conflicts. ' \
617
- "DD_SPAN_SAMPLING_RULES_FILE=#{rules_file} DD_SPAN_SAMPLING_RULES=#{rules}"
618
- )
619
- end
620
- rules
621
- elsif rules_file
622
- begin
623
- File.read(rules_file)
624
- rescue => e
625
- # `File#read` errors have clear and actionable messages, no need to add extra exception info.
626
- Datadog.logger.warn(
627
- "Cannot read span sampling rules file `#{rules_file}`: #{e.message}." \
628
- 'No span sampling rules will be applied.'
629
- )
630
- nil
631
- end
632
- end
633
- end
634
- o.lazy
635
- end
636
- end
637
-
638
- # [Continuous Integration Visibility](https://docs.datadoghq.com/continuous_integration/) configuration.
639
- # @public_api
640
- settings :test_mode do
641
- # Enable test mode. This allows the tracer to collect spans from test runs.
642
- #
643
- # It also prevents the tracer from collecting spans in a production environment. Only use in a test environment.
644
- #
645
- # @default `DD_TRACE_TEST_MODE_ENABLED` environment variable, otherwise `false`
646
- # @return [Boolean]
647
- option :enabled do |o|
648
- o.default { env_to_bool(Tracing::Configuration::Ext::Test::ENV_MODE_ENABLED, false) }
649
- o.lazy
650
- end
651
-
652
- option :trace_flush do |o|
653
- o.default { nil }
654
- o.lazy
655
- end
656
-
657
- option :writer_options do |o|
658
- o.default { {} }
659
- o.lazy
660
- end
661
- end
662
-
663
- # @see file:docs/GettingStarted.md#configuring-the-transport-layer Configuring the transport layer
664
- #
665
- # A {Proc} that configures a custom tracer transport.
666
- # @yield Receives a {Datadog::Transport::HTTP} that can be modified with custom adapters and settings.
667
- # @yieldparam [Datadog::Transport::HTTP] t transport to be configured.
668
- # @default `nil`
669
- # @return [Proc,nil]
670
- option :transport_options, default: nil
671
-
672
- # A custom writer instance.
673
- # The object must respect the {Datadog::Tracing::Writer} interface.
674
- #
675
- # This option is recommended for internal use only.
676
- #
677
- # @default `nil`
678
- # @return [Object,nil]
679
- option :writer
680
-
681
- # A custom {Hash} with keyword options to be passed to {Datadog::Tracing::Writer#initialize}.
682
- #
683
- # This option is recommended for internal use only.
684
- #
685
- # @default `{}`
686
- # @return [Hash,nil]
687
- option :writer_options, default: ->(_i) { {} }, lazy: true
688
-
689
- # Client IP configuration
690
- # @public_api
691
- settings :client_ip do
692
- # Whether client IP collection is enabled. When enabled client IPs from HTTP requests will
693
- # be reported in traces.
694
- #
695
- # Usage of the DD_TRACE_CLIENT_IP_HEADER_DISABLED environment variable is deprecated.
696
- #
697
- # @see https://docs.datadoghq.com/tracing/configure_data_security#configuring-a-client-ip-header
698
- #
699
- # @default `DD_TRACE_CLIENT_IP_ENABLED` environment variable, otherwise `false`.
700
- # @return [Boolean]
701
- option :enabled do |o|
702
- o.default do
703
- disabled = env_to_bool(Tracing::Configuration::Ext::ClientIp::ENV_DISABLED)
704
-
705
- enabled = if disabled.nil?
706
- false
707
- else
708
- Datadog.logger.warn { "#{Tracing::Configuration::Ext::ClientIp::ENV_DISABLED} environment variable is deprecated, found set to #{disabled}, use #{Tracing::Configuration::Ext::ClientIp::ENV_ENABLED}=#{!disabled}" }
709
-
710
- !disabled
711
- end
712
-
713
- # ENABLED env var takes precedence over deprecated DISABLED
714
- env_to_bool(Tracing::Configuration::Ext::ClientIp::ENV_ENABLED, enabled)
715
- end
716
- o.lazy
717
- end
718
-
719
- # An optional name of a custom header to resolve the client IP from.
720
- #
721
- # @default `DD_TRACE_CLIENT_IP_HEADER` environment variable, otherwise `nil`.
722
- # @return [String,nil]
723
- option :header_name do |o|
724
- o.default { ENV.fetch(Tracing::Configuration::Ext::ClientIp::ENV_HEADER_NAME, nil) }
725
- o.lazy
726
- end
727
- end
728
-
729
- # Maximum size for the `x-datadog-tags` distributed trace tags header.
730
- #
731
- # If the serialized size of distributed trace tags is larger than this value, it will
732
- # not be parsed if incoming, nor exported if outgoing. An error message will be logged
733
- # in this case.
734
- #
735
- # @default `DD_TRACE_X_DATADOG_TAGS_MAX_LENGTH` environment variable, otherwise `512`
736
- # @return [Integer]
737
- option :x_datadog_tags_max_length do |o|
738
- o.default { env_to_int(Tracing::Configuration::Ext::Distributed::ENV_X_DATADOG_TAGS_MAX_LENGTH, 512) }
739
- o.lazy
740
- end
741
- end
742
-
743
415
  # The `version` tag in Datadog. Use it to enable [Deployment Tracking](https://docs.datadoghq.com/tracing/deployment_tracking/).
744
416
  # @see https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging
745
417
  # @default `DD_VERSION` environment variable, otherwise `nils`
@@ -763,9 +435,12 @@ module Datadog
763
435
  o.lazy
764
436
  end
765
437
  end
438
+
439
+ # TODO: Tracing should manage its own settings.
440
+ # Keep this extension here for now to keep things working.
441
+ extend Datadog::Tracing::Configuration::Settings
766
442
  end
767
443
  # rubocop:enable Metrics/BlockLength
768
- # rubocop:enable Layout/LineLength
769
444
  end
770
445
  end
771
446
  end
@@ -221,9 +221,9 @@ module Datadog
221
221
  !!Datadog.configuration.diagnostics.health_metrics.enabled
222
222
  end
223
223
 
224
- # TODO: Populate when profiling is implemented
225
- # def profiling_enabled
226
- # end
224
+ def profiling_enabled
225
+ !!Datadog.configuration.profiling.enabled
226
+ end
227
227
 
228
228
  # TODO: Populate when automatic log correlation is implemented
229
229
  # def logs_correlation_enabled
@@ -254,6 +254,7 @@ module Datadog
254
254
  partial_flushing_enabled: partial_flushing_enabled,
255
255
  priority_sampling_enabled: priority_sampling_enabled,
256
256
  health_metrics_enabled: health_metrics_enabled,
257
+ profiling_enabled: profiling_enabled,
257
258
  **instrumented_integrations_settings
258
259
  }
259
260
  end
@@ -1,7 +1,7 @@
1
- # typed: strict
1
+ # typed: ignore
2
2
 
3
- require_relative 'ext'
4
3
  require_relative '../metrics/client'
4
+ require_relative '../../tracing/diagnostics/health'
5
5
 
6
6
  module Datadog
7
7
  module Core
@@ -10,26 +10,8 @@ module Datadog
10
10
  module Health
11
11
  # Health metrics for diagnostics
12
12
  class Metrics < Core::Metrics::Client
13
- count :api_errors, Ext::Health::Metrics::METRIC_API_ERRORS
14
- count :api_requests, Ext::Health::Metrics::METRIC_API_REQUESTS
15
- count :api_responses, Ext::Health::Metrics::METRIC_API_RESPONSES
16
- count :error_context_overflow, Ext::Health::Metrics::METRIC_ERROR_CONTEXT_OVERFLOW
17
- count :error_instrumentation_patch, Ext::Health::Metrics::METRIC_ERROR_INSTRUMENTATION_PATCH
18
- count :error_span_finish, Ext::Health::Metrics::METRIC_ERROR_SPAN_FINISH
19
- count :error_unfinished_spans, Ext::Health::Metrics::METRIC_ERROR_UNFINISHED_SPANS
20
- count :instrumentation_patched, Ext::Health::Metrics::METRIC_INSTRUMENTATION_PATCHED
21
- count :queue_accepted, Ext::Health::Metrics::METRIC_QUEUE_ACCEPTED
22
- count :queue_accepted_lengths, Ext::Health::Metrics::METRIC_QUEUE_ACCEPTED_LENGTHS
23
- count :queue_dropped, Ext::Health::Metrics::METRIC_QUEUE_DROPPED
24
- count :traces_filtered, Ext::Health::Metrics::METRIC_TRACES_FILTERED
25
- count :transport_trace_too_large, Ext::Health::Metrics::METRIC_TRANSPORT_TRACE_TOO_LARGE
26
- count :transport_chunked, Ext::Health::Metrics::METRIC_TRANSPORT_CHUNKED
27
- count :writer_cpu_time, Ext::Health::Metrics::METRIC_WRITER_CPU_TIME
28
-
29
- gauge :queue_length, Ext::Health::Metrics::METRIC_QUEUE_LENGTH
30
- gauge :queue_max_length, Ext::Health::Metrics::METRIC_QUEUE_MAX_LENGTH
31
- gauge :queue_spans, Ext::Health::Metrics::METRIC_QUEUE_SPANS
32
- gauge :sampling_service_cache_length, Ext::Health::Metrics::METRIC_SAMPLING_SERVICE_CACHE_LENGTH
13
+ # TODO: Don't reference this. Have tracing add its metrics behavior.
14
+ extend Tracing::Diagnostics::Health::Metrics
33
15
  end
34
16
  end
35
17
  end
@@ -9,18 +9,45 @@ module Datadog
9
9
  module VariableHelpers
10
10
  extend self
11
11
 
12
- def env_to_bool(var, default = nil)
13
- var = decode_array(var)
12
+ # Reads an environment variable as a Boolean.
13
+ #
14
+ # @param [String] var environment variable
15
+ # @param [Array<String>] var list of environment variables
16
+ # @param [Boolean] default the default value if the keys in `var` are not present in the environment
17
+ # @param [Boolean] deprecation_warning when `var` is a list, record a deprecation log when
18
+ # the first key in `var` is not used.
19
+ # @return [Boolean] if the environment value is the string `true`
20
+ # @return [default] if the environment value is not found
21
+ def env_to_bool(var, default = nil, deprecation_warning: true)
22
+ var = decode_array(var, deprecation_warning)
14
23
  var && ENV.key?(var) ? ENV[var].to_s.strip.downcase == 'true' : default
15
24
  end
16
25
 
17
- def env_to_int(var, default = nil)
18
- var = decode_array(var)
26
+ # Reads an environment variable as an Integer.
27
+ #
28
+ # @param [String] var environment variable
29
+ # @param [Array<String>] var list of environment variables
30
+ # @param [Integer] default the default value if the keys in `var` are not present in the environment
31
+ # @param [Boolean] deprecation_warning when `var` is a list, record a deprecation log when
32
+ # the first key in `var` is not used.
33
+ # @return [Integer] if the environment value is a valid Integer
34
+ # @return [default] if the environment value is not found
35
+ def env_to_int(var, default = nil, deprecation_warning: true)
36
+ var = decode_array(var, deprecation_warning)
19
37
  var && ENV.key?(var) ? ENV[var].to_i : default
20
38
  end
21
39
 
22
- def env_to_float(var, default = nil)
23
- var = decode_array(var)
40
+ # Reads an environment variable as a Float.
41
+ #
42
+ # @param [String] var environment variable
43
+ # @param [Array<String>] var list of environment variables
44
+ # @param [Float] default the default value if the keys in `var` are not present in the environment
45
+ # @param [Boolean] deprecation_warning when `var` is a list, record a deprecation log when
46
+ # the first key in `var` is not used.
47
+ # @return [Float] if the environment value is a valid Float
48
+ # @return [default] if the environment value is not found
49
+ def env_to_float(var, default = nil, deprecation_warning: true)
50
+ var = decode_array(var, deprecation_warning)
24
51
  var && ENV.key?(var) ? ENV[var].to_f : default
25
52
  end
26
53
 
@@ -33,8 +60,16 @@ module Datadog
33
60
  # either trailing or leading are trimmed.
34
61
  #
35
62
  # Empty entries, after trimmed, are also removed from the result.
36
- def env_to_list(var, default = [], comma_separated_only:)
37
- var = decode_array(var)
63
+ #
64
+ # @param [String] var environment variable
65
+ # @param [Array<String>] var list of environment variables
66
+ # @param [Array<Object>] default the default value if the keys in `var` are not present in the environment
67
+ # @param [Boolean] deprecation_warning when `var` is a list, record a deprecation log when
68
+ # the first key in `var` is not used.
69
+ # @return [Array<Object>] if the environment value is a valid list
70
+ # @return [default] if the environment value is not found
71
+ def env_to_list(var, default = [], comma_separated_only:, deprecation_warning: true)
72
+ var = decode_array(var, deprecation_warning)
38
73
  if var && ENV.key?(var)
39
74
  value = ENV[var]
40
75
 
@@ -59,8 +94,21 @@ module Datadog
59
94
 
60
95
  private
61
96
 
62
- def decode_array(var)
63
- var.is_a?(Array) ? var.find { |env_var| ENV.key?(env_var) } : var
97
+ def decode_array(var, deprecation_warning)
98
+ if var.is_a?(Array)
99
+ var.find.with_index do |env_var, i|
100
+ found = ENV.key?(env_var)
101
+
102
+ # Check if we are using a non-preferred environment variable
103
+ if deprecation_warning && found && i != 0
104
+ Datadog::Core.log_deprecation { "#{env_var} environment variable is deprecated, use #{var.first} instead." }
105
+ end
106
+
107
+ found
108
+ end
109
+ else
110
+ var
111
+ end
64
112
  end
65
113
  end
66
114
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative '../utils/time'
4
4
  require_relative '../utils/only_once'
5
+ require_relative '../configuration/ext'
5
6
 
6
7
  require_relative 'ext'
7
8
  require_relative 'options'
@@ -50,11 +51,11 @@ module Datadog
50
51
  end
51
52
 
52
53
  def default_hostname
53
- ENV.fetch(Ext::ENV_DEFAULT_HOST, Ext::DEFAULT_HOST)
54
+ ENV.fetch(Configuration::Ext::Transport::ENV_DEFAULT_HOST, Ext::DEFAULT_HOST)
54
55
  end
55
56
 
56
57
  def default_port
57
- ENV.fetch(Ext::ENV_DEFAULT_PORT, Ext::DEFAULT_PORT).to_i
58
+ ENV.fetch(Configuration::Ext::Metrics::ENV_DEFAULT_PORT, Ext::DEFAULT_PORT).to_i
58
59
  end
59
60
 
60
61
  def default_statsd_client
@@ -7,8 +7,6 @@ module Datadog
7
7
  module Ext
8
8
  DEFAULT_HOST = '127.0.0.1'.freeze
9
9
  DEFAULT_PORT = 8125
10
- ENV_DEFAULT_HOST = 'DD_AGENT_HOST'.freeze
11
- ENV_DEFAULT_PORT = 'DD_METRIC_AGENT_PORT'.freeze
12
10
 
13
11
  TAG_LANG = 'language'.freeze
14
12
  TAG_LANG_INTERPRETER = 'language-interpreter'.freeze
@@ -135,6 +135,7 @@ module Datadog
135
135
  format_configuration_value(configuration.tracing.writer_options[:flush_interval])
136
136
  options['logger.instance'] = configuration.logger.instance.class.to_s
137
137
  options['appsec.enabled'] = configuration.dig('appsec', 'enabled') if configuration.respond_to?('appsec')
138
+ options['tracing.opentelemetry.enabled'] = !defined?(Datadog::OpenTelemetry::LOADED).nil?
138
139
  compact_hash(options)
139
140
  end
140
141
 
@@ -1,7 +1,6 @@
1
1
  # typed: true
2
2
 
3
3
  require_relative 'utils/forking'
4
- require_relative '../tracing/span'
5
4
 
6
5
  module Datadog
7
6
  module Core
@@ -11,26 +10,6 @@ module Datadog
11
10
  extend Forking
12
11
 
13
12
  EMPTY_STRING = ''.encode(::Encoding::UTF_8).freeze
14
- # We use a custom random number generator because we want no interference
15
- # with the default one. Using the default prng, we could break code that
16
- # would rely on srand/rand sequences.
17
-
18
- # Return a randomly generated integer, valid as a Span ID or Trace ID.
19
- # This method is thread-safe and fork-safe.
20
- def self.next_id
21
- after_fork! { reset! }
22
- id_rng.rand(Tracing::Span::RUBY_ID_RANGE)
23
- end
24
-
25
- def self.id_rng
26
- @id_rng ||= Random.new
27
- end
28
-
29
- def self.reset!
30
- @id_rng = Random.new
31
- end
32
-
33
- private_class_method :id_rng, :reset!
34
13
 
35
14
  # Stringifies `value` and ensures the outcome is
36
15
  # string is no longer than `size`.