ddtrace 1.4.1 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +144 -1
- data/LICENSE-3rdparty.csv +1 -0
- data/ext/ddtrace_profiling_loader/ddtrace_profiling_loader.c +9 -2
- data/ext/ddtrace_profiling_loader/extconf.rb +17 -0
- data/ext/ddtrace_profiling_native_extension/NativeExtensionDesign.md +38 -2
- data/ext/ddtrace_profiling_native_extension/clock_id.h +1 -0
- data/ext/ddtrace_profiling_native_extension/clock_id_from_pthread.c +1 -0
- data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.c +517 -42
- data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.h +3 -0
- data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +208 -30
- data/ext/ddtrace_profiling_native_extension/collectors_stack.c +156 -46
- data/ext/ddtrace_profiling_native_extension/collectors_stack.h +11 -2
- data/ext/ddtrace_profiling_native_extension/extconf.rb +11 -1
- data/ext/ddtrace_profiling_native_extension/http_transport.c +83 -64
- data/ext/ddtrace_profiling_native_extension/libdatadog_helpers.h +4 -4
- data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +3 -4
- data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +59 -0
- data/ext/ddtrace_profiling_native_extension/private_vm_api_access.h +3 -0
- data/ext/ddtrace_profiling_native_extension/profiling.c +10 -0
- data/ext/ddtrace_profiling_native_extension/ruby_helpers.c +0 -1
- data/ext/ddtrace_profiling_native_extension/ruby_helpers.h +4 -2
- data/ext/ddtrace_profiling_native_extension/stack_recorder.c +45 -29
- data/ext/ddtrace_profiling_native_extension/stack_recorder.h +7 -7
- data/lib/datadog/appsec/assets/waf_rules/recommended.json +1169 -275
- data/lib/datadog/appsec/assets/waf_rules/risky.json +78 -78
- data/lib/datadog/appsec/assets/waf_rules/strict.json +278 -88
- data/lib/datadog/appsec/configuration/settings.rb +0 -2
- data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +25 -20
- data/lib/datadog/appsec/contrib/rack/reactive/request.rb +11 -11
- data/lib/datadog/appsec/contrib/rack/reactive/request_body.rb +11 -11
- data/lib/datadog/appsec/contrib/rack/reactive/response.rb +11 -11
- data/lib/datadog/appsec/contrib/rack/request.rb +3 -0
- data/lib/datadog/appsec/contrib/rack/request_middleware.rb +46 -19
- data/lib/datadog/appsec/contrib/rails/gateway/watcher.rb +7 -6
- data/lib/datadog/appsec/contrib/rails/integration.rb +1 -1
- data/lib/datadog/appsec/contrib/rails/reactive/action.rb +11 -11
- data/lib/datadog/appsec/contrib/rails/request.rb +3 -0
- data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +14 -12
- data/lib/datadog/appsec/contrib/sinatra/reactive/routed.rb +11 -11
- data/lib/datadog/appsec/event.rb +6 -10
- data/lib/datadog/appsec/instrumentation/gateway.rb +16 -2
- data/lib/datadog/appsec/processor.rb +18 -2
- data/lib/datadog/ci/ext/environment.rb +16 -4
- data/lib/datadog/core/configuration/agent_settings_resolver.rb +0 -3
- data/lib/datadog/core/configuration/components.rb +28 -16
- data/lib/datadog/core/configuration/settings.rb +127 -8
- data/lib/datadog/core/configuration.rb +1 -1
- data/lib/datadog/core/diagnostics/environment_logger.rb +5 -1
- data/lib/datadog/core/header_collection.rb +41 -0
- data/lib/datadog/core/telemetry/collector.rb +0 -2
- data/lib/datadog/core/utils/compression.rb +5 -1
- data/lib/datadog/core/workers/async.rb +0 -2
- data/lib/datadog/core.rb +0 -54
- data/lib/datadog/opentracer/tracer.rb +4 -6
- data/lib/datadog/profiling/collectors/cpu_and_wall_time.rb +12 -2
- data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +5 -3
- data/lib/datadog/profiling/collectors/old_stack.rb +1 -1
- data/lib/datadog/profiling/exporter.rb +2 -4
- data/lib/datadog/profiling/http_transport.rb +1 -1
- data/lib/datadog/profiling.rb +1 -1
- data/lib/datadog/tracing/client_ip.rb +164 -0
- data/lib/datadog/tracing/configuration/ext.rb +14 -0
- data/lib/datadog/tracing/contrib/aws/instrumentation.rb +2 -0
- data/lib/datadog/tracing/contrib/aws/services.rb +0 -2
- data/lib/datadog/tracing/contrib/dalli/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +4 -0
- data/lib/datadog/tracing/contrib/elasticsearch/ext.rb +2 -0
- data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +3 -0
- data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +2 -2
- data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +2 -0
- data/lib/datadog/tracing/contrib/excon/middleware.rb +2 -0
- data/lib/datadog/tracing/contrib/ext.rb +25 -0
- data/lib/datadog/tracing/contrib/faraday/middleware.rb +3 -2
- data/lib/datadog/tracing/contrib/grape/endpoint.rb +0 -2
- data/lib/datadog/tracing/contrib/graphql/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +5 -0
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +7 -1
- data/lib/datadog/tracing/contrib/grpc/ext.rb +2 -0
- data/lib/datadog/tracing/contrib/hanami/action_tracer.rb +47 -0
- data/lib/datadog/tracing/contrib/hanami/configuration/settings.rb +22 -0
- data/lib/datadog/tracing/contrib/hanami/ext.rb +24 -0
- data/lib/datadog/tracing/contrib/hanami/integration.rb +44 -0
- data/lib/datadog/tracing/contrib/hanami/patcher.rb +33 -0
- data/lib/datadog/tracing/contrib/hanami/plugin.rb +23 -0
- data/lib/datadog/tracing/contrib/hanami/renderer_policy_tracing.rb +41 -0
- data/lib/datadog/tracing/contrib/hanami/router_tracing.rb +44 -0
- data/lib/datadog/tracing/contrib/http/instrumentation.rb +2 -0
- data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +2 -0
- data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +2 -0
- data/lib/datadog/tracing/contrib/mongodb/ext.rb +7 -0
- data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +4 -0
- data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +12 -0
- data/lib/datadog/tracing/contrib/mysql2/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +16 -0
- data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +12 -0
- data/lib/datadog/tracing/contrib/pg/ext.rb +2 -1
- data/lib/datadog/tracing/contrib/pg/instrumentation.rb +38 -21
- data/lib/datadog/tracing/contrib/propagation/sql_comment/comment.rb +43 -0
- data/lib/datadog/tracing/contrib/propagation/sql_comment/ext.rb +32 -0
- data/lib/datadog/tracing/contrib/propagation/sql_comment/mode.rb +28 -0
- data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +49 -0
- data/lib/datadog/tracing/contrib/rack/header_collection.rb +35 -0
- data/lib/datadog/tracing/contrib/rack/middlewares.rb +105 -43
- data/lib/datadog/tracing/contrib/redis/ext.rb +2 -0
- data/lib/datadog/tracing/contrib/redis/instrumentation.rb +4 -2
- data/lib/datadog/tracing/contrib/redis/integration.rb +2 -1
- data/lib/datadog/tracing/contrib/redis/patcher.rb +40 -0
- data/lib/datadog/tracing/contrib/redis/tags.rb +5 -0
- data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +2 -0
- data/lib/datadog/tracing/contrib/sinatra/env.rb +12 -23
- data/lib/datadog/tracing/contrib/sinatra/ext.rb +7 -3
- data/lib/datadog/tracing/contrib/sinatra/patcher.rb +2 -2
- data/lib/datadog/tracing/contrib/sinatra/tracer.rb +8 -80
- data/lib/datadog/tracing/contrib/sinatra/tracer_middleware.rb +14 -9
- data/lib/datadog/tracing/contrib/utils/quantization/http.rb +92 -10
- data/lib/datadog/tracing/contrib.rb +1 -0
- data/lib/datadog/tracing/distributed/datadog_tags_codec.rb +84 -0
- data/lib/datadog/tracing/distributed/headers/datadog.rb +122 -30
- data/lib/datadog/tracing/distributed/headers/ext.rb +2 -0
- data/lib/datadog/tracing/flush.rb +57 -35
- data/lib/datadog/tracing/metadata/ext.rb +11 -9
- data/lib/datadog/tracing/metadata/tagging.rb +9 -0
- data/lib/datadog/tracing/propagation/http.rb +9 -1
- data/lib/datadog/tracing/sampling/ext.rb +31 -0
- data/lib/datadog/tracing/sampling/priority_sampler.rb +46 -4
- data/lib/datadog/tracing/sampling/rate_by_key_sampler.rb +8 -9
- data/lib/datadog/tracing/sampling/rate_by_service_sampler.rb +29 -5
- data/lib/datadog/tracing/sampling/rate_limiter.rb +3 -0
- data/lib/datadog/tracing/sampling/rate_sampler.rb +20 -3
- data/lib/datadog/tracing/sampling/rule_sampler.rb +4 -3
- data/lib/datadog/tracing/sampling/span/ext.rb +25 -0
- data/lib/datadog/tracing/sampling/span/matcher.rb +9 -0
- data/lib/datadog/tracing/sampling/span/rule.rb +82 -0
- data/lib/datadog/tracing/sampling/span/rule_parser.rb +104 -0
- data/lib/datadog/tracing/sampling/span/sampler.rb +75 -0
- data/lib/datadog/tracing/span_operation.rb +0 -2
- data/lib/datadog/tracing/trace_digest.rb +3 -0
- data/lib/datadog/tracing/trace_operation.rb +32 -3
- data/lib/datadog/tracing/trace_segment.rb +7 -2
- data/lib/datadog/tracing/tracer.rb +34 -6
- data/lib/datadog/tracing/writer.rb +7 -0
- data/lib/ddtrace/transport/trace_formatter.rb +7 -0
- data/lib/ddtrace/transport/traces.rb +3 -1
- data/lib/ddtrace/version.rb +1 -1
- metadata +36 -18
- data/lib/datadog/profiling/old_ext.rb +0 -42
- data/lib/datadog/profiling/transport/http/api/endpoint.rb +0 -85
- data/lib/datadog/profiling/transport/http/api/instance.rb +0 -38
- data/lib/datadog/profiling/transport/http/api/spec.rb +0 -42
- data/lib/datadog/profiling/transport/http/api.rb +0 -45
- data/lib/datadog/profiling/transport/http/builder.rb +0 -30
- data/lib/datadog/profiling/transport/http/client.rb +0 -37
- data/lib/datadog/profiling/transport/http/response.rb +0 -21
- data/lib/datadog/profiling/transport/http.rb +0 -118
data/lib/datadog/appsec/event.rb
CHANGED
@@ -51,9 +51,8 @@ module Datadog
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
# rubocop:disable Metrics/AbcSize
|
55
54
|
# rubocop:disable Metrics/MethodLength
|
56
|
-
def self.record_via_span(*events)
|
55
|
+
def self.record_via_span(*events) # rubocop:disable Metrics/AbcSize
|
57
56
|
events.group_by { |e| e[:trace] }.each do |trace, event_group|
|
58
57
|
unless trace
|
59
58
|
Datadog.logger.debug { "{ error: 'no trace: cannot record', event_group: #{event_group.inspect}}" }
|
@@ -61,13 +60,13 @@ module Datadog
|
|
61
60
|
end
|
62
61
|
|
63
62
|
trace.keep!
|
63
|
+
trace.set_tag(
|
64
|
+
Datadog::Tracing::Metadata::Ext::Distributed::TAG_DECISION_MAKER,
|
65
|
+
Datadog::Tracing::Sampling::Ext::Decision::ASM
|
66
|
+
)
|
64
67
|
|
65
68
|
# prepare and gather tags to apply
|
66
69
|
trace_tags = event_group.each_with_object({}) do |event, tags|
|
67
|
-
span = event[:span]
|
68
|
-
|
69
|
-
span.set_tag('appsec.event', 'true') if span
|
70
|
-
|
71
70
|
# TODO: assume HTTP request context for now
|
72
71
|
|
73
72
|
if (request = event[:request])
|
@@ -81,9 +80,7 @@ module Datadog
|
|
81
80
|
|
82
81
|
tags['http.host'] = request.host
|
83
82
|
tags['http.useragent'] = request.user_agent
|
84
|
-
tags['network.client.ip'] = request.
|
85
|
-
|
86
|
-
# tags['actor.ip'] = request.ip # TODO: uses client IP resolution algorithm
|
83
|
+
tags['network.client.ip'] = request.env['REMOTE_ADDR'] if request.env['REMOTE_ADDR']
|
87
84
|
end
|
88
85
|
|
89
86
|
if (response = event[:response])
|
@@ -115,7 +112,6 @@ module Datadog
|
|
115
112
|
end
|
116
113
|
end
|
117
114
|
# rubocop:enable Metrics/MethodLength
|
118
|
-
# rubocop:enable Metrics/AbcSize
|
119
115
|
end
|
120
116
|
end
|
121
117
|
end
|
@@ -6,6 +6,20 @@ module Datadog
|
|
6
6
|
module Instrumentation
|
7
7
|
# Instrumentation gateway implementation
|
8
8
|
class Gateway
|
9
|
+
# Instrumentation gateway middleware
|
10
|
+
class Middleware
|
11
|
+
attr_reader :key, :block
|
12
|
+
|
13
|
+
def initialize(key, &block)
|
14
|
+
@key = key
|
15
|
+
@block = block
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(*args, **kwargs, &block)
|
19
|
+
@block.call(*args, **kwargs, &block)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
9
23
|
def initialize
|
10
24
|
@middlewares = Hash.new { |h, k| h[k] = [] }
|
11
25
|
end
|
@@ -31,8 +45,8 @@ module Datadog
|
|
31
45
|
stack.call(env)
|
32
46
|
end
|
33
47
|
|
34
|
-
def watch(name, &block)
|
35
|
-
@middlewares[name] << block
|
48
|
+
def watch(name, key, &block)
|
49
|
+
@middlewares[name] << Middleware.new(key, &block) unless @middlewares[name].any? { |m| m.key == key }
|
36
50
|
end
|
37
51
|
end
|
38
52
|
|
@@ -31,7 +31,7 @@ module Datadog
|
|
31
31
|
def run(*args)
|
32
32
|
start_ns = Core::Utils::Time.get_time(:nanosecond)
|
33
33
|
|
34
|
-
|
34
|
+
_code, res = @context.run(*args)
|
35
35
|
|
36
36
|
stop_ns = Core::Utils::Time.get_time(:nanosecond)
|
37
37
|
|
@@ -39,7 +39,11 @@ module Datadog
|
|
39
39
|
@time_ext_ns += (stop_ns - start_ns)
|
40
40
|
@timeouts += 1 if res.timeout
|
41
41
|
|
42
|
-
|
42
|
+
res
|
43
|
+
end
|
44
|
+
|
45
|
+
def finalize
|
46
|
+
@context.finalize
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
@@ -64,6 +68,18 @@ module Datadog
|
|
64
68
|
Context.new(self)
|
65
69
|
end
|
66
70
|
|
71
|
+
def update_rule_data(data)
|
72
|
+
@handle.update_rule_data(data)
|
73
|
+
end
|
74
|
+
|
75
|
+
def toggle_rules(map)
|
76
|
+
@handle.toggle_rules(map)
|
77
|
+
end
|
78
|
+
|
79
|
+
def finalize
|
80
|
+
@handle.finalize
|
81
|
+
end
|
82
|
+
|
67
83
|
protected
|
68
84
|
|
69
85
|
attr_reader :handle
|
@@ -10,7 +10,6 @@ module Datadog
|
|
10
10
|
module CI
|
11
11
|
module Ext
|
12
12
|
# Defines constants for CI tags
|
13
|
-
# rubocop:disable Metrics/ModuleLength:
|
14
13
|
module Environment
|
15
14
|
include Kernel # Ensure that kernel methods are always available (https://sorbet.org/docs/error-reference#7003)
|
16
15
|
|
@@ -97,6 +96,12 @@ module Datadog
|
|
97
96
|
tag = env['APPVEYOR_REPO_TAG_NAME']
|
98
97
|
end
|
99
98
|
|
99
|
+
commit_message = env['APPVEYOR_REPO_COMMIT_MESSAGE']
|
100
|
+
if commit_message
|
101
|
+
extended = env['APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED']
|
102
|
+
commit_message = "#{commit_message}\n#{extended}" if extended
|
103
|
+
end
|
104
|
+
|
100
105
|
{
|
101
106
|
TAG_PROVIDER_NAME => 'appveyor',
|
102
107
|
Core::Git::Ext::TAG_REPOSITORY_URL => repository,
|
@@ -111,7 +116,7 @@ module Datadog
|
|
111
116
|
Core::Git::Ext::TAG_TAG => tag,
|
112
117
|
Core::Git::Ext::TAG_COMMIT_AUTHOR_NAME => env['APPVEYOR_REPO_COMMIT_AUTHOR'],
|
113
118
|
Core::Git::Ext::TAG_COMMIT_AUTHOR_EMAIL => env['APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL'],
|
114
|
-
Core::Git::Ext::TAG_COMMIT_MESSAGE =>
|
119
|
+
Core::Git::Ext::TAG_COMMIT_MESSAGE => commit_message
|
115
120
|
}
|
116
121
|
end
|
117
122
|
|
@@ -330,6 +335,10 @@ module Datadog
|
|
330
335
|
branch = (
|
331
336
|
env['BITRISEIO_GIT_BRANCH_DEST'] || env['BITRISE_GIT_BRANCH']
|
332
337
|
)
|
338
|
+
commiter_email = (
|
339
|
+
env['GIT_CLONE_COMMIT_COMMITER_EMAIL'] || env['GIT_CLONE_COMMIT_COMMITER_NAME']
|
340
|
+
)
|
341
|
+
|
333
342
|
{
|
334
343
|
TAG_PROVIDER_NAME => 'bitrise',
|
335
344
|
TAG_PIPELINE_ID => env['BITRISE_BUILD_SLUG'],
|
@@ -341,7 +350,11 @@ module Datadog
|
|
341
350
|
Core::Git::Ext::TAG_COMMIT_SHA => commit,
|
342
351
|
Core::Git::Ext::TAG_BRANCH => branch,
|
343
352
|
Core::Git::Ext::TAG_TAG => env['BITRISE_GIT_TAG'],
|
344
|
-
Core::Git::Ext::TAG_COMMIT_MESSAGE => env['BITRISE_GIT_MESSAGE']
|
353
|
+
Core::Git::Ext::TAG_COMMIT_MESSAGE => env['BITRISE_GIT_MESSAGE'],
|
354
|
+
Core::Git::Ext::TAG_COMMIT_AUTHOR_NAME => env['GIT_CLONE_COMMIT_AUTHOR_NAME'],
|
355
|
+
Core::Git::Ext::TAG_COMMIT_AUTHOR_EMAIL => env['GIT_CLONE_COMMIT_AUTHOR_EMAIL'],
|
356
|
+
Core::Git::Ext::TAG_COMMIT_COMMITTER_NAME => env['GIT_CLONE_COMMIT_COMMITER_NAME'],
|
357
|
+
Core::Git::Ext::TAG_COMMIT_COMMITTER_EMAIL => commiter_email
|
345
358
|
}
|
346
359
|
end
|
347
360
|
|
@@ -499,7 +512,6 @@ module Datadog
|
|
499
512
|
[nil, name_and_email]
|
500
513
|
end
|
501
514
|
end
|
502
|
-
# rubocop:enable Metrics/ModuleLength:
|
503
515
|
end
|
504
516
|
end
|
505
517
|
end
|
@@ -18,8 +18,6 @@ module Datadog
|
|
18
18
|
#
|
19
19
|
# Whenever there is a conflict (different configurations are provided in different orders), it MUST warn the users
|
20
20
|
# about it and pick a value based on the following priority: code > environment variable > defaults.
|
21
|
-
#
|
22
|
-
# rubocop:disable Metrics/ClassLength
|
23
21
|
class AgentSettingsResolver
|
24
22
|
AgentSettings = \
|
25
23
|
Struct.new(
|
@@ -359,7 +357,6 @@ module Datadog
|
|
359
357
|
end
|
360
358
|
end
|
361
359
|
end
|
362
|
-
# rubocop:enable Metrics/ClassLength
|
363
360
|
end
|
364
361
|
end
|
365
362
|
end
|
@@ -11,12 +11,13 @@ require_relative '../workers/runtime_metrics'
|
|
11
11
|
require_relative '../../tracing/tracer'
|
12
12
|
require_relative '../../tracing/flush'
|
13
13
|
require_relative '../../tracing/sync_writer'
|
14
|
+
require_relative '../../tracing/sampling/span/rule_parser'
|
15
|
+
require_relative '../../tracing/sampling/span/sampler'
|
14
16
|
|
15
17
|
module Datadog
|
16
18
|
module Core
|
17
19
|
module Configuration
|
18
20
|
# Global components for the trace library.
|
19
|
-
# rubocop:disable Metrics/ClassLength
|
20
21
|
class Components
|
21
22
|
class << self
|
22
23
|
def build_health_metrics(settings)
|
@@ -80,6 +81,7 @@ module Datadog
|
|
80
81
|
enabled: settings.tracing.enabled,
|
81
82
|
trace_flush: trace_flush,
|
82
83
|
sampler: sampler,
|
84
|
+
span_sampler: build_span_sampler(settings),
|
83
85
|
writer: writer,
|
84
86
|
tags: build_tracer_tags(settings),
|
85
87
|
)
|
@@ -179,10 +181,15 @@ module Datadog
|
|
179
181
|
|
180
182
|
next unless response && !response.internal_error? && response.service_rates
|
181
183
|
|
182
|
-
sampler.update(response.service_rates)
|
184
|
+
sampler.update(response.service_rates, decision: Tracing::Sampling::Ext::Decision::AGENT_RATE)
|
183
185
|
end
|
184
186
|
end
|
185
187
|
|
188
|
+
def build_span_sampler(settings)
|
189
|
+
rules = Tracing::Sampling::Span::RuleParser.parse_json(settings.tracing.sampling.span_rules)
|
190
|
+
Tracing::Sampling::Span::Sampler.new(rules || [])
|
191
|
+
end
|
192
|
+
|
186
193
|
def build_profiler(settings, agent_settings, tracer)
|
187
194
|
return unless settings.profiling.enabled
|
188
195
|
|
@@ -244,7 +251,9 @@ module Datadog
|
|
244
251
|
recorder = Datadog::Profiling::StackRecorder.new
|
245
252
|
collector = Datadog::Profiling::Collectors::CpuAndWallTimeWorker.new(
|
246
253
|
recorder: recorder,
|
247
|
-
max_frames: settings.profiling.advanced.max_frames
|
254
|
+
max_frames: settings.profiling.advanced.max_frames,
|
255
|
+
tracer: tracer,
|
256
|
+
gc_profiling_enabled: should_enable_gc_profiling?(settings)
|
248
257
|
)
|
249
258
|
else
|
250
259
|
trace_identifiers_helper = Profiling::TraceIdentifiers::Helper.new(
|
@@ -313,18 +322,6 @@ module Datadog
|
|
313
322
|
|
314
323
|
def build_profiler_transport(settings, agent_settings)
|
315
324
|
settings.profiling.exporter.transport ||
|
316
|
-
if settings.profiling.advanced.legacy_transport_enabled
|
317
|
-
require_relative '../../profiling/transport/http'
|
318
|
-
|
319
|
-
Datadog.logger.warn('Using legacy profiling transport. Do not use unless instructed to by support.')
|
320
|
-
|
321
|
-
Profiling::Transport::HTTP.default(
|
322
|
-
agent_settings: agent_settings,
|
323
|
-
site: settings.site,
|
324
|
-
api_key: settings.api_key,
|
325
|
-
profiling_upload_timeout_seconds: settings.profiling.upload.timeout_seconds
|
326
|
-
)
|
327
|
-
end ||
|
328
325
|
Profiling::HttpTransport.new(
|
329
326
|
agent_settings: agent_settings,
|
330
327
|
site: settings.site,
|
@@ -332,6 +329,22 @@ module Datadog
|
|
332
329
|
upload_timeout_seconds: settings.profiling.upload.timeout_seconds,
|
333
330
|
)
|
334
331
|
end
|
332
|
+
|
333
|
+
def should_enable_gc_profiling?(settings)
|
334
|
+
return true if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3')
|
335
|
+
|
336
|
+
# See comments on the setting definition for more context on why it exists.
|
337
|
+
if settings.profiling.advanced.force_enable_gc_profiling
|
338
|
+
Datadog.logger.debug(
|
339
|
+
'Profiling time/resources spent in Garbage Collection force enabled. Do not use Ractors in combination ' \
|
340
|
+
'with this option as profiles will be incomplete.'
|
341
|
+
)
|
342
|
+
|
343
|
+
true
|
344
|
+
else
|
345
|
+
false
|
346
|
+
end
|
347
|
+
end
|
335
348
|
end
|
336
349
|
|
337
350
|
attr_reader \
|
@@ -423,7 +436,6 @@ module Datadog
|
|
423
436
|
telemetry.emit_closing! unless replacement
|
424
437
|
end
|
425
438
|
end
|
426
|
-
# rubocop:enable Metrics/ClassLength
|
427
439
|
end
|
428
440
|
end
|
429
441
|
end
|
@@ -15,7 +15,6 @@ module Datadog
|
|
15
15
|
# Global configuration settings for the trace library.
|
16
16
|
# @public_api
|
17
17
|
# rubocop:disable Metrics/BlockLength
|
18
|
-
# rubocop:disable Metrics/ClassLength
|
19
18
|
# rubocop:disable Layout/LineLength
|
20
19
|
class Settings
|
21
20
|
include Base
|
@@ -235,11 +234,17 @@ module Datadog
|
|
235
234
|
# categorization of stack traces.
|
236
235
|
option :code_provenance_enabled, default: true
|
237
236
|
|
238
|
-
#
|
239
|
-
#
|
237
|
+
# No longer does anything, and will be removed on dd-trace-rb 2.0.
|
238
|
+
#
|
239
|
+
# This was added as a temporary support option in case of issues with the new `Profiling::HttpTransport` class
|
240
|
+
# but we're now confident it's working nicely so we've removed the old code path.
|
240
241
|
option :legacy_transport_enabled do |o|
|
241
|
-
o.
|
242
|
-
|
242
|
+
o.on_set do
|
243
|
+
Datadog.logger.warn(
|
244
|
+
'The profiling.advanced.legacy_transport_enabled setting has been deprecated for removal and no ' \
|
245
|
+
'longer does anything. Please remove it from your Datadog.configure block.'
|
246
|
+
)
|
247
|
+
end
|
243
248
|
end
|
244
249
|
|
245
250
|
# Forces enabling the new profiler. We do not yet recommend turning on this option.
|
@@ -251,6 +256,25 @@ module Datadog
|
|
251
256
|
o.default { env_to_bool('DD_PROFILING_FORCE_ENABLE_NEW', false) }
|
252
257
|
o.lazy
|
253
258
|
end
|
259
|
+
|
260
|
+
# Forces enabling of profiling of time/resources spent in Garbage Collection.
|
261
|
+
#
|
262
|
+
# Note that setting this to "false" (or not setting it) will not prevent the feature from being
|
263
|
+
# being automatically enabled in the future.
|
264
|
+
#
|
265
|
+
# This toggle was added because, although this feature is safe and enabled by default on Ruby 2.x,
|
266
|
+
# on Ruby 3.x it can break in applications that make use of Ractors due to two Ruby VM bugs:
|
267
|
+
# https://bugs.ruby-lang.org/issues/19112 AND https://bugs.ruby-lang.org/issues/18464.
|
268
|
+
#
|
269
|
+
# If you use Ruby 3.x and your application does not use Ractors (or if your Ruby has been patched), the
|
270
|
+
# feature is fully safe to enable and this toggle can be used to do so.
|
271
|
+
#
|
272
|
+
# We expect that once the above issue is patched, we'll automatically re-enable the feature on fixed Ruby
|
273
|
+
# versions.
|
274
|
+
option :force_enable_gc_profiling do |o|
|
275
|
+
o.default { env_to_bool('DD_PROFILING_FORCE_ENABLE_GC', false) }
|
276
|
+
o.lazy
|
277
|
+
end
|
254
278
|
end
|
255
279
|
|
256
280
|
# @public_api
|
@@ -324,8 +348,8 @@ module Datadog
|
|
324
348
|
|
325
349
|
# Parse tags from environment
|
326
350
|
env_to_list(Core::Environment::Ext::ENV_TAGS, comma_separated_only: false).each do |tag|
|
327
|
-
|
328
|
-
tags[
|
351
|
+
key, value = tag.split(':', 2)
|
352
|
+
tags[key] = value if value && !value.empty?
|
329
353
|
end
|
330
354
|
|
331
355
|
# Override tags if defined
|
@@ -540,6 +564,7 @@ module Datadog
|
|
540
564
|
option :sampler
|
541
565
|
|
542
566
|
# Client-side sampling configuration.
|
567
|
+
# @see https://docs.datadoghq.com/tracing/trace_ingestion/mechanisms/
|
543
568
|
# @public_api
|
544
569
|
settings :sampling do
|
545
570
|
# Default sampling rate for the tracer.
|
@@ -566,6 +591,48 @@ module Datadog
|
|
566
591
|
o.default { env_to_float(Tracing::Configuration::Ext::Sampling::ENV_RATE_LIMIT, 100) }
|
567
592
|
o.lazy
|
568
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
|
569
636
|
end
|
570
637
|
|
571
638
|
# [Continuous Integration Visibility](https://docs.datadoghq.com/continuous_integration/) configuration.
|
@@ -618,6 +685,59 @@ module Datadog
|
|
618
685
|
# @default `{}`
|
619
686
|
# @return [Hash,nil]
|
620
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
|
621
741
|
end
|
622
742
|
|
623
743
|
# The `version` tag in Datadog. Use it to enable [Deployment Tracking](https://docs.datadoghq.com/tracing/deployment_tracking/).
|
@@ -645,7 +765,6 @@ module Datadog
|
|
645
765
|
end
|
646
766
|
end
|
647
767
|
# rubocop:enable Metrics/BlockLength
|
648
|
-
# rubocop:enable Metrics/ClassLength
|
649
768
|
# rubocop:enable Layout/LineLength
|
650
769
|
end
|
651
770
|
end
|
@@ -9,7 +9,7 @@ require_relative 'pin'
|
|
9
9
|
module Datadog
|
10
10
|
module Core
|
11
11
|
# Configuration provides a unique access point for configurations
|
12
|
-
module Configuration
|
12
|
+
module Configuration
|
13
13
|
include Kernel # Ensure that kernel methods are always available (https://sorbet.org/docs/error-reference#7003)
|
14
14
|
|
15
15
|
# Used to ensure that @components initialization/reconfiguration is performed one-at-a-time, by a single thread.
|
@@ -106,10 +106,14 @@ module Datadog
|
|
106
106
|
Datadog.configuration.version
|
107
107
|
end
|
108
108
|
|
109
|
-
# @return [String] target agent URL for trace flushing
|
109
|
+
# @return [String, nil] target agent URL for trace flushing
|
110
110
|
def agent_url
|
111
111
|
# Retrieve the effect agent URL, regardless of how it was configured
|
112
112
|
transport = Tracing.send(:tracer).writer.transport
|
113
|
+
|
114
|
+
# return `nil` with IO transport
|
115
|
+
return unless transport.respond_to?(:client)
|
116
|
+
|
113
117
|
adapter = transport.client.api.adapter
|
114
118
|
adapter.url
|
115
119
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Datadog
|
2
|
+
module Core
|
3
|
+
# A some-what abstract class representing a collection of headers.
|
4
|
+
#
|
5
|
+
# Use the `HeaderCollection.from_hash` function to create a header collection from a `Hash`.
|
6
|
+
# Another option is to use `HashHeaderCollection` directly.
|
7
|
+
class HeaderCollection
|
8
|
+
# Gets a single value of the header with the given name, case insensitive.
|
9
|
+
#
|
10
|
+
# @param [String] header_name Name of the header to get the value of.
|
11
|
+
# @returns [String, nil] A single value of the header, or nil if the header with
|
12
|
+
# the given name is missing from the collection.
|
13
|
+
def get(header_name)
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
# Create a header collection that retrieves headers from the given Hash.
|
18
|
+
#
|
19
|
+
# This can be useful for testing or other trivial use cases.
|
20
|
+
#
|
21
|
+
# @param [Hash] hash Hash with the headers.
|
22
|
+
def self.from_hash(hash)
|
23
|
+
HashHeaderCollection.new(hash)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# A header collection implementation that looks up headers in a Hash.
|
28
|
+
class HashHeaderCollection < HeaderCollection
|
29
|
+
def initialize(hash)
|
30
|
+
super()
|
31
|
+
@hash = {}.tap do |res|
|
32
|
+
hash.each_pair { |key, value| res[key.downcase] = value }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def get(header_name)
|
37
|
+
@hash[header_name.downcase]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -18,7 +18,6 @@ module Datadog
|
|
18
18
|
module Core
|
19
19
|
module Telemetry
|
20
20
|
# Module defining methods for collecting metadata for telemetry
|
21
|
-
# rubocop:disable Metrics/ModuleLength
|
22
21
|
module Collector
|
23
22
|
include Datadog::Core::Configuration
|
24
23
|
|
@@ -228,7 +227,6 @@ module Datadog
|
|
228
227
|
end
|
229
228
|
end
|
230
229
|
end
|
231
|
-
# rubocop:enable Metrics/ModuleLength
|
232
230
|
end
|
233
231
|
end
|
234
232
|
end
|
@@ -6,10 +6,13 @@ require 'zlib'
|
|
6
6
|
module Datadog
|
7
7
|
module Core
|
8
8
|
module Utils
|
9
|
-
#
|
9
|
+
# Compression/decompression utility functions.
|
10
|
+
#
|
11
|
+
# @deprecated This is no longer used by ddtrace and will be removed in 2.0.
|
10
12
|
module Compression
|
11
13
|
module_function
|
12
14
|
|
15
|
+
# @deprecated This is no longer used by ddtrace and will be removed in 2.0.
|
13
16
|
def gzip(string, level: nil, strategy: nil)
|
14
17
|
sio = StringIO.new
|
15
18
|
sio.binmode
|
@@ -19,6 +22,7 @@ module Datadog
|
|
19
22
|
sio.string
|
20
23
|
end
|
21
24
|
|
25
|
+
# @deprecated This is no longer used by ddtrace and will be removed in 2.0.
|
22
26
|
def gunzip(string, encoding = ::Encoding::ASCII_8BIT)
|
23
27
|
sio = StringIO.new(string)
|
24
28
|
gz = Zlib::GzipReader.new(sio, encoding: encoding)
|
@@ -8,7 +8,6 @@ module Datadog
|
|
8
8
|
module Async
|
9
9
|
# Adds threading behavior to workers
|
10
10
|
# to run tasks asynchronously.
|
11
|
-
# rubocop:disable Metrics/ModuleLength
|
12
11
|
module Thread
|
13
12
|
FORK_POLICY_STOP = :stop
|
14
13
|
FORK_POLICY_RESTART = :restart
|
@@ -175,7 +174,6 @@ module Datadog
|
|
175
174
|
end
|
176
175
|
end
|
177
176
|
end
|
178
|
-
# rubocop:enable Metrics/ModuleLength
|
179
177
|
end
|
180
178
|
end
|
181
179
|
end
|
data/lib/datadog/core.rb
CHANGED
@@ -1,59 +1,5 @@
|
|
1
1
|
# typed: strict
|
2
2
|
|
3
|
-
# TODO: Move these requires to smaller modules.
|
4
|
-
# Would be better to lazy load these; not
|
5
|
-
# all of these components will be used in
|
6
|
-
# every application.
|
7
|
-
# require_relative 'core/buffer/cruby'
|
8
|
-
# require_relative 'core/buffer/random'
|
9
|
-
# require_relative 'core/buffer/thread_safe'
|
10
|
-
# require_relative 'core/chunker'
|
11
|
-
# require_relative 'core/configuration'
|
12
|
-
# require_relative 'core/diagnostics/environment_logger'
|
13
|
-
# require_relative 'core/diagnostics/ext'
|
14
|
-
# require_relative 'core/diagnostics/health'
|
15
|
-
# require_relative 'core/encoding'
|
16
|
-
# require_relative 'core/environment/cgroup'
|
17
|
-
# require_relative 'core/environment/class_count'
|
18
|
-
# require_relative 'core/environment/container'
|
19
|
-
# require_relative 'core/environment/ext'
|
20
|
-
# require_relative 'core/environment/gc'
|
21
|
-
# require_relative 'core/environment/identity'
|
22
|
-
# require_relative 'core/environment/socket'
|
23
|
-
# require_relative 'core/environment/thread_count'
|
24
|
-
# require_relative 'core/environment/variable_helpers'
|
25
|
-
# require_relative 'core/environment/vm_cache'
|
26
|
-
# require_relative 'core/error'
|
27
|
-
# require_relative 'core/event'
|
28
|
-
# require_relative 'core/git/ext'
|
29
|
-
# require_relative 'core/logger'
|
30
|
-
# require_relative 'core/metrics/client'
|
31
|
-
# require_relative 'core/metrics/ext'
|
32
|
-
# require_relative 'core/metrics/helpers'
|
33
|
-
# require_relative 'core/metrics/logging'
|
34
|
-
# require_relative 'core/metrics/metric'
|
35
|
-
# require_relative 'core/metrics/options'
|
36
|
-
# require_relative 'core/pin'
|
37
|
-
# require_relative 'core/quantization/hash'
|
38
|
-
# require_relative 'core/quantization/http'
|
39
|
-
# require_relative 'core/runtime/ext'
|
40
|
-
# require_relative 'core/runtime/metrics'
|
41
|
-
# require_relative 'core/utils'
|
42
|
-
# require_relative 'core/utils/compression'
|
43
|
-
# require_relative 'core/utils/database'
|
44
|
-
# require_relative 'core/utils/forking'
|
45
|
-
# require_relative 'core/utils/object_set'
|
46
|
-
# require_relative 'core/utils/only_once'
|
47
|
-
# require_relative 'core/utils/sequence'
|
48
|
-
# require_relative 'core/utils/string_table'
|
49
|
-
# require_relative 'core/utils/time'
|
50
|
-
# require_relative 'core/worker'
|
51
|
-
# require_relative 'core/workers/async'
|
52
|
-
# require_relative 'core/workers/interval_loop'
|
53
|
-
# require_relative 'core/workers/polling'
|
54
|
-
# require_relative 'core/workers/queue'
|
55
|
-
# require_relative 'core/workers/runtime_metrics'
|
56
|
-
|
57
3
|
require_relative 'core/extensions'
|
58
4
|
|
59
5
|
# We must load core extensions to make certain global APIs
|