datadog 2.0.0 → 2.2.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 (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +66 -2
  3. data/README.md +1 -1
  4. data/ext/datadog_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +19 -1
  5. data/ext/datadog_profiling_native_extension/collectors_stack.c +41 -0
  6. data/ext/datadog_profiling_native_extension/collectors_thread_context.c +1 -1
  7. data/ext/datadog_profiling_native_extension/crashtracker.c +1 -1
  8. data/ext/datadog_profiling_native_extension/extconf.rb +6 -4
  9. data/ext/datadog_profiling_native_extension/native_extension_helpers.rb +47 -1
  10. data/ext/datadog_profiling_native_extension/setup_signal_handler.c +1 -1
  11. data/ext/datadog_profiling_native_extension/stack_recorder.c +13 -6
  12. data/ext/datadog_profiling_native_extension/stack_recorder.h +1 -0
  13. data/lib/datadog/appsec/configuration/settings.rb +5 -0
  14. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +0 -1
  15. data/lib/datadog/appsec/contrib/sinatra/patcher.rb +1 -1
  16. data/lib/datadog/appsec/extensions.rb +1 -0
  17. data/lib/datadog/core/configuration/components.rb +6 -3
  18. data/lib/datadog/core/configuration/ext.rb +1 -0
  19. data/lib/datadog/core/configuration/option.rb +21 -14
  20. data/lib/datadog/core/configuration/options.rb +5 -1
  21. data/lib/datadog/core/configuration/settings.rb +68 -5
  22. data/lib/datadog/core/configuration.rb +3 -17
  23. data/lib/datadog/core/deprecations.rb +58 -0
  24. data/lib/datadog/core/environment/ext.rb +2 -0
  25. data/lib/datadog/core/environment/yjit.rb +5 -0
  26. data/lib/datadog/core/runtime/ext.rb +2 -0
  27. data/lib/datadog/core/runtime/metrics.rb +6 -0
  28. data/lib/datadog/core/telemetry/component.rb +107 -0
  29. data/lib/datadog/core/telemetry/event.rb +124 -31
  30. data/lib/datadog/core/telemetry/ext.rb +2 -0
  31. data/lib/datadog/core/telemetry/http/adapters/net.rb +1 -1
  32. data/lib/datadog/core/telemetry/metric.rb +167 -0
  33. data/lib/datadog/core/telemetry/metrics_collection.rb +81 -0
  34. data/lib/datadog/core/telemetry/metrics_manager.rb +81 -0
  35. data/lib/datadog/core/telemetry/request.rb +1 -1
  36. data/lib/datadog/core/telemetry/worker.rb +173 -0
  37. data/lib/datadog/core/utils/only_once_successful.rb +76 -0
  38. data/lib/datadog/core.rb +2 -19
  39. data/lib/datadog/opentelemetry/sdk/propagator.rb +5 -10
  40. data/lib/datadog/opentelemetry/sdk/span_processor.rb +5 -2
  41. data/lib/datadog/profiling/collectors/code_provenance.rb +18 -5
  42. data/lib/datadog/profiling/component.rb +18 -1
  43. data/lib/datadog/profiling/ext/dir_monkey_patches.rb +410 -0
  44. data/lib/datadog/profiling.rb +1 -0
  45. data/lib/datadog/tracing/configuration/ext.rb +7 -0
  46. data/lib/datadog/tracing/configuration/settings.rb +52 -3
  47. data/lib/datadog/tracing/contrib/action_cable/event.rb +1 -1
  48. data/lib/datadog/tracing/contrib/action_cable/events/broadcast.rb +1 -1
  49. data/lib/datadog/tracing/contrib/action_cable/events/perform_action.rb +1 -1
  50. data/lib/datadog/tracing/contrib/action_cable/events/transmit.rb +1 -1
  51. data/lib/datadog/tracing/contrib/action_mailer/event.rb +4 -6
  52. data/lib/datadog/tracing/contrib/action_mailer/events/deliver.rb +9 -4
  53. data/lib/datadog/tracing/contrib/action_mailer/events/process.rb +3 -2
  54. data/lib/datadog/tracing/contrib/action_view/events/render_partial.rb +1 -5
  55. data/lib/datadog/tracing/contrib/action_view/events/render_template.rb +1 -1
  56. data/lib/datadog/tracing/contrib/active_job/events/discard.rb +1 -1
  57. data/lib/datadog/tracing/contrib/active_job/events/enqueue.rb +1 -1
  58. data/lib/datadog/tracing/contrib/active_job/events/enqueue_at.rb +1 -1
  59. data/lib/datadog/tracing/contrib/active_job/events/enqueue_retry.rb +1 -1
  60. data/lib/datadog/tracing/contrib/active_job/events/perform.rb +1 -1
  61. data/lib/datadog/tracing/contrib/active_job/events/retry_stopped.rb +1 -1
  62. data/lib/datadog/tracing/contrib/active_model_serializers/events/render.rb +1 -1
  63. data/lib/datadog/tracing/contrib/active_model_serializers/events/serialize.rb +1 -1
  64. data/lib/datadog/tracing/contrib/active_record/events/instantiation.rb +1 -1
  65. data/lib/datadog/tracing/contrib/active_record/events/sql.rb +1 -1
  66. data/lib/datadog/tracing/contrib/active_support/cache/event.rb +32 -0
  67. data/lib/datadog/tracing/contrib/active_support/cache/events/cache.rb +156 -0
  68. data/lib/datadog/tracing/contrib/active_support/cache/events.rb +34 -0
  69. data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +45 -41
  70. data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +17 -40
  71. data/lib/datadog/tracing/contrib/active_support/cache/redis.rb +4 -1
  72. data/lib/datadog/tracing/contrib/active_support/notifications/event.rb +29 -6
  73. data/lib/datadog/tracing/contrib/active_support/notifications/subscriber.rb +16 -4
  74. data/lib/datadog/tracing/contrib/active_support/notifications/subscription.rb +33 -29
  75. data/lib/datadog/tracing/contrib/analytics.rb +5 -0
  76. data/lib/datadog/tracing/contrib/graphql/configuration/settings.rb +5 -0
  77. data/lib/datadog/tracing/contrib/graphql/patcher.rb +8 -2
  78. data/lib/datadog/tracing/contrib/graphql/unified_trace.rb +166 -0
  79. data/lib/datadog/tracing/contrib/graphql/unified_trace_patcher.rb +25 -0
  80. data/lib/datadog/tracing/contrib/kafka/consumer_event.rb +1 -1
  81. data/lib/datadog/tracing/contrib/kafka/consumer_group_event.rb +1 -1
  82. data/lib/datadog/tracing/contrib/kafka/event.rb +1 -1
  83. data/lib/datadog/tracing/contrib/kafka/events/connection/request.rb +3 -3
  84. data/lib/datadog/tracing/contrib/kafka/events/consumer/process_batch.rb +3 -3
  85. data/lib/datadog/tracing/contrib/kafka/events/consumer/process_message.rb +3 -3
  86. data/lib/datadog/tracing/contrib/kafka/events/consumer_group/heartbeat.rb +3 -3
  87. data/lib/datadog/tracing/contrib/kafka/events/produce_operation/send_messages.rb +3 -3
  88. data/lib/datadog/tracing/contrib/kafka/events/producer/deliver_messages.rb +3 -3
  89. data/lib/datadog/tracing/contrib/racecar/event.rb +2 -2
  90. data/lib/datadog/tracing/contrib/rails/ext.rb +9 -0
  91. data/lib/datadog/tracing/contrib/rails/patcher.rb +7 -0
  92. data/lib/datadog/tracing/contrib/rails/runner.rb +95 -0
  93. data/lib/datadog/tracing/distributed/b3_multi.rb +1 -1
  94. data/lib/datadog/tracing/distributed/b3_single.rb +3 -1
  95. data/lib/datadog/tracing/distributed/datadog.rb +2 -2
  96. data/lib/datadog/tracing/distributed/propagation.rb +39 -4
  97. data/lib/datadog/tracing/distributed/trace_context.rb +5 -3
  98. data/lib/datadog/tracing/metadata/ext.rb +1 -0
  99. data/lib/datadog/tracing/span_operation.rb +3 -2
  100. data/lib/datadog/tracing/trace_operation.rb +7 -3
  101. data/lib/datadog/tracing/trace_segment.rb +4 -1
  102. data/lib/datadog/tracing/tracer.rb +9 -2
  103. data/lib/datadog/tracing.rb +5 -1
  104. data/lib/datadog/version.rb +2 -2
  105. metadata +21 -8
  106. data/lib/datadog/core/telemetry/client.rb +0 -95
  107. data/lib/datadog/core/telemetry/heartbeat.rb +0 -33
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datadog
4
+ module Tracing
5
+ module Contrib
6
+ module Rails
7
+ # Instruments the `bin/rails runner` command.
8
+ # This command executes the provided code with the host Rails application loaded.
9
+ # The command can be either:
10
+ # * `-`: for code provided through the STDIN.
11
+ # * File path: for code provided through a local file.
12
+ # * `inline code`: for code provided directly as a command line argument.
13
+ # @see https://guides.rubyonrails.org/v6.1/command_line.html#bin-rails-runner
14
+ module Runner
15
+ # Limit the maximum size of the source code captured in the source tag.
16
+ MAX_TAG_VALUE_SIZE = 4096
17
+ private_constant :MAX_TAG_VALUE_SIZE
18
+
19
+ def runner(code_or_file = nil, *_command_argv)
20
+ if code_or_file == '-'
21
+ name = Ext::SPAN_RUNNER_STDIN
22
+ resource = nil
23
+ operation = Ext::TAG_OPERATION_STDIN
24
+ # The source is not yet available for STDIN, but it will be captured in `eval`.
25
+ elsif File.exist?(code_or_file)
26
+ name = Ext::SPAN_RUNNER_FILE
27
+ resource = code_or_file
28
+ operation = Ext::TAG_OPERATION_FILE
29
+ source = File.read(code_or_file)
30
+ else
31
+ name = Ext::SPAN_RUNNER_INLINE
32
+ resource = nil
33
+ operation = Ext::TAG_OPERATION_INLINE
34
+ source = code_or_file
35
+ end
36
+
37
+ Tracing.trace(
38
+ name,
39
+ service: Datadog.configuration.tracing[:rails][:service_name],
40
+ resource: resource,
41
+ tags: {
42
+ Tracing::Metadata::Ext::TAG_COMPONENT => Ext::TAG_COMPONENT,
43
+ Tracing::Metadata::Ext::TAG_OPERATION => operation,
44
+ }
45
+ ) do |span|
46
+ if source
47
+ span.set_tag(
48
+ Ext::TAG_RUNNER_SOURCE,
49
+ Core::Utils.truncate(source, MAX_TAG_VALUE_SIZE)
50
+ )
51
+ end
52
+ Contrib::Analytics.set_rate!(span, Datadog.configuration.tracing[:rails])
53
+
54
+ super
55
+ end
56
+ end
57
+
58
+ # Capture the executed source code when provided from STDIN.
59
+ def eval(*args)
60
+ span = Datadog::Tracing.active_span
61
+ if span.name == Ext::SPAN_RUNNER_STDIN
62
+ source = args[0]
63
+ span.set_tag(
64
+ Ext::TAG_RUNNER_SOURCE,
65
+ Core::Utils.truncate(source, MAX_TAG_VALUE_SIZE)
66
+ )
67
+ end
68
+
69
+ super
70
+ end
71
+
72
+ ruby2_keywords :eval if respond_to?(:ruby2_keywords, true)
73
+ end
74
+
75
+ # The instrumentation target, {Rails::Command::RunnerCommand} is only loaded
76
+ # right before `bin/rails runner` is executed. This means there's not much
77
+ # opportunity to patch it ahead of time.
78
+ # To ensure we can patch it successfully, we patch it's caller, {Rails::Command}
79
+ # and promptly patch {Rails::Command::RunnerCommand} when it is loaded.
80
+ module Command
81
+ def find_by_namespace(*args)
82
+ ret = super
83
+ # Patch RunnerCommand if it is loaded and not already patched.
84
+ if defined?(::Rails::Command::RunnerCommand) && !(::Rails::Command::RunnerCommand < Runner)
85
+ ::Rails::Command::RunnerCommand.prepend(Runner)
86
+ end
87
+ ret
88
+ end
89
+
90
+ ruby2_keywords :find_by_namespace if respond_to?(:ruby2_keywords, true)
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -31,7 +31,7 @@ module Datadog
31
31
 
32
32
  # DEV: We need these to be hex encoded
33
33
  data[@trace_id_key] = format('%032x', digest.trace_id)
34
- data[@span_id_key] = format('%016x', digest.span_id)
34
+ data[@span_id_key] = format('%016x', digest.span_id || 0) # # Fall back to zero (invalid) if not present
35
35
 
36
36
  if digest.trace_sampling_priority
37
37
  sampling_priority = Helpers.clamp_sampling_priority(
@@ -25,8 +25,10 @@ module Datadog
25
25
  def inject!(digest, env)
26
26
  return if digest.nil?
27
27
 
28
+ span_id = digest.span_id || 0 # Fall back to zero (invalid) if not present
29
+
28
30
  # DEV: We need these to be hex encoded
29
- value = "#{format('%032x', digest.trace_id)}-#{format('%016x', digest.span_id)}"
31
+ value = "#{format('%032x', digest.trace_id)}-#{format('%016x', span_id)}"
30
32
 
31
33
  if digest.trace_sampling_priority
32
34
  sampling_priority = Helpers.clamp_sampling_priority(
@@ -42,7 +42,7 @@ module Datadog
42
42
 
43
43
  data[@trace_id_key] = Tracing::Utils::TraceId.to_low_order(digest.trace_id).to_s
44
44
 
45
- data[@parent_id_key] = digest.span_id.to_s
45
+ data[@parent_id_key] = digest.span_id.to_s if digest.span_id
46
46
  data[@sampling_priority_key] = digest.trace_sampling_priority.to_s if digest.trace_sampling_priority
47
47
  data[@origin_key] = digest.trace_origin.to_s if digest.trace_origin
48
48
 
@@ -109,7 +109,7 @@ module Datadog
109
109
 
110
110
  return tags if high_order == 0
111
111
 
112
- tags.merge(Tracing::Metadata::Ext::Distributed::TAG_TID => high_order.to_s(16))
112
+ tags.merge(Tracing::Metadata::Ext::Distributed::TAG_TID => format('%016x', high_order))
113
113
  end
114
114
 
115
115
  # Side effect: Remove high order 64 bit hex-encoded `tid` tag from distributed tags
@@ -32,7 +32,9 @@ module Datadog
32
32
 
33
33
  # inject! populates the env with span ID, trace ID and sampling priority
34
34
  #
35
- # This method will never raise errors, but instead log them to `Datadog.logger`.
35
+ # This method will never raise errors.
36
+ # It can propagate partial data, if deemed useful, instead of failing.
37
+ # In case of unrecoverable errors, it will log them to `Datadog.logger`.
36
38
  #
37
39
  # DEV-2.0: inject! should work without arguments, injecting the active_trace's digest
38
40
  # DEV-2.0: and returning a new Hash with the injected data.
@@ -45,7 +47,7 @@ module Datadog
45
47
  # @param digest [TraceDigest]
46
48
  # @param data [Hash]
47
49
  # @return [Boolean] `true` if injected successfully, `false` if no propagation style is configured
48
- # @return [nil] in case of error, see `Datadog.logger` output for details.
50
+ # @return [nil] in case of unrecoverable errors, see `Datadog.logger` output for details.
49
51
  def inject!(digest, data)
50
52
  if digest.nil?
51
53
  ::Datadog.logger.debug('Cannot inject distributed trace data: digest is nil.')
@@ -54,6 +56,11 @@ module Datadog
54
56
 
55
57
  digest = digest.to_digest if digest.respond_to?(:to_digest)
56
58
 
59
+ if digest.trace_id.nil?
60
+ ::Datadog.logger.debug('Cannot inject distributed trace data: digest.trace_id is nil.')
61
+ return nil
62
+ end
63
+
57
64
  result = false
58
65
 
59
66
  # Inject all configured propagation styles
@@ -101,10 +108,22 @@ module Datadog
101
108
  # Only parse if it represent the same trace as the successfully extracted one
102
109
  next unless tracecontext_digest.trace_id == extracted_trace_digest.trace_id
103
110
 
104
- # Preserve the `tracestate`
111
+ parent_id = extracted_trace_digest.span_id
112
+ distributed_tags = extracted_trace_digest.trace_distributed_tags
113
+ unless extracted_trace_digest.span_id == tracecontext_digest.span_id
114
+ # span_id in the tracecontext header takes precedence over the value in all conflicting headers
115
+ parent_id = tracecontext_digest.span_id
116
+ if (lp_id = last_datadog_parent_id(data, tracecontext_digest.trace_distributed_tags))
117
+ distributed_tags = extracted_trace_digest.trace_distributed_tags&.dup || {}
118
+ distributed_tags[Tracing::Metadata::Ext::Distributed::TAG_DD_PARENT_ID] = lp_id
119
+ end
120
+ end
121
+ # Preserve the trace state and last datadog span id
105
122
  extracted_trace_digest = extracted_trace_digest.merge(
123
+ span_id: parent_id,
106
124
  trace_state: tracecontext_digest.trace_state,
107
- trace_state_unknown_fields: tracecontext_digest.trace_state_unknown_fields
125
+ trace_state_unknown_fields: tracecontext_digest.trace_state_unknown_fields,
126
+ trace_distributed_tags: distributed_tags
108
127
  )
109
128
  end
110
129
  rescue => e
@@ -115,6 +134,22 @@ module Datadog
115
134
 
116
135
  extracted_trace_digest
117
136
  end
137
+
138
+ private
139
+
140
+ def last_datadog_parent_id(headers, tracecontext_tags)
141
+ dd_propagator = @propagation_style_extract.find { |propagator| propagator.is_a?(Datadog) }
142
+ if tracecontext_tags&.fetch(
143
+ Tracing::Metadata::Ext::Distributed::TAG_DD_PARENT_ID,
144
+ Tracing::Metadata::Ext::Distributed::DD_PARENT_ID_DEFAULT
145
+ ) != Tracing::Metadata::Ext::Distributed::DD_PARENT_ID_DEFAULT
146
+ # tracecontext headers contain a p value, ensure this value is sent to backend
147
+ tracecontext_tags[Tracing::Metadata::Ext::Distributed::TAG_DD_PARENT_ID]
148
+ elsif dd_propagator && (dd_digest = dd_propagator.extract(headers))
149
+ # if p value is not present in tracestate, use the parent id from the datadog headers
150
+ format('%016x', dd_digest.span_id)
151
+ end
152
+ end
118
153
  end
119
154
  end
120
155
  end
@@ -57,7 +57,8 @@ module Datadog
57
57
  end
58
58
 
59
59
  tags ||= {}
60
- tags[Tracing::Metadata::Ext::Distributed::TAG_DD_PARENT_ID] = ts_parent_id || '0000000000000000'
60
+ tags[Tracing::Metadata::Ext::Distributed::TAG_DD_PARENT_ID] =
61
+ ts_parent_id || Tracing::Metadata::Ext::Distributed::DD_PARENT_ID_DEFAULT
61
62
 
62
63
  TraceDigest.new(
63
64
  span_id: parent_id,
@@ -106,7 +107,7 @@ module Datadog
106
107
  def build_traceparent(digest)
107
108
  build_traceparent_string(
108
109
  digest.trace_id,
109
- digest.span_id,
110
+ digest.span_id || 0, # Fall back to zero (invalid) if not present
110
111
  build_trace_flags(digest)
111
112
  )
112
113
  end
@@ -197,7 +198,8 @@ module Datadog
197
198
 
198
199
  def last_dd_parent_id(digest)
199
200
  if !digest.span_remote
200
- "p:#{format('%016x', digest.span_id)};"
201
+ span_id = digest.span_id || 0 # Fall back to zero (invalid) if not present
202
+ "p:#{format('%016x', span_id)};"
201
203
  elsif digest.trace_distributed_tags&.key?(Tracing::Metadata::Ext::Distributed::TAG_DD_PARENT_ID)
202
204
  "p:#{digest.trace_distributed_tags[Tracing::Metadata::Ext::Distributed::TAG_DD_PARENT_ID]};"
203
205
  else
@@ -55,6 +55,7 @@ module Datadog
55
55
  TAG_SAMPLING_PRIORITY = '_sampling_priority_v1'
56
56
 
57
57
  TAG_DD_PARENT_ID = '_dd.parent_id'
58
+ DD_PARENT_ID_DEFAULT = '0000000000000000'
58
59
 
59
60
  # Trace tags with this prefix will propagate from a trace through distributed tracing.
60
61
  # Distributed headers tags with this prefix will be injected into the active trace.
@@ -48,7 +48,8 @@ module Datadog
48
48
  tags: nil,
49
49
  trace_id: nil,
50
50
  type: nil,
51
- links: nil
51
+ links: nil,
52
+ id: nil
52
53
  )
53
54
  # Ensure dynamically created strings are UTF-8 encoded.
54
55
  #
@@ -60,7 +61,7 @@ module Datadog
60
61
  self.type = type
61
62
  self.resource = resource
62
63
 
63
- @id = Tracing::Utils.next_id
64
+ @id = id.nil? ? Tracing::Utils.next_id : id
64
65
  @parent_id = parent_id || 0
65
66
  @trace_id = trace_id || Tracing::Utils::TraceId.next_id
66
67
 
@@ -181,6 +181,7 @@ module Datadog
181
181
  start_time: nil,
182
182
  tags: nil,
183
183
  type: nil,
184
+ id: nil,
184
185
  &block
185
186
  )
186
187
  # Don't allow more span measurements if the
@@ -197,7 +198,8 @@ module Datadog
197
198
  service: service,
198
199
  start_time: start_time,
199
200
  tags: tags,
200
- type: type
201
+ type: type,
202
+ id: id
201
203
  )
202
204
 
203
205
  # Start span measurement
@@ -212,7 +214,8 @@ module Datadog
212
214
  service: nil,
213
215
  start_time: nil,
214
216
  tags: nil,
215
- type: nil
217
+ type: nil,
218
+ id: nil
216
219
  )
217
220
  begin
218
221
  # Resolve span options:
@@ -249,7 +252,8 @@ module Datadog
249
252
  start_time: start_time,
250
253
  tags: tags,
251
254
  trace_id: trace_id,
252
- type: type
255
+ type: type,
256
+ id: id
253
257
  )
254
258
  rescue StandardError => e
255
259
  Datadog.logger.debug { "Failed to build new span: #{e}" }
@@ -132,10 +132,13 @@ module Datadog
132
132
  || sampling_priority == Sampling::Ext::Priority::USER_KEEP
133
133
  end
134
134
 
135
+ # Returns the high order part of the trace id as a hexadecimal string; the most significant 64 bits.
136
+ # The String returned is padded with zeros, having a fixed length of 16 characters.
137
+ # If the high order part is zero, it returns nil.
135
138
  def high_order_tid
136
139
  high_order = Tracing::Utils::TraceId.to_high_order(@id)
137
140
 
138
- high_order.to_s(16) if high_order != 0
141
+ format('%016x', high_order) if high_order != 0
139
142
  end
140
143
 
141
144
  protected
@@ -114,6 +114,7 @@ module Datadog
114
114
  # @param [Time] start_time time which the span should have started.
115
115
  # @param [Hash<String,String>] tags extra tags which should be added to the span.
116
116
  # @param [String] type the type of the span. See {Datadog::Tracing::Metadata::Ext::AppTypes}.
117
+ # @param [Integer] the id of the new span.
117
118
  # @return [Object] If a block is provided, returns the result of the block execution.
118
119
  # @return [Datadog::Tracing::SpanOperation] If no block is provided, returns the active,
119
120
  # unfinished {Datadog::Tracing::SpanOperation}.
@@ -130,6 +131,7 @@ module Datadog
130
131
  start_time: nil,
131
132
  tags: nil,
132
133
  type: nil,
134
+ id: nil,
133
135
  &block
134
136
  )
135
137
  return skip_trace(name, &block) unless enabled
@@ -162,6 +164,7 @@ module Datadog
162
164
  tags: tags,
163
165
  type: type,
164
166
  _trace: trace,
167
+ id: id,
165
168
  &block
166
169
  )
167
170
  end
@@ -178,7 +181,8 @@ module Datadog
178
181
  start_time: start_time,
179
182
  tags: tags,
180
183
  type: type,
181
- _trace: trace
184
+ _trace: trace,
185
+ id: id
182
186
  )
183
187
  end
184
188
  end
@@ -375,6 +379,7 @@ module Datadog
375
379
  tags: nil,
376
380
  type: nil,
377
381
  _trace: nil,
382
+ id: nil,
378
383
  &block
379
384
  )
380
385
  trace = _trace || start_trace(continue_from: continue_from)
@@ -391,6 +396,7 @@ module Datadog
391
396
  service: service,
392
397
  tags: resolve_tags(tags),
393
398
  type: type,
399
+ id: id,
394
400
  &block
395
401
  )
396
402
  else
@@ -403,7 +409,8 @@ module Datadog
403
409
  service: service,
404
410
  start_time: start_time,
405
411
  tags: resolve_tags(tags),
406
- type: type
412
+ type: type,
413
+ id: id
407
414
  )
408
415
 
409
416
  span.start(start_time)
@@ -23,6 +23,7 @@ module Datadog
23
23
  start_time: nil,
24
24
  tags: nil,
25
25
  type: nil,
26
+ id: nil,
26
27
  &block
27
28
  )
28
29
 
@@ -35,6 +36,7 @@ module Datadog
35
36
  start_time: start_time,
36
37
  tags: tags,
37
38
  type: type,
39
+ id: id,
38
40
  &block
39
41
  )
40
42
  end
@@ -117,9 +119,11 @@ module Datadog
117
119
  # # dd.env=prod dd.service=auth dd.version=13.8 dd.trace_id=5458478252992251 dd.span_id=7117552347370098 My message
118
120
  # ```
119
121
  #
120
- # @return [String] correlation information
122
+ # @return [String] correlation information; or an empty String if Tracing is disabled (`!enabled?`)
121
123
  # @public_api
122
124
  def log_correlation
125
+ return '' unless enabled?
126
+
123
127
  correlation.to_log_format
124
128
  end
125
129
 
@@ -3,7 +3,7 @@
3
3
  module Datadog
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 0
6
+ MINOR = 2
7
7
  PATCH = 0
8
8
  PRE = nil
9
9
  BUILD = nil
@@ -21,6 +21,6 @@ module Datadog
21
21
  # To allow testing with the next unreleased version of Ruby, the version check is performed
22
22
  # as `< #{MAXIMUM_RUBY_VERSION}`, meaning prereleases of MAXIMUM_RUBY_VERSION are allowed
23
23
  # but not stable MAXIMUM_RUBY_VERSION releases.
24
- MAXIMUM_RUBY_VERSION = '3.4'
24
+ MAXIMUM_RUBY_VERSION = '3.5'
25
25
  end
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datadog
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.2.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: 2024-06-06 00:00:00.000000000 Z
11
+ date: 2024-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 9.0.0.1.0
61
+ version: 10.0.0.1.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 9.0.0.1.0
68
+ version: 10.0.0.1.0
69
69
  description: |
70
70
  datadog is Datadog's client library for Ruby. It includes a suite of tools
71
71
  which provide visibility into the performance and security of Ruby applications,
@@ -223,6 +223,7 @@ files:
223
223
  - lib/datadog/core/configuration/option_definition.rb
224
224
  - lib/datadog/core/configuration/options.rb
225
225
  - lib/datadog/core/configuration/settings.rb
226
+ - lib/datadog/core/deprecations.rb
226
227
  - lib/datadog/core/diagnostics/environment_logger.rb
227
228
  - lib/datadog/core/diagnostics/health.rb
228
229
  - lib/datadog/core/encoding.rb
@@ -281,17 +282,20 @@ files:
281
282
  - lib/datadog/core/remote/worker.rb
282
283
  - lib/datadog/core/runtime/ext.rb
283
284
  - lib/datadog/core/runtime/metrics.rb
284
- - lib/datadog/core/telemetry/client.rb
285
+ - lib/datadog/core/telemetry/component.rb
285
286
  - lib/datadog/core/telemetry/emitter.rb
286
287
  - lib/datadog/core/telemetry/event.rb
287
288
  - lib/datadog/core/telemetry/ext.rb
288
- - lib/datadog/core/telemetry/heartbeat.rb
289
289
  - lib/datadog/core/telemetry/http/adapters/net.rb
290
290
  - lib/datadog/core/telemetry/http/env.rb
291
291
  - lib/datadog/core/telemetry/http/ext.rb
292
292
  - lib/datadog/core/telemetry/http/response.rb
293
293
  - lib/datadog/core/telemetry/http/transport.rb
294
+ - lib/datadog/core/telemetry/metric.rb
295
+ - lib/datadog/core/telemetry/metrics_collection.rb
296
+ - lib/datadog/core/telemetry/metrics_manager.rb
294
297
  - lib/datadog/core/telemetry/request.rb
298
+ - lib/datadog/core/telemetry/worker.rb
295
299
  - lib/datadog/core/transport/ext.rb
296
300
  - lib/datadog/core/transport/http/adapters/net.rb
297
301
  - lib/datadog/core/transport/http/adapters/registry.rb
@@ -312,6 +316,7 @@ files:
312
316
  - lib/datadog/core/utils/hash.rb
313
317
  - lib/datadog/core/utils/network.rb
314
318
  - lib/datadog/core/utils/only_once.rb
319
+ - lib/datadog/core/utils/only_once_successful.rb
315
320
  - lib/datadog/core/utils/safe_dup.rb
316
321
  - lib/datadog/core/utils/sequence.rb
317
322
  - lib/datadog/core/utils/time.rb
@@ -355,6 +360,7 @@ files:
355
360
  - lib/datadog/profiling/crashtracker.rb
356
361
  - lib/datadog/profiling/exporter.rb
357
362
  - lib/datadog/profiling/ext.rb
363
+ - lib/datadog/profiling/ext/dir_monkey_patches.rb
358
364
  - lib/datadog/profiling/ext/forking.rb
359
365
  - lib/datadog/profiling/flush.rb
360
366
  - lib/datadog/profiling/http_transport.rb
@@ -447,6 +453,9 @@ files:
447
453
  - lib/datadog/tracing/contrib/active_record/integration.rb
448
454
  - lib/datadog/tracing/contrib/active_record/patcher.rb
449
455
  - lib/datadog/tracing/contrib/active_record/utils.rb
456
+ - lib/datadog/tracing/contrib/active_support/cache/event.rb
457
+ - lib/datadog/tracing/contrib/active_support/cache/events.rb
458
+ - lib/datadog/tracing/contrib/active_support/cache/events/cache.rb
450
459
  - lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb
451
460
  - lib/datadog/tracing/contrib/active_support/cache/patcher.rb
452
461
  - lib/datadog/tracing/contrib/active_support/cache/redis.rb
@@ -536,6 +545,8 @@ files:
536
545
  - lib/datadog/tracing/contrib/graphql/patcher.rb
537
546
  - lib/datadog/tracing/contrib/graphql/trace_patcher.rb
538
547
  - lib/datadog/tracing/contrib/graphql/tracing_patcher.rb
548
+ - lib/datadog/tracing/contrib/graphql/unified_trace.rb
549
+ - lib/datadog/tracing/contrib/graphql/unified_trace_patcher.rb
539
550
  - lib/datadog/tracing/contrib/grpc.rb
540
551
  - lib/datadog/tracing/contrib/grpc/configuration/settings.rb
541
552
  - lib/datadog/tracing/contrib/grpc/datadog_interceptor.rb
@@ -664,6 +675,7 @@ files:
664
675
  - lib/datadog/tracing/contrib/rails/middlewares.rb
665
676
  - lib/datadog/tracing/contrib/rails/patcher.rb
666
677
  - lib/datadog/tracing/contrib/rails/railtie.rb
678
+ - lib/datadog/tracing/contrib/rails/runner.rb
667
679
  - lib/datadog/tracing/contrib/rails/utils.rb
668
680
  - lib/datadog/tracing/contrib/rake/configuration/settings.rb
669
681
  - lib/datadog/tracing/contrib/rake/ext.rb
@@ -840,7 +852,8 @@ licenses:
840
852
  - Apache-2.0
841
853
  metadata:
842
854
  allowed_push_host: https://rubygems.org
843
- changelog_uri: https://github.com/DataDog/dd-trace-rb/blob/master/CHANGELOG.md
855
+ changelog_uri: https://github.com/DataDog/dd-trace-rb/blob/v2.2.0/CHANGELOG.md
856
+ source_code_uri: https://github.com/DataDog/dd-trace-rb/tree/v2.2.0
844
857
  post_install_message:
845
858
  rdoc_options: []
846
859
  require_paths:
@@ -852,7 +865,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
852
865
  version: 2.5.0
853
866
  - - "<"
854
867
  - !ruby/object:Gem::Version
855
- version: '3.4'
868
+ version: '3.5'
856
869
  required_rubygems_version: !ruby/object:Gem::Requirement
857
870
  requirements:
858
871
  - - ">="
@@ -1,95 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'emitter'
4
- require_relative 'event'
5
- require_relative 'heartbeat'
6
- require_relative '../utils/forking'
7
-
8
- module Datadog
9
- module Core
10
- module Telemetry
11
- # Telemetry entrypoint, coordinates sending telemetry events at various points in app lifecycle.
12
- class Client
13
- attr_reader \
14
- :enabled,
15
- :unsupported
16
-
17
- include Core::Utils::Forking
18
-
19
- # @param enabled [Boolean] Determines whether telemetry events should be sent to the API
20
- # @param heartbeat_interval_seconds [Float] How frequently heartbeats will be reported, in seconds.
21
- # @param [Boolean] dependency_collection Whether to send the `app-dependencies-loaded` event
22
- def initialize(heartbeat_interval_seconds:, dependency_collection:, enabled: true)
23
- @enabled = enabled
24
- @emitter = Emitter.new
25
- @stopped = false
26
- @unsupported = false
27
- @started = false
28
- @dependency_collection = dependency_collection
29
-
30
- @worker = Telemetry::Heartbeat.new(enabled: @enabled, heartbeat_interval_seconds: heartbeat_interval_seconds) do
31
- next unless @started # `started!` should be the first event, thus ensure that `heartbeat!` is not sent first.
32
-
33
- heartbeat!
34
- end
35
- end
36
-
37
- def disable!
38
- @enabled = false
39
- @worker.enabled = false
40
- end
41
-
42
- def started!
43
- return if !@enabled || forked?
44
-
45
- res = @emitter.request(Event::AppStarted.new)
46
-
47
- if res.not_found? # Telemetry is only supported by agent versions 7.34 and up
48
- Datadog.logger.debug('Agent does not support telemetry; disabling future telemetry events.')
49
- disable!
50
- @unsupported = true # Prevent telemetry from getting re-enabled
51
- return res
52
- end
53
-
54
- @emitter.request(Event::AppDependenciesLoaded.new) if @dependency_collection
55
-
56
- @started = true
57
- end
58
-
59
- def emit_closing!
60
- return if !@enabled || forked?
61
-
62
- @emitter.request(Event::AppClosing.new)
63
- end
64
-
65
- def stop!
66
- return if @stopped
67
-
68
- @worker.stop(true, 0)
69
- @stopped = true
70
- end
71
-
72
- def integrations_change!
73
- return if !@enabled || forked?
74
-
75
- @emitter.request(Event::AppIntegrationsChange.new)
76
- end
77
-
78
- # Report configuration changes caused by Remote Configuration.
79
- def client_configuration_change!(changes)
80
- return if !@enabled || forked?
81
-
82
- @emitter.request(Event::AppClientConfigurationChange.new(changes, 'remote_config'))
83
- end
84
-
85
- private
86
-
87
- def heartbeat!
88
- return if !@enabled || forked?
89
-
90
- @emitter.request(Event::AppHeartbeat.new)
91
- end
92
- end
93
- end
94
- end
95
- end