ddtrace 1.7.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -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 +15 -41
  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/extconf.rb +21 -7
  15. data/ext/ddtrace_profiling_native_extension/helpers.h +5 -0
  16. data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +8 -0
  17. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +108 -24
  18. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.h +9 -0
  19. data/ext/ddtrace_profiling_native_extension/profiling.c +205 -0
  20. data/ext/ddtrace_profiling_native_extension/ruby_helpers.c +86 -0
  21. data/ext/ddtrace_profiling_native_extension/ruby_helpers.h +28 -6
  22. data/ext/ddtrace_profiling_native_extension/setup_signal_handler.c +23 -4
  23. data/ext/ddtrace_profiling_native_extension/setup_signal_handler.h +4 -0
  24. data/ext/ddtrace_profiling_native_extension/stack_recorder.c +15 -18
  25. data/ext/ddtrace_profiling_native_extension/time_helpers.c +17 -0
  26. data/ext/ddtrace_profiling_native_extension/time_helpers.h +10 -0
  27. data/lib/datadog/core/configuration/components.rb +27 -6
  28. data/lib/datadog/core/configuration/ext.rb +18 -0
  29. data/lib/datadog/core/configuration/settings.rb +14 -341
  30. data/lib/datadog/core/diagnostics/health.rb +4 -22
  31. data/lib/datadog/core/environment/variable_helpers.rb +58 -10
  32. data/lib/datadog/core/utils.rb +0 -21
  33. data/lib/datadog/core.rb +21 -1
  34. data/lib/datadog/opentracer/distributed_headers.rb +2 -2
  35. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +16 -5
  36. data/lib/datadog/profiling/collectors/dynamic_sampling_rate.rb +14 -0
  37. data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +68 -0
  38. data/lib/datadog/profiling/stack_recorder.rb +14 -0
  39. data/lib/datadog/profiling.rb +2 -0
  40. data/lib/datadog/tracing/configuration/ext.rb +33 -3
  41. data/lib/datadog/tracing/configuration/settings.rb +433 -0
  42. data/lib/datadog/tracing/contrib/aws/configuration/settings.rb +4 -1
  43. data/lib/datadog/tracing/contrib/aws/ext.rb +1 -0
  44. data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +4 -1
  45. data/lib/datadog/tracing/contrib/dalli/ext.rb +1 -0
  46. data/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +5 -1
  47. data/lib/datadog/tracing/contrib/elasticsearch/ext.rb +1 -0
  48. data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +6 -1
  49. data/lib/datadog/tracing/contrib/ethon/ext.rb +1 -0
  50. data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +5 -1
  51. data/lib/datadog/tracing/contrib/excon/ext.rb +1 -0
  52. data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +5 -1
  53. data/lib/datadog/tracing/contrib/faraday/ext.rb +1 -0
  54. data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +6 -1
  55. data/lib/datadog/tracing/contrib/grpc/distributed/propagation.rb +9 -4
  56. data/lib/datadog/tracing/contrib/grpc/ext.rb +1 -0
  57. data/lib/datadog/tracing/contrib/http/configuration/settings.rb +6 -1
  58. data/lib/datadog/tracing/contrib/http/distributed/propagation.rb +9 -4
  59. data/lib/datadog/tracing/contrib/http/ext.rb +1 -0
  60. data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +6 -1
  61. data/lib/datadog/tracing/contrib/httpclient/ext.rb +1 -0
  62. data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +6 -1
  63. data/lib/datadog/tracing/contrib/httprb/ext.rb +1 -0
  64. data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +5 -1
  65. data/lib/datadog/tracing/contrib/mongodb/ext.rb +1 -0
  66. data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +4 -1
  67. data/lib/datadog/tracing/contrib/mysql2/ext.rb +1 -0
  68. data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +2 -2
  69. data/lib/datadog/tracing/contrib/patcher.rb +3 -2
  70. data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +4 -1
  71. data/lib/datadog/tracing/contrib/pg/ext.rb +1 -0
  72. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +12 -2
  73. data/lib/datadog/tracing/contrib/presto/configuration/settings.rb +4 -1
  74. data/lib/datadog/tracing/contrib/presto/ext.rb +1 -0
  75. data/lib/datadog/tracing/contrib/propagation/sql_comment/ext.rb +1 -0
  76. data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +10 -12
  77. data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +4 -1
  78. data/lib/datadog/tracing/contrib/redis/ext.rb +1 -0
  79. data/lib/datadog/tracing/contrib/redis/instrumentation.rb +30 -23
  80. data/lib/datadog/tracing/contrib/redis/integration.rb +34 -2
  81. data/lib/datadog/tracing/contrib/redis/patcher.rb +18 -14
  82. data/lib/datadog/tracing/contrib/redis/quantize.rb +12 -9
  83. data/lib/datadog/tracing/contrib/redis/tags.rb +4 -6
  84. data/lib/datadog/tracing/contrib/redis/trace_middleware.rb +72 -0
  85. data/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +6 -1
  86. data/lib/datadog/tracing/contrib/rest_client/ext.rb +1 -0
  87. data/lib/datadog/{core → tracing}/diagnostics/ext.rb +1 -6
  88. data/lib/datadog/tracing/diagnostics/health.rb +40 -0
  89. data/lib/datadog/tracing/distributed/{b3.rb → b3_multi.rb} +2 -2
  90. data/lib/datadog/tracing/distributed/helpers.rb +2 -1
  91. data/lib/datadog/tracing/distributed/none.rb +19 -0
  92. data/lib/datadog/tracing/distributed/trace_context.rb +369 -0
  93. data/lib/datadog/tracing/metadata/ext.rb +1 -1
  94. data/lib/datadog/tracing/sampling/priority_sampler.rb +11 -0
  95. data/lib/datadog/tracing/sampling/rate_sampler.rb +3 -3
  96. data/lib/datadog/tracing/span.rb +3 -19
  97. data/lib/datadog/tracing/span_operation.rb +5 -4
  98. data/lib/datadog/tracing/trace_digest.rb +75 -2
  99. data/lib/datadog/tracing/trace_operation.rb +5 -4
  100. data/lib/datadog/tracing/utils.rb +50 -0
  101. data/lib/ddtrace/version.rb +1 -1
  102. metadata +20 -5
@@ -7,10 +7,11 @@ require_relative '../core/environment/identity'
7
7
  require_relative '../core/utils'
8
8
  require_relative '../core/utils/time'
9
9
 
10
- require_relative 'metadata/ext'
11
10
  require_relative 'event'
12
- require_relative 'span'
13
11
  require_relative 'metadata'
12
+ require_relative 'metadata/ext'
13
+ require_relative 'span'
14
+ require_relative 'utils'
14
15
 
15
16
  module Datadog
16
17
  module Tracing
@@ -61,9 +62,9 @@ module Datadog
61
62
  self.type = type
62
63
  self.resource = resource
63
64
 
64
- @id = Core::Utils.next_id
65
+ @id = Tracing::Utils.next_id
65
66
  @parent_id = parent_id || 0
66
- @trace_id = trace_id || Core::Utils.next_id
67
+ @trace_id = trace_id || Tracing::Utils.next_id
67
68
 
68
69
  @status = 0
69
70
 
@@ -6,6 +6,70 @@ module Datadog
6
6
  # Used to propagate context and continue traces across execution boundaries.
7
7
  # @public_api
8
8
  class TraceDigest
9
+ # @!attribute [r] span_id
10
+ # Datadog id for the currently active span.
11
+ # @return [Integer]
12
+ # @!attribute [r] span_name
13
+ # The operation name of the currently active span.
14
+ # @return [String]
15
+ # @!attribute [r] span_resource
16
+ # The resource name of the currently active span.
17
+ # @return [String]
18
+ # @!attribute [r] span_service
19
+ # The service of the currently active span.
20
+ # @return [String]
21
+ # @!attribute [r] span_type
22
+ # The type of the currently active span.
23
+ # @return [String]
24
+ # @!attribute [r] trace_distributed_tags
25
+ # Datadog-specific tags that support richer distributed tracing association.
26
+ # @return [Hash<String,String>]
27
+ # @!attribute [r] trace_hostname
28
+ # The hostname of the currently active trace. Use to attribute traces to hosts.
29
+ # @return [String]
30
+ # @!attribute [r] trace_id
31
+ # Datadog id for the currently active trace.
32
+ # @return [Integer]
33
+ # @!attribute [r] trace_name
34
+ # Operation name for the currently active trace.
35
+ # @return [Integer]
36
+ # @!attribute [r] trace_origin
37
+ # Datadog-specific attribution of this trace's creation.
38
+ # @return [String]
39
+ # @!attribute [r] trace_process_id
40
+ # The OS-specific process id.
41
+ # @return [Integer]
42
+ # @!attribute [r] trace_resource
43
+ # The resource name of the currently active trace.
44
+ # @return [String]
45
+ # @!attribute [r] trace_runtime_id
46
+ # Unique id to this Ruby process. Used to differentiate traces coming from
47
+ # child processes forked from same parent process.
48
+ # @return [String]
49
+ # @!attribute [r] trace_sampling_priority
50
+ # Datadog-specific sampling decision for the currently active trace.
51
+ # @return [Integer]
52
+ # @!attribute [r] trace_service
53
+ # The service of the currently active trace.
54
+ # @return [String]
55
+ # @!attribute [r] trace_distributed_id
56
+ # The trace id extracted from a distributed context, if different from `trace_id`.
57
+ #
58
+ # The current use case is when the distributed context has a trace id integer larger than 64-bit:
59
+ # This attribute will preserve the original id, while `trace_id` will only contain the lower 64 bits.
60
+ # @return [Integer]
61
+ # @see https://www.w3.org/TR/trace-context/#trace-id
62
+ # @!attribute [r] trace_tracestate
63
+ # The W3C "tracestate" extracted from a distributed context.
64
+ # This field is a string representing vendor-specific distribution data.
65
+ # @return [String]
66
+ # @see https://www.w3.org/TR/trace-context/#tracestate-header
67
+ # @!attribute [r] trace_flags
68
+ # The W3C "trace-flags" extracted from a distributed context. This field is an 8-bit unsigned integer.
69
+ # @return [Integer]
70
+ # @see https://www.w3.org/TR/trace-context/#trace-flags
71
+ # TODO: The documentation for the last attribute above won't be rendered.
72
+ # TODO: This might be a YARD bug as adding an attribute, making it now second-last attribute, renders correctly.
9
73
  attr_reader \
10
74
  :span_id,
11
75
  :span_name,
@@ -21,7 +85,10 @@ module Datadog
21
85
  :trace_resource,
22
86
  :trace_runtime_id,
23
87
  :trace_sampling_priority,
24
- :trace_service
88
+ :trace_service,
89
+ :trace_distributed_id,
90
+ :trace_flags,
91
+ :trace_state
25
92
 
26
93
  def initialize(
27
94
  span_id: nil,
@@ -38,7 +105,10 @@ module Datadog
38
105
  trace_resource: nil,
39
106
  trace_runtime_id: nil,
40
107
  trace_sampling_priority: nil,
41
- trace_service: nil
108
+ trace_service: nil,
109
+ trace_distributed_id: nil,
110
+ trace_flags: nil,
111
+ trace_state: nil
42
112
  )
43
113
  @span_id = span_id
44
114
  @span_name = span_name && span_name.dup.freeze
@@ -55,6 +125,9 @@ module Datadog
55
125
  @trace_runtime_id = trace_runtime_id && trace_runtime_id.dup.freeze
56
126
  @trace_sampling_priority = trace_sampling_priority
57
127
  @trace_service = trace_service && trace_service.dup.freeze
128
+ @trace_distributed_id = trace_distributed_id
129
+ @trace_flags = trace_flags
130
+ @trace_state = trace_state && trace_state.dup.freeze
58
131
 
59
132
  freeze
60
133
  end
@@ -4,12 +4,13 @@ require_relative '../core'
4
4
  require_relative '../core/environment/identity'
5
5
  require_relative '../core/utils'
6
6
 
7
- require_relative 'sampling/ext'
8
7
  require_relative 'event'
8
+ require_relative 'metadata/tagging'
9
+ require_relative 'sampling/ext'
9
10
  require_relative 'span_operation'
10
- require_relative 'trace_segment'
11
11
  require_relative 'trace_digest'
12
- require_relative 'metadata/tagging'
12
+ require_relative 'trace_segment'
13
+ require_relative 'utils'
13
14
 
14
15
  module Datadog
15
16
  module Tracing
@@ -70,7 +71,7 @@ module Datadog
70
71
  metrics: nil
71
72
  )
72
73
  # Attributes
73
- @id = id || Core::Utils.next_id
74
+ @id = id || Tracing::Utils.next_id
74
75
  @max_length = max_length || DEFAULT_MAX_LENGTH
75
76
  @parent_span_id = parent_span_id
76
77
  @sampled = sampled.nil? ? true : sampled
@@ -0,0 +1,50 @@
1
+ # typed: true
2
+
3
+ require_relative '../core/utils/forking'
4
+
5
+ module Datadog
6
+ module Tracing
7
+ # Utils contains low-level tracing utility functions.
8
+ # @public_api
9
+ module Utils
10
+ extend Datadog::Core::Utils::Forking
11
+
12
+ # The max value for a {Datadog::Tracing::Span} identifier.
13
+ # Span and trace identifiers should be strictly positive and strictly inferior to this limit.
14
+ #
15
+ # Limited to +2<<62-1+ positive integers, as Ruby is able to represent such numbers "inline",
16
+ # inside a +VALUE+ scalar, thus not requiring memory allocation.
17
+ #
18
+ # The range of IDs also has to consider portability across different languages and platforms.
19
+ RUBY_MAX_ID = (1 << 62) - 1
20
+
21
+ # Excludes zero from possible values
22
+ RUBY_ID_RANGE = (1..RUBY_MAX_ID).freeze
23
+
24
+ # While we only generate 63-bit integers due to limitations in other languages, we support
25
+ # parsing 64-bit integers for distributed tracing since an upstream system may generate one
26
+ EXTERNAL_MAX_ID = 1 << 64
27
+
28
+ # We use a custom random number generator because we want no interference
29
+ # with the default one. Using the default prng, we could break code that
30
+ # would rely on srand/rand sequences.
31
+
32
+ # Return a randomly generated integer, valid as a Span ID or Trace ID.
33
+ # This method is thread-safe and fork-safe.
34
+ def self.next_id
35
+ after_fork! { reset! }
36
+ id_rng.rand(RUBY_ID_RANGE)
37
+ end
38
+
39
+ def self.id_rng
40
+ @id_rng ||= Random.new
41
+ end
42
+
43
+ def self.reset!
44
+ @id_rng = Random.new
45
+ end
46
+
47
+ private_class_method :id_rng, :reset!
48
+ end
49
+ end
50
+ end
@@ -3,7 +3,7 @@
3
3
  module DDTrace
4
4
  module VERSION
5
5
  MAJOR = 1
6
- MINOR = 7
6
+ MINOR = 8
7
7
  PATCH = 0
8
8
  PRE = nil
9
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddtrace
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Datadog, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-29 00:00:00.000000000 Z
11
+ date: 2022-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -102,6 +102,10 @@ files:
102
102
  - ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.c
103
103
  - ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.h
104
104
  - ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c
105
+ - ext/ddtrace_profiling_native_extension/collectors_dynamic_sampling_rate.c
106
+ - ext/ddtrace_profiling_native_extension/collectors_dynamic_sampling_rate.h
107
+ - ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.c
108
+ - ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.h
105
109
  - ext/ddtrace_profiling_native_extension/collectors_stack.c
106
110
  - ext/ddtrace_profiling_native_extension/collectors_stack.h
107
111
  - ext/ddtrace_profiling_native_extension/extconf.rb
@@ -118,6 +122,8 @@ files:
118
122
  - ext/ddtrace_profiling_native_extension/setup_signal_handler.h
119
123
  - ext/ddtrace_profiling_native_extension/stack_recorder.c
120
124
  - ext/ddtrace_profiling_native_extension/stack_recorder.h
125
+ - ext/ddtrace_profiling_native_extension/time_helpers.c
126
+ - ext/ddtrace_profiling_native_extension/time_helpers.h
121
127
  - lib/datadog/appsec.rb
122
128
  - lib/datadog/appsec/assets.rb
123
129
  - lib/datadog/appsec/assets/blocked.html
@@ -204,6 +210,7 @@ files:
204
210
  - lib/datadog/core/configuration/base.rb
205
211
  - lib/datadog/core/configuration/components.rb
206
212
  - lib/datadog/core/configuration/dependency_resolver.rb
213
+ - lib/datadog/core/configuration/ext.rb
207
214
  - lib/datadog/core/configuration/option.rb
208
215
  - lib/datadog/core/configuration/option_definition.rb
209
216
  - lib/datadog/core/configuration/option_definition_set.rb
@@ -211,7 +218,6 @@ files:
211
218
  - lib/datadog/core/configuration/options.rb
212
219
  - lib/datadog/core/configuration/settings.rb
213
220
  - lib/datadog/core/diagnostics/environment_logger.rb
214
- - lib/datadog/core/diagnostics/ext.rb
215
221
  - lib/datadog/core/diagnostics/health.rb
216
222
  - lib/datadog/core/encoding.rb
217
223
  - lib/datadog/core/environment/cgroup.rb
@@ -307,6 +313,8 @@ files:
307
313
  - lib/datadog/profiling/collectors/code_provenance.rb
308
314
  - lib/datadog/profiling/collectors/cpu_and_wall_time.rb
309
315
  - lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb
316
+ - lib/datadog/profiling/collectors/dynamic_sampling_rate.rb
317
+ - lib/datadog/profiling/collectors/idle_sampling_helper.rb
310
318
  - lib/datadog/profiling/collectors/old_stack.rb
311
319
  - lib/datadog/profiling/collectors/stack.rb
312
320
  - lib/datadog/profiling/encoding/profile.rb
@@ -344,6 +352,7 @@ files:
344
352
  - lib/datadog/tracing/buffer.rb
345
353
  - lib/datadog/tracing/client_ip.rb
346
354
  - lib/datadog/tracing/configuration/ext.rb
355
+ - lib/datadog/tracing/configuration/settings.rb
347
356
  - lib/datadog/tracing/context.rb
348
357
  - lib/datadog/tracing/context_provider.rb
349
358
  - lib/datadog/tracing/contrib.rb
@@ -631,6 +640,7 @@ files:
631
640
  - lib/datadog/tracing/contrib/redis/patcher.rb
632
641
  - lib/datadog/tracing/contrib/redis/quantize.rb
633
642
  - lib/datadog/tracing/contrib/redis/tags.rb
643
+ - lib/datadog/tracing/contrib/redis/trace_middleware.rb
634
644
  - lib/datadog/tracing/contrib/redis/vendor/LICENSE
635
645
  - lib/datadog/tracing/contrib/redis/vendor/resolver.rb
636
646
  - lib/datadog/tracing/contrib/registerable.rb
@@ -698,14 +708,18 @@ files:
698
708
  - lib/datadog/tracing/contrib/utils/quantization/hash.rb
699
709
  - lib/datadog/tracing/contrib/utils/quantization/http.rb
700
710
  - lib/datadog/tracing/correlation.rb
701
- - lib/datadog/tracing/distributed/b3.rb
711
+ - lib/datadog/tracing/diagnostics/ext.rb
712
+ - lib/datadog/tracing/diagnostics/health.rb
713
+ - lib/datadog/tracing/distributed/b3_multi.rb
702
714
  - lib/datadog/tracing/distributed/b3_single.rb
703
715
  - lib/datadog/tracing/distributed/datadog.rb
704
716
  - lib/datadog/tracing/distributed/datadog_tags_codec.rb
705
717
  - lib/datadog/tracing/distributed/fetcher.rb
706
718
  - lib/datadog/tracing/distributed/headers/ext.rb
707
719
  - lib/datadog/tracing/distributed/helpers.rb
720
+ - lib/datadog/tracing/distributed/none.rb
708
721
  - lib/datadog/tracing/distributed/propagation.rb
722
+ - lib/datadog/tracing/distributed/trace_context.rb
709
723
  - lib/datadog/tracing/event.rb
710
724
  - lib/datadog/tracing/flush.rb
711
725
  - lib/datadog/tracing/metadata.rb
@@ -741,6 +755,7 @@ files:
741
755
  - lib/datadog/tracing/trace_operation.rb
742
756
  - lib/datadog/tracing/trace_segment.rb
743
757
  - lib/datadog/tracing/tracer.rb
758
+ - lib/datadog/tracing/utils.rb
744
759
  - lib/datadog/tracing/workers.rb
745
760
  - lib/datadog/tracing/workers/trace_writer.rb
746
761
  - lib/datadog/tracing/writer.rb
@@ -801,7 +816,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
801
816
  - !ruby/object:Gem::Version
802
817
  version: 2.0.0
803
818
  requirements: []
804
- rubygems_version: 3.1.6
819
+ rubygems_version: 3.3.26
805
820
  signing_key:
806
821
  specification_version: 4
807
822
  summary: Datadog tracing code for your Ruby applications