datadog 2.16.0 → 2.17.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -1
- data/ext/datadog_profiling_native_extension/encoded_profile.c +22 -12
- data/ext/datadog_profiling_native_extension/encoded_profile.h +1 -0
- data/ext/datadog_profiling_native_extension/http_transport.c +45 -72
- data/ext/datadog_profiling_native_extension/stack_recorder.c +4 -5
- data/ext/libdatadog_api/crashtracker.c +10 -3
- data/ext/libdatadog_api/macos_development.md +3 -3
- data/ext/libdatadog_extconf_helpers.rb +1 -1
- data/lib/datadog/appsec/api_security/lru_cache.rb +49 -0
- data/lib/datadog/appsec/api_security.rb +9 -0
- data/lib/datadog/core/buffer/random.rb +18 -2
- data/lib/datadog/core/configuration/agent_settings_resolver.rb +5 -5
- data/lib/datadog/core/configuration/components.rb +29 -20
- data/lib/datadog/core/configuration/components_state.rb +23 -0
- data/lib/datadog/core/configuration/option.rb +18 -18
- data/lib/datadog/core/configuration/option_definition.rb +4 -4
- data/lib/datadog/core/configuration/options.rb +1 -1
- data/lib/datadog/core/configuration/settings.rb +10 -10
- data/lib/datadog/core/configuration.rb +16 -16
- data/lib/datadog/core/crashtracking/component.rb +2 -1
- data/lib/datadog/core/encoding.rb +1 -1
- data/lib/datadog/core/environment/cgroup.rb +10 -12
- data/lib/datadog/core/environment/container.rb +38 -40
- data/lib/datadog/core/environment/ext.rb +6 -6
- data/lib/datadog/core/environment/identity.rb +3 -3
- data/lib/datadog/core/environment/platform.rb +3 -3
- data/lib/datadog/core/error.rb +11 -9
- data/lib/datadog/core/logger.rb +2 -2
- data/lib/datadog/core/metrics/client.rb +12 -14
- data/lib/datadog/core/metrics/logging.rb +5 -5
- data/lib/datadog/core/rate_limiter.rb +4 -2
- data/lib/datadog/core/remote/client.rb +32 -31
- data/lib/datadog/core/remote/component.rb +3 -3
- data/lib/datadog/core/remote/configuration/digest.rb +7 -7
- data/lib/datadog/core/remote/configuration/path.rb +1 -1
- data/lib/datadog/core/remote/transport/http/client.rb +1 -1
- data/lib/datadog/core/remote/transport/http/config.rb +21 -5
- data/lib/datadog/core/remote/transport/http/negotiation.rb +1 -1
- data/lib/datadog/core/runtime/metrics.rb +3 -3
- data/lib/datadog/core/telemetry/component.rb +39 -24
- data/lib/datadog/core/telemetry/emitter.rb +7 -1
- data/lib/datadog/core/telemetry/event/app_client_configuration_change.rb +65 -0
- data/lib/datadog/core/telemetry/event/app_closing.rb +18 -0
- data/lib/datadog/core/telemetry/event/app_dependencies_loaded.rb +33 -0
- data/lib/datadog/core/telemetry/event/app_heartbeat.rb +18 -0
- data/lib/datadog/core/telemetry/event/app_integrations_change.rb +58 -0
- data/lib/datadog/core/telemetry/event/app_started.rb +179 -0
- data/lib/datadog/core/telemetry/event/base.rb +40 -0
- data/lib/datadog/core/telemetry/event/distributions.rb +18 -0
- data/lib/datadog/core/telemetry/event/generate_metrics.rb +43 -0
- data/lib/datadog/core/telemetry/event/log.rb +76 -0
- data/lib/datadog/core/telemetry/event/message_batch.rb +42 -0
- data/lib/datadog/core/telemetry/event/synth_app_client_configuration_change.rb +43 -0
- data/lib/datadog/core/telemetry/event.rb +17 -475
- data/lib/datadog/core/telemetry/logger.rb +1 -1
- data/lib/datadog/core/telemetry/metric.rb +3 -3
- data/lib/datadog/core/telemetry/transport/http/telemetry.rb +2 -2
- data/lib/datadog/core/telemetry/transport/telemetry.rb +0 -1
- data/lib/datadog/core/telemetry/worker.rb +48 -27
- data/lib/datadog/core/transport/http/adapters/test.rb +2 -1
- data/lib/datadog/core/transport/http/builder.rb +13 -13
- data/lib/datadog/core/utils/at_fork_monkey_patch.rb +6 -6
- data/lib/datadog/core/utils/duration.rb +32 -32
- data/lib/datadog/core/utils/forking.rb +2 -2
- data/lib/datadog/core/utils/network.rb +6 -6
- data/lib/datadog/core/utils/only_once_successful.rb +16 -5
- data/lib/datadog/core/utils/time.rb +10 -2
- data/lib/datadog/core/utils/truncation.rb +21 -0
- data/lib/datadog/core/vendor/multipart-post/multipart/post/composite_read_io.rb +1 -1
- data/lib/datadog/core/vendor/multipart-post/multipart/post/multipartable.rb +8 -8
- data/lib/datadog/core/vendor/multipart-post/multipart/post/parts.rb +7 -7
- data/lib/datadog/core/worker.rb +1 -1
- data/lib/datadog/core/workers/async.rb +9 -10
- data/lib/datadog/error_tracking/component.rb +2 -2
- data/lib/datadog/profiling/collectors/code_provenance.rb +1 -1
- data/lib/datadog/profiling/ext.rb +0 -1
- data/lib/datadog/profiling/flush.rb +1 -1
- data/lib/datadog/profiling/http_transport.rb +1 -6
- data/lib/datadog/profiling/scheduler.rb +8 -1
- data/lib/datadog/profiling/tag_builder.rb +1 -5
- data/lib/datadog/tracing/contrib/active_support/cache/events/cache.rb +4 -1
- data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +33 -0
- data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +4 -0
- data/lib/datadog/tracing/contrib/active_support/cache/redis.rb +2 -4
- data/lib/datadog/tracing/contrib/aws/instrumentation.rb +10 -0
- data/lib/datadog/tracing/contrib/aws/parsed_context.rb +5 -1
- data/lib/datadog/tracing/contrib/http/instrumentation.rb +1 -5
- data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +1 -5
- data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +1 -5
- data/lib/datadog/tracing/contrib/patcher.rb +5 -2
- data/lib/datadog/tracing/contrib/support.rb +28 -0
- data/lib/datadog/tracing/metadata/errors.rb +4 -4
- data/lib/datadog/version.rb +1 -1
- metadata +23 -6
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'agent_settings_resolver'
|
4
|
+
require_relative 'components_state'
|
4
5
|
require_relative 'ext'
|
5
6
|
require_relative '../diagnostics/environment_logger'
|
6
7
|
require_relative '../diagnostics/health'
|
@@ -8,7 +9,6 @@ require_relative '../logger'
|
|
8
9
|
require_relative '../runtime/metrics'
|
9
10
|
require_relative '../telemetry/component'
|
10
11
|
require_relative '../workers/runtime_metrics'
|
11
|
-
|
12
12
|
require_relative '../remote/component'
|
13
13
|
require_relative '../../tracing/component'
|
14
14
|
require_relative '../../profiling/component'
|
@@ -16,7 +16,6 @@ require_relative '../../appsec/component'
|
|
16
16
|
require_relative '../../di/component'
|
17
17
|
require_relative '../../error_tracking/component'
|
18
18
|
require_relative '../crashtracking/component'
|
19
|
-
|
20
19
|
require_relative '../environment/agent_info'
|
21
20
|
require_relative '../process_discovery'
|
22
21
|
|
@@ -30,7 +29,7 @@ module Datadog
|
|
30
29
|
|
31
30
|
def build_health_metrics(settings, logger, telemetry)
|
32
31
|
settings = settings.health_metrics
|
33
|
-
options = {
|
32
|
+
options = {enabled: settings.enabled}
|
34
33
|
options[:statsd] = settings.statsd unless settings.statsd.nil?
|
35
34
|
|
36
35
|
Core::Diagnostics::Health::Metrics.new(telemetry: telemetry, logger: logger, **options)
|
@@ -44,7 +43,7 @@ module Datadog
|
|
44
43
|
end
|
45
44
|
|
46
45
|
def build_runtime_metrics(settings, logger, telemetry)
|
47
|
-
options = {
|
46
|
+
options = {enabled: settings.runtime_metrics.enabled}
|
48
47
|
options[:statsd] = settings.runtime_metrics.statsd unless settings.runtime_metrics.statsd.nil?
|
49
48
|
options[:services] = [settings.service] unless settings.service.nil?
|
50
49
|
options[:experimental_runtime_id_enabled] = settings.runtime_metrics.experimental_runtime_id_enabled
|
@@ -135,6 +134,8 @@ module Datadog
|
|
135
134
|
|
136
135
|
# Starts up components
|
137
136
|
def startup!(settings, old_state: nil)
|
137
|
+
telemetry.start(old_state&.telemetry_enabled?)
|
138
|
+
|
138
139
|
if settings.profiling.enabled
|
139
140
|
if profiler
|
140
141
|
profiler.start
|
@@ -145,7 +146,7 @@ module Datadog
|
|
145
146
|
end
|
146
147
|
end
|
147
148
|
|
148
|
-
if settings.remote.enabled && old_state&.
|
149
|
+
if settings.remote.enabled && old_state&.remote_started?
|
149
150
|
# The library was reconfigured and previously it already started
|
150
151
|
# the remote component (i.e., it received at least one request
|
151
152
|
# through the installed Rack middleware which started the remote).
|
@@ -163,20 +164,20 @@ module Datadog
|
|
163
164
|
# and avoid tearing down parts still in use.
|
164
165
|
def shutdown!(replacement = nil)
|
165
166
|
# Shutdown remote configuration
|
166
|
-
remote
|
167
|
+
remote&.shutdown!
|
167
168
|
|
168
169
|
# Shutdown DI after remote, since remote config triggers DI operations.
|
169
170
|
dynamic_instrumentation&.shutdown!
|
170
171
|
|
171
172
|
# Decommission AppSec
|
172
|
-
appsec
|
173
|
+
appsec&.shutdown!
|
173
174
|
|
174
175
|
# Shutdown the old tracer, unless it's still being used.
|
175
176
|
# (e.g. a custom tracer instance passed in.)
|
176
|
-
tracer.shutdown! unless replacement && tracer
|
177
|
+
tracer.shutdown! unless replacement && tracer.equal?(replacement.tracer)
|
177
178
|
|
178
179
|
# Shutdown old profiler
|
179
|
-
profiler
|
180
|
+
profiler&.shutdown!
|
180
181
|
|
181
182
|
# Shutdown workers
|
182
183
|
runtime_metrics.stop(true, close_metrics: false)
|
@@ -194,25 +195,33 @@ module Datadog
|
|
194
195
|
health_metrics.statsd
|
195
196
|
].compact.uniq
|
196
197
|
|
197
|
-
new_statsd =
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
198
|
+
new_statsd = if replacement
|
199
|
+
[
|
200
|
+
replacement.runtime_metrics.metrics.statsd,
|
201
|
+
replacement.health_metrics.statsd
|
202
|
+
].compact.uniq
|
203
|
+
else
|
204
|
+
[]
|
205
|
+
end
|
205
206
|
|
206
207
|
unused_statsd = (old_statsd - (old_statsd & new_statsd))
|
207
208
|
unused_statsd.each(&:close)
|
208
209
|
|
209
|
-
# enqueue closing event before stopping telemetry so it will be
|
210
|
-
telemetry.emit_closing! unless replacement
|
211
|
-
telemetry.
|
210
|
+
# enqueue closing event before stopping telemetry so it will be sent out on shutdown
|
211
|
+
telemetry.emit_closing! unless replacement&.telemetry&.enabled
|
212
|
+
telemetry.shutdown!
|
212
213
|
|
213
214
|
# TODO: Re-enable this once we have updated libdatadog to 17.1
|
214
215
|
# Core::ProcessDiscovery._native_close_tracer_memfd(@process_discovery_fd, @logger) if @process_discovery_fd
|
215
216
|
end
|
217
|
+
|
218
|
+
# Returns the current state of various components.
|
219
|
+
def state
|
220
|
+
ComponentsState.new(
|
221
|
+
telemetry_enabled: telemetry.enabled,
|
222
|
+
remote_started: remote&.started?,
|
223
|
+
)
|
224
|
+
end
|
216
225
|
end
|
217
226
|
end
|
218
227
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module Core
|
5
|
+
module Configuration
|
6
|
+
# Stores the state of component tree when replacing the tree.
|
7
|
+
class ComponentsState
|
8
|
+
def initialize(telemetry_enabled:, remote_started:)
|
9
|
+
@telemetry_enabled = !!telemetry_enabled
|
10
|
+
@remote_started = !!remote_started
|
11
|
+
end
|
12
|
+
|
13
|
+
def telemetry_enabled?
|
14
|
+
@telemetry_enabled
|
15
|
+
end
|
16
|
+
|
17
|
+
def remote_started?
|
18
|
+
@remote_started
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -142,14 +142,14 @@ module Datadog
|
|
142
142
|
|
143
143
|
def reset
|
144
144
|
@value = if definition.resetter
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
145
|
+
# Don't change @is_set to false; custom resetters are
|
146
|
+
# responsible for changing @value back to a good state.
|
147
|
+
# Setting @is_set = false would cause a default to be applied.
|
148
|
+
context_exec(@value, &definition.resetter)
|
149
|
+
else
|
150
|
+
@is_set = false
|
151
|
+
nil
|
152
|
+
end
|
153
153
|
|
154
154
|
# Reset back to the lowest precedence, to allow all `set`s to succeed right after a reset.
|
155
155
|
@precedence_set = Precedence::DEFAULT
|
@@ -227,20 +227,20 @@ module Datadog
|
|
227
227
|
|
228
228
|
unless valid_type
|
229
229
|
raise_error = if @definition.type_options[:nilable]
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
230
|
+
!value.is_a?(NilClass)
|
231
|
+
else
|
232
|
+
true
|
233
|
+
end
|
234
234
|
end
|
235
235
|
|
236
236
|
if raise_error
|
237
237
|
error_msg = if @definition.type_options[:nilable]
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
238
|
+
"The setting `#{@definition.name}` inside your app's `Datadog.configure` block expects a " \
|
239
|
+
"#{@definition.type} or `nil`, but a `#{value.class}` was provided (#{value.inspect})." \
|
240
|
+
else
|
241
|
+
"The setting `#{@definition.name}` inside your app's `Datadog.configure` block expects a " \
|
242
|
+
"#{@definition.type}, but a `#{value.class}` was provided (#{value.inspect})." \
|
243
|
+
end
|
244
244
|
|
245
245
|
error_msg = "#{error_msg} Please update your `configure` block. "
|
246
246
|
|
@@ -71,11 +71,11 @@ module Datadog
|
|
71
71
|
validate_options!
|
72
72
|
end
|
73
73
|
|
74
|
-
def env(value)
|
74
|
+
def env(value) # standard:disable Style/TrivialAccessors
|
75
75
|
@env = value
|
76
76
|
end
|
77
77
|
|
78
|
-
def deprecated_env(value)
|
78
|
+
def deprecated_env(value) # standard:disable Style/TrivialAccessors
|
79
79
|
@deprecated_env = value
|
80
80
|
end
|
81
81
|
|
@@ -111,7 +111,7 @@ module Datadog
|
|
111
111
|
|
112
112
|
def type(value, nilable: false)
|
113
113
|
@type = value
|
114
|
-
@type_options = {
|
114
|
+
@type_options = {nilable: nilable}
|
115
115
|
|
116
116
|
value
|
117
117
|
end
|
@@ -156,7 +156,7 @@ module Datadog
|
|
156
156
|
if !@default.nil? && @default_proc
|
157
157
|
raise InvalidOptionError,
|
158
158
|
'Using `default` and `default_proc` is not allowed. Please use one or the other.' \
|
159
|
-
'If you want to store a block as the default value use `default_proc`'\
|
159
|
+
'If you want to store a block as the default value use `default_proc`' \
|
160
160
|
' otherwise use `default`'
|
161
161
|
end
|
162
162
|
end
|
@@ -18,7 +18,7 @@ module Datadog
|
|
18
18
|
module ClassMethods
|
19
19
|
def options
|
20
20
|
# Allows for class inheritance of option definitions
|
21
|
-
@options ||= superclass <= Options ? superclass.options.dup : {}
|
21
|
+
@options ||= (superclass <= Options) ? superclass.options.dup : {}
|
22
22
|
end
|
23
23
|
|
24
24
|
protected
|
@@ -18,7 +18,7 @@ module Datadog
|
|
18
18
|
module Configuration
|
19
19
|
# Global configuration settings for the Datadog library.
|
20
20
|
# @public_api
|
21
|
-
#
|
21
|
+
# standard:disable Metrics/BlockLength
|
22
22
|
class Settings
|
23
23
|
include Base
|
24
24
|
|
@@ -123,7 +123,7 @@ module Datadog
|
|
123
123
|
# @return [Boolean]
|
124
124
|
option :debug do |o|
|
125
125
|
o.env [Datadog::Core::Configuration::Ext::Diagnostics::ENV_DEBUG_ENABLED,
|
126
|
-
|
126
|
+
Datadog::Core::Configuration::Ext::Diagnostics::ENV_OTEL_LOG_LEVEL]
|
127
127
|
o.default false
|
128
128
|
o.type :bool
|
129
129
|
o.env_parser do |value|
|
@@ -137,7 +137,7 @@ module Datadog
|
|
137
137
|
o.after_set do |enabled|
|
138
138
|
# Enable rich debug print statements.
|
139
139
|
# We do not need to unnecessarily load 'pp' unless in debugging mode.
|
140
|
-
require 'pp' if enabled
|
140
|
+
require 'pp' if enabled # standard:disable Lint/RedundantRequireStatement
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
@@ -454,7 +454,7 @@ module Datadog
|
|
454
454
|
o.after_set do |_, _, precedence|
|
455
455
|
unless precedence == Datadog::Core::Configuration::Option::Precedence::DEFAULT
|
456
456
|
Core.log_deprecation(key: :experimental_crash_tracking_enabled) do
|
457
|
-
'The profiling.advanced.experimental_crash_tracking_enabled setting has been deprecated for removal '\
|
457
|
+
'The profiling.advanced.experimental_crash_tracking_enabled setting has been deprecated for removal ' \
|
458
458
|
'and no longer does anything. Please remove it from your Datadog.configure block.'
|
459
459
|
end
|
460
460
|
end
|
@@ -641,11 +641,11 @@ module Datadog
|
|
641
641
|
val ||= ''
|
642
642
|
# maps OpenTelemetry semantic attributes to Datadog tags
|
643
643
|
key = case key.downcase
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
644
|
+
when 'deployment.environment' then 'env'
|
645
|
+
when 'service.version' then 'version'
|
646
|
+
when 'service.name' then 'service'
|
647
|
+
else key
|
648
|
+
end
|
649
649
|
result[key] = val unless key.empty?
|
650
650
|
end
|
651
651
|
end
|
@@ -995,7 +995,7 @@ module Datadog
|
|
995
995
|
# Keep this extension here for now to keep things working.
|
996
996
|
extend Datadog::Tracing::Configuration::Settings
|
997
997
|
end
|
998
|
-
#
|
998
|
+
# standard:enable Metrics/BlockLength
|
999
999
|
end
|
1000
1000
|
end
|
1001
1001
|
end
|
@@ -235,16 +235,14 @@ module Datadog
|
|
235
235
|
end
|
236
236
|
|
237
237
|
COMPONENTS_WRITE_LOCK.synchronize do
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
nil
|
247
|
-
end
|
238
|
+
yield write_components
|
239
|
+
rescue ThreadError => e
|
240
|
+
logger_without_components.error(
|
241
|
+
'Detected deadlock during datadog initialization. ' \
|
242
|
+
'Please report this at https://github.com/datadog/dd-trace-rb/blob/master/CONTRIBUTING.md#found-a-bug' \
|
243
|
+
"\n\tSource:\n\t#{Array(e.backtrace).join("\n\t")}"
|
244
|
+
)
|
245
|
+
nil
|
248
246
|
end
|
249
247
|
end
|
250
248
|
|
@@ -267,12 +265,14 @@ module Datadog
|
|
267
265
|
components = Components.new(settings)
|
268
266
|
|
269
267
|
# Carry over state from existing components to the new ones.
|
270
|
-
# Currently
|
271
|
-
#
|
272
|
-
#
|
273
|
-
|
274
|
-
|
275
|
-
|
268
|
+
# Currently:
|
269
|
+
# 1. If we already started the remote component (which
|
270
|
+
# happens after a request goes through installed Rack middleware),
|
271
|
+
# we will start the new remote component as well.
|
272
|
+
# 2. If telemetry has been enabled and is enabled in the new
|
273
|
+
# component tree, we send AppConfigurationChange event instead
|
274
|
+
# of AppStarted event.
|
275
|
+
old_state = old.state
|
276
276
|
|
277
277
|
old.shutdown!(components)
|
278
278
|
components.startup!(settings, old_state: old_state)
|
@@ -92,7 +92,8 @@ module Datadog
|
|
92
92
|
path_to_crashtracking_receiver_binary: path_to_crashtracking_receiver_binary,
|
93
93
|
ld_library_path: ld_library_path,
|
94
94
|
tags_as_array: tags.to_a,
|
95
|
-
|
95
|
+
# @ivoanjo: On my machine this needs to be > 5 seconds, and seems to work with 10; the extra 15 is extra margin
|
96
|
+
upload_timeout_seconds: 15,
|
96
97
|
)
|
97
98
|
logger.debug("Crash tracking action: #{action} successful")
|
98
99
|
rescue => e
|
@@ -23,20 +23,18 @@ module Datadog
|
|
23
23
|
|
24
24
|
def descriptors(process = 'self')
|
25
25
|
[].tap do |descriptors|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
descriptors << parse(line) unless line.empty?
|
33
|
-
end
|
26
|
+
filepath = "/proc/#{process}/cgroup"
|
27
|
+
|
28
|
+
if File.exist?(filepath)
|
29
|
+
File.foreach("/proc/#{process}/cgroup") do |line|
|
30
|
+
line = line.strip
|
31
|
+
descriptors << parse(line) unless line.empty?
|
34
32
|
end
|
35
|
-
rescue StandardError => e
|
36
|
-
Datadog.logger.error(
|
37
|
-
"Error while parsing cgroup. Cause: #{e.class.name} #{e.message} Location: #{Array(e.backtrace).first}"
|
38
|
-
)
|
39
33
|
end
|
34
|
+
rescue => e
|
35
|
+
Datadog.logger.error(
|
36
|
+
"Error while parsing cgroup. Cause: #{e.class.name} #{e.message} Location: #{Array(e.backtrace).first}"
|
37
|
+
)
|
40
38
|
end
|
41
39
|
end
|
42
40
|
|
@@ -37,52 +37,50 @@ module Datadog
|
|
37
37
|
|
38
38
|
def descriptor
|
39
39
|
@descriptor ||= Descriptor.new.tap do |descriptor|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
40
|
+
Cgroup.descriptors.each do |cgroup_descriptor|
|
41
|
+
# Parse container data from cgroup descriptor
|
42
|
+
path = cgroup_descriptor.path
|
43
|
+
next if path.nil?
|
44
|
+
|
45
|
+
# Split path into parts
|
46
|
+
parts = path.split('/')
|
47
|
+
parts.shift # Remove leading empty part
|
48
|
+
|
49
|
+
# Read info from path
|
50
|
+
next if parts.empty?
|
51
|
+
|
52
|
+
platform = parts[0][PLATFORM_REGEX, :platform]
|
53
|
+
container_id, task_uid = nil
|
54
|
+
|
55
|
+
case parts.length
|
56
|
+
when 0..1
|
57
|
+
next
|
58
|
+
when 2
|
59
|
+
container_id = parts[-1][CONTAINER_REGEX, :container] \
|
60
|
+
|| parts[-1][FARGATE_14_CONTAINER_REGEX, :container]
|
61
|
+
else
|
62
|
+
if (container_id = parts[-1][CONTAINER_REGEX, :container])
|
63
|
+
task_uid = parts[-2][POD_REGEX, :pod] || parts[1][POD_REGEX, :pod]
|
62
64
|
else
|
63
|
-
|
64
|
-
task_uid = parts[-2][POD_REGEX, :pod] || parts[1][POD_REGEX, :pod]
|
65
|
-
else
|
66
|
-
container_id = parts[-1][FARGATE_14_CONTAINER_REGEX, :container]
|
67
|
-
end
|
65
|
+
container_id = parts[-1][FARGATE_14_CONTAINER_REGEX, :container]
|
68
66
|
end
|
67
|
+
end
|
69
68
|
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
# If container ID wasn't found, ignore.
|
70
|
+
# Path might describe a non-container environment.
|
71
|
+
next if container_id.nil?
|
73
72
|
|
74
|
-
|
75
|
-
|
76
|
-
|
73
|
+
descriptor.platform = platform
|
74
|
+
descriptor.container_id = container_id
|
75
|
+
descriptor.task_uid = task_uid
|
77
76
|
|
78
|
-
|
79
|
-
end
|
80
|
-
rescue StandardError => e
|
81
|
-
Datadog.logger.error(
|
82
|
-
"Error while parsing container info. Cause: #{e.class.name} #{e.message} " \
|
83
|
-
"Location: #{Array(e.backtrace).first}"
|
84
|
-
)
|
77
|
+
break
|
85
78
|
end
|
79
|
+
rescue => e
|
80
|
+
Datadog.logger.error(
|
81
|
+
"Error while parsing container info. Cause: #{e.class.name} #{e.message} " \
|
82
|
+
"Location: #{Array(e.backtrace).first}"
|
83
|
+
)
|
86
84
|
end
|
87
85
|
end
|
88
86
|
end
|
@@ -9,11 +9,11 @@ module Datadog
|
|
9
9
|
module Ext
|
10
10
|
# e.g for CRuby '3.0.1', for JRuby '9.2.19.0', for TruffleRuby '21.1.0'
|
11
11
|
ENGINE_VERSION = if defined?(RUBY_ENGINE_VERSION)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
RUBY_ENGINE_VERSION
|
13
|
+
else
|
14
|
+
# CRuby < 2.3 doesn't support RUBY_ENGINE_VERSION
|
15
|
+
RUBY_VERSION
|
16
|
+
end
|
17
17
|
|
18
18
|
ENV_API_KEY = 'DD_API_KEY'
|
19
19
|
ENV_ENVIRONMENT = 'DD_ENV'
|
@@ -26,7 +26,7 @@ module Datadog
|
|
26
26
|
FALLBACK_SERVICE_NAME =
|
27
27
|
begin
|
28
28
|
File.basename($PROGRAM_NAME, '.*')
|
29
|
-
rescue
|
29
|
+
rescue
|
30
30
|
'ruby'
|
31
31
|
end.freeze
|
32
32
|
|
@@ -67,12 +67,12 @@ module Datadog
|
|
67
67
|
|
68
68
|
rest.split('.').tap do |segments|
|
69
69
|
if segments.length >= 4
|
70
|
-
pre
|
71
|
-
build = "+#{segments.join(
|
70
|
+
pre = "-#{segments.shift}"
|
71
|
+
build = "+#{segments.join(".")}"
|
72
72
|
elsif segments.length == 1
|
73
73
|
pre = "-#{segments.shift}"
|
74
74
|
else
|
75
|
-
build = "+#{segments.join(
|
75
|
+
build = "+#{segments.join(".")}"
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -13,18 +13,18 @@ module Datadog
|
|
13
13
|
|
14
14
|
# @return [String] ISA of host; `uname -m`
|
15
15
|
def architecture
|
16
|
-
Identity.lang_version >= '2.2' ? Etc.uname[:machine] : Gem::Platform.local.cpu
|
16
|
+
(Identity.lang_version >= '2.2') ? Etc.uname[:machine] : Gem::Platform.local.cpu
|
17
17
|
end
|
18
18
|
|
19
19
|
# @return [String] name of host; `uname -n`
|
20
20
|
def hostname
|
21
|
-
Identity.lang_version >= '2.2' ? Etc.uname[:nodename] : nil
|
21
|
+
(Identity.lang_version >= '2.2') ? Etc.uname[:nodename] : nil
|
22
22
|
end
|
23
23
|
|
24
24
|
# System name, normally `Linux` or `Darwin` (but 'Mac OS X' on JRuby);
|
25
25
|
# @return [String] name of kernel; `uname -s`.
|
26
26
|
def kernel_name
|
27
|
-
Identity.lang_version >= '2.2' ? Etc.uname[:sysname] : Gem::Platform.local.os.capitalize
|
27
|
+
(Identity.lang_version >= '2.2') ? Etc.uname[:sysname] : Gem::Platform.local.os.capitalize
|
28
28
|
end
|
29
29
|
|
30
30
|
# @return [String] kernel release; `uname -r`
|
data/lib/datadog/core/error.rb
CHANGED
@@ -11,12 +11,17 @@ module Datadog
|
|
11
11
|
class << self
|
12
12
|
def build_from(value)
|
13
13
|
case value
|
14
|
-
|
15
|
-
when Array then new(*value)
|
14
|
+
# A Ruby {Exception} is the most common parameter type.
|
16
15
|
when Exception then new(value.class, value.message, full_backtrace(value))
|
17
|
-
|
16
|
+
# steep:ignore:start
|
17
|
+
# Steep doesn't like an array with up to 3 elements to be passed here: it thinks the array is unbounded.
|
18
|
+
when Array then new(*value)
|
19
|
+
# Steep can not follow the logic inside the lambda, thus it doesn't know `value` responds to `:message`.
|
20
|
+
when ->(v) { v.respond_to?(:message) } then new(value.class, value.message)
|
21
|
+
# steep:ignore:end
|
18
22
|
when String then new(nil, value)
|
19
|
-
|
23
|
+
when Error then value
|
24
|
+
else Error.new # Blank error
|
20
25
|
end
|
21
26
|
end
|
22
27
|
|
@@ -34,7 +39,7 @@ module Datadog
|
|
34
39
|
# but it's around 3x faster in our benchmark test
|
35
40
|
# at `error_spec.rb`.
|
36
41
|
def full_backtrace(ex)
|
37
|
-
backtrace =
|
42
|
+
backtrace = +''
|
38
43
|
backtrace_for(ex, backtrace)
|
39
44
|
|
40
45
|
# Avoid circular causes
|
@@ -75,7 +80,7 @@ module Datadog
|
|
75
80
|
if trace[1]
|
76
81
|
# Ident stack trace for caller lines, to separate
|
77
82
|
# them from the main error lines.
|
78
|
-
trace[1..-1]
|
83
|
+
trace[1..-1]&.each do |line|
|
79
84
|
backtrace << "\n\tfrom "
|
80
85
|
backtrace << line
|
81
86
|
end
|
@@ -92,9 +97,6 @@ module Datadog
|
|
92
97
|
@message = Utils.utf8_encode(message)
|
93
98
|
@backtrace = Utils.utf8_encode(backtrace)
|
94
99
|
end
|
95
|
-
|
96
|
-
BlankError = Error.new
|
97
|
-
ContainsMessage = ->(v) { v.respond_to?(:message) }
|
98
100
|
end
|
99
101
|
end
|
100
102
|
end
|
data/lib/datadog/core/logger.rb
CHANGED
@@ -28,7 +28,7 @@ module Datadog
|
|
28
28
|
|
29
29
|
if message.nil?
|
30
30
|
if block
|
31
|
-
super
|
31
|
+
super do
|
32
32
|
"[#{self.progname}] #{where}#{yield}"
|
33
33
|
end
|
34
34
|
else
|
@@ -39,7 +39,7 @@ module Datadog
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
|
42
|
+
alias_method :log, :add
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|