datadog 2.12.1 → 2.13.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 +45 -2
- data/ext/datadog_profiling_native_extension/collectors_thread_context.c +14 -13
- data/ext/datadog_profiling_native_extension/private_vm_api_access.c +8 -0
- data/lib/datadog/appsec/actions_handler/serializable_backtrace.rb +89 -0
- data/lib/datadog/appsec/actions_handler.rb +22 -1
- data/lib/datadog/appsec/anonymizer.rb +16 -0
- data/lib/datadog/appsec/configuration/settings.rb +62 -10
- data/lib/datadog/appsec/contrib/auto_instrument.rb +1 -1
- data/lib/datadog/appsec/contrib/devise/configuration.rb +7 -31
- data/lib/datadog/appsec/contrib/devise/data_extractor.rb +79 -0
- data/lib/datadog/appsec/contrib/devise/ext.rb +21 -0
- data/lib/datadog/appsec/contrib/devise/integration.rb +0 -1
- data/lib/datadog/appsec/contrib/devise/patcher.rb +36 -23
- data/lib/datadog/appsec/contrib/devise/patches/signin_tracking_patch.rb +102 -0
- data/lib/datadog/appsec/contrib/devise/patches/signup_tracking_patch.rb +69 -0
- data/lib/datadog/appsec/contrib/devise/{patcher/rememberable_patch.rb → patches/skip_signin_tracking_patch.rb} +2 -2
- data/lib/datadog/appsec/contrib/devise/tracking_middleware.rb +93 -0
- data/lib/datadog/appsec/contrib/rack/ext.rb +34 -0
- data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +27 -0
- data/lib/datadog/appsec/contrib/rack/request_middleware.rb +3 -2
- data/lib/datadog/appsec/event.rb +1 -1
- data/lib/datadog/appsec/ext.rb +4 -2
- data/lib/datadog/appsec/instrumentation/gateway/argument.rb +4 -2
- data/lib/datadog/appsec/instrumentation/gateway/middleware.rb +24 -0
- data/lib/datadog/appsec/instrumentation/gateway.rb +17 -22
- data/lib/datadog/appsec/monitor/gateway/watcher.rb +8 -3
- data/lib/datadog/appsec/processor/rule_merger.rb +2 -1
- data/lib/datadog/appsec/remote.rb +7 -0
- data/lib/datadog/appsec/security_engine/runner.rb +2 -2
- data/lib/datadog/appsec/utils.rb +0 -2
- data/lib/datadog/core/configuration/components.rb +2 -1
- data/lib/datadog/core/configuration/ext.rb +4 -0
- data/lib/datadog/core/configuration/options.rb +2 -2
- data/lib/datadog/core/configuration/settings.rb +53 -30
- data/lib/datadog/core/environment/agent_info.rb +4 -3
- data/lib/datadog/core/remote/component.rb +3 -6
- data/lib/datadog/core/remote/configuration/repository.rb +2 -1
- data/lib/datadog/core/remote/negotiation.rb +9 -9
- data/lib/datadog/core/remote/transport/config.rb +4 -3
- data/lib/datadog/core/remote/transport/http/client.rb +4 -3
- data/lib/datadog/core/remote/transport/http/config.rb +6 -32
- data/lib/datadog/core/remote/transport/http/negotiation.rb +6 -32
- data/lib/datadog/core/remote/transport/http.rb +22 -57
- data/lib/datadog/core/remote/transport/negotiation.rb +4 -3
- data/lib/datadog/core/runtime/metrics.rb +8 -1
- data/lib/datadog/core/telemetry/http/adapters/net.rb +1 -1
- data/lib/datadog/core/transport/http/api/instance.rb +17 -0
- data/lib/datadog/core/transport/http/api/spec.rb +17 -0
- data/lib/datadog/core/transport/http/builder.rb +5 -3
- data/lib/datadog/core/transport/http.rb +39 -2
- data/lib/datadog/di/component.rb +0 -2
- data/lib/datadog/di/probe_notifier_worker.rb +16 -16
- data/lib/datadog/di/transport/diagnostics.rb +4 -3
- data/lib/datadog/di/transport/http/api.rb +2 -12
- data/lib/datadog/di/transport/http/client.rb +4 -3
- data/lib/datadog/di/transport/http/diagnostics.rb +7 -33
- data/lib/datadog/di/transport/http/input.rb +7 -33
- data/lib/datadog/di/transport/http.rb +14 -56
- data/lib/datadog/di/transport/input.rb +4 -3
- data/lib/datadog/di/utils.rb +5 -0
- data/lib/datadog/kit/appsec/events.rb +9 -0
- data/lib/datadog/kit/identity.rb +5 -1
- data/lib/datadog/opentelemetry/api/baggage.rb +90 -0
- data/lib/datadog/opentelemetry/api/baggage.rbs +26 -0
- data/lib/datadog/opentelemetry/api/context.rb +16 -2
- data/lib/datadog/opentelemetry/sdk/trace/span.rb +1 -1
- data/lib/datadog/opentelemetry.rb +2 -1
- data/lib/datadog/profiling/collectors/thread_context.rb +1 -1
- data/lib/datadog/profiling.rb +5 -2
- data/lib/datadog/tracing/component.rb +15 -12
- data/lib/datadog/tracing/configuration/ext.rb +7 -1
- data/lib/datadog/tracing/configuration/settings.rb +18 -2
- data/lib/datadog/tracing/context_provider.rb +1 -1
- data/lib/datadog/tracing/contrib/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +4 -5
- data/lib/datadog/tracing/contrib/excon/middleware.rb +5 -3
- data/lib/datadog/tracing/contrib/faraday/middleware.rb +5 -3
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +7 -1
- data/lib/datadog/tracing/contrib/grpc/distributed/propagation.rb +3 -0
- data/lib/datadog/tracing/contrib/http/circuit_breaker.rb +0 -15
- data/lib/datadog/tracing/contrib/http/distributed/propagation.rb +4 -1
- data/lib/datadog/tracing/contrib/http/instrumentation.rb +5 -5
- data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +5 -11
- data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +6 -10
- data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +5 -3
- data/lib/datadog/tracing/contrib/sidekiq/client_tracer.rb +6 -1
- data/lib/datadog/tracing/contrib/sidekiq/distributed/propagation.rb +3 -0
- data/lib/datadog/tracing/correlation.rb +9 -2
- data/lib/datadog/tracing/distributed/baggage.rb +131 -0
- data/lib/datadog/tracing/distributed/datadog.rb +2 -0
- data/lib/datadog/tracing/distributed/propagation.rb +25 -4
- data/lib/datadog/tracing/distributed/propagation_policy.rb +42 -0
- data/lib/datadog/tracing/metadata/ext.rb +5 -0
- data/lib/datadog/tracing/metadata/metastruct.rb +36 -0
- data/lib/datadog/tracing/metadata/metastruct_tagging.rb +42 -0
- data/lib/datadog/tracing/metadata.rb +2 -0
- data/lib/datadog/tracing/sampling/span/rule.rb +0 -1
- data/lib/datadog/tracing/span.rb +10 -1
- data/lib/datadog/tracing/span_operation.rb +8 -2
- data/lib/datadog/tracing/sync_writer.rb +1 -2
- data/lib/datadog/tracing/trace_digest.rb +9 -2
- data/lib/datadog/tracing/trace_operation.rb +29 -17
- data/lib/datadog/tracing/trace_segment.rb +6 -4
- data/lib/datadog/tracing/tracer.rb +38 -2
- data/lib/datadog/tracing/transport/http/api.rb +2 -10
- data/lib/datadog/tracing/transport/http/client.rb +5 -4
- data/lib/datadog/tracing/transport/http/traces.rb +13 -41
- data/lib/datadog/tracing/transport/http.rb +11 -44
- data/lib/datadog/tracing/transport/serializable_trace.rb +3 -1
- data/lib/datadog/tracing/transport/trace_formatter.rb +7 -0
- data/lib/datadog/tracing/transport/traces.rb +21 -9
- data/lib/datadog/tracing/workers/trace_writer.rb +2 -6
- data/lib/datadog/tracing/writer.rb +2 -6
- data/lib/datadog/tracing.rb +16 -3
- data/lib/datadog/version.rb +2 -2
- metadata +20 -13
- data/lib/datadog/appsec/contrib/devise/event.rb +0 -54
- data/lib/datadog/appsec/contrib/devise/patcher/authenticatable_patch.rb +0 -72
- data/lib/datadog/appsec/contrib/devise/patcher/registration_controller_patch.rb +0 -47
- data/lib/datadog/appsec/contrib/devise/resource.rb +0 -35
- data/lib/datadog/appsec/contrib/devise/tracking.rb +0 -57
- data/lib/datadog/appsec/utils/trace_operation.rb +0 -15
@@ -7,6 +7,23 @@ module Datadog
|
|
7
7
|
module API
|
8
8
|
# An API configured with adapter and routes
|
9
9
|
class Instance
|
10
|
+
# Raised when an endpoint is invoked on an API that is not the
|
11
|
+
# of expected API class for that endpoint.
|
12
|
+
class EndpointNotSupportedError < StandardError
|
13
|
+
attr_reader :spec, :endpoint_name
|
14
|
+
|
15
|
+
def initialize(endpoint_name, spec)
|
16
|
+
@spec = spec
|
17
|
+
@endpoint_name = endpoint_name
|
18
|
+
|
19
|
+
super(message)
|
20
|
+
end
|
21
|
+
|
22
|
+
def message
|
23
|
+
"#{endpoint_name} not supported for this API!"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
10
27
|
attr_reader \
|
11
28
|
:adapter,
|
12
29
|
:headers,
|
@@ -8,6 +8,23 @@ module Datadog
|
|
8
8
|
# Specification for an HTTP API
|
9
9
|
# Defines behaviors without specific configuration details.
|
10
10
|
class Spec
|
11
|
+
# Raised when an endpoint is invoked on an API that did not
|
12
|
+
# define that endpoint.
|
13
|
+
class EndpointNotDefinedError < StandardError
|
14
|
+
attr_reader :spec, :endpoint_name
|
15
|
+
|
16
|
+
def initialize(endpoint_name, spec)
|
17
|
+
@spec = spec
|
18
|
+
@endpoint_name = endpoint_name
|
19
|
+
|
20
|
+
super(message)
|
21
|
+
end
|
22
|
+
|
23
|
+
def message
|
24
|
+
"No #{endpoint_name} endpoint is defined for API specification!"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
11
28
|
def initialize
|
12
29
|
yield(self) if block_given?
|
13
30
|
end
|
@@ -18,9 +18,10 @@ module Datadog
|
|
18
18
|
:api_options,
|
19
19
|
:default_adapter,
|
20
20
|
:default_api,
|
21
|
-
:default_headers
|
21
|
+
:default_headers,
|
22
|
+
:logger
|
22
23
|
|
23
|
-
def initialize(api_instance_class:)
|
24
|
+
def initialize(api_instance_class:, logger:)
|
24
25
|
# Global settings
|
25
26
|
@default_adapter = nil
|
26
27
|
@default_headers = {}
|
@@ -33,6 +34,7 @@ module Datadog
|
|
33
34
|
@api_options = {}
|
34
35
|
|
35
36
|
@api_instance_class = api_instance_class
|
37
|
+
@logger = logger
|
36
38
|
|
37
39
|
yield(self) if block_given?
|
38
40
|
end
|
@@ -86,7 +88,7 @@ module Datadog
|
|
86
88
|
def to_transport(klass)
|
87
89
|
raise NoDefaultApiError if @default_api.nil?
|
88
90
|
|
89
|
-
klass.new(to_api_instances, @default_api)
|
91
|
+
klass.new(to_api_instances, @default_api, logger)
|
90
92
|
end
|
91
93
|
|
92
94
|
def to_api_instances
|
@@ -29,8 +29,45 @@ module Datadog
|
|
29
29
|
# Helper function that delegates to Builder.new
|
30
30
|
# but is under HTTP namespace so that client code requires this file
|
31
31
|
# to get the adapters configured, and not the builder directly.
|
32
|
-
def build(api_instance_class:, &block)
|
33
|
-
Builder.new(api_instance_class: api_instance_class,
|
32
|
+
def build(api_instance_class:, agent_settings:, logger:, api_version: nil, headers: nil, &block)
|
33
|
+
Builder.new(api_instance_class: api_instance_class, logger: logger) do |transport|
|
34
|
+
transport.adapter(agent_settings)
|
35
|
+
transport.headers(default_headers)
|
36
|
+
|
37
|
+
# The caller must define APIs before we set the default API.
|
38
|
+
yield transport
|
39
|
+
|
40
|
+
# Apply any settings given by options
|
41
|
+
transport.default_api = api_version if api_version
|
42
|
+
transport.headers(headers) if headers
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def default_headers
|
47
|
+
{
|
48
|
+
Datadog::Core::Transport::Ext::HTTP::HEADER_CLIENT_COMPUTED_TOP_LEVEL => '1',
|
49
|
+
Datadog::Core::Transport::Ext::HTTP::HEADER_META_LANG =>
|
50
|
+
Datadog::Core::Environment::Ext::LANG,
|
51
|
+
Datadog::Core::Transport::Ext::HTTP::HEADER_META_LANG_VERSION =>
|
52
|
+
Datadog::Core::Environment::Ext::LANG_VERSION,
|
53
|
+
Datadog::Core::Transport::Ext::HTTP::HEADER_META_LANG_INTERPRETER =>
|
54
|
+
Datadog::Core::Environment::Ext::LANG_INTERPRETER,
|
55
|
+
Datadog::Core::Transport::Ext::HTTP::HEADER_META_LANG_INTERPRETER_VENDOR =>
|
56
|
+
Core::Environment::Ext::LANG_ENGINE,
|
57
|
+
Datadog::Core::Transport::Ext::HTTP::HEADER_META_TRACER_VERSION =>
|
58
|
+
Datadog::Core::Environment::Ext::GEM_DATADOG_VERSION
|
59
|
+
}.tap do |headers|
|
60
|
+
# Add container ID, if present.
|
61
|
+
if (container_id = Datadog::Core::Environment::Container.container_id)
|
62
|
+
headers[Datadog::Core::Transport::Ext::HTTP::HEADER_CONTAINER_ID] = container_id
|
63
|
+
end
|
64
|
+
# TODO: inject configuration rather than reading from global here
|
65
|
+
unless Datadog.configuration.apm.tracing.enabled
|
66
|
+
# Sending this header to the agent will disable metrics computation (and billing) on the agent side
|
67
|
+
# by pretending it has already been done on the library side.
|
68
|
+
headers[Datadog::Core::Transport::Ext::HTTP::HEADER_CLIENT_COMPUTED_STATS] = 'yes'
|
69
|
+
end
|
70
|
+
end
|
34
71
|
end
|
35
72
|
end
|
36
73
|
end
|
data/lib/datadog/di/component.rb
CHANGED
@@ -171,7 +171,7 @@ module Datadog
|
|
171
171
|
attr_reader :last_sent
|
172
172
|
|
173
173
|
def status_transport
|
174
|
-
@status_transport ||= DI::Transport::HTTP.diagnostics(agent_settings: agent_settings)
|
174
|
+
@status_transport ||= DI::Transport::HTTP.diagnostics(agent_settings: agent_settings, logger: logger)
|
175
175
|
end
|
176
176
|
|
177
177
|
def do_send_status(batch)
|
@@ -179,7 +179,7 @@ module Datadog
|
|
179
179
|
end
|
180
180
|
|
181
181
|
def snapshot_transport
|
182
|
-
@snapshot_transport ||= DI::Transport::HTTP.input(agent_settings: agent_settings)
|
182
|
+
@snapshot_transport ||= DI::Transport::HTTP.input(agent_settings: agent_settings, logger: logger)
|
183
183
|
end
|
184
184
|
|
185
185
|
def do_send_snapshot(batch)
|
@@ -227,20 +227,6 @@ module Datadog
|
|
227
227
|
start
|
228
228
|
end
|
229
229
|
|
230
|
-
# Determine how much longer the worker thread should sleep
|
231
|
-
# so as not to send in less than min send interval since the last send.
|
232
|
-
# Important: this method must be called when @lock is held.
|
233
|
-
#
|
234
|
-
# Returns the time remaining to sleep.
|
235
|
-
def set_sleep_remaining
|
236
|
-
now = Core::Utils::Time.get_time
|
237
|
-
@sleep_remaining = if last_sent
|
238
|
-
[last_sent + min_send_interval - now, 0].max
|
239
|
-
else
|
240
|
-
0
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
230
|
public "add_#{event_type}"
|
245
231
|
|
246
232
|
# Sends pending probe statuses or snapshots.
|
@@ -288,6 +274,20 @@ module Datadog
|
|
288
274
|
end
|
289
275
|
end
|
290
276
|
|
277
|
+
# Determine how much longer the worker thread should sleep
|
278
|
+
# so as not to send in less than min send interval since the last send.
|
279
|
+
# Important: this method must be called when @lock is held.
|
280
|
+
#
|
281
|
+
# Returns the time remaining to sleep.
|
282
|
+
def set_sleep_remaining
|
283
|
+
now = Core::Utils::Time.get_time
|
284
|
+
@sleep_remaining = if last_sent
|
285
|
+
[last_sent + min_send_interval - now, 0].max
|
286
|
+
else
|
287
|
+
0
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
291
|
def maybe_send
|
292
292
|
rv = maybe_send_status
|
293
293
|
maybe_send_snapshot || rv
|
@@ -15,12 +15,13 @@ module Datadog
|
|
15
15
|
end
|
16
16
|
|
17
17
|
class Transport
|
18
|
-
attr_reader :client, :apis, :default_api, :current_api_id
|
18
|
+
attr_reader :client, :apis, :default_api, :current_api_id, :logger
|
19
19
|
|
20
|
-
def initialize(apis, default_api)
|
20
|
+
def initialize(apis, default_api, logger)
|
21
21
|
@apis = apis
|
22
|
+
@logger = logger
|
22
23
|
|
23
|
-
@client = HTTP::Client.new(current_api)
|
24
|
+
@client = HTTP::Client.new(current_api, logger)
|
24
25
|
end
|
25
26
|
|
26
27
|
def current_api
|
@@ -21,13 +21,13 @@ module Datadog
|
|
21
21
|
|
22
22
|
def defaults
|
23
23
|
Datadog::Core::Transport::HTTP::API::Map[
|
24
|
-
DIAGNOSTICS => Spec.new do |s|
|
24
|
+
DIAGNOSTICS => Diagnostics::API::Spec.new do |s|
|
25
25
|
s.diagnostics = Diagnostics::API::Endpoint.new(
|
26
26
|
'/debugger/v1/diagnostics',
|
27
27
|
Core::Encoding::JSONEncoder,
|
28
28
|
)
|
29
29
|
end,
|
30
|
-
INPUT => Spec.new do |s|
|
30
|
+
INPUT => Input::API::Spec.new do |s|
|
31
31
|
s.input = Input::API::Endpoint.new(
|
32
32
|
'/debugger/v1/input',
|
33
33
|
Core::Encoding::JSONEncoder,
|
@@ -35,16 +35,6 @@ module Datadog
|
|
35
35
|
end,
|
36
36
|
]
|
37
37
|
end
|
38
|
-
|
39
|
-
class Instance < Core::Transport::HTTP::API::Instance
|
40
|
-
include Diagnostics::API::Instance
|
41
|
-
include Input::API::Instance
|
42
|
-
end
|
43
|
-
|
44
|
-
class Spec < Core::Transport::HTTP::API::Spec
|
45
|
-
include Diagnostics::API::Spec
|
46
|
-
include Input::API::Spec
|
47
|
-
end
|
48
38
|
end
|
49
39
|
end
|
50
40
|
end
|
@@ -14,10 +14,11 @@ module Datadog
|
|
14
14
|
module HTTP
|
15
15
|
# Routes, encodes, and sends DI data to the trace agent via HTTP.
|
16
16
|
class Client
|
17
|
-
attr_reader :api
|
17
|
+
attr_reader :api, :logger
|
18
18
|
|
19
|
-
def initialize(api)
|
19
|
+
def initialize(api, logger)
|
20
20
|
@api = api
|
21
|
+
@logger = logger
|
21
22
|
end
|
22
23
|
|
23
24
|
def send_request(request, &block)
|
@@ -31,7 +32,7 @@ module Datadog
|
|
31
32
|
"Internal error during #{self.class.name} request. Cause: #{e.class.name} #{e.message} " \
|
32
33
|
"Location: #{Array(e.backtrace).first}"
|
33
34
|
|
34
|
-
|
35
|
+
logger.debug(message)
|
35
36
|
|
36
37
|
Datadog::Core::Transport::InternalErrorResponse.new(e)
|
37
38
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative '../../../core/transport/http/api/instance'
|
4
|
+
require_relative '../../../core/transport/http/api/spec'
|
3
5
|
require_relative 'client'
|
4
6
|
|
5
7
|
module Datadog
|
@@ -16,52 +18,24 @@ module Datadog
|
|
16
18
|
end
|
17
19
|
|
18
20
|
module API
|
19
|
-
|
21
|
+
class Instance < Core::Transport::HTTP::API::Instance
|
20
22
|
def send_diagnostics(env)
|
21
|
-
raise
|
23
|
+
raise Core::Transport::HTTP::API::Instance::EndpointNotSupportedError.new('diagnostics', self) unless spec.is_a?(Diagnostics::API::Spec)
|
22
24
|
|
23
25
|
spec.send_diagnostics(env) do |request_env|
|
24
26
|
call(request_env)
|
25
27
|
end
|
26
28
|
end
|
27
|
-
|
28
|
-
class DiagnosticsNotSupportedError < StandardError
|
29
|
-
attr_reader :spec
|
30
|
-
|
31
|
-
def initialize(spec)
|
32
|
-
super
|
33
|
-
|
34
|
-
@spec = spec
|
35
|
-
end
|
36
|
-
|
37
|
-
def message
|
38
|
-
'Diagnostics not supported for this API!'
|
39
|
-
end
|
40
|
-
end
|
41
29
|
end
|
42
30
|
|
43
|
-
|
31
|
+
class Spec < Core::Transport::HTTP::API::Spec
|
44
32
|
attr_accessor :diagnostics
|
45
33
|
|
46
34
|
def send_diagnostics(env, &block)
|
47
|
-
raise
|
35
|
+
raise Core::Transport::HTTP::API::Spec::EndpointNotDefinedError.new('diagnostics', self) if diagnostics.nil?
|
48
36
|
|
49
37
|
diagnostics.call(env, &block)
|
50
38
|
end
|
51
|
-
|
52
|
-
class NoDiagnosticsEndpointDefinedError < StandardError
|
53
|
-
attr_reader :spec
|
54
|
-
|
55
|
-
def initialize(spec)
|
56
|
-
super
|
57
|
-
|
58
|
-
@spec = spec
|
59
|
-
end
|
60
|
-
|
61
|
-
def message
|
62
|
-
'No diagnostics endpoint is defined for API specification!'
|
63
|
-
end
|
64
|
-
end
|
65
39
|
end
|
66
40
|
|
67
41
|
# Endpoint for negotiation
|
@@ -79,7 +53,7 @@ module Datadog
|
|
79
53
|
)
|
80
54
|
env.form = {'event' => event_payload}
|
81
55
|
|
82
|
-
super
|
56
|
+
super
|
83
57
|
end
|
84
58
|
end
|
85
59
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative '../../../core/transport/http/api/instance'
|
4
|
+
require_relative '../../../core/transport/http/api/spec'
|
3
5
|
require_relative 'client'
|
4
6
|
|
5
7
|
module Datadog
|
@@ -16,52 +18,24 @@ module Datadog
|
|
16
18
|
end
|
17
19
|
|
18
20
|
module API
|
19
|
-
|
21
|
+
class Instance < Core::Transport::HTTP::API::Instance
|
20
22
|
def send_input(env)
|
21
|
-
raise
|
23
|
+
raise Core::Transport::HTTP::API::Instance::EndpointNotSupportedError.new('input', self) unless spec.is_a?(Input::API::Spec)
|
22
24
|
|
23
25
|
spec.send_input(env) do |request_env|
|
24
26
|
call(request_env)
|
25
27
|
end
|
26
28
|
end
|
27
|
-
|
28
|
-
class InputNotSupportedError < StandardError
|
29
|
-
attr_reader :spec
|
30
|
-
|
31
|
-
def initialize(spec)
|
32
|
-
super
|
33
|
-
|
34
|
-
@spec = spec
|
35
|
-
end
|
36
|
-
|
37
|
-
def message
|
38
|
-
'Input not supported for this API!'
|
39
|
-
end
|
40
|
-
end
|
41
29
|
end
|
42
30
|
|
43
|
-
|
31
|
+
class Spec < Core::Transport::HTTP::API::Spec
|
44
32
|
attr_accessor :input
|
45
33
|
|
46
34
|
def send_input(env, &block)
|
47
|
-
raise
|
35
|
+
raise Core::Transport::HTTP::API::Spec::EndpointNotDefinedError.new('input', self) if input.nil?
|
48
36
|
|
49
37
|
input.call(env, &block)
|
50
38
|
end
|
51
|
-
|
52
|
-
class NoInputEndpointDefinedError < StandardError
|
53
|
-
attr_reader :spec
|
54
|
-
|
55
|
-
def initialize(spec)
|
56
|
-
super
|
57
|
-
|
58
|
-
@spec = spec
|
59
|
-
end
|
60
|
-
|
61
|
-
def message
|
62
|
-
'No input endpoint is defined for API specification!'
|
63
|
-
end
|
64
|
-
end
|
65
39
|
end
|
66
40
|
|
67
41
|
# Endpoint for negotiation
|
@@ -81,7 +55,7 @@ module Datadog
|
|
81
55
|
env.headers[HEADER_CONTENT_TYPE] = encoder.content_type
|
82
56
|
env.body = env.request.parcel.data
|
83
57
|
|
84
|
-
super
|
58
|
+
super
|
85
59
|
end
|
86
60
|
end
|
87
61
|
end
|
@@ -18,86 +18,44 @@ module Datadog
|
|
18
18
|
module HTTP
|
19
19
|
module_function
|
20
20
|
|
21
|
-
# Builds a new Transport::HTTP::Client
|
22
|
-
def new(klass, &block)
|
23
|
-
Core::Transport::HTTP.build(
|
24
|
-
api_instance_class: API::Instance, &block
|
25
|
-
).to_transport(klass)
|
26
|
-
end
|
27
|
-
|
28
21
|
# Builds a new Transport::HTTP::Client with default settings
|
29
22
|
# Pass a block to override any settings.
|
30
23
|
def diagnostics(
|
31
24
|
agent_settings:,
|
32
|
-
|
25
|
+
logger:,
|
26
|
+
api_version: nil,
|
27
|
+
headers: nil
|
33
28
|
)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
29
|
+
Core::Transport::HTTP.build(api_instance_class: Diagnostics::API::Instance,
|
30
|
+
logger: logger,
|
31
|
+
agent_settings: agent_settings, api_version: api_version, headers: headers) do |transport|
|
38
32
|
apis = API.defaults
|
39
33
|
|
40
34
|
transport.api API::DIAGNOSTICS, apis[API::DIAGNOSTICS]
|
41
35
|
|
42
|
-
# Apply any settings given by options
|
43
|
-
unless options.empty?
|
44
|
-
transport.default_api = options[:api_version] if options.key?(:api_version)
|
45
|
-
transport.headers options[:headers] if options.key?(:headers)
|
46
|
-
end
|
47
|
-
|
48
36
|
# Call block to apply any customization, if provided
|
49
37
|
yield(transport) if block_given?
|
50
|
-
end
|
38
|
+
end.to_transport(DI::Transport::Diagnostics::Transport)
|
51
39
|
end
|
52
40
|
|
53
41
|
# Builds a new Transport::HTTP::Client with default settings
|
54
42
|
# Pass a block to override any settings.
|
55
43
|
def input(
|
56
44
|
agent_settings:,
|
57
|
-
|
45
|
+
logger:,
|
46
|
+
api_version: nil,
|
47
|
+
headers: nil
|
58
48
|
)
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
49
|
+
Core::Transport::HTTP.build(api_instance_class: Input::API::Instance,
|
50
|
+
logger: logger,
|
51
|
+
agent_settings: agent_settings, api_version: api_version, headers: headers) do |transport|
|
63
52
|
apis = API.defaults
|
64
53
|
|
65
54
|
transport.api API::INPUT, apis[API::INPUT]
|
66
55
|
|
67
|
-
# Apply any settings given by options
|
68
|
-
unless options.empty?
|
69
|
-
transport.default_api = options[:api_version] if options.key?(:api_version)
|
70
|
-
transport.headers options[:headers] if options.key?(:headers)
|
71
|
-
end
|
72
|
-
|
73
56
|
# Call block to apply any customization, if provided
|
74
57
|
yield(transport) if block_given?
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def default_headers
|
79
|
-
{
|
80
|
-
Datadog::Core::Transport::Ext::HTTP::HEADER_CLIENT_COMPUTED_TOP_LEVEL => '1',
|
81
|
-
Datadog::Core::Transport::Ext::HTTP::HEADER_META_LANG => Datadog::Core::Environment::Ext::LANG,
|
82
|
-
Datadog::Core::Transport::Ext::HTTP::HEADER_META_LANG_VERSION => Datadog::Core::Environment::Ext::LANG_VERSION,
|
83
|
-
Datadog::Core::Transport::Ext::HTTP::HEADER_META_LANG_INTERPRETER =>
|
84
|
-
Datadog::Core::Environment::Ext::LANG_INTERPRETER,
|
85
|
-
Datadog::Core::Transport::Ext::HTTP::HEADER_META_LANG_INTERPRETER_VENDOR => Core::Environment::Ext::LANG_ENGINE,
|
86
|
-
Datadog::Core::Transport::Ext::HTTP::HEADER_META_TRACER_VERSION =>
|
87
|
-
Datadog::Core::Environment::Ext::GEM_DATADOG_VERSION
|
88
|
-
}.tap do |headers|
|
89
|
-
# Add container ID, if present.
|
90
|
-
container_id = Datadog::Core::Environment::Container.container_id
|
91
|
-
headers[Datadog::Core::Transport::Ext::HTTP::HEADER_CONTAINER_ID] = container_id unless container_id.nil?
|
92
|
-
# Pretend that stats computation are already done by the client
|
93
|
-
if Datadog.configuration.appsec.standalone.enabled
|
94
|
-
headers[Datadog::Core::Transport::Ext::HTTP::HEADER_CLIENT_COMPUTED_STATS] = 'yes'
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def default_adapter
|
100
|
-
Datadog::Core::Configuration::Ext::Agent::HTTP::ADAPTER
|
58
|
+
end.to_transport(DI::Transport::Input::Transport)
|
101
59
|
end
|
102
60
|
end
|
103
61
|
end
|
@@ -15,12 +15,13 @@ module Datadog
|
|
15
15
|
end
|
16
16
|
|
17
17
|
class Transport
|
18
|
-
attr_reader :client, :apis, :default_api, :current_api_id
|
18
|
+
attr_reader :client, :apis, :default_api, :current_api_id, :logger
|
19
19
|
|
20
|
-
def initialize(apis, default_api)
|
20
|
+
def initialize(apis, default_api, logger)
|
21
21
|
@apis = apis
|
22
|
+
@logger = logger
|
22
23
|
|
23
|
-
@client = HTTP::Client.new(current_api)
|
24
|
+
@client = HTTP::Client.new(current_api, logger)
|
24
25
|
end
|
25
26
|
|
26
27
|
def current_api
|
data/lib/datadog/di/utils.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# standard gets itself into an infinite loop over this
|
4
|
+
# rubocop:disable Layout/SpaceAfterNot
|
5
|
+
|
3
6
|
module Datadog
|
4
7
|
module DI
|
5
8
|
module Utils
|
@@ -135,3 +138,5 @@ module Datadog
|
|
135
138
|
end
|
136
139
|
end
|
137
140
|
end
|
141
|
+
|
142
|
+
# rubocop:enable Layout/SpaceAfterNot
|
@@ -30,11 +30,14 @@ module Datadog
|
|
30
30
|
set_trace_and_span_context('track_login_success', trace, span) do |active_trace, active_span|
|
31
31
|
user_options = user.dup
|
32
32
|
user_id = user_options.delete(:id)
|
33
|
+
user_login = user_options[:login] || others[:'usr.login'] || user_id
|
33
34
|
|
34
35
|
raise ArgumentError, 'missing required key: :user => { :id }' if user_id.nil?
|
35
36
|
|
37
|
+
others[:'usr.login'] = user_login
|
36
38
|
track(LOGIN_SUCCESS_EVENT, active_trace, active_span, **others)
|
37
39
|
|
40
|
+
user_options[:login] = user_login
|
38
41
|
Kit::Identity.set_user(active_trace, active_span, id: user_id, **user_options)
|
39
42
|
end
|
40
43
|
end
|
@@ -55,6 +58,7 @@ module Datadog
|
|
55
58
|
# event information to attach to the trace.
|
56
59
|
def track_login_failure(trace = nil, span = nil, user_exists:, user_id: nil, **others)
|
57
60
|
set_trace_and_span_context('track_login_failure', trace, span) do |active_trace, active_span|
|
61
|
+
others[:'usr.login'] = user_id if user_id && !others.key?(:'usr.login')
|
58
62
|
track(LOGIN_FAILURE_EVENT, active_trace, active_span, **others)
|
59
63
|
|
60
64
|
active_span.set_tag('appsec.events.users.login.failure.usr.id', user_id) if user_id
|
@@ -80,11 +84,14 @@ module Datadog
|
|
80
84
|
set_trace_and_span_context('track_signup', trace, span) do |active_trace, active_span|
|
81
85
|
user_options = user.dup
|
82
86
|
user_id = user_options.delete(:id)
|
87
|
+
user_login = user_options[:login] || others[:'usr.login'] || user_id
|
83
88
|
|
84
89
|
raise ArgumentError, 'missing required key: :user => { :id }' if user_id.nil?
|
85
90
|
|
91
|
+
others[:'usr.login'] = user_login
|
86
92
|
track(SIGNUP_EVENT, active_trace, active_span, **others)
|
87
93
|
|
94
|
+
user_options[:login] = user_login
|
88
95
|
Kit::Identity.set_user(trace, id: user_id, **user_options)
|
89
96
|
end
|
90
97
|
end
|
@@ -131,6 +138,8 @@ module Datadog
|
|
131
138
|
active_trace.keep!
|
132
139
|
end
|
133
140
|
end
|
141
|
+
|
142
|
+
::Datadog::AppSec::Instrumentation.gateway.push('appsec.events.user_lifecycle', event)
|
134
143
|
end
|
135
144
|
|
136
145
|
private
|
data/lib/datadog/kit/identity.rb
CHANGED
@@ -33,6 +33,7 @@ module Datadog
|
|
33
33
|
# @param others [Hash<Symbol, String>] Additional free-form
|
34
34
|
# user information to attach to the trace.
|
35
35
|
#
|
36
|
+
# rubocop:disable Metrics/AbcSize
|
36
37
|
# rubocop:disable Metrics/CyclomaticComplexity
|
37
38
|
# rubocop:disable Metrics/PerceivedComplexity
|
38
39
|
def set_user(
|
@@ -67,11 +68,14 @@ module Datadog
|
|
67
68
|
end
|
68
69
|
|
69
70
|
if Datadog::AppSec.active_context
|
70
|
-
user
|
71
|
+
active_span.set_tag('_dd.appsec.user.collection_mode', 'sdk')
|
72
|
+
|
73
|
+
user = ::Datadog::AppSec::Instrumentation::Gateway::User.new(id, others[:login])
|
71
74
|
::Datadog::AppSec::Instrumentation.gateway.push('identity.set_user', user)
|
72
75
|
end
|
73
76
|
end
|
74
77
|
end
|
78
|
+
# rubocop:enable Metrics/AbcSize
|
75
79
|
# rubocop:enable Metrics/PerceivedComplexity
|
76
80
|
# rubocop:enable Metrics/CyclomaticComplexity
|
77
81
|
|