ddtrace 1.6.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +89 -2
  3. data/README.md +2 -2
  4. data/ext/ddtrace_profiling_loader/extconf.rb +5 -2
  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 +81 -47
  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 +332 -125
  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 +11 -13
  15. data/ext/ddtrace_profiling_native_extension/extconf.rb +22 -8
  16. data/ext/ddtrace_profiling_native_extension/helpers.h +5 -0
  17. data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +8 -0
  18. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +111 -26
  19. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.h +9 -0
  20. data/ext/ddtrace_profiling_native_extension/profiling.c +205 -0
  21. data/ext/ddtrace_profiling_native_extension/ruby_helpers.c +86 -0
  22. data/ext/ddtrace_profiling_native_extension/ruby_helpers.h +28 -6
  23. data/ext/ddtrace_profiling_native_extension/setup_signal_handler.c +115 -0
  24. data/ext/ddtrace_profiling_native_extension/setup_signal_handler.h +11 -0
  25. data/ext/ddtrace_profiling_native_extension/stack_recorder.c +84 -35
  26. data/ext/ddtrace_profiling_native_extension/stack_recorder.h +1 -0
  27. data/ext/ddtrace_profiling_native_extension/time_helpers.c +17 -0
  28. data/ext/ddtrace_profiling_native_extension/time_helpers.h +10 -0
  29. data/lib/datadog/appsec/assets/blocked.html +98 -3
  30. data/lib/datadog/appsec/assets/blocked.json +1 -0
  31. data/lib/datadog/appsec/assets/blocked.text +5 -0
  32. data/lib/datadog/appsec/assets/waf_rules/recommended.json +35 -46
  33. data/lib/datadog/appsec/assets/waf_rules/risky.json +1 -1
  34. data/lib/datadog/appsec/assets/waf_rules/strict.json +46 -1
  35. data/lib/datadog/appsec/assets.rb +2 -2
  36. data/lib/datadog/appsec/configuration/settings.rb +6 -0
  37. data/lib/datadog/appsec/configuration.rb +4 -0
  38. data/lib/datadog/appsec/contrib/rack/reactive/request.rb +4 -8
  39. data/lib/datadog/appsec/contrib/rack/request.rb +17 -0
  40. data/lib/datadog/appsec/contrib/rack/request_body_middleware.rb +2 -2
  41. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +2 -2
  42. data/lib/datadog/appsec/contrib/rails/patcher.rb +3 -6
  43. data/lib/datadog/appsec/contrib/sinatra/ext.rb +1 -0
  44. data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +1 -1
  45. data/lib/datadog/appsec/contrib/sinatra/patcher.rb +11 -8
  46. data/lib/datadog/appsec/extensions.rb +10 -0
  47. data/lib/datadog/appsec/processor.rb +18 -0
  48. data/lib/datadog/appsec/response.rb +54 -0
  49. data/lib/datadog/core/configuration/components.rb +27 -6
  50. data/lib/datadog/core/configuration/ext.rb +18 -0
  51. data/lib/datadog/core/configuration/settings.rb +14 -341
  52. data/lib/datadog/core/diagnostics/health.rb +4 -22
  53. data/lib/datadog/core/environment/variable_helpers.rb +58 -10
  54. data/lib/datadog/core/runtime/ext.rb +1 -1
  55. data/lib/datadog/core/utils.rb +0 -21
  56. data/lib/datadog/core.rb +21 -1
  57. data/lib/datadog/opentracer/distributed_headers.rb +7 -9
  58. data/lib/datadog/opentracer/rack_propagator.rb +0 -3
  59. data/lib/datadog/opentracer/text_map_propagator.rb +5 -7
  60. data/lib/datadog/profiling/collectors/cpu_and_wall_time.rb +10 -4
  61. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +20 -5
  62. data/lib/datadog/profiling/collectors/dynamic_sampling_rate.rb +14 -0
  63. data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +68 -0
  64. data/lib/datadog/profiling/collectors/old_stack.rb +7 -0
  65. data/lib/datadog/profiling/exporter.rb +5 -0
  66. data/lib/datadog/profiling/old_recorder.rb +8 -0
  67. data/lib/datadog/profiling/profiler.rb +7 -0
  68. data/lib/datadog/profiling/scheduler.rb +4 -7
  69. data/lib/datadog/profiling/stack_recorder.rb +36 -0
  70. data/lib/datadog/profiling/tasks/setup.rb +0 -7
  71. data/lib/datadog/profiling.rb +2 -0
  72. data/lib/datadog/tracing/configuration/ext.rb +33 -3
  73. data/lib/datadog/tracing/configuration/settings.rb +433 -0
  74. data/lib/datadog/tracing/contrib/aws/configuration/settings.rb +4 -1
  75. data/lib/datadog/tracing/contrib/aws/ext.rb +1 -0
  76. data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +4 -1
  77. data/lib/datadog/tracing/contrib/dalli/ext.rb +1 -0
  78. data/lib/datadog/tracing/contrib/delayed_job/plugin.rb +4 -0
  79. data/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +5 -1
  80. data/lib/datadog/tracing/contrib/elasticsearch/ext.rb +1 -0
  81. data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +6 -1
  82. data/lib/datadog/tracing/contrib/ethon/ext.rb +1 -0
  83. data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +5 -1
  84. data/lib/datadog/tracing/contrib/excon/ext.rb +1 -0
  85. data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +5 -1
  86. data/lib/datadog/tracing/contrib/faraday/ext.rb +1 -0
  87. data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +6 -1
  88. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +2 -1
  89. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +6 -12
  90. data/lib/datadog/tracing/contrib/grpc/distributed/fetcher.rb +27 -0
  91. data/lib/datadog/tracing/contrib/grpc/distributed/propagation.rb +43 -0
  92. data/lib/datadog/tracing/contrib/grpc/ext.rb +1 -0
  93. data/lib/datadog/tracing/contrib/grpc/patcher.rb +0 -2
  94. data/lib/datadog/tracing/contrib/http/configuration/settings.rb +6 -1
  95. data/lib/datadog/tracing/contrib/http/distributed/fetcher.rb +32 -0
  96. data/lib/datadog/tracing/contrib/http/distributed/propagation.rb +38 -0
  97. data/lib/datadog/tracing/contrib/http/ext.rb +1 -0
  98. data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +6 -1
  99. data/lib/datadog/tracing/contrib/httpclient/ext.rb +1 -0
  100. data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +6 -1
  101. data/lib/datadog/tracing/contrib/httprb/ext.rb +1 -0
  102. data/lib/datadog/tracing/contrib/kafka/consumer_event.rb +1 -0
  103. data/lib/datadog/tracing/contrib/kafka/events/produce_operation/send_messages.rb +1 -0
  104. data/lib/datadog/tracing/contrib/kafka/events/producer/deliver_messages.rb +1 -0
  105. data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +5 -1
  106. data/lib/datadog/tracing/contrib/mongodb/ext.rb +1 -0
  107. data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +2 -0
  108. data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +4 -1
  109. data/lib/datadog/tracing/contrib/mysql2/ext.rb +1 -0
  110. data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +2 -2
  111. data/lib/datadog/tracing/contrib/patcher.rb +3 -2
  112. data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +4 -1
  113. data/lib/datadog/tracing/contrib/pg/ext.rb +1 -0
  114. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +12 -2
  115. data/lib/datadog/tracing/contrib/presto/configuration/settings.rb +4 -1
  116. data/lib/datadog/tracing/contrib/presto/ext.rb +1 -0
  117. data/lib/datadog/tracing/contrib/propagation/sql_comment/ext.rb +1 -0
  118. data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +10 -12
  119. data/lib/datadog/tracing/contrib/que/tracer.rb +2 -0
  120. data/lib/datadog/tracing/contrib/racecar/events/batch.rb +4 -1
  121. data/lib/datadog/tracing/contrib/racecar/events/message.rb +4 -1
  122. data/lib/datadog/tracing/contrib/rack/middlewares.rb +2 -0
  123. data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +4 -1
  124. data/lib/datadog/tracing/contrib/redis/ext.rb +1 -0
  125. data/lib/datadog/tracing/contrib/redis/instrumentation.rb +30 -21
  126. data/lib/datadog/tracing/contrib/redis/integration.rb +34 -2
  127. data/lib/datadog/tracing/contrib/redis/patcher.rb +18 -14
  128. data/lib/datadog/tracing/contrib/redis/quantize.rb +12 -9
  129. data/lib/datadog/tracing/contrib/redis/tags.rb +4 -6
  130. data/lib/datadog/tracing/contrib/redis/trace_middleware.rb +72 -0
  131. data/lib/datadog/tracing/contrib/resque/resque_job.rb +2 -0
  132. data/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +6 -1
  133. data/lib/datadog/tracing/contrib/rest_client/ext.rb +1 -0
  134. data/lib/datadog/tracing/contrib/shoryuken/tracer.rb +2 -0
  135. data/lib/datadog/tracing/contrib/sidekiq/client_tracer.rb +5 -0
  136. data/lib/datadog/tracing/contrib/sidekiq/server_tracer.rb +5 -0
  137. data/lib/datadog/tracing/contrib/sneakers/tracer.rb +2 -0
  138. data/lib/datadog/{core → tracing}/diagnostics/ext.rb +1 -6
  139. data/lib/datadog/tracing/diagnostics/health.rb +40 -0
  140. data/lib/datadog/tracing/distributed/b3_multi.rb +66 -0
  141. data/lib/datadog/tracing/distributed/b3_single.rb +66 -0
  142. data/lib/datadog/tracing/distributed/datadog.rb +153 -0
  143. data/lib/datadog/tracing/distributed/datadog_tags_codec.rb +1 -0
  144. data/lib/datadog/tracing/distributed/fetcher.rb +30 -0
  145. data/lib/datadog/tracing/distributed/headers/ext.rb +18 -16
  146. data/lib/datadog/tracing/distributed/helpers.rb +9 -7
  147. data/lib/datadog/tracing/distributed/none.rb +19 -0
  148. data/lib/datadog/tracing/distributed/propagation.rb +127 -0
  149. data/lib/datadog/tracing/distributed/trace_context.rb +369 -0
  150. data/lib/datadog/tracing/metadata/ext.rb +1 -1
  151. data/lib/datadog/tracing/propagation/http.rb +3 -106
  152. data/lib/datadog/tracing/sampling/priority_sampler.rb +11 -0
  153. data/lib/datadog/tracing/sampling/rate_sampler.rb +3 -3
  154. data/lib/datadog/tracing/span.rb +3 -19
  155. data/lib/datadog/tracing/span_operation.rb +5 -4
  156. data/lib/datadog/tracing/trace_digest.rb +75 -2
  157. data/lib/datadog/tracing/trace_operation.rb +5 -4
  158. data/lib/datadog/tracing/trace_segment.rb +1 -1
  159. data/lib/datadog/tracing/utils.rb +50 -0
  160. data/lib/ddtrace/transport/trace_formatter.rb +2 -5
  161. data/lib/ddtrace/version.rb +2 -2
  162. metadata +35 -15
  163. data/lib/datadog/tracing/distributed/headers/b3.rb +0 -55
  164. data/lib/datadog/tracing/distributed/headers/b3_single.rb +0 -67
  165. data/lib/datadog/tracing/distributed/headers/datadog.rb +0 -144
  166. data/lib/datadog/tracing/distributed/headers/parser.rb +0 -37
  167. data/lib/datadog/tracing/distributed/metadata/b3.rb +0 -55
  168. data/lib/datadog/tracing/distributed/metadata/b3_single.rb +0 -66
  169. data/lib/datadog/tracing/distributed/metadata/datadog.rb +0 -73
  170. data/lib/datadog/tracing/distributed/metadata/parser.rb +0 -34
  171. data/lib/datadog/tracing/propagation/grpc.rb +0 -98
@@ -3,22 +3,27 @@
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
 
23
+ # TODO: Tracing should manage its own settings.
24
+ # Keep this extension here for now to keep things working.
25
+ extend Datadog::Tracing::Configuration::Settings
26
+
22
27
  # @!visibility private
23
28
  def initialize(*_)
24
29
  super
@@ -99,7 +104,7 @@ module Datadog
99
104
  # @default `DD_TRACE_DEBUG` environment variable, otherwise `false`
100
105
  # @return [Boolean]
101
106
  option :debug do |o|
102
- o.default { env_to_bool(Datadog::Core::Diagnostics::Ext::DD_TRACE_DEBUG, false) }
107
+ o.default { env_to_bool(Datadog::Core::Configuration::Ext::Diagnostics::ENV_DEBUG_ENABLED, false) }
103
108
  o.lazy
104
109
  o.on_set do |enabled|
105
110
  # Enable rich debug print statements.
@@ -110,7 +115,6 @@ module Datadog
110
115
 
111
116
  # Internal {Datadog::Statsd} metrics collection.
112
117
  #
113
- # The list of metrics collected can be found in {Datadog::Core::Diagnostics::Ext::Health::Metrics}.
114
118
  # @public_api
115
119
  settings :health_metrics do
116
120
  # Enable health metrics collection.
@@ -118,7 +122,7 @@ module Datadog
118
122
  # @default `DD_HEALTH_METRICS_ENABLED` environment variable, otherwise `false`
119
123
  # @return [Boolean]
120
124
  option :enabled do |o|
121
- o.default { env_to_bool(Datadog::Core::Diagnostics::Ext::Health::Metrics::ENV_ENABLED, false) }
125
+ o.default { env_to_bool(Datadog::Core::Configuration::Ext::Diagnostics::ENV_HEALTH_METRICS_ENABLED, false) }
122
126
  o.lazy
123
127
  end
124
128
 
@@ -144,7 +148,7 @@ module Datadog
144
148
  # @return [Boolean,nil]
145
149
  option :enabled do |o|
146
150
  # 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) }
151
+ o.default { env_to_bool(Datadog::Core::Configuration::Ext::Diagnostics::ENV_STARTUP_LOGS_ENABLED, nil) }
148
152
  o.lazy
149
153
  end
150
154
  end
@@ -269,7 +273,9 @@ module Datadog
269
273
  # If you use Ruby 3.x and your application does not use Ractors (or if your Ruby has been patched), the
270
274
  # feature is fully safe to enable and this toggle can be used to do so.
271
275
  #
272
- # We expect that once the above issue is patched, we'll automatically re-enable the feature on fixed Ruby
276
+ # Furthermore, currently this feature can add a lot of overhead for GC-heavy workloads.
277
+ #
278
+ # We expect the once the above issues are overcome, we'll automatically enable the feature on fixed Ruby
273
279
  # versions.
274
280
  option :force_enable_gc_profiling do |o|
275
281
  o.default { env_to_bool('DD_PROFILING_FORCE_ENABLE_GC', false) }
@@ -408,338 +414,6 @@ module Datadog
408
414
  end
409
415
  end
410
416
 
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
417
  # The `version` tag in Datadog. Use it to enable [Deployment Tracking](https://docs.datadoghq.com/tracing/deployment_tracking/).
744
418
  # @see https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging
745
419
  # @default `DD_VERSION` environment variable, otherwise `nils`
@@ -765,7 +439,6 @@ module Datadog
765
439
  end
766
440
  end
767
441
  # rubocop:enable Metrics/BlockLength
768
- # rubocop:enable Layout/LineLength
769
442
  end
770
443
  end
771
444
  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
@@ -7,7 +7,7 @@ module Datadog
7
7
  module Ext
8
8
  TAG_ID = 'runtime-id'.freeze
9
9
  TAG_LANG = 'language'.freeze
10
- TAG_PID = 'system.pid'.freeze
10
+ TAG_PROCESS_ID = 'process_id'.freeze
11
11
 
12
12
  # Metrics
13
13
  # @public_api
@@ -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`.
data/lib/datadog/core.rb CHANGED
@@ -1,4 +1,5 @@
1
- # typed: strict
1
+ # frozen_string_literal: true
2
+ # typed: true
2
3
 
3
4
  require_relative 'core/extensions'
4
5
 
@@ -9,6 +10,25 @@ module Datadog
9
10
  # products. It is a dependency of each product. Contrast with Datadog::Kit
10
11
  # for higher-level features.
11
12
  module Core
13
+ class << self
14
+ # Records the occurrence of a deprecated operation in this library.
15
+ #
16
+ # Currently, these operations are logged to `Datadog.logger` at `warn` level.
17
+ #
18
+ # `disallowed_next_major` adds a message informing that the deprecated operation
19
+ # won't be allowed in the next major release.
20
+ #
21
+ # @yieldreturn [String] a String with the lazily evaluated deprecation message.
22
+ # @param [Boolean] disallowed_next_major whether this deprecation will be enforced in the next major release.
23
+ def log_deprecation(disallowed_next_major: true)
24
+ Datadog.logger.warn do
25
+ message = yield
26
+ message += ' This will be enforced in the next major release.' if disallowed_next_major
27
+ message
28
+ end
29
+ nil
30
+ end
31
+ end
12
32
  end
13
33
 
14
34
  extend Core::Extensions