datadog 2.14.0 → 2.16.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 +67 -1
- data/ext/datadog_profiling_native_extension/collectors_thread_context.c +7 -6
- data/ext/datadog_profiling_native_extension/datadog_ruby_common.c +1 -4
- data/ext/datadog_profiling_native_extension/datadog_ruby_common.h +10 -0
- data/ext/datadog_profiling_native_extension/encoded_profile.c +69 -0
- data/ext/datadog_profiling_native_extension/encoded_profile.h +7 -0
- data/ext/datadog_profiling_native_extension/extconf.rb +3 -0
- data/ext/datadog_profiling_native_extension/heap_recorder.c +8 -1
- data/ext/datadog_profiling_native_extension/http_transport.c +25 -32
- data/ext/datadog_profiling_native_extension/profiling.c +2 -0
- data/ext/datadog_profiling_native_extension/stack_recorder.c +22 -21
- data/ext/libdatadog_api/crashtracker.c +1 -9
- data/ext/libdatadog_api/crashtracker.h +5 -0
- data/ext/libdatadog_api/datadog_ruby_common.c +1 -4
- data/ext/libdatadog_api/datadog_ruby_common.h +10 -0
- data/ext/libdatadog_api/init.c +15 -0
- data/ext/libdatadog_api/library_config.c +122 -0
- data/ext/libdatadog_api/library_config.h +19 -0
- data/ext/libdatadog_api/process_discovery.c +117 -0
- data/ext/libdatadog_api/process_discovery.h +5 -0
- data/lib/datadog/appsec/actions_handler.rb +3 -2
- data/lib/datadog/appsec/assets/waf_rules/README.md +50 -5
- data/lib/datadog/appsec/assets/waf_rules/processors.json +239 -10
- data/lib/datadog/appsec/assets/waf_rules/scanners.json +926 -17
- data/lib/datadog/appsec/autoload.rb +1 -1
- data/lib/datadog/appsec/component.rb +29 -20
- data/lib/datadog/appsec/compressed_json.rb +40 -0
- data/lib/datadog/appsec/configuration/settings.rb +31 -18
- data/lib/datadog/appsec/context.rb +1 -1
- data/lib/datadog/appsec/contrib/active_record/instrumentation.rb +10 -12
- data/lib/datadog/appsec/contrib/active_record/integration.rb +2 -2
- data/lib/datadog/appsec/contrib/active_record/patcher.rb +22 -22
- data/lib/datadog/appsec/contrib/devise/data_extractor.rb +2 -3
- data/lib/datadog/appsec/contrib/devise/ext.rb +1 -0
- data/lib/datadog/appsec/contrib/devise/integration.rb +1 -1
- data/lib/datadog/appsec/contrib/devise/patcher.rb +3 -5
- data/lib/datadog/appsec/contrib/devise/tracking_middleware.rb +17 -4
- data/lib/datadog/appsec/contrib/excon/integration.rb +1 -1
- data/lib/datadog/appsec/contrib/excon/ssrf_detection_middleware.rb +9 -10
- data/lib/datadog/appsec/contrib/faraday/integration.rb +1 -1
- data/lib/datadog/appsec/contrib/faraday/ssrf_detection_middleware.rb +8 -9
- data/lib/datadog/appsec/contrib/graphql/gateway/watcher.rb +8 -9
- data/lib/datadog/appsec/contrib/graphql/integration.rb +1 -1
- data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +22 -32
- data/lib/datadog/appsec/contrib/rack/integration.rb +1 -1
- data/lib/datadog/appsec/contrib/rack/request_middleware.rb +16 -16
- data/lib/datadog/appsec/contrib/rails/gateway/watcher.rb +11 -13
- data/lib/datadog/appsec/contrib/rails/integration.rb +1 -1
- data/lib/datadog/appsec/contrib/rails/patcher.rb +21 -21
- data/lib/datadog/appsec/contrib/rest_client/integration.rb +1 -1
- data/lib/datadog/appsec/contrib/rest_client/request_ssrf_detection_patch.rb +10 -11
- data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +17 -23
- data/lib/datadog/appsec/contrib/sinatra/integration.rb +1 -1
- data/lib/datadog/appsec/event.rb +95 -134
- data/lib/datadog/appsec/instrumentation/gateway/argument.rb +5 -2
- data/lib/datadog/appsec/metrics/telemetry.rb +1 -1
- data/lib/datadog/appsec/monitor/gateway/watcher.rb +42 -12
- data/lib/datadog/appsec/processor/rule_loader.rb +26 -28
- data/lib/datadog/appsec/processor/rule_merger.rb +5 -5
- data/lib/datadog/appsec/processor.rb +1 -1
- data/lib/datadog/appsec/remote.rb +16 -11
- data/lib/datadog/appsec/response.rb +6 -6
- data/lib/datadog/appsec/security_engine/runner.rb +1 -1
- data/lib/datadog/appsec/security_event.rb +39 -0
- data/lib/datadog/appsec.rb +1 -1
- data/lib/datadog/core/configuration/agentless_settings_resolver.rb +176 -0
- data/lib/datadog/core/configuration/components.rb +19 -10
- data/lib/datadog/core/configuration/option.rb +61 -25
- data/lib/datadog/core/configuration/settings.rb +10 -0
- data/lib/datadog/core/configuration/stable_config.rb +23 -0
- data/lib/datadog/core/configuration.rb +24 -0
- data/lib/datadog/core/crashtracking/component.rb +1 -9
- data/lib/datadog/core/diagnostics/environment_logger.rb +1 -1
- data/lib/datadog/core/environment/git.rb +1 -0
- data/lib/datadog/core/environment/variable_helpers.rb +1 -1
- data/lib/datadog/core/metrics/client.rb +8 -7
- data/lib/datadog/core/process_discovery.rb +32 -0
- data/lib/datadog/core/remote/client.rb +7 -0
- data/lib/datadog/core/runtime/metrics.rb +1 -1
- data/lib/datadog/core/telemetry/component.rb +60 -50
- data/lib/datadog/core/telemetry/emitter.rb +17 -11
- data/lib/datadog/core/telemetry/event.rb +7 -4
- data/lib/datadog/core/telemetry/http/adapters/net.rb +12 -97
- data/lib/datadog/core/telemetry/metric.rb +5 -5
- data/lib/datadog/core/telemetry/request.rb +4 -4
- data/lib/datadog/core/telemetry/transport/http/api.rb +43 -0
- data/lib/datadog/core/telemetry/transport/http/client.rb +49 -0
- data/lib/datadog/core/telemetry/transport/http/telemetry.rb +92 -0
- data/lib/datadog/core/telemetry/transport/http.rb +63 -0
- data/lib/datadog/core/telemetry/transport/telemetry.rb +52 -0
- data/lib/datadog/core/telemetry/worker.rb +45 -0
- data/lib/datadog/core/utils/time.rb +12 -0
- data/lib/datadog/core/workers/async.rb +20 -2
- data/lib/datadog/core/workers/interval_loop.rb +12 -1
- data/lib/datadog/core/workers/runtime_metrics.rb +2 -2
- data/lib/datadog/core.rb +8 -0
- data/lib/datadog/di/boot.rb +34 -0
- data/lib/datadog/di/probe_notification_builder.rb +1 -1
- data/lib/datadog/di/remote.rb +2 -0
- data/lib/datadog/di/transport/http/diagnostics.rb +0 -1
- data/lib/datadog/di/transport/http/input.rb +0 -1
- data/lib/datadog/di/transport/http.rb +0 -6
- data/lib/datadog/di.rb +5 -32
- data/lib/datadog/error_tracking/collector.rb +87 -0
- data/lib/datadog/error_tracking/component.rb +167 -0
- data/lib/datadog/error_tracking/configuration/settings.rb +63 -0
- data/lib/datadog/error_tracking/configuration.rb +11 -0
- data/lib/datadog/error_tracking/ext.rb +18 -0
- data/lib/datadog/error_tracking/extensions.rb +16 -0
- data/lib/datadog/error_tracking/filters.rb +77 -0
- data/lib/datadog/error_tracking.rb +18 -0
- data/lib/datadog/kit/identity.rb +1 -1
- data/lib/datadog/profiling/collectors/info.rb +3 -0
- data/lib/datadog/profiling/encoded_profile.rb +11 -0
- data/lib/datadog/profiling/exporter.rb +3 -4
- data/lib/datadog/profiling/ext.rb +0 -1
- data/lib/datadog/profiling/flush.rb +4 -7
- data/lib/datadog/profiling/http_transport.rb +10 -59
- data/lib/datadog/profiling/stack_recorder.rb +4 -4
- data/lib/datadog/profiling.rb +1 -0
- data/lib/datadog/tracing/analytics.rb +1 -1
- data/lib/datadog/tracing/contrib/active_record/integration.rb +1 -1
- data/lib/datadog/tracing/contrib/karafka/distributed/propagation.rb +2 -0
- data/lib/datadog/tracing/contrib/karafka/monitor.rb +1 -1
- data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +8 -0
- data/lib/datadog/tracing/contrib/mongodb/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +18 -1
- data/lib/datadog/tracing/contrib/opensearch/configuration/settings.rb +17 -0
- data/lib/datadog/tracing/contrib/opensearch/ext.rb +9 -0
- data/lib/datadog/tracing/contrib/opensearch/patcher.rb +5 -1
- data/lib/datadog/tracing/contrib/rack/request_queue.rb +1 -1
- data/lib/datadog/tracing/contrib/sidekiq/server_tracer.rb +1 -1
- data/lib/datadog/tracing/distributed/b3_multi.rb +1 -1
- data/lib/datadog/tracing/distributed/b3_single.rb +1 -1
- data/lib/datadog/tracing/distributed/datadog.rb +2 -2
- data/lib/datadog/tracing/sampling/rate_sampler.rb +2 -1
- data/lib/datadog/tracing/span_event.rb +1 -1
- data/lib/datadog/tracing/span_operation.rb +38 -14
- data/lib/datadog/tracing/trace_operation.rb +15 -7
- data/lib/datadog/tracing/tracer.rb +7 -3
- data/lib/datadog/tracing/utils.rb +1 -1
- data/lib/datadog/version.rb +1 -1
- data/lib/datadog.rb +2 -3
- metadata +40 -10
- data/lib/datadog/core/telemetry/http/env.rb +0 -20
- data/lib/datadog/core/telemetry/http/ext.rb +0 -28
- data/lib/datadog/core/telemetry/http/response.rb +0 -70
- data/lib/datadog/core/telemetry/http/transport.rb +0 -90
@@ -0,0 +1,167 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
require_relative 'collector'
|
5
|
+
require_relative 'filters'
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
module ErrorTracking
|
9
|
+
# Component for Error Tracking.
|
10
|
+
#
|
11
|
+
# Only one instance of the Component should ever be active.
|
12
|
+
#
|
13
|
+
# The component instance records every handled exceptions from the configured scopes
|
14
|
+
# (user, third_party packages, specified files or everything).
|
15
|
+
class Component
|
16
|
+
LOCK = Mutex.new
|
17
|
+
|
18
|
+
class << self
|
19
|
+
def build(settings, tracer, logger)
|
20
|
+
return if !settings.respond_to?(:error_tracking) || (settings.error_tracking.handled_errors.nil? &&
|
21
|
+
settings.error_tracking.handled_errors_include.empty?)
|
22
|
+
|
23
|
+
return unless environment_supported?(logger)
|
24
|
+
|
25
|
+
new(
|
26
|
+
tracer: tracer,
|
27
|
+
handled_errors: settings.error_tracking.handled_errors,
|
28
|
+
handled_errors_include: settings.error_tracking.handled_errors_include,
|
29
|
+
).tap(&:start)
|
30
|
+
end
|
31
|
+
|
32
|
+
def environment_supported?(logger)
|
33
|
+
if RUBY_ENGINE != 'ruby'
|
34
|
+
logger.warn("error tracking: cannot enable error tracking: MRI is required, but running on #{RUBY_ENGINE}")
|
35
|
+
false
|
36
|
+
elsif RUBY_VERSION < '2.6'
|
37
|
+
logger.warn(
|
38
|
+
"error tracking: cannot enable error tracking: Ruby 2.6+ is required, but running
|
39
|
+
on #{RUBY_VERSION}"
|
40
|
+
)
|
41
|
+
false
|
42
|
+
else
|
43
|
+
true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def initialize(tracer:, handled_errors:, handled_errors_include:)
|
49
|
+
@tracer = tracer
|
50
|
+
|
51
|
+
# Hash containing the paths to the instrumented files
|
52
|
+
@instrumented_files = Set.new unless handled_errors_include.empty?
|
53
|
+
# Array containing file paths, file names and gems names to instrument.
|
54
|
+
# This is coming from the DD_ERROR_TRACKING_HANDLED_ERRORS_INCLUDE env variable
|
55
|
+
@handled_errors_include = handled_errors_include
|
56
|
+
|
57
|
+
# Filter function is used to filter out the exception
|
58
|
+
# we do not want to report. For instance exception from gems.
|
59
|
+
@filter_function = Filters.generate_filter(handled_errors, @instrumented_files)
|
60
|
+
|
61
|
+
# :rescue event was added in Ruby 3.3
|
62
|
+
#
|
63
|
+
# Before Ruby3.3 the TracePoint listen for :raise events.
|
64
|
+
# If an error is not handled, we will delete the according
|
65
|
+
# span event in the collector.
|
66
|
+
event = (RUBY_VERSION >= '3.3') ? :rescue : :raise
|
67
|
+
|
68
|
+
# This TracePoint is in charge of capturing the handled exceptions
|
69
|
+
# and of adding the corresponding span events to the collector
|
70
|
+
@handled_exc_tracker = create_exc_tracker_trace_point(event)
|
71
|
+
|
72
|
+
if @instrumented_files
|
73
|
+
# The only thing we know about the handled errors is the path of the file
|
74
|
+
# in which the error was rescued. Therefore, we need to retrieve the path
|
75
|
+
# of the files the user want to instrument. This TracePoint is used for that
|
76
|
+
# purpose
|
77
|
+
@include_path_getter = create_script_compiled_trace_point
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def create_exc_tracker_trace_point(event)
|
82
|
+
TracePoint.new(event) do |tp|
|
83
|
+
active_span = @tracer.active_span
|
84
|
+
if active_span
|
85
|
+
raised_exception = tp.raised_exception
|
86
|
+
# Note that in 3.2, this will give the path of where the error was raised
|
87
|
+
# which may cause the handled_error_include env variable to malfunction.
|
88
|
+
rescue_file_path = tp.path
|
89
|
+
if @filter_function.call(rescue_file_path)
|
90
|
+
span_event = generate_span_event(raised_exception)
|
91
|
+
LOCK.synchronize do
|
92
|
+
collector = active_span.get_collector_or_initialize { Collector.new }
|
93
|
+
collector.add_span_event(active_span, span_event, raised_exception)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def create_script_compiled_trace_point
|
101
|
+
TracePoint.new(:script_compiled) do |tp|
|
102
|
+
next if tp.eval_script
|
103
|
+
|
104
|
+
path = tp.instruction_sequence.path
|
105
|
+
next if path.nil?
|
106
|
+
|
107
|
+
@handled_errors_include.each do |file_to_instr|
|
108
|
+
# The user can provide either
|
109
|
+
# - absolute_path starting with '/'. In that case the path of the file
|
110
|
+
# should begin with file_to_instr
|
111
|
+
# - a relative_path starting with './'. In that case, we extend the path
|
112
|
+
# and it is the same as above
|
113
|
+
# - otherwise we just check if the name provided is in the path and is
|
114
|
+
# either the name of a folder or of a ruby file.
|
115
|
+
regex =
|
116
|
+
if file_to_instr.start_with?('/')
|
117
|
+
%r{\A#{Regexp.escape(file_to_instr)}(?:/|\.rb\z|\z)}
|
118
|
+
elsif file_to_instr.start_with?('./')
|
119
|
+
abs_path = File.expand_path(file_to_instr)
|
120
|
+
%r{\A#{Regexp.escape(abs_path)}(?:/|\.rb\z|\z)}
|
121
|
+
else
|
122
|
+
%r{/#{Regexp.escape(file_to_instr)}(?:/|\.rb\z|\z)}
|
123
|
+
end
|
124
|
+
|
125
|
+
add_instrumented_file(path) if path.match?(regex)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# Starts the TracePoints.
|
131
|
+
#
|
132
|
+
# Enables the script_compiled TracePoint if handled_errors_include is not empty.
|
133
|
+
def start
|
134
|
+
@handled_exc_tracker.enable
|
135
|
+
@include_path_getter&.enable
|
136
|
+
end
|
137
|
+
|
138
|
+
# Shuts down error tracker.
|
139
|
+
#
|
140
|
+
# Disables the TracePoints.
|
141
|
+
def shutdown!
|
142
|
+
@handled_exc_tracker.disable
|
143
|
+
@include_path_getter&.disable
|
144
|
+
end
|
145
|
+
|
146
|
+
private
|
147
|
+
|
148
|
+
# Generates a span event from the exception info.
|
149
|
+
#
|
150
|
+
# The event follows the otel semantics.
|
151
|
+
# https://opentelemetry.io/docs/specs/otel/trace/exceptions/
|
152
|
+
def generate_span_event(exception)
|
153
|
+
formatted_exception = Datadog::Core::Error.build_from(exception)
|
154
|
+
attributes = {
|
155
|
+
'exception.type' => formatted_exception.type,
|
156
|
+
'exception.message' => formatted_exception.message,
|
157
|
+
'exception.stacktrace' => formatted_exception.backtrace
|
158
|
+
}
|
159
|
+
Datadog::Tracing::SpanEvent.new('exception', attributes: attributes)
|
160
|
+
end
|
161
|
+
|
162
|
+
def add_instrumented_file(file_path)
|
163
|
+
@instrumented_files&.add(file_path)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../ext'
|
4
|
+
|
5
|
+
module Datadog
|
6
|
+
module ErrorTracking
|
7
|
+
module Configuration
|
8
|
+
# Settings
|
9
|
+
module Settings
|
10
|
+
def self.extended(base)
|
11
|
+
base = base.singleton_class unless base.is_a?(Class)
|
12
|
+
add_settings!(base)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.add_settings!(base)
|
16
|
+
base.class_eval do
|
17
|
+
# Error Tracking specific configurations.
|
18
|
+
# @public_api
|
19
|
+
settings :error_tracking do
|
20
|
+
# Enable automatic reporting of handled errors and defines the scope
|
21
|
+
# for which to report errors: user code, gems, or both. Possible
|
22
|
+
# values are: all | user | third_party.
|
23
|
+
#
|
24
|
+
# @default 'DD_ERROR_TRACKING_HANDLED_ERRORS' environment variable, otherwise `nil`
|
25
|
+
# @return [String, nil]
|
26
|
+
option :handled_errors do |o|
|
27
|
+
o.type :string, nilable: true
|
28
|
+
o.default Ext::DEFAULT_HANDLED_ERRORS
|
29
|
+
o.env Ext::ENV_HANDLED_ERRORS
|
30
|
+
o.setter do |value|
|
31
|
+
next value if Ext::VALID_HANDLED_ERRORS.include?(value)
|
32
|
+
|
33
|
+
unless value.nil?
|
34
|
+
Datadog.logger.warn(
|
35
|
+
"Invalid handled errors scope: #{value}. " \
|
36
|
+
"Supported values are: #{Ext::VALID_HANDLED_ERRORS.join(" | ")}. " \
|
37
|
+
'Deactivating the feature.'
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
Ext::DEFAULT_HANDLED_ERRORS
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Enable automatic reporting of handled errors and specify what files should be
|
46
|
+
# instrumented. The value is a list of comma separated paths, filenames or gem names.
|
47
|
+
# The paths can be absolute, starting with '/' or relative to directory in which the program
|
48
|
+
# is launched, starting with './'.
|
49
|
+
#
|
50
|
+
# @default 'DD_ERROR_TRACKING_HANDLED_ERRORS_MODULES' environment variable, otherwise `nil`
|
51
|
+
# @return [String, nil]
|
52
|
+
option :handled_errors_include do |o|
|
53
|
+
o.type :array
|
54
|
+
o.default []
|
55
|
+
o.env Ext::ENV_HANDLED_ERRORS_INCLUDE
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module ErrorTracking
|
5
|
+
# Error Tracking constants
|
6
|
+
module Ext
|
7
|
+
ENV_HANDLED_ERRORS = 'DD_ERROR_TRACKING_HANDLED_ERRORS'
|
8
|
+
ENV_HANDLED_ERRORS_INCLUDE = 'DD_ERROR_TRACKING_HANDLED_ERRORS_INCLUDE'
|
9
|
+
HANDLED_ERRORS_ALL = 'all'
|
10
|
+
HANDLED_ERRORS_USER = 'user'
|
11
|
+
HANDLED_ERRORS_THIRD_PARTY = 'third_party'
|
12
|
+
DEFAULT_HANDLED_ERRORS = nil
|
13
|
+
VALID_HANDLED_ERRORS = [HANDLED_ERRORS_ALL, HANDLED_ERRORS_USER, HANDLED_ERRORS_THIRD_PARTY].freeze
|
14
|
+
SPAN_EVENTS_HAS_EXCEPTION = '_dd.span_events.has_exception'
|
15
|
+
RUBY_VERSION_WITH_RESCUE_EVENT = '3.3'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'configuration'
|
4
|
+
require_relative '../core/configuration'
|
5
|
+
|
6
|
+
module Datadog
|
7
|
+
module ErrorTracking
|
8
|
+
# Extends Datadog tracing with ErrorTracking features
|
9
|
+
module Extensions
|
10
|
+
# Inject Error Tracking into global objects.
|
11
|
+
def self.activate!
|
12
|
+
Core::Configuration::Settings.extend(Configuration::Settings)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module ErrorTracking
|
5
|
+
# Based on configuration, the TracePoint listening to :rescue or :raise
|
6
|
+
# may report more handled errors than we want to report. Therefore we need
|
7
|
+
# a function to filter the events. As the filter function both depends
|
8
|
+
# on configuration and is called numerous time, we generate it during
|
9
|
+
# during the initialization of the feature to have the best performance
|
10
|
+
# possible.
|
11
|
+
#
|
12
|
+
# @api private
|
13
|
+
module Filters
|
14
|
+
module_function
|
15
|
+
|
16
|
+
def get_gem_name(file_path)
|
17
|
+
regex = %r{gems/([^/]+)-\d}
|
18
|
+
regex_match = regex.match(file_path)
|
19
|
+
return unless regex_match
|
20
|
+
|
21
|
+
gem_name = regex_match[1]
|
22
|
+
|
23
|
+
begin
|
24
|
+
Gem::Specification.find_by_name(gem_name) # steep:ignore
|
25
|
+
rescue Gem::MissingSpecError
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def user_code?(file_path)
|
31
|
+
!get_gem_name(file_path)
|
32
|
+
end
|
33
|
+
|
34
|
+
def datadog_code?(file_path)
|
35
|
+
file_path.include?('lib/datadog/')
|
36
|
+
end
|
37
|
+
|
38
|
+
def third_party_code?(file_path)
|
39
|
+
gem_name = get_gem_name(file_path)
|
40
|
+
gem_name && gem_name != "datadog"
|
41
|
+
end
|
42
|
+
|
43
|
+
def file_included?(file_path, instrumented_files)
|
44
|
+
instrumented_files.include?(file_path)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Generate the proc used in the TracePoint
|
48
|
+
def generate_filter(to_instrument_scope, handled_errors_include = nil)
|
49
|
+
case to_instrument_scope
|
50
|
+
# If DD_ERROR_TRACKING_HANDLED_ERRORS is set
|
51
|
+
when 'all'
|
52
|
+
proc { |file_path| !datadog_code?(file_path) }
|
53
|
+
when 'user'
|
54
|
+
# If DD_ERROR_TRACKING_HANDLED_ERRORS_INCLUDE is set
|
55
|
+
if handled_errors_include
|
56
|
+
proc { |file_path|
|
57
|
+
user_code?(file_path) || file_included?(file_path, handled_errors_include)
|
58
|
+
}
|
59
|
+
else
|
60
|
+
proc { |file_path| user_code?(file_path) }
|
61
|
+
end
|
62
|
+
when 'third_party'
|
63
|
+
if handled_errors_include
|
64
|
+
proc { |file_path|
|
65
|
+
third_party_code?(file_path) || file_included?(file_path, handled_errors_include)
|
66
|
+
}
|
67
|
+
else
|
68
|
+
proc { |file_path| third_party_code?(file_path) }
|
69
|
+
end
|
70
|
+
else
|
71
|
+
# If only DD_ERROR_TRACKING_HANDLED_ERRORS_INCLUDE is set
|
72
|
+
proc { |file_path| file_included?(file_path, handled_errors_include) }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'error_tracking/collector'
|
4
|
+
require_relative 'error_tracking/component'
|
5
|
+
require_relative 'error_tracking/configuration'
|
6
|
+
require_relative 'error_tracking/ext'
|
7
|
+
require_relative 'error_tracking/extensions'
|
8
|
+
require_relative 'error_tracking/filters'
|
9
|
+
|
10
|
+
module Datadog
|
11
|
+
# Namespace for Datadog ErrorTracking.
|
12
|
+
#
|
13
|
+
# @api private
|
14
|
+
module ErrorTracking
|
15
|
+
# Expose ErrorTracking to global shared objects
|
16
|
+
Extensions.activate!
|
17
|
+
end
|
18
|
+
end
|
data/lib/datadog/kit/identity.rb
CHANGED
@@ -70,7 +70,7 @@ module Datadog
|
|
70
70
|
if Datadog::AppSec.active_context
|
71
71
|
active_span.set_tag('_dd.appsec.user.collection_mode', 'sdk')
|
72
72
|
|
73
|
-
user = ::Datadog::AppSec::Instrumentation::Gateway::User.new(id, others[:login])
|
73
|
+
user = ::Datadog::AppSec::Instrumentation::Gateway::User.new(id, others[:login], session_id)
|
74
74
|
::Datadog::AppSec::Instrumentation.gateway.push('identity.set_user', user)
|
75
75
|
end
|
76
76
|
end
|
@@ -31,6 +31,9 @@ module Datadog
|
|
31
31
|
# Instead of trying to figure out real process start time by checking
|
32
32
|
# /proc or some other complex/non-portable way, approximate start time
|
33
33
|
# by time of requirement of this file.
|
34
|
+
#
|
35
|
+
# Note: this does not use Core::Utils::Time.now because this constant
|
36
|
+
# gets initialized before a user has a chance to configure the library.
|
34
37
|
START_TIME = Time.now.utc.freeze
|
35
38
|
|
36
39
|
def collect_platform_info
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module Profiling
|
5
|
+
# This class exists to wrap a ddog_prof_EncodedProfile into a Ruby object
|
6
|
+
#
|
7
|
+
# This class is not empty; all of this class is implemented as native code.
|
8
|
+
class EncodedProfile # rubocop:disable Lint/EmptyClass
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -49,7 +49,7 @@ module Datadog
|
|
49
49
|
@internal_metadata = internal_metadata
|
50
50
|
# NOTE: At the time of this comment collected info does not change over time so we'll hardcode
|
51
51
|
# it on startup to prevent serializing the same info on every flush.
|
52
|
-
@info_json = JSON.
|
52
|
+
@info_json = JSON.generate(info_collector.info).freeze
|
53
53
|
end
|
54
54
|
|
55
55
|
def flush
|
@@ -57,7 +57,7 @@ module Datadog
|
|
57
57
|
serialization_result = pprof_recorder.serialize
|
58
58
|
return if serialization_result.nil?
|
59
59
|
|
60
|
-
start, finish,
|
60
|
+
start, finish, encoded_profile, profile_stats = serialization_result
|
61
61
|
@last_flush_finish_at = finish
|
62
62
|
|
63
63
|
if duration_below_threshold?(start, finish)
|
@@ -70,8 +70,7 @@ module Datadog
|
|
70
70
|
Flush.new(
|
71
71
|
start: start,
|
72
72
|
finish: finish,
|
73
|
-
|
74
|
-
pprof_data: compressed_pprof.to_s,
|
73
|
+
encoded_profile: encoded_profile,
|
75
74
|
code_provenance_file_name: Datadog::Profiling::Ext::Transport::HTTP::CODE_PROVENANCE_FILENAME,
|
76
75
|
code_provenance_data: uncompressed_code_provenance,
|
77
76
|
tags_as_array: Datadog::Profiling::TagBuilder.call(settings: Datadog.configuration).to_a,
|
@@ -9,10 +9,9 @@ module Datadog
|
|
9
9
|
attr_reader \
|
10
10
|
:start,
|
11
11
|
:finish,
|
12
|
-
:
|
13
|
-
:pprof_data, # gzipped pprof bytes
|
12
|
+
:encoded_profile,
|
14
13
|
:code_provenance_file_name,
|
15
|
-
:code_provenance_data,
|
14
|
+
:code_provenance_data,
|
16
15
|
:tags_as_array,
|
17
16
|
:internal_metadata_json,
|
18
17
|
:info_json
|
@@ -20,8 +19,7 @@ module Datadog
|
|
20
19
|
def initialize(
|
21
20
|
start:,
|
22
21
|
finish:,
|
23
|
-
|
24
|
-
pprof_data:,
|
22
|
+
encoded_profile:,
|
25
23
|
code_provenance_file_name:,
|
26
24
|
code_provenance_data:,
|
27
25
|
tags_as_array:,
|
@@ -30,8 +28,7 @@ module Datadog
|
|
30
28
|
)
|
31
29
|
@start = start
|
32
30
|
@finish = finish
|
33
|
-
@
|
34
|
-
@pprof_data = pprof_data
|
31
|
+
@encoded_profile = encoded_profile
|
35
32
|
@code_provenance_file_name = code_provenance_file_name
|
36
33
|
@code_provenance_data = code_provenance_data
|
37
34
|
@tags_as_array = tags_as_array
|
@@ -20,34 +20,21 @@ module Datadog
|
|
20
20
|
[:agent, agent_settings.url].freeze
|
21
21
|
end
|
22
22
|
|
23
|
-
status, result =
|
23
|
+
status, result = self.class._native_validate_exporter(exporter_configuration)
|
24
24
|
|
25
25
|
raise(ArgumentError, "Failed to initialize transport: #{result}") if status == :error
|
26
26
|
end
|
27
27
|
|
28
28
|
def export(flush)
|
29
|
-
status, result =
|
30
|
-
exporter_configuration
|
31
|
-
|
32
|
-
|
33
|
-
#
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
start_timespec_nanoseconds: flush.start.tv_nsec,
|
39
|
-
finish_timespec_seconds: flush.finish.tv_sec,
|
40
|
-
finish_timespec_nanoseconds: flush.finish.tv_nsec,
|
41
|
-
|
42
|
-
pprof_file_name: flush.pprof_file_name,
|
43
|
-
pprof_data: flush.pprof_data,
|
44
|
-
code_provenance_file_name: flush.code_provenance_file_name,
|
45
|
-
code_provenance_data: flush.code_provenance_data,
|
46
|
-
|
47
|
-
tags_as_array: flush.tags_as_array,
|
48
|
-
internal_metadata_json: flush.internal_metadata_json,
|
49
|
-
|
50
|
-
info_json: flush.info_json
|
29
|
+
status, result = self.class._native_do_export(
|
30
|
+
exporter_configuration,
|
31
|
+
@upload_timeout_milliseconds,
|
32
|
+
flush,
|
33
|
+
# TODO: This is going to be removed once we move to libdatadog 17
|
34
|
+
flush.start.tv_sec,
|
35
|
+
flush.start.tv_nsec,
|
36
|
+
flush.finish.tv_sec,
|
37
|
+
flush.finish.tv_nsec,
|
51
38
|
)
|
52
39
|
|
53
40
|
if status == :ok
|
@@ -77,42 +64,6 @@ module Datadog
|
|
77
64
|
site && api_key && Core::Environment::VariableHelpers.env_to_bool(Profiling::Ext::ENV_AGENTLESS, false)
|
78
65
|
end
|
79
66
|
|
80
|
-
def validate_exporter(exporter_configuration)
|
81
|
-
self.class._native_validate_exporter(exporter_configuration)
|
82
|
-
end
|
83
|
-
|
84
|
-
def do_export(
|
85
|
-
exporter_configuration:,
|
86
|
-
upload_timeout_milliseconds:,
|
87
|
-
start_timespec_seconds:,
|
88
|
-
start_timespec_nanoseconds:,
|
89
|
-
finish_timespec_seconds:,
|
90
|
-
finish_timespec_nanoseconds:,
|
91
|
-
pprof_file_name:,
|
92
|
-
pprof_data:,
|
93
|
-
code_provenance_file_name:,
|
94
|
-
code_provenance_data:,
|
95
|
-
tags_as_array:,
|
96
|
-
internal_metadata_json:,
|
97
|
-
info_json:
|
98
|
-
)
|
99
|
-
self.class._native_do_export(
|
100
|
-
exporter_configuration,
|
101
|
-
upload_timeout_milliseconds,
|
102
|
-
start_timespec_seconds,
|
103
|
-
start_timespec_nanoseconds,
|
104
|
-
finish_timespec_seconds,
|
105
|
-
finish_timespec_nanoseconds,
|
106
|
-
pprof_file_name,
|
107
|
-
pprof_data,
|
108
|
-
code_provenance_file_name,
|
109
|
-
code_provenance_data,
|
110
|
-
tags_as_array,
|
111
|
-
internal_metadata_json,
|
112
|
-
info_json,
|
113
|
-
)
|
114
|
-
end
|
115
|
-
|
116
67
|
def config_without_api_key
|
117
68
|
"#{exporter_configuration[0]}: #{exporter_configuration[1]}"
|
118
69
|
end
|
@@ -63,11 +63,11 @@ module Datadog
|
|
63
63
|
status, result = @no_concurrent_synchronize_mutex.synchronize { self.class._native_serialize(self) }
|
64
64
|
|
65
65
|
if status == :ok
|
66
|
-
start, finish,
|
66
|
+
start, finish, encoded_profile, profile_stats = result
|
67
67
|
|
68
68
|
Datadog.logger.debug { "Encoded profile covering #{start.iso8601} to #{finish.iso8601}" }
|
69
69
|
|
70
|
-
[start, finish,
|
70
|
+
[start, finish, encoded_profile, profile_stats]
|
71
71
|
else
|
72
72
|
error_message = result
|
73
73
|
|
@@ -82,9 +82,9 @@ module Datadog
|
|
82
82
|
status, result = @no_concurrent_synchronize_mutex.synchronize { self.class._native_serialize(self) }
|
83
83
|
|
84
84
|
if status == :ok
|
85
|
-
_start, _finish,
|
85
|
+
_start, _finish, encoded_profile = result
|
86
86
|
|
87
|
-
|
87
|
+
encoded_profile
|
88
88
|
else
|
89
89
|
error_message = result
|
90
90
|
|
data/lib/datadog/profiling.rb
CHANGED
@@ -149,6 +149,7 @@ module Datadog
|
|
149
149
|
require_relative 'profiling/collectors/thread_context'
|
150
150
|
require_relative 'profiling/stack_recorder'
|
151
151
|
require_relative 'profiling/exporter'
|
152
|
+
require_relative 'profiling/encoded_profile'
|
152
153
|
require_relative 'profiling/flush'
|
153
154
|
require_relative 'profiling/scheduler'
|
154
155
|
require_relative 'profiling/tasks/setup'
|
@@ -16,7 +16,7 @@ module Datadog
|
|
16
16
|
def set_measured(span_op, value = true)
|
17
17
|
return if span_op.nil?
|
18
18
|
|
19
|
-
value = value == true || value == 1 ? 1 : 0
|
19
|
+
value = value == true || value == 1 ? 1 : 0
|
20
20
|
span_op.set_metric(Metadata::Ext::Analytics::TAG_MEASURED, value)
|
21
21
|
end
|
22
22
|
end
|
@@ -31,6 +31,8 @@ module Datadog
|
|
31
31
|
Tracing::Distributed::Datadog.new(fetcher: Tracing::Distributed::Fetcher),
|
32
32
|
Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_TRACE_CONTEXT =>
|
33
33
|
Tracing::Distributed::TraceContext.new(fetcher: Tracing::Distributed::Fetcher),
|
34
|
+
Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_BAGGAGE =>
|
35
|
+
Tracing::Distributed::Baggage.new(fetcher: Tracing::Distributed::Fetcher),
|
34
36
|
Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_NONE => Tracing::Distributed::None.new
|
35
37
|
},
|
36
38
|
propagation_style_inject: propagation_style_inject,
|
@@ -15,7 +15,7 @@ module Datadog
|
|
15
15
|
worker.processed
|
16
16
|
].freeze
|
17
17
|
|
18
|
-
def instrument(event_id, payload =
|
18
|
+
def instrument(event_id, payload = {}, &block)
|
19
19
|
return super unless TRACEABLE_EVENTS.include?(event_id)
|
20
20
|
|
21
21
|
Datadog::Tracing.trace(Ext::SPAN_WORKER_PROCESS) do |span|
|
@@ -48,6 +48,14 @@ module Datadog
|
|
48
48
|
o.type :string, nilable: true
|
49
49
|
o.env Ext::ENV_PEER_SERVICE
|
50
50
|
end
|
51
|
+
|
52
|
+
# Serializes the command to JSON format, which is the desired format for the agent and Datadog UI.
|
53
|
+
# Setting this to false is deprecated and does not have any advantages.
|
54
|
+
option :json_command do |o|
|
55
|
+
o.type :bool
|
56
|
+
o.env Ext::ENV_JSON_COMMAND
|
57
|
+
o.default false
|
58
|
+
end
|
51
59
|
end
|
52
60
|
end
|
53
61
|
end
|
@@ -13,6 +13,7 @@ module Datadog
|
|
13
13
|
# @!visibility private
|
14
14
|
ENV_ANALYTICS_ENABLED = 'DD_TRACE_MONGO_ANALYTICS_ENABLED'
|
15
15
|
ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_MONGO_ANALYTICS_SAMPLE_RATE'
|
16
|
+
ENV_JSON_COMMAND = 'DD_TRACE_MONGO_JSON_COMMAND'
|
16
17
|
DEFAULT_PEER_SERVICE_NAME = 'mongodb'
|
17
18
|
SPAN_COMMAND = 'mongo.cmd'
|
18
19
|
SPAN_TYPE_COMMAND = 'mongodb'
|