ddtrace 1.7.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +50 -1
- data/README.md +2 -2
- data/ext/ddtrace_profiling_loader/extconf.rb +4 -1
- data/ext/ddtrace_profiling_native_extension/NativeExtensionDesign.md +1 -1
- data/ext/ddtrace_profiling_native_extension/clock_id_from_pthread.c +3 -2
- data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.c +15 -41
- data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.h +1 -1
- data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +284 -74
- data/ext/ddtrace_profiling_native_extension/collectors_dynamic_sampling_rate.c +142 -0
- data/ext/ddtrace_profiling_native_extension/collectors_dynamic_sampling_rate.h +14 -0
- data/ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.c +241 -0
- data/ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.h +3 -0
- data/ext/ddtrace_profiling_native_extension/extconf.rb +21 -7
- data/ext/ddtrace_profiling_native_extension/helpers.h +5 -0
- data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +8 -0
- data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +108 -24
- data/ext/ddtrace_profiling_native_extension/private_vm_api_access.h +9 -0
- data/ext/ddtrace_profiling_native_extension/profiling.c +205 -0
- data/ext/ddtrace_profiling_native_extension/ruby_helpers.c +86 -0
- data/ext/ddtrace_profiling_native_extension/ruby_helpers.h +28 -6
- data/ext/ddtrace_profiling_native_extension/setup_signal_handler.c +23 -4
- data/ext/ddtrace_profiling_native_extension/setup_signal_handler.h +4 -0
- data/ext/ddtrace_profiling_native_extension/stack_recorder.c +15 -18
- data/ext/ddtrace_profiling_native_extension/time_helpers.c +17 -0
- data/ext/ddtrace_profiling_native_extension/time_helpers.h +10 -0
- data/lib/datadog/core/configuration/components.rb +27 -6
- data/lib/datadog/core/configuration/ext.rb +18 -0
- data/lib/datadog/core/configuration/settings.rb +14 -341
- data/lib/datadog/core/diagnostics/health.rb +4 -22
- data/lib/datadog/core/environment/variable_helpers.rb +58 -10
- data/lib/datadog/core/utils.rb +0 -21
- data/lib/datadog/core.rb +21 -1
- data/lib/datadog/opentracer/distributed_headers.rb +2 -2
- data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +16 -5
- data/lib/datadog/profiling/collectors/dynamic_sampling_rate.rb +14 -0
- data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +68 -0
- data/lib/datadog/profiling/stack_recorder.rb +14 -0
- data/lib/datadog/profiling.rb +2 -0
- data/lib/datadog/tracing/configuration/ext.rb +33 -3
- data/lib/datadog/tracing/configuration/settings.rb +433 -0
- data/lib/datadog/tracing/contrib/aws/configuration/settings.rb +4 -1
- data/lib/datadog/tracing/contrib/aws/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +4 -1
- data/lib/datadog/tracing/contrib/dalli/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +5 -1
- data/lib/datadog/tracing/contrib/elasticsearch/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +6 -1
- data/lib/datadog/tracing/contrib/ethon/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +5 -1
- data/lib/datadog/tracing/contrib/excon/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +5 -1
- data/lib/datadog/tracing/contrib/faraday/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +6 -1
- data/lib/datadog/tracing/contrib/grpc/distributed/propagation.rb +9 -4
- data/lib/datadog/tracing/contrib/grpc/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/http/configuration/settings.rb +6 -1
- data/lib/datadog/tracing/contrib/http/distributed/propagation.rb +9 -4
- data/lib/datadog/tracing/contrib/http/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +6 -1
- data/lib/datadog/tracing/contrib/httpclient/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +6 -1
- data/lib/datadog/tracing/contrib/httprb/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +5 -1
- data/lib/datadog/tracing/contrib/mongodb/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +4 -1
- data/lib/datadog/tracing/contrib/mysql2/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +2 -2
- data/lib/datadog/tracing/contrib/patcher.rb +3 -2
- data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +4 -1
- data/lib/datadog/tracing/contrib/pg/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/pg/instrumentation.rb +12 -2
- data/lib/datadog/tracing/contrib/presto/configuration/settings.rb +4 -1
- data/lib/datadog/tracing/contrib/presto/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/propagation/sql_comment/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +10 -12
- data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +4 -1
- data/lib/datadog/tracing/contrib/redis/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/redis/instrumentation.rb +30 -23
- data/lib/datadog/tracing/contrib/redis/integration.rb +34 -2
- data/lib/datadog/tracing/contrib/redis/patcher.rb +18 -14
- data/lib/datadog/tracing/contrib/redis/quantize.rb +12 -9
- data/lib/datadog/tracing/contrib/redis/tags.rb +4 -6
- data/lib/datadog/tracing/contrib/redis/trace_middleware.rb +72 -0
- data/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +6 -1
- data/lib/datadog/tracing/contrib/rest_client/ext.rb +1 -0
- data/lib/datadog/{core → tracing}/diagnostics/ext.rb +1 -6
- data/lib/datadog/tracing/diagnostics/health.rb +40 -0
- data/lib/datadog/tracing/distributed/{b3.rb → b3_multi.rb} +2 -2
- data/lib/datadog/tracing/distributed/helpers.rb +2 -1
- data/lib/datadog/tracing/distributed/none.rb +19 -0
- data/lib/datadog/tracing/distributed/trace_context.rb +369 -0
- data/lib/datadog/tracing/metadata/ext.rb +1 -1
- data/lib/datadog/tracing/sampling/priority_sampler.rb +11 -0
- data/lib/datadog/tracing/sampling/rate_sampler.rb +3 -3
- data/lib/datadog/tracing/span.rb +3 -19
- data/lib/datadog/tracing/span_operation.rb +5 -4
- data/lib/datadog/tracing/trace_digest.rb +75 -2
- data/lib/datadog/tracing/trace_operation.rb +5 -4
- data/lib/datadog/tracing/utils.rb +50 -0
- data/lib/ddtrace/version.rb +1 -1
- metadata +20 -5
@@ -175,7 +175,7 @@ static VALUE _native_active_slot(DDTRACE_UNUSED VALUE _self, VALUE recorder_inst
|
|
175
175
|
static VALUE _native_is_slot_one_mutex_locked(DDTRACE_UNUSED VALUE _self, VALUE recorder_instance);
|
176
176
|
static VALUE _native_is_slot_two_mutex_locked(DDTRACE_UNUSED VALUE _self, VALUE recorder_instance);
|
177
177
|
static VALUE test_slot_mutex_state(VALUE recorder_instance, int slot);
|
178
|
-
static ddog_Timespec time_now();
|
178
|
+
static ddog_Timespec time_now(void);
|
179
179
|
static VALUE _native_reset_after_fork(DDTRACE_UNUSED VALUE self, VALUE recorder_instance);
|
180
180
|
static void serializer_set_start_timestamp_for_next_profile(struct stack_recorder_state *state, ddog_Timespec timestamp);
|
181
181
|
static VALUE _native_record_endpoint(DDTRACE_UNUSED VALUE _self, VALUE recorder_instance, VALUE local_root_span_id, VALUE endpoint);
|
@@ -239,8 +239,7 @@ static void initialize_slot_concurrency_control(struct stack_recorder_state *sta
|
|
239
239
|
state->slot_two_mutex = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER;
|
240
240
|
|
241
241
|
// A newly-created StackRecorder starts with slot one being active for samples, so let's lock slot two
|
242
|
-
|
243
|
-
if (error) rb_syserr_fail(error, "Unexpected failure during pthread_mutex_lock");
|
242
|
+
ENFORCE_SUCCESS_GVL(pthread_mutex_lock(&state->slot_two_mutex));
|
244
243
|
|
245
244
|
state->active_slot = 1;
|
246
245
|
}
|
@@ -361,7 +360,7 @@ static struct active_slot_pair sampler_lock_active_profile(struct stack_recorder
|
|
361
360
|
|
362
361
|
for (int attempts = 0; attempts < 2; attempts++) {
|
363
362
|
error = pthread_mutex_trylock(&state->slot_one_mutex);
|
364
|
-
if (error && error != EBUSY)
|
363
|
+
if (error && error != EBUSY) ENFORCE_SUCCESS_GVL(error);
|
365
364
|
|
366
365
|
// Slot one is active
|
367
366
|
if (!error) return (struct active_slot_pair) {.mutex = &state->slot_one_mutex, .profile = state->slot_one_profile};
|
@@ -369,7 +368,7 @@ static struct active_slot_pair sampler_lock_active_profile(struct stack_recorder
|
|
369
368
|
// If we got here, slot one was not active, let's try slot two
|
370
369
|
|
371
370
|
error = pthread_mutex_trylock(&state->slot_two_mutex);
|
372
|
-
if (error && error != EBUSY)
|
371
|
+
if (error && error != EBUSY) ENFORCE_SUCCESS_GVL(error);
|
373
372
|
|
374
373
|
// Slot two is active
|
375
374
|
if (!error) return (struct active_slot_pair) {.mutex = &state->slot_two_mutex, .profile = state->slot_two_profile};
|
@@ -380,28 +379,24 @@ static struct active_slot_pair sampler_lock_active_profile(struct stack_recorder
|
|
380
379
|
}
|
381
380
|
|
382
381
|
static void sampler_unlock_active_profile(struct active_slot_pair active_slot) {
|
383
|
-
|
384
|
-
if (error != 0) rb_syserr_fail(error, "Unexpected failure in sampler_unlock_active_profile");
|
382
|
+
ENFORCE_SUCCESS_GVL(pthread_mutex_unlock(active_slot.mutex));
|
385
383
|
}
|
386
384
|
|
387
385
|
static ddog_Profile *serializer_flip_active_and_inactive_slots(struct stack_recorder_state *state) {
|
388
|
-
int error;
|
389
386
|
int previously_active_slot = state->active_slot;
|
390
387
|
|
391
388
|
if (previously_active_slot != 1 && previously_active_slot != 2) {
|
392
|
-
|
389
|
+
grab_gvl_and_raise(rb_eRuntimeError, "Unexpected active_slot state %d in serializer_flip_active_and_inactive_slots", previously_active_slot);
|
393
390
|
}
|
394
391
|
|
395
392
|
pthread_mutex_t *previously_active = (previously_active_slot == 1) ? &state->slot_one_mutex : &state->slot_two_mutex;
|
396
393
|
pthread_mutex_t *previously_inactive = (previously_active_slot == 1) ? &state->slot_two_mutex : &state->slot_one_mutex;
|
397
394
|
|
398
395
|
// Release the lock, thus making this slot active
|
399
|
-
|
400
|
-
if (error) rb_syserr_fail(error, "Unexpected failure during serializer_flip_active_and_inactive_slots for previously_inactive");
|
396
|
+
ENFORCE_SUCCESS_NO_GVL(pthread_mutex_unlock(previously_inactive));
|
401
397
|
|
402
398
|
// Grab the lock, thus making this slot inactive
|
403
|
-
|
404
|
-
if (error) rb_syserr_fail(error, "Unexpected failure during serializer_flip_active_and_inactive_slots for previously_active");
|
399
|
+
ENFORCE_SUCCESS_NO_GVL(pthread_mutex_lock(previously_active));
|
405
400
|
|
406
401
|
// Update active_slot
|
407
402
|
state->active_slot = (previously_active_slot == 1) ? 2 : 1;
|
@@ -438,21 +433,23 @@ static VALUE test_slot_mutex_state(VALUE recorder_instance, int slot) {
|
|
438
433
|
|
439
434
|
if (error == 0) {
|
440
435
|
// Mutex was unlocked
|
441
|
-
pthread_mutex_unlock(slot_mutex);
|
436
|
+
ENFORCE_SUCCESS_GVL(pthread_mutex_unlock(slot_mutex));
|
442
437
|
return Qfalse;
|
443
438
|
} else if (error == EBUSY) {
|
444
439
|
// Mutex was locked
|
445
440
|
return Qtrue;
|
446
441
|
} else {
|
447
|
-
|
442
|
+
ENFORCE_SUCCESS_GVL(error);
|
443
|
+
rb_raise(rb_eRuntimeError, "Failed to raise exception in test_slot_mutex_state; this should never happen");
|
448
444
|
}
|
449
445
|
}
|
450
446
|
|
451
|
-
// Note that this is using CLOCK_REALTIME (e.g. actual time since unix epoch) and not the CLOCK_MONOTONIC as we use in
|
452
|
-
|
447
|
+
// Note that this is using CLOCK_REALTIME (e.g. actual time since unix epoch) and not the CLOCK_MONOTONIC as we use in
|
448
|
+
// monotonic_wall_time_now_ns (used in other parts of the codebase)
|
449
|
+
static ddog_Timespec time_now(void) {
|
453
450
|
struct timespec current_time;
|
454
451
|
|
455
|
-
if (clock_gettime(CLOCK_REALTIME, ¤t_time) != 0)
|
452
|
+
if (clock_gettime(CLOCK_REALTIME, ¤t_time) != 0) ENFORCE_SUCCESS_GVL(errno);
|
456
453
|
|
457
454
|
return (ddog_Timespec) {.seconds = current_time.tv_sec, .nanoseconds = (uint32_t) current_time.tv_nsec};
|
458
455
|
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#include <errno.h>
|
2
|
+
#include <time.h>
|
3
|
+
|
4
|
+
#include "ruby_helpers.h"
|
5
|
+
#include "time_helpers.h"
|
6
|
+
|
7
|
+
// Safety: This function is assumed never to raise exceptions by callers when raise_on_failure == false
|
8
|
+
long monotonic_wall_time_now_ns(bool raise_on_failure) {
|
9
|
+
struct timespec current_monotonic;
|
10
|
+
|
11
|
+
if (clock_gettime(CLOCK_MONOTONIC, ¤t_monotonic) != 0) {
|
12
|
+
if (raise_on_failure) ENFORCE_SUCCESS_GVL(errno);
|
13
|
+
return 0;
|
14
|
+
}
|
15
|
+
|
16
|
+
return current_monotonic.tv_nsec + SECONDS_AS_NS(current_monotonic.tv_sec);
|
17
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#define SECONDS_AS_NS(value) (value * 1000 * 1000 * 1000L)
|
4
|
+
#define MILLIS_AS_NS(value) (value * 1000 * 1000L)
|
5
|
+
|
6
|
+
#define RAISE_ON_FAILURE true
|
7
|
+
#define DO_NOT_RAISE_ON_FAILURE false
|
8
|
+
|
9
|
+
// Safety: This function is assumed never to raise exceptions by callers when raise_on_failure == false
|
10
|
+
long monotonic_wall_time_now_ns(bool raise_on_failure);
|
@@ -248,6 +248,8 @@ module Datadog
|
|
248
248
|
# NOTE: Please update the Initialization section of ProfilingDevelopment.md with any changes to this method
|
249
249
|
|
250
250
|
if settings.profiling.advanced.force_enable_new_profiler
|
251
|
+
print_new_profiler_warnings
|
252
|
+
|
251
253
|
recorder = Datadog::Profiling::StackRecorder.new
|
252
254
|
collector = Datadog::Profiling::Collectors::CpuAndWallTimeWorker.new(
|
253
255
|
recorder: recorder,
|
@@ -331,20 +333,39 @@ module Datadog
|
|
331
333
|
end
|
332
334
|
|
333
335
|
def should_enable_gc_profiling?(settings)
|
334
|
-
return true if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3')
|
335
|
-
|
336
336
|
# See comments on the setting definition for more context on why it exists.
|
337
337
|
if settings.profiling.advanced.force_enable_gc_profiling
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
338
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3')
|
339
|
+
Datadog.logger.debug(
|
340
|
+
'Profiling time/resources spent in Garbage Collection force enabled. Do not use Ractors in combination ' \
|
341
|
+
'with this option as profiles will be incomplete.'
|
342
|
+
)
|
343
|
+
end
|
342
344
|
|
343
345
|
true
|
344
346
|
else
|
345
347
|
false
|
346
348
|
end
|
347
349
|
end
|
350
|
+
|
351
|
+
def print_new_profiler_warnings
|
352
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6')
|
353
|
+
Datadog.logger.warn(
|
354
|
+
'New Ruby profiler has been force-enabled. This feature is in beta state. We do not yet recommend ' \
|
355
|
+
'running it in production environments. Please report any issues ' \
|
356
|
+
'you run into to Datadog support or via <https://github.com/datadog/dd-trace-rb/issues/new>!'
|
357
|
+
)
|
358
|
+
else
|
359
|
+
# For more details on the issue, see the "BIG Issue" comment on `gvl_owner` function in
|
360
|
+
# `private_vm_api_access.c`.
|
361
|
+
Datadog.logger.warn(
|
362
|
+
'New Ruby profiler has been force-enabled on a legacy Ruby version (< 2.6). This is not recommended in ' \
|
363
|
+
'production environments, as due to limitations in Ruby APIs, we suspect it may lead to crashes in very ' \
|
364
|
+
'rare situations. Please report any issues you run into to Datadog support or ' \
|
365
|
+
'via <https://github.com/datadog/dd-trace-rb/issues/new>!'
|
366
|
+
)
|
367
|
+
end
|
368
|
+
end
|
348
369
|
end
|
349
370
|
|
350
371
|
attr_reader \
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module Core
|
5
|
+
module Configuration
|
6
|
+
# Constants for configuration settings
|
7
|
+
# e.g. Env vars, default values, enums, etc...
|
8
|
+
module Ext
|
9
|
+
# @public_api
|
10
|
+
module Diagnostics
|
11
|
+
ENV_DEBUG_ENABLED = 'DD_TRACE_DEBUG'.freeze
|
12
|
+
ENV_HEALTH_METRICS_ENABLED = 'DD_HEALTH_METRICS_ENABLED'.freeze
|
13
|
+
ENV_STARTUP_LOGS_ENABLED = 'DD_TRACE_STARTUP_LOGS'.freeze
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -3,22 +3,27 @@
|
|
3
3
|
require 'logger'
|
4
4
|
|
5
5
|
require_relative 'base'
|
6
|
+
require_relative 'ext'
|
6
7
|
require_relative '../environment/ext'
|
7
8
|
require_relative '../runtime/ext'
|
8
9
|
require_relative '../telemetry/ext'
|
9
10
|
require_relative '../../profiling/ext'
|
10
|
-
|
11
|
+
|
12
|
+
require_relative '../../tracing/configuration/settings'
|
11
13
|
|
12
14
|
module Datadog
|
13
15
|
module Core
|
14
16
|
module Configuration
|
15
|
-
# Global configuration settings for the
|
17
|
+
# Global configuration settings for the Datadog library.
|
16
18
|
# @public_api
|
17
19
|
# rubocop:disable Metrics/BlockLength
|
18
|
-
# rubocop:disable Layout/LineLength
|
19
20
|
class Settings
|
20
21
|
include Base
|
21
22
|
|
23
|
+
# TODO: Tracing should manage its own settings.
|
24
|
+
# Keep this extension here for now to keep things working.
|
25
|
+
extend Datadog::Tracing::Configuration::Settings
|
26
|
+
|
22
27
|
# @!visibility private
|
23
28
|
def initialize(*_)
|
24
29
|
super
|
@@ -99,7 +104,7 @@ module Datadog
|
|
99
104
|
# @default `DD_TRACE_DEBUG` environment variable, otherwise `false`
|
100
105
|
# @return [Boolean]
|
101
106
|
option :debug do |o|
|
102
|
-
o.default { env_to_bool(Datadog::Core::
|
107
|
+
o.default { env_to_bool(Datadog::Core::Configuration::Ext::Diagnostics::ENV_DEBUG_ENABLED, false) }
|
103
108
|
o.lazy
|
104
109
|
o.on_set do |enabled|
|
105
110
|
# Enable rich debug print statements.
|
@@ -110,7 +115,6 @@ module Datadog
|
|
110
115
|
|
111
116
|
# Internal {Datadog::Statsd} metrics collection.
|
112
117
|
#
|
113
|
-
# The list of metrics collected can be found in {Datadog::Core::Diagnostics::Ext::Health::Metrics}.
|
114
118
|
# @public_api
|
115
119
|
settings :health_metrics do
|
116
120
|
# Enable health metrics collection.
|
@@ -118,7 +122,7 @@ module Datadog
|
|
118
122
|
# @default `DD_HEALTH_METRICS_ENABLED` environment variable, otherwise `false`
|
119
123
|
# @return [Boolean]
|
120
124
|
option :enabled do |o|
|
121
|
-
o.default { env_to_bool(Datadog::Core::
|
125
|
+
o.default { env_to_bool(Datadog::Core::Configuration::Ext::Diagnostics::ENV_HEALTH_METRICS_ENABLED, false) }
|
122
126
|
o.lazy
|
123
127
|
end
|
124
128
|
|
@@ -144,7 +148,7 @@ module Datadog
|
|
144
148
|
# @return [Boolean,nil]
|
145
149
|
option :enabled do |o|
|
146
150
|
# Defaults to nil as we want to know when the default value is being used
|
147
|
-
o.default { env_to_bool(Datadog::Core::
|
151
|
+
o.default { env_to_bool(Datadog::Core::Configuration::Ext::Diagnostics::ENV_STARTUP_LOGS_ENABLED, nil) }
|
148
152
|
o.lazy
|
149
153
|
end
|
150
154
|
end
|
@@ -269,7 +273,9 @@ module Datadog
|
|
269
273
|
# If you use Ruby 3.x and your application does not use Ractors (or if your Ruby has been patched), the
|
270
274
|
# feature is fully safe to enable and this toggle can be used to do so.
|
271
275
|
#
|
272
|
-
#
|
276
|
+
# Furthermore, currently this feature can add a lot of overhead for GC-heavy workloads.
|
277
|
+
#
|
278
|
+
# We expect the once the above issues are overcome, we'll automatically enable the feature on fixed Ruby
|
273
279
|
# versions.
|
274
280
|
option :force_enable_gc_profiling do |o|
|
275
281
|
o.default { env_to_bool('DD_PROFILING_FORCE_ENABLE_GC', false) }
|
@@ -408,338 +414,6 @@ module Datadog
|
|
408
414
|
end
|
409
415
|
end
|
410
416
|
|
411
|
-
# Tracer specific configurations.
|
412
|
-
# @public_api
|
413
|
-
settings :tracing do
|
414
|
-
# Legacy [App Analytics](https://docs.datadoghq.com/tracing/legacy_app_analytics/) configuration.
|
415
|
-
#
|
416
|
-
# @configure_with {Datadog::Tracing}
|
417
|
-
# @deprecated Use [Trace Retention and Ingestion](https://docs.datadoghq.com/tracing/trace_retention_and_ingestion/)
|
418
|
-
# controls.
|
419
|
-
# @public_api
|
420
|
-
settings :analytics do
|
421
|
-
# @default `DD_TRACE_ANALYTICS_ENABLED` environment variable, otherwise `nil`
|
422
|
-
# @return [Boolean,nil]
|
423
|
-
option :enabled do |o|
|
424
|
-
o.default { env_to_bool(Tracing::Configuration::Ext::Analytics::ENV_TRACE_ANALYTICS_ENABLED, nil) }
|
425
|
-
o.lazy
|
426
|
-
end
|
427
|
-
end
|
428
|
-
|
429
|
-
# [Distributed Tracing](https://docs.datadoghq.com/tracing/setup_overview/setup/ruby/#distributed-tracing) propagation
|
430
|
-
# style configuration.
|
431
|
-
#
|
432
|
-
# The supported formats are:
|
433
|
-
# * `Datadog`: Datadog propagation format, described by [Distributed Tracing](https://docs.datadoghq.com/tracing/setup_overview/setup/ruby/#distributed-tracing).
|
434
|
-
# * `B3`: B3 Propagation using multiple headers, described by [openzipkin/b3-propagation](https://github.com/openzipkin/b3-propagation#multiple-headers).
|
435
|
-
# * `B3 single header`: B3 Propagation using a single header, described by [openzipkin/b3-propagation](https://github.com/openzipkin/b3-propagation#single-header).
|
436
|
-
#
|
437
|
-
# @public_api
|
438
|
-
settings :distributed_tracing do
|
439
|
-
# An ordered list of what data propagation styles the tracer will use to extract distributed tracing propagation
|
440
|
-
# data from incoming requests and messages.
|
441
|
-
#
|
442
|
-
# The tracer will try to find distributed headers in the order they are present in the list provided to this option.
|
443
|
-
# The first format to have valid data present will be used.
|
444
|
-
#
|
445
|
-
# @default `DD_PROPAGATION_STYLE_EXTRACT` environment variable (comma-separated list),
|
446
|
-
# otherwise `['Datadog','B3','B3 single header']`.
|
447
|
-
# @return [Array<String>]
|
448
|
-
option :propagation_extract_style do |o|
|
449
|
-
o.default do
|
450
|
-
# Look for all headers by default
|
451
|
-
env_to_list(
|
452
|
-
Tracing::Configuration::Ext::Distributed::ENV_PROPAGATION_STYLE_EXTRACT,
|
453
|
-
[
|
454
|
-
Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_DATADOG,
|
455
|
-
Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3,
|
456
|
-
Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_SINGLE_HEADER
|
457
|
-
],
|
458
|
-
comma_separated_only: true
|
459
|
-
)
|
460
|
-
end
|
461
|
-
|
462
|
-
o.lazy
|
463
|
-
end
|
464
|
-
|
465
|
-
# The data propagation styles the tracer will use to inject distributed tracing propagation
|
466
|
-
# data into outgoing requests and messages.
|
467
|
-
#
|
468
|
-
# The tracer will inject data from all styles specified in this option.
|
469
|
-
#
|
470
|
-
# @default `DD_PROPAGATION_STYLE_INJECT` environment variable (comma-separated list), otherwise `['Datadog']`.
|
471
|
-
# @return [Array<String>]
|
472
|
-
option :propagation_inject_style do |o|
|
473
|
-
o.default do
|
474
|
-
env_to_list(
|
475
|
-
Tracing::Configuration::Ext::Distributed::ENV_PROPAGATION_STYLE_INJECT,
|
476
|
-
[Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_DATADOG],
|
477
|
-
comma_separated_only: true # Only inject Datadog headers by default
|
478
|
-
)
|
479
|
-
end
|
480
|
-
|
481
|
-
o.lazy
|
482
|
-
end
|
483
|
-
end
|
484
|
-
|
485
|
-
# Enable trace collection and span generation.
|
486
|
-
#
|
487
|
-
# You can use this option to disable tracing without having to
|
488
|
-
# remove the library as a whole.
|
489
|
-
#
|
490
|
-
# @default `DD_TRACE_ENABLED` environment variable, otherwise `true`
|
491
|
-
# @return [Boolean]
|
492
|
-
option :enabled do |o|
|
493
|
-
o.default { env_to_bool(Datadog::Core::Diagnostics::Ext::DD_TRACE_ENABLED, true) }
|
494
|
-
o.lazy
|
495
|
-
end
|
496
|
-
|
497
|
-
# A custom tracer instance.
|
498
|
-
#
|
499
|
-
# It must respect the contract of {Datadog::Tracing::Tracer}.
|
500
|
-
# It's recommended to delegate methods to {Datadog::Tracing::Tracer} to ease the implementation
|
501
|
-
# of a custom tracer.
|
502
|
-
#
|
503
|
-
# This option will not return the live tracer instance: it only holds a custom tracing instance, if any.
|
504
|
-
#
|
505
|
-
# For internal use only.
|
506
|
-
#
|
507
|
-
# @default `nil`
|
508
|
-
# @return [Object,nil]
|
509
|
-
option :instance
|
510
|
-
|
511
|
-
# Automatic correlation between tracing and logging.
|
512
|
-
# @see https://docs.datadoghq.com/tracing/setup_overview/setup/ruby/#trace-correlation
|
513
|
-
# @return [Boolean]
|
514
|
-
option :log_injection do |o|
|
515
|
-
o.default { env_to_bool(Tracing::Configuration::Ext::Correlation::ENV_LOGS_INJECTION_ENABLED, true) }
|
516
|
-
o.lazy
|
517
|
-
end
|
518
|
-
|
519
|
-
# Configures an alternative trace transport behavior, where
|
520
|
-
# traces can be sent to the agent and backend before all spans
|
521
|
-
# have finished.
|
522
|
-
#
|
523
|
-
# This is useful for long-running jobs or very large traces.
|
524
|
-
#
|
525
|
-
# The trace flame graph will display the partial trace as it is received and constantly
|
526
|
-
# update with new spans as they are flushed.
|
527
|
-
# @public_api
|
528
|
-
settings :partial_flush do
|
529
|
-
# Enable partial trace flushing.
|
530
|
-
#
|
531
|
-
# @default `false`
|
532
|
-
# @return [Boolean]
|
533
|
-
option :enabled, default: false
|
534
|
-
|
535
|
-
# Minimum number of finished spans required in a single unfinished trace before
|
536
|
-
# the tracer will consider that trace for partial flushing.
|
537
|
-
#
|
538
|
-
# This option helps preserve a minimum amount of batching in the
|
539
|
-
# flushing process, reducing network overhead.
|
540
|
-
#
|
541
|
-
# This threshold only applies to unfinished traces. Traces that have finished
|
542
|
-
# are always flushed immediately.
|
543
|
-
#
|
544
|
-
# @default 500
|
545
|
-
# @return [Integer]
|
546
|
-
option :min_spans_threshold, default: 500
|
547
|
-
end
|
548
|
-
|
549
|
-
# Enables {https://docs.datadoghq.com/tracing/trace_retention_and_ingestion/#datadog-intelligent-retention-filter
|
550
|
-
# Datadog intelligent retention filter}.
|
551
|
-
# @default `true`
|
552
|
-
# @return [Boolean,nil]
|
553
|
-
option :priority_sampling
|
554
|
-
|
555
|
-
option :report_hostname do |o|
|
556
|
-
o.default { env_to_bool(Tracing::Configuration::Ext::NET::ENV_REPORT_HOSTNAME, false) }
|
557
|
-
o.lazy
|
558
|
-
end
|
559
|
-
|
560
|
-
# A custom sampler instance.
|
561
|
-
# The object must respect the {Datadog::Tracing::Sampling::Sampler} interface.
|
562
|
-
# @default `nil`
|
563
|
-
# @return [Object,nil]
|
564
|
-
option :sampler
|
565
|
-
|
566
|
-
# Client-side sampling configuration.
|
567
|
-
# @see https://docs.datadoghq.com/tracing/trace_ingestion/mechanisms/
|
568
|
-
# @public_api
|
569
|
-
settings :sampling do
|
570
|
-
# Default sampling rate for the tracer.
|
571
|
-
#
|
572
|
-
# If `nil`, the trace uses an automatic sampling strategy that tries to ensure
|
573
|
-
# the collection of traces that are considered important (e.g. traces with an error, traces
|
574
|
-
# for resources not seen recently).
|
575
|
-
#
|
576
|
-
# @default `DD_TRACE_SAMPLE_RATE` environment variable, otherwise `nil`.
|
577
|
-
# @return [Float,nil]
|
578
|
-
option :default_rate do |o|
|
579
|
-
o.default { env_to_float(Tracing::Configuration::Ext::Sampling::ENV_SAMPLE_RATE, nil) }
|
580
|
-
o.lazy
|
581
|
-
end
|
582
|
-
|
583
|
-
# Rate limit for number of spans per second.
|
584
|
-
#
|
585
|
-
# Spans created above the limit will contribute to service metrics, but won't
|
586
|
-
# have their payload stored.
|
587
|
-
#
|
588
|
-
# @default `DD_TRACE_RATE_LIMIT` environment variable, otherwise 100.
|
589
|
-
# @return [Numeric,nil]
|
590
|
-
option :rate_limit do |o|
|
591
|
-
o.default { env_to_float(Tracing::Configuration::Ext::Sampling::ENV_RATE_LIMIT, 100) }
|
592
|
-
o.lazy
|
593
|
-
end
|
594
|
-
|
595
|
-
# Single span sampling rules.
|
596
|
-
# These rules allow a span to be kept when its encompassing trace is dropped.
|
597
|
-
#
|
598
|
-
# The syntax for single span sampling rules can be found here:
|
599
|
-
# TODO: <Single Span Sampling documentation URL here>
|
600
|
-
#
|
601
|
-
# @default `DD_SPAN_SAMPLING_RULES` environment variable.
|
602
|
-
# Otherwise, `ENV_SPAN_SAMPLING_RULES_FILE` environment variable.
|
603
|
-
# Otherwise `nil`.
|
604
|
-
# @return [String,nil]
|
605
|
-
# @public_api
|
606
|
-
option :span_rules do |o|
|
607
|
-
o.default do
|
608
|
-
rules = ENV[Tracing::Configuration::Ext::Sampling::Span::ENV_SPAN_SAMPLING_RULES]
|
609
|
-
rules_file = ENV[Tracing::Configuration::Ext::Sampling::Span::ENV_SPAN_SAMPLING_RULES_FILE]
|
610
|
-
|
611
|
-
if rules
|
612
|
-
if rules_file
|
613
|
-
Datadog.logger.warn(
|
614
|
-
'Both DD_SPAN_SAMPLING_RULES and DD_SPAN_SAMPLING_RULES_FILE were provided: only ' \
|
615
|
-
'DD_SPAN_SAMPLING_RULES will be used. Please do not provide DD_SPAN_SAMPLING_RULES_FILE when ' \
|
616
|
-
'also providing DD_SPAN_SAMPLING_RULES as their configuration conflicts. ' \
|
617
|
-
"DD_SPAN_SAMPLING_RULES_FILE=#{rules_file} DD_SPAN_SAMPLING_RULES=#{rules}"
|
618
|
-
)
|
619
|
-
end
|
620
|
-
rules
|
621
|
-
elsif rules_file
|
622
|
-
begin
|
623
|
-
File.read(rules_file)
|
624
|
-
rescue => e
|
625
|
-
# `File#read` errors have clear and actionable messages, no need to add extra exception info.
|
626
|
-
Datadog.logger.warn(
|
627
|
-
"Cannot read span sampling rules file `#{rules_file}`: #{e.message}." \
|
628
|
-
'No span sampling rules will be applied.'
|
629
|
-
)
|
630
|
-
nil
|
631
|
-
end
|
632
|
-
end
|
633
|
-
end
|
634
|
-
o.lazy
|
635
|
-
end
|
636
|
-
end
|
637
|
-
|
638
|
-
# [Continuous Integration Visibility](https://docs.datadoghq.com/continuous_integration/) configuration.
|
639
|
-
# @public_api
|
640
|
-
settings :test_mode do
|
641
|
-
# Enable test mode. This allows the tracer to collect spans from test runs.
|
642
|
-
#
|
643
|
-
# It also prevents the tracer from collecting spans in a production environment. Only use in a test environment.
|
644
|
-
#
|
645
|
-
# @default `DD_TRACE_TEST_MODE_ENABLED` environment variable, otherwise `false`
|
646
|
-
# @return [Boolean]
|
647
|
-
option :enabled do |o|
|
648
|
-
o.default { env_to_bool(Tracing::Configuration::Ext::Test::ENV_MODE_ENABLED, false) }
|
649
|
-
o.lazy
|
650
|
-
end
|
651
|
-
|
652
|
-
option :trace_flush do |o|
|
653
|
-
o.default { nil }
|
654
|
-
o.lazy
|
655
|
-
end
|
656
|
-
|
657
|
-
option :writer_options do |o|
|
658
|
-
o.default { {} }
|
659
|
-
o.lazy
|
660
|
-
end
|
661
|
-
end
|
662
|
-
|
663
|
-
# @see file:docs/GettingStarted.md#configuring-the-transport-layer Configuring the transport layer
|
664
|
-
#
|
665
|
-
# A {Proc} that configures a custom tracer transport.
|
666
|
-
# @yield Receives a {Datadog::Transport::HTTP} that can be modified with custom adapters and settings.
|
667
|
-
# @yieldparam [Datadog::Transport::HTTP] t transport to be configured.
|
668
|
-
# @default `nil`
|
669
|
-
# @return [Proc,nil]
|
670
|
-
option :transport_options, default: nil
|
671
|
-
|
672
|
-
# A custom writer instance.
|
673
|
-
# The object must respect the {Datadog::Tracing::Writer} interface.
|
674
|
-
#
|
675
|
-
# This option is recommended for internal use only.
|
676
|
-
#
|
677
|
-
# @default `nil`
|
678
|
-
# @return [Object,nil]
|
679
|
-
option :writer
|
680
|
-
|
681
|
-
# A custom {Hash} with keyword options to be passed to {Datadog::Tracing::Writer#initialize}.
|
682
|
-
#
|
683
|
-
# This option is recommended for internal use only.
|
684
|
-
#
|
685
|
-
# @default `{}`
|
686
|
-
# @return [Hash,nil]
|
687
|
-
option :writer_options, default: ->(_i) { {} }, lazy: true
|
688
|
-
|
689
|
-
# Client IP configuration
|
690
|
-
# @public_api
|
691
|
-
settings :client_ip do
|
692
|
-
# Whether client IP collection is enabled. When enabled client IPs from HTTP requests will
|
693
|
-
# be reported in traces.
|
694
|
-
#
|
695
|
-
# Usage of the DD_TRACE_CLIENT_IP_HEADER_DISABLED environment variable is deprecated.
|
696
|
-
#
|
697
|
-
# @see https://docs.datadoghq.com/tracing/configure_data_security#configuring-a-client-ip-header
|
698
|
-
#
|
699
|
-
# @default `DD_TRACE_CLIENT_IP_ENABLED` environment variable, otherwise `false`.
|
700
|
-
# @return [Boolean]
|
701
|
-
option :enabled do |o|
|
702
|
-
o.default do
|
703
|
-
disabled = env_to_bool(Tracing::Configuration::Ext::ClientIp::ENV_DISABLED)
|
704
|
-
|
705
|
-
enabled = if disabled.nil?
|
706
|
-
false
|
707
|
-
else
|
708
|
-
Datadog.logger.warn { "#{Tracing::Configuration::Ext::ClientIp::ENV_DISABLED} environment variable is deprecated, found set to #{disabled}, use #{Tracing::Configuration::Ext::ClientIp::ENV_ENABLED}=#{!disabled}" }
|
709
|
-
|
710
|
-
!disabled
|
711
|
-
end
|
712
|
-
|
713
|
-
# ENABLED env var takes precedence over deprecated DISABLED
|
714
|
-
env_to_bool(Tracing::Configuration::Ext::ClientIp::ENV_ENABLED, enabled)
|
715
|
-
end
|
716
|
-
o.lazy
|
717
|
-
end
|
718
|
-
|
719
|
-
# An optional name of a custom header to resolve the client IP from.
|
720
|
-
#
|
721
|
-
# @default `DD_TRACE_CLIENT_IP_HEADER` environment variable, otherwise `nil`.
|
722
|
-
# @return [String,nil]
|
723
|
-
option :header_name do |o|
|
724
|
-
o.default { ENV.fetch(Tracing::Configuration::Ext::ClientIp::ENV_HEADER_NAME, nil) }
|
725
|
-
o.lazy
|
726
|
-
end
|
727
|
-
end
|
728
|
-
|
729
|
-
# Maximum size for the `x-datadog-tags` distributed trace tags header.
|
730
|
-
#
|
731
|
-
# If the serialized size of distributed trace tags is larger than this value, it will
|
732
|
-
# not be parsed if incoming, nor exported if outgoing. An error message will be logged
|
733
|
-
# in this case.
|
734
|
-
#
|
735
|
-
# @default `DD_TRACE_X_DATADOG_TAGS_MAX_LENGTH` environment variable, otherwise `512`
|
736
|
-
# @return [Integer]
|
737
|
-
option :x_datadog_tags_max_length do |o|
|
738
|
-
o.default { env_to_int(Tracing::Configuration::Ext::Distributed::ENV_X_DATADOG_TAGS_MAX_LENGTH, 512) }
|
739
|
-
o.lazy
|
740
|
-
end
|
741
|
-
end
|
742
|
-
|
743
417
|
# The `version` tag in Datadog. Use it to enable [Deployment Tracking](https://docs.datadoghq.com/tracing/deployment_tracking/).
|
744
418
|
# @see https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging
|
745
419
|
# @default `DD_VERSION` environment variable, otherwise `nils`
|
@@ -765,7 +439,6 @@ module Datadog
|
|
765
439
|
end
|
766
440
|
end
|
767
441
|
# rubocop:enable Metrics/BlockLength
|
768
|
-
# rubocop:enable Layout/LineLength
|
769
442
|
end
|
770
443
|
end
|
771
444
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
# typed:
|
1
|
+
# typed: ignore
|
2
2
|
|
3
|
-
require_relative 'ext'
|
4
3
|
require_relative '../metrics/client'
|
4
|
+
require_relative '../../tracing/diagnostics/health'
|
5
5
|
|
6
6
|
module Datadog
|
7
7
|
module Core
|
@@ -10,26 +10,8 @@ module Datadog
|
|
10
10
|
module Health
|
11
11
|
# Health metrics for diagnostics
|
12
12
|
class Metrics < Core::Metrics::Client
|
13
|
-
|
14
|
-
|
15
|
-
count :api_responses, Ext::Health::Metrics::METRIC_API_RESPONSES
|
16
|
-
count :error_context_overflow, Ext::Health::Metrics::METRIC_ERROR_CONTEXT_OVERFLOW
|
17
|
-
count :error_instrumentation_patch, Ext::Health::Metrics::METRIC_ERROR_INSTRUMENTATION_PATCH
|
18
|
-
count :error_span_finish, Ext::Health::Metrics::METRIC_ERROR_SPAN_FINISH
|
19
|
-
count :error_unfinished_spans, Ext::Health::Metrics::METRIC_ERROR_UNFINISHED_SPANS
|
20
|
-
count :instrumentation_patched, Ext::Health::Metrics::METRIC_INSTRUMENTATION_PATCHED
|
21
|
-
count :queue_accepted, Ext::Health::Metrics::METRIC_QUEUE_ACCEPTED
|
22
|
-
count :queue_accepted_lengths, Ext::Health::Metrics::METRIC_QUEUE_ACCEPTED_LENGTHS
|
23
|
-
count :queue_dropped, Ext::Health::Metrics::METRIC_QUEUE_DROPPED
|
24
|
-
count :traces_filtered, Ext::Health::Metrics::METRIC_TRACES_FILTERED
|
25
|
-
count :transport_trace_too_large, Ext::Health::Metrics::METRIC_TRANSPORT_TRACE_TOO_LARGE
|
26
|
-
count :transport_chunked, Ext::Health::Metrics::METRIC_TRANSPORT_CHUNKED
|
27
|
-
count :writer_cpu_time, Ext::Health::Metrics::METRIC_WRITER_CPU_TIME
|
28
|
-
|
29
|
-
gauge :queue_length, Ext::Health::Metrics::METRIC_QUEUE_LENGTH
|
30
|
-
gauge :queue_max_length, Ext::Health::Metrics::METRIC_QUEUE_MAX_LENGTH
|
31
|
-
gauge :queue_spans, Ext::Health::Metrics::METRIC_QUEUE_SPANS
|
32
|
-
gauge :sampling_service_cache_length, Ext::Health::Metrics::METRIC_SAMPLING_SERVICE_CACHE_LENGTH
|
13
|
+
# TODO: Don't reference this. Have tracing add its metrics behavior.
|
14
|
+
extend Tracing::Diagnostics::Health::Metrics
|
33
15
|
end
|
34
16
|
end
|
35
17
|
end
|