ddtrace 1.13.0 → 1.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -1
  3. data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +15 -0
  4. data/lib/datadog/appsec/configuration/settings.rb +7 -1
  5. data/lib/datadog/core/configuration/agent_settings_resolver.rb +9 -5
  6. data/lib/datadog/core/configuration/components.rb +2 -0
  7. data/lib/datadog/core/configuration/settings.rb +25 -2
  8. data/lib/datadog/core/diagnostics/environment_logger.rb +130 -234
  9. data/lib/datadog/core/environment/execution.rb +65 -0
  10. data/lib/datadog/core/telemetry/collector.rb +10 -2
  11. data/lib/datadog/profiling/component.rb +14 -4
  12. data/lib/datadog/profiling/diagnostics/environment_logger.rb +39 -0
  13. data/lib/datadog/profiling/exporter.rb +4 -4
  14. data/lib/datadog/profiling/flush.rb +2 -4
  15. data/lib/datadog/profiling/http_transport.rb +9 -2
  16. data/lib/datadog/profiling.rb +1 -0
  17. data/lib/datadog/tracing/component.rb +2 -1
  18. data/lib/datadog/tracing/contrib/active_record/configuration/resolver.rb +18 -11
  19. data/lib/datadog/tracing/contrib/active_record/utils.rb +1 -1
  20. data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +99 -102
  21. data/lib/datadog/tracing/contrib/http/instrumentation.rb +5 -2
  22. data/lib/datadog/tracing/contrib/lograge/instrumentation.rb +1 -17
  23. data/lib/datadog/tracing/contrib/rails/log_injection.rb +6 -3
  24. data/lib/datadog/tracing/contrib/rails/patcher.rb +1 -1
  25. data/lib/datadog/tracing/contrib/semantic_logger/instrumentation.rb +3 -20
  26. data/lib/datadog/tracing/contrib/utils/quantization/http.rb +9 -9
  27. data/lib/datadog/tracing/contrib.rb +1 -0
  28. data/lib/datadog/tracing/correlation.rb +20 -0
  29. data/lib/datadog/tracing/diagnostics/environment_logger.rb +159 -0
  30. data/lib/datadog/tracing/workers/trace_writer.rb +1 -1
  31. data/lib/ddtrace/version.rb +1 -1
  32. metadata +9 -6
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'date'
2
4
  require 'json'
3
5
  require 'rbconfig'
@@ -5,280 +7,174 @@ require 'rbconfig'
5
7
  module Datadog
6
8
  module Core
7
9
  module Diagnostics
8
- # A holistic collection of the environment in which ddtrace is running.
9
- # This logger should allow for easy reporting by users to Datadog support.
10
- #
11
- module EnvironmentLogger
12
- class << self
13
- # Outputs environment information to {Datadog.logger}.
14
- # Executes only once for the lifetime of the program.
15
- def log!(transport_responses)
16
- return if (defined?(@executed) && @executed) || !log?
17
-
18
- @executed = true
19
-
20
- data = EnvironmentCollector.new.collect!(transport_responses)
21
- data.reject! { |_, v| v.nil? } # Remove empty values from hash output
22
-
23
- log_environment!(data.to_json)
24
- log_error!('Agent Error'.freeze, data[:agent_error]) if data[:agent_error]
25
- rescue => e
26
- Datadog.logger.warn("Failed to collect environment information: #{e} Location: #{Array(e.backtrace).first}")
27
- end
28
-
29
- private
30
-
31
- def log_environment!(line)
32
- Datadog.logger.info("DATADOG CONFIGURATION - #{line}")
33
- end
34
-
35
- def log_error!(type, error)
36
- Datadog.logger.warn("DATADOG DIAGNOSTIC - #{type}: #{error}")
37
- end
38
-
39
- # Are we logging the environment data?
40
- def log?
41
- startup_logs_enabled = Datadog.configuration.diagnostics.startup_logs.enabled
42
- if startup_logs_enabled.nil?
43
- !repl? # Suppress logs if we running in a REPL
44
- else
45
- startup_logs_enabled
46
- end
47
- end
48
-
49
- REPL_PROGRAM_NAMES = %w[irb pry].freeze
50
-
51
- def repl?
52
- REPL_PROGRAM_NAMES.include?($PROGRAM_NAME)
53
- end
54
- end
55
- end
56
-
57
- # Collects environment information for diagnostic logging
58
- class EnvironmentCollector
59
- # @return [String] current time in ISO8601 format
60
- def date
61
- DateTime.now.iso8601
62
- end
63
-
64
- # Best portable guess of OS information.
65
- # @return [String] platform string
66
- def os_name
67
- RbConfig::CONFIG['host'.freeze]
10
+ # Base class for EnvironmentLoggers - should allow for easy reporting by users to Datadog support.
11
+ module EnvironmentLogging
12
+ def log_configuration!(prefix, data)
13
+ logger.info("DATADOG CONFIGURATION - #{prefix} - #{data}")
68
14
  end
69
15
 
70
- # @return [String] ddtrace version
71
- def version
72
- DDTrace::VERSION::STRING
16
+ def log_error!(prefix, type, error)
17
+ logger.warn("DATADOG ERROR - #{prefix} - #{type}: #{error}")
73
18
  end
74
19
 
75
- # @return [String] "ruby"
76
- def lang
77
- Core::Environment::Ext::LANG
78
- end
20
+ protected
79
21
 
80
- # Supported Ruby language version.
81
- # Will be distinct from VM version for non-MRI environments.
82
- # @return [String]
83
- def lang_version
84
- Core::Environment::Ext::LANG_VERSION
22
+ def logger
23
+ Datadog.logger
85
24
  end
86
25
 
87
- # @return [String] configured application environment
88
- def env
89
- Datadog.configuration.env
90
- end
26
+ # If logger should log and hasn't logged already, then output environment configuration and possible errors.
27
+ def log_once!
28
+ # Check if already been executed
29
+ return false if (defined?(@executed) && @executed) || !log?
91
30
 
92
- # @return [Boolean, nil]
93
- def enabled
94
- Datadog.configuration.tracing.enabled
95
- end
31
+ yield if block_given?
96
32
 
97
- # @return [String] configured application service name
98
- def service
99
- Datadog.configuration.service
33
+ @executed = true
100
34
  end
101
35
 
102
- # @return [String] configured application version
103
- def dd_version
104
- Datadog.configuration.version
105
- end
106
-
107
- # @return [String, nil] target agent URL for trace flushing
108
- def agent_url
109
- # Retrieve the effect agent URL, regardless of how it was configured
110
- transport = Tracing.send(:tracer).writer.transport
111
-
112
- # return `nil` with IO transport
113
- return unless transport.respond_to?(:client)
114
-
115
- adapter = transport.client.api.adapter
116
- adapter.url
36
+ # Are we logging the environment data?
37
+ def log?
38
+ startup_logs_enabled = Datadog.configuration.diagnostics.startup_logs.enabled
39
+ if startup_logs_enabled.nil?
40
+ !repl? && !rspec? # Suppress logs if we are running in a REPL or rspec
41
+ else
42
+ startup_logs_enabled
43
+ end
117
44
  end
118
45
 
119
- # Error returned by Datadog agent during a tracer flush attempt
120
- # @return [String] concatenated list of transport errors
121
- def agent_error(transport_responses)
122
- error_responses = transport_responses.reject(&:ok?)
46
+ REPL_PROGRAM_NAMES = %w[irb pry].freeze
123
47
 
124
- return nil if error_responses.empty?
125
-
126
- error_responses.map(&:inspect).join(','.freeze)
127
- end
128
-
129
- # @return [Boolean, nil] debug mode enabled in configuration
130
- def debug
131
- !!Datadog.configuration.diagnostics.debug
48
+ def repl?
49
+ REPL_PROGRAM_NAMES.include?($PROGRAM_NAME)
132
50
  end
133
51
 
134
- # @return [Boolean, nil] analytics enabled in configuration
135
- def analytics_enabled
136
- !!Datadog.configuration.tracing.analytics.enabled
52
+ def rspec?
53
+ $PROGRAM_NAME.end_with?('rspec')
137
54
  end
55
+ end
138
56
 
139
- # @return [Numeric, nil] tracer sample rate configured
140
- def sample_rate
141
- sampler = Datadog.configuration.tracing.sampler
142
- return nil unless sampler
57
+ # Collects and logs Core diagnostic information
58
+ module EnvironmentLogger
59
+ extend EnvironmentLogging
143
60
 
144
- sampler.sample_rate(nil) rescue nil
61
+ def self.collect_and_log!
62
+ log_once! do
63
+ data = EnvironmentCollector.collect_config!
64
+ log_configuration!('CORE', data.to_json)
65
+ end
66
+ rescue => e
67
+ logger.warn("Failed to collect core environment information: #{e} Location: #{Array(e.backtrace).first}")
145
68
  end
69
+ end
146
70
 
147
- # DEV: We currently only support SimpleRule instances.
148
- # DEV: These are the most commonly used rules.
149
- # DEV: We should expand support for other rules in the future,
150
- # DEV: although it is tricky to serialize arbitrary rules.
151
- #
152
- # @return [Hash, nil] sample rules configured
153
- def sampling_rules
154
- sampler = Datadog.configuration.tracing.sampler
155
- return nil unless sampler.is_a?(Tracing::Sampling::PrioritySampler) &&
156
- sampler.priority_sampler.is_a?(Tracing::Sampling::RuleSampler)
157
-
158
- sampler.priority_sampler.rules.map do |rule|
159
- next unless rule.is_a?(Tracing::Sampling::SimpleRule)
160
-
71
+ # Collects environment information for Core diagnostic logging
72
+ module EnvironmentCollector
73
+ class << self
74
+ def collect_config!
161
75
  {
162
- name: rule.matcher.name,
163
- service: rule.matcher.service,
164
- sample_rate: rule.sampler.sample_rate(nil)
76
+ date: date,
77
+ os_name: os_name,
78
+ version: version,
79
+ lang: lang,
80
+ lang_version: lang_version,
81
+ env: env,
82
+ service: service,
83
+ dd_version: dd_version,
84
+ debug: debug,
85
+ tags: tags,
86
+ runtime_metrics_enabled: runtime_metrics_enabled,
87
+ vm: vm,
88
+ health_metrics_enabled: health_metrics_enabled
165
89
  }
166
- end.compact
167
- end
168
-
169
- # @return [Hash, nil] concatenated list of global tracer tags configured
170
- def tags
171
- tags = Datadog.configuration.tags
172
- return nil if tags.empty?
90
+ end
173
91
 
174
- hash_serializer(tags)
175
- end
92
+ # @return [String] current time in ISO8601 format
93
+ def date
94
+ DateTime.now.iso8601
95
+ end
176
96
 
177
- # @return [Boolean, nil] runtime metrics enabled in configuration
178
- def runtime_metrics_enabled
179
- Datadog.configuration.runtime_metrics.enabled
180
- end
97
+ # Best portable guess of OS information.
98
+ # @return [String] platform string
99
+ def os_name
100
+ RbConfig::CONFIG['host']
101
+ end
181
102
 
182
- # Concatenated list of integrations activated, with their gem version.
183
- # Example: "rails@6.0.3,rack@2.2.3"
184
- #
185
- # @return [String, nil]
186
- def integrations_loaded
187
- integrations = instrumented_integrations
188
- return if integrations.empty?
103
+ # @return [String] ddtrace version
104
+ def version
105
+ DDTrace::VERSION::STRING
106
+ end
189
107
 
190
- integrations.map { |name, integration| "#{name}@#{integration.class.version}" }.join(','.freeze)
191
- end
108
+ # @return [String] "ruby"
109
+ def lang
110
+ Core::Environment::Ext::LANG
111
+ end
192
112
 
193
- # Ruby VM name and version.
194
- # Examples: "ruby-2.7.1", "jruby-9.2.11.1", "truffleruby-20.1.0"
195
- # @return [String, nil]
196
- def vm
197
- # RUBY_ENGINE_VERSION returns the VM version, which
198
- # will differ from RUBY_VERSION for non-mri VMs.
199
- if defined?(RUBY_ENGINE_VERSION)
200
- "#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION}"
201
- else
202
- # Ruby < 2.3 doesn't support RUBY_ENGINE_VERSION
203
- "#{RUBY_ENGINE}-#{RUBY_VERSION}"
113
+ # Supported Ruby language version.
114
+ # Will be distinct from VM version for non-MRI environments.
115
+ # @return [String]
116
+ def lang_version
117
+ Core::Environment::Ext::LANG_VERSION
204
118
  end
205
- end
206
119
 
207
- # @return [Boolean, nil] partial flushing enabled in configuration
208
- def partial_flushing_enabled
209
- !!Datadog.configuration.tracing.partial_flush.enabled
210
- end
120
+ # @return [String] configured application environment
121
+ def env
122
+ Datadog.configuration.env
123
+ end
211
124
 
212
- # @return [Boolean, nil] priority sampling enabled in configuration
213
- def priority_sampling_enabled
214
- !!Datadog.configuration.tracing.priority_sampling
215
- end
125
+ # @return [String] configured application service name
126
+ def service
127
+ Datadog.configuration.service
128
+ end
216
129
 
217
- # @return [Boolean, nil] health metrics enabled in configuration
218
- def health_metrics_enabled
219
- !!Datadog.configuration.diagnostics.health_metrics.enabled
220
- end
130
+ # @return [String] configured application version
131
+ def dd_version
132
+ Datadog.configuration.version
133
+ end
221
134
 
222
- def profiling_enabled
223
- !!Datadog.configuration.profiling.enabled
224
- end
135
+ # @return [Boolean, nil] debug mode enabled in configuration
136
+ def debug
137
+ !!Datadog.configuration.diagnostics.debug
138
+ end
225
139
 
226
- # TODO: Populate when automatic log correlation is implemented
227
- # def logs_correlation_enabled
228
- # end
140
+ # @return [Hash, nil] concatenated list of global tracer tags configured
141
+ def tags
142
+ tags = Datadog.configuration.tags
143
+ return nil if tags.empty?
229
144
 
230
- # @return [Hash] environment information available at call time
231
- def collect!(transport_responses)
232
- {
233
- date: date,
234
- os_name: os_name,
235
- version: version,
236
- lang: lang,
237
- lang_version: lang_version,
238
- env: env,
239
- enabled: enabled,
240
- service: service,
241
- dd_version: dd_version,
242
- agent_url: agent_url,
243
- agent_error: agent_error(transport_responses),
244
- debug: debug,
245
- analytics_enabled: analytics_enabled,
246
- sample_rate: sample_rate,
247
- sampling_rules: sampling_rules,
248
- tags: tags,
249
- runtime_metrics_enabled: runtime_metrics_enabled,
250
- integrations_loaded: integrations_loaded,
251
- vm: vm,
252
- partial_flushing_enabled: partial_flushing_enabled,
253
- priority_sampling_enabled: priority_sampling_enabled,
254
- health_metrics_enabled: health_metrics_enabled,
255
- profiling_enabled: profiling_enabled,
256
- **instrumented_integrations_settings
257
- }
258
- end
145
+ hash_serializer(tags)
146
+ end
259
147
 
260
- private
148
+ # @return [Boolean, nil] runtime metrics enabled in configuration
149
+ def runtime_metrics_enabled
150
+ Datadog.configuration.runtime_metrics.enabled
151
+ end
261
152
 
262
- def instrumented_integrations
263
- Datadog.configuration.tracing.instrumented_integrations
264
- end
153
+ # Ruby VM name and version.
154
+ # Examples: "ruby-2.7.1", "jruby-9.2.11.1", "truffleruby-20.1.0"
155
+ # @return [String, nil]
156
+ def vm
157
+ # RUBY_ENGINE_VERSION returns the VM version, which
158
+ # will differ from RUBY_VERSION for non-mri VMs.
159
+ if defined?(RUBY_ENGINE_VERSION)
160
+ "#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION}"
161
+ else
162
+ # Ruby < 2.3 doesn't support RUBY_ENGINE_VERSION
163
+ "#{RUBY_ENGINE}-#{RUBY_VERSION}"
164
+ end
165
+ end
265
166
 
266
- # Capture all active integration settings into "integrationName_settingName: value" entries.
267
- def instrumented_integrations_settings
268
- instrumented_integrations.flat_map do |name, integration|
269
- integration.configuration.to_h.flat_map do |setting, value|
270
- next [] if setting == :tracer # Skip internal Ruby objects
167
+ # @return [Boolean, nil] health metrics enabled in configuration
168
+ def health_metrics_enabled
169
+ !!Datadog.configuration.diagnostics.health_metrics.enabled
170
+ end
271
171
 
272
- # Convert value to a string to avoid custom #to_json
273
- # handlers possibly causing errors.
274
- [[:"integration_#{name}_#{setting}", value.to_s]]
275
- end
276
- end.to_h
277
- end
172
+ private
278
173
 
279
- # Outputs "k1:v1,k2:v2,..."
280
- def hash_serializer(h)
281
- h.map { |k, v| "#{k}:#{v}" }.join(','.freeze)
174
+ # Outputs "k1:v1,k2:v2,..."
175
+ def hash_serializer(h)
176
+ h.map { |k, v| "#{k}:#{v}" }.join(',')
177
+ end
282
178
  end
283
179
  end
284
180
  end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datadog
4
+ module Core
5
+ module Environment
6
+ # Provides information about the execution environment on the current process.
7
+ module Execution
8
+ class << self
9
+ # Is this process running in a development environment?
10
+ # This can be used to make decisions about when to enable
11
+ # background systems like worker threads or telemetry.
12
+ def development?
13
+ !!(repl? || test? || rails_development?)
14
+ end
15
+
16
+ private
17
+
18
+ # Is this process running a test?
19
+ def test?
20
+ rspec? || minitest?
21
+ end
22
+
23
+ # Is this process running inside on a Read–eval–print loop?
24
+ # DEV: REPLs always set the program name to the exact REPL name.
25
+ def repl?
26
+ REPL_PROGRAM_NAMES.include?($PROGRAM_NAME)
27
+ end
28
+
29
+ REPL_PROGRAM_NAMES = %w[irb pry].freeze
30
+ private_constant :REPL_PROGRAM_NAMES
31
+
32
+ # RSpec always runs using the `rspec` file https://github.com/rspec/rspec-core/blob/main/exe/rspec
33
+ def rspec?
34
+ $PROGRAM_NAME.end_with?(RSPEC_PROGRAM_NAME)
35
+ end
36
+
37
+ RSPEC_PROGRAM_NAME = '/rspec'
38
+ private_constant :RSPEC_PROGRAM_NAME
39
+
40
+ # Check if Minitest is present and installed to run.
41
+ def minitest?
42
+ # Minitest >= 5
43
+ (defined?(::Minitest) &&
44
+ ::Minitest.class_variable_defined?(:@@installed_at_exit) &&
45
+ ::Minitest.class_variable_get(:@@installed_at_exit)) ||
46
+ # Minitest < 5
47
+ (defined?(::Minitest::Unit) &&
48
+ ::Minitest::Unit.class_variable_defined?(:@@installed_at_exit) &&
49
+ ::Minitest::Unit.class_variable_get(:@@installed_at_exit))
50
+ end
51
+
52
+ # A Rails Spring Ruby process is a bit peculiar: the process is agnostic
53
+ # whether the application is running as a console or server.
54
+ # Luckily, the Spring gem *must not* be installed in a production environment so
55
+ # detecting its presence is enough to deduct if this is a development environment.
56
+ #
57
+ # @see https://github.com/rails/spring/blob/48b299348ace2188444489a0c216a6f3e9687281/README.md?plain=1#L204-L207
58
+ def rails_development?
59
+ defined?(::Spring)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -43,11 +43,19 @@ module Datadog
43
43
 
44
44
  # Forms a hash of standard key value pairs to be sent in the app-started event configuration
45
45
  def configurations
46
+ config = Datadog.configuration
46
47
  hash = {
47
- DD_AGENT_HOST: Datadog.configuration.agent.host,
48
+ DD_AGENT_HOST: config.agent.host,
48
49
  DD_AGENT_TRANSPORT: agent_transport,
49
- DD_TRACE_SAMPLE_RATE: format_configuration_value(Datadog.configuration.tracing.sampling.default_rate),
50
+ DD_TRACE_SAMPLE_RATE: format_configuration_value(config.tracing.sampling.default_rate),
51
+ DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED: config.tracing.contrib.global_default_service_name.enabled
50
52
  }
53
+ peer_service_mapping_str = ''
54
+ unless config.tracing.contrib.peer_service_mapping.empty?
55
+ peer_service_mapping = config.tracing.contrib.peer_service_mapping
56
+ peer_service_mapping_str = peer_service_mapping.map { |key, value| "#{key}:#{value}" }.join(',')
57
+ end
58
+ hash[:DD_TRACE_PEER_SERVICE_MAPPING] = peer_service_mapping_str
51
59
  hash.compact!
52
60
  hash
53
61
  end
@@ -8,6 +8,9 @@ module Datadog
8
8
  # * Code Hotspots panel in the trace viewer, as well as scoping a profile down to a span
9
9
  # * Endpoint aggregation in the profiler UX, including normalization (resource per endpoint call)
10
10
  def self.build_profiler_component(settings:, agent_settings:, optional_tracer:) # rubocop:disable Metrics/MethodLength
11
+ require_relative '../profiling/diagnostics/environment_logger'
12
+ Profiling::Diagnostics::EnvironmentLogger.collect_and_log!
13
+
11
14
  return unless settings.profiling.enabled
12
15
 
13
16
  # Workaround for weird dependency direction: the Core::Configuration::Components class currently has a
@@ -65,9 +68,11 @@ module Datadog
65
68
  # NOTE: Please update the Initialization section of ProfilingDevelopment.md with any changes to this method
66
69
 
67
70
  no_signals_workaround_enabled = false
71
+ timeline_enabled = false
68
72
 
69
73
  if enable_new_profiler?(settings)
70
74
  no_signals_workaround_enabled = no_signals_workaround_enabled?(settings)
75
+ timeline_enabled = settings.profiling.advanced.experimental_timeline_enabled
71
76
 
72
77
  recorder = Datadog::Profiling::StackRecorder.new(
73
78
  cpu_time_enabled: RUBY_PLATFORM.include?('linux'), # Only supported on Linux currently
@@ -81,7 +86,7 @@ module Datadog
81
86
  gc_profiling_enabled: enable_gc_profiling?(settings),
82
87
  allocation_counting_enabled: settings.profiling.advanced.allocation_counting_enabled,
83
88
  no_signals_workaround_enabled: no_signals_workaround_enabled,
84
- timeline_enabled: settings.profiling.advanced.experimental_timeline_enabled,
89
+ timeline_enabled: timeline_enabled,
85
90
  )
86
91
  else
87
92
  load_pprof_support
@@ -90,7 +95,12 @@ module Datadog
90
95
  collector = build_profiler_oldstack_collector(settings, recorder, optional_tracer)
91
96
  end
92
97
 
93
- exporter = build_profiler_exporter(settings, recorder, no_signals_workaround_enabled: no_signals_workaround_enabled)
98
+ internal_metadata = {
99
+ no_signals_workaround_enabled: no_signals_workaround_enabled,
100
+ timeline_enabled: timeline_enabled,
101
+ }.freeze
102
+
103
+ exporter = build_profiler_exporter(settings, recorder, internal_metadata: internal_metadata)
94
104
  transport = build_profiler_transport(settings, agent_settings)
95
105
  scheduler = Profiling::Scheduler.new(exporter: exporter, transport: transport)
96
106
 
@@ -101,14 +111,14 @@ module Datadog
101
111
  Profiling::OldRecorder.new([Profiling::Events::StackSample], settings.profiling.advanced.max_events)
102
112
  end
103
113
 
104
- private_class_method def self.build_profiler_exporter(settings, recorder, no_signals_workaround_enabled:)
114
+ private_class_method def self.build_profiler_exporter(settings, recorder, internal_metadata:)
105
115
  code_provenance_collector =
106
116
  (Profiling::Collectors::CodeProvenance.new if settings.profiling.advanced.code_provenance_enabled)
107
117
 
108
118
  Profiling::Exporter.new(
109
119
  pprof_recorder: recorder,
110
120
  code_provenance_collector: code_provenance_collector,
111
- no_signals_workaround_enabled: no_signals_workaround_enabled,
121
+ internal_metadata: internal_metadata,
112
122
  )
113
123
  end
114
124
 
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require 'json'
5
+ require 'rbconfig'
6
+ require_relative '../../core/diagnostics/environment_logger'
7
+
8
+ module Datadog
9
+ module Profiling
10
+ module Diagnostics
11
+ # Collects and logs Profiling diagnostic information
12
+ module EnvironmentLogger
13
+ extend Core::Diagnostics::EnvironmentLogging
14
+
15
+ def self.collect_and_log!
16
+ log_once! do
17
+ data = EnvironmentCollector.collect_config!
18
+ log_configuration!('PROFILING', data.to_json)
19
+ end
20
+ rescue => e
21
+ logger.warn("Failed to collect profiling environment information: #{e} Location: #{Array(e.backtrace).first}")
22
+ end
23
+ end
24
+
25
+ # Collects environment information for Profiling diagnostic logging
26
+ module EnvironmentCollector
27
+ def self.collect_config!(*args)
28
+ {
29
+ profiling_enabled: profiling_enabled
30
+ }
31
+ end
32
+
33
+ def self.profiling_enabled
34
+ !!Datadog.configuration.profiling.enabled
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -23,14 +23,14 @@ module Datadog
23
23
  :time_provider,
24
24
  :last_flush_finish_at,
25
25
  :created_at,
26
- :no_signals_workaround_enabled
26
+ :internal_metadata
27
27
 
28
28
  public
29
29
 
30
30
  def initialize(
31
31
  pprof_recorder:,
32
32
  code_provenance_collector:,
33
- no_signals_workaround_enabled:,
33
+ internal_metadata:,
34
34
  minimum_duration_seconds: PROFILE_DURATION_THRESHOLD_SECONDS,
35
35
  time_provider: Time
36
36
  )
@@ -40,7 +40,7 @@ module Datadog
40
40
  @time_provider = time_provider
41
41
  @last_flush_finish_at = nil
42
42
  @created_at = time_provider.now.utc
43
- @no_signals_workaround_enabled = no_signals_workaround_enabled
43
+ @internal_metadata = internal_metadata
44
44
  end
45
45
 
46
46
  def flush
@@ -64,7 +64,7 @@ module Datadog
64
64
  code_provenance_file_name: Datadog::Profiling::Ext::Transport::HTTP::CODE_PROVENANCE_FILENAME,
65
65
  code_provenance_data: uncompressed_code_provenance,
66
66
  tags_as_array: Datadog::Profiling::TagBuilder.call(settings: Datadog.configuration).to_a,
67
- no_signals_workaround_enabled: no_signals_workaround_enabled,
67
+ internal_metadata: internal_metadata,
68
68
  )
69
69
  end
70
70
 
@@ -27,7 +27,7 @@ module Datadog
27
27
  code_provenance_file_name:,
28
28
  code_provenance_data:,
29
29
  tags_as_array:,
30
- no_signals_workaround_enabled:
30
+ internal_metadata:
31
31
  )
32
32
  @start = start
33
33
  @finish = finish
@@ -36,9 +36,7 @@ module Datadog
36
36
  @code_provenance_file_name = code_provenance_file_name
37
37
  @code_provenance_data = code_provenance_data
38
38
  @tags_as_array = tags_as_array
39
- @internal_metadata_json = JSON.fast_generate(
40
- no_signals_workaround_enabled: (!!no_signals_workaround_enabled).to_s,
41
- )
39
+ @internal_metadata_json = JSON.fast_generate(internal_metadata.map { |k, v| [k, v.to_s] }.to_h)
42
40
  end
43
41
  end
44
42
  end