datadog 2.10.0 → 2.12.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 +56 -1
- data/ext/datadog_profiling_native_extension/collectors_stack.c +3 -3
- data/ext/datadog_profiling_native_extension/collectors_thread_context.c +44 -1
- data/ext/datadog_profiling_native_extension/extconf.rb +4 -0
- data/ext/datadog_profiling_native_extension/gvl_profiling_helper.c +2 -0
- data/ext/datadog_profiling_native_extension/gvl_profiling_helper.h +0 -8
- data/ext/datadog_profiling_native_extension/heap_recorder.c +1 -1
- data/ext/datadog_profiling_native_extension/private_vm_api_access.c +56 -0
- data/ext/datadog_profiling_native_extension/private_vm_api_access.h +7 -0
- data/ext/datadog_profiling_native_extension/profiling.c +7 -0
- data/ext/libdatadog_api/crashtracker.c +4 -4
- data/ext/libdatadog_extconf_helpers.rb +1 -1
- data/lib/datadog/appsec/configuration/settings.rb +64 -11
- data/lib/datadog/appsec/contrib/active_record/patcher.rb +0 -3
- data/lib/datadog/appsec/contrib/devise/configuration.rb +76 -0
- data/lib/datadog/appsec/contrib/devise/event.rb +4 -7
- data/lib/datadog/appsec/contrib/devise/patcher/authenticatable_patch.rb +16 -21
- data/lib/datadog/appsec/contrib/devise/patcher/registration_controller_patch.rb +8 -15
- data/lib/datadog/appsec/contrib/devise/patcher/rememberable_patch.rb +1 -1
- data/lib/datadog/appsec/contrib/devise/patcher.rb +0 -3
- data/lib/datadog/appsec/contrib/devise/tracking.rb +1 -1
- data/lib/datadog/appsec/contrib/excon/integration.rb +41 -0
- data/lib/datadog/appsec/contrib/excon/patcher.rb +28 -0
- data/lib/datadog/appsec/contrib/excon/ssrf_detection_middleware.rb +43 -0
- data/lib/datadog/appsec/contrib/faraday/connection_patch.rb +22 -0
- data/lib/datadog/appsec/contrib/faraday/integration.rb +42 -0
- data/lib/datadog/appsec/contrib/faraday/patcher.rb +53 -0
- data/lib/datadog/appsec/contrib/faraday/rack_builder_patch.rb +22 -0
- data/lib/datadog/appsec/contrib/faraday/ssrf_detection_middleware.rb +42 -0
- data/lib/datadog/appsec/contrib/graphql/gateway/watcher.rb +10 -12
- data/lib/datadog/appsec/contrib/graphql/patcher.rb +0 -3
- data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +65 -73
- data/lib/datadog/appsec/contrib/rack/patcher.rb +0 -3
- data/lib/datadog/appsec/contrib/rails/gateway/watcher.rb +20 -25
- data/lib/datadog/appsec/contrib/rails/patcher.rb +0 -3
- data/lib/datadog/appsec/contrib/rest_client/integration.rb +45 -0
- data/lib/datadog/appsec/contrib/rest_client/patcher.rb +28 -0
- data/lib/datadog/appsec/contrib/rest_client/request_ssrf_detection_patch.rb +39 -0
- data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +38 -49
- data/lib/datadog/appsec/contrib/sinatra/patcher.rb +0 -3
- data/lib/datadog/appsec/monitor/gateway/watcher.rb +19 -25
- data/lib/datadog/appsec/remote.rb +4 -0
- data/lib/datadog/appsec.rb +3 -0
- data/lib/datadog/core/configuration/components.rb +8 -2
- data/lib/datadog/core/configuration/ext.rb +1 -1
- data/lib/datadog/core/configuration/option_definition.rb +2 -0
- data/lib/datadog/core/configuration/settings.rb +22 -6
- data/lib/datadog/core/encoding.rb +16 -0
- data/lib/datadog/core/environment/agent_info.rb +77 -0
- data/lib/datadog/core/remote/component.rb +11 -9
- data/lib/datadog/core/remote/transport/http/api.rb +13 -18
- data/lib/datadog/core/remote/transport/http/config.rb +0 -18
- data/lib/datadog/core/remote/transport/http/negotiation.rb +1 -18
- data/lib/datadog/core/remote/transport/http.rb +7 -12
- data/lib/datadog/core/remote/transport/negotiation.rb +13 -1
- data/lib/datadog/core/remote/worker.rb +10 -7
- data/lib/datadog/core/telemetry/component.rb +5 -1
- data/lib/datadog/core/telemetry/event.rb +5 -0
- data/lib/datadog/core/telemetry/worker.rb +9 -5
- data/lib/datadog/core/transport/http/adapters/unix_socket.rb +1 -1
- data/lib/datadog/{tracing → core}/transport/http/api/instance.rb +1 -1
- data/lib/datadog/{tracing → core}/transport/http/api/spec.rb +1 -1
- data/lib/datadog/{tracing → core}/transport/http/builder.rb +37 -17
- data/lib/datadog/core/transport/response.rb +4 -0
- data/lib/datadog/di/code_tracker.rb +15 -8
- data/lib/datadog/di/component.rb +2 -3
- data/lib/datadog/di/configuration/settings.rb +14 -0
- data/lib/datadog/di/contrib.rb +2 -0
- data/lib/datadog/di/logger.rb +30 -0
- data/lib/datadog/di/probe.rb +3 -6
- data/lib/datadog/di/probe_manager.rb +5 -2
- data/lib/datadog/di/probe_notifier_worker.rb +35 -8
- data/lib/datadog/di/remote.rb +3 -3
- data/lib/datadog/di/transport/diagnostics.rb +61 -0
- data/lib/datadog/di/transport/http/api.rb +52 -0
- data/lib/datadog/di/transport/http/client.rb +46 -0
- data/lib/datadog/di/transport/http/diagnostics.rb +92 -0
- data/lib/datadog/di/transport/http/input.rb +94 -0
- data/lib/datadog/di/transport/http.rb +119 -0
- data/lib/datadog/di/transport/input.rb +61 -0
- data/lib/datadog/di/utils.rb +91 -0
- data/lib/datadog/di.rb +5 -1
- data/lib/datadog/profiling/component.rb +2 -8
- data/lib/datadog/profiling/load_native_extension.rb +1 -33
- data/lib/datadog/tracing/component.rb +1 -0
- data/lib/datadog/tracing/configuration/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/extensions.rb +14 -0
- data/lib/datadog/tracing/contrib/graphql/configuration/error_extension_env_parser.rb +21 -0
- data/lib/datadog/tracing/contrib/graphql/configuration/settings.rb +11 -0
- data/lib/datadog/tracing/contrib/graphql/ext.rb +5 -0
- data/lib/datadog/tracing/contrib/graphql/unified_trace.rb +102 -11
- data/lib/datadog/tracing/contrib/rack/header_collection.rb +11 -1
- data/lib/datadog/tracing/contrib/rack/middlewares.rb +1 -1
- data/lib/datadog/tracing/contrib/span_attribute_schema.rb +6 -1
- data/lib/datadog/tracing/sync_writer.rb +5 -2
- data/lib/datadog/tracing/tracer.rb +10 -7
- data/lib/datadog/tracing/transport/http/api.rb +11 -2
- data/lib/datadog/tracing/transport/http/traces.rb +0 -3
- data/lib/datadog/tracing/transport/http.rb +12 -7
- data/lib/datadog/tracing/transport/serializable_trace.rb +8 -4
- data/lib/datadog/tracing/transport/traces.rb +25 -8
- data/lib/datadog/tracing/workers/trace_writer.rb +4 -1
- data/lib/datadog/tracing/workers.rb +5 -4
- data/lib/datadog/tracing/writer.rb +6 -2
- data/lib/datadog/version.rb +1 -1
- metadata +33 -29
- data/ext/datadog_profiling_loader/datadog_profiling_loader.c +0 -142
- data/ext/datadog_profiling_loader/extconf.rb +0 -60
- data/lib/datadog/appsec/contrib/graphql/reactive/multiplex.rb +0 -46
- data/lib/datadog/appsec/contrib/patcher.rb +0 -12
- data/lib/datadog/appsec/contrib/rack/reactive/request.rb +0 -69
- data/lib/datadog/appsec/contrib/rack/reactive/request_body.rb +0 -47
- data/lib/datadog/appsec/contrib/rack/reactive/response.rb +0 -53
- data/lib/datadog/appsec/contrib/rails/reactive/action.rb +0 -53
- data/lib/datadog/appsec/contrib/sinatra/reactive/routed.rb +0 -48
- data/lib/datadog/appsec/monitor/reactive/set_user.rb +0 -45
- data/lib/datadog/appsec/reactive/address_hash.rb +0 -22
- data/lib/datadog/appsec/reactive/engine.rb +0 -47
- data/lib/datadog/appsec/reactive/subscriber.rb +0 -19
- data/lib/datadog/core/remote/transport/http/api/instance.rb +0 -39
- data/lib/datadog/core/remote/transport/http/api/spec.rb +0 -21
- data/lib/datadog/core/remote/transport/http/builder.rb +0 -219
- data/lib/datadog/di/transport.rb +0 -79
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../request'
|
4
|
-
|
5
|
-
module Datadog
|
6
|
-
module AppSec
|
7
|
-
module Contrib
|
8
|
-
module Rails
|
9
|
-
module Reactive
|
10
|
-
# Dispatch data from a Rails request to the WAF context
|
11
|
-
module Action
|
12
|
-
ADDRESSES = [
|
13
|
-
'rails.request.body',
|
14
|
-
'rails.request.route_params',
|
15
|
-
].freeze
|
16
|
-
private_constant :ADDRESSES
|
17
|
-
|
18
|
-
def self.publish(engine, gateway_request)
|
19
|
-
catch(:block) do
|
20
|
-
# params have been parsed from the request body
|
21
|
-
engine.publish('rails.request.body', gateway_request.parsed_body)
|
22
|
-
engine.publish('rails.request.route_params', gateway_request.route_params)
|
23
|
-
|
24
|
-
nil
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.subscribe(engine, context)
|
29
|
-
engine.subscribe(*ADDRESSES) do |*values|
|
30
|
-
Datadog.logger.debug { "reacted to #{ADDRESSES.inspect}: #{values.inspect}" }
|
31
|
-
body = values[0]
|
32
|
-
path_params = values[1]
|
33
|
-
|
34
|
-
persistent_data = {
|
35
|
-
'server.request.body' => body,
|
36
|
-
'server.request.path_params' => path_params,
|
37
|
-
}
|
38
|
-
|
39
|
-
waf_timeout = Datadog.configuration.appsec.waf_timeout
|
40
|
-
result = context.run_waf(persistent_data, {}, waf_timeout)
|
41
|
-
|
42
|
-
next unless result.match?
|
43
|
-
|
44
|
-
yield result
|
45
|
-
throw(:block, true) unless result.actions.empty?
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Datadog
|
4
|
-
module AppSec
|
5
|
-
module Contrib
|
6
|
-
module Sinatra
|
7
|
-
module Reactive
|
8
|
-
# Dispatch data from a Sinatra request to the WAF context
|
9
|
-
module Routed
|
10
|
-
ADDRESSES = [
|
11
|
-
'sinatra.request.route_params',
|
12
|
-
].freeze
|
13
|
-
private_constant :ADDRESSES
|
14
|
-
|
15
|
-
def self.publish(engine, data)
|
16
|
-
_request, route_params = data
|
17
|
-
|
18
|
-
catch(:block) do
|
19
|
-
engine.publish('sinatra.request.route_params', route_params.params)
|
20
|
-
|
21
|
-
nil
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.subscribe(engine, context)
|
26
|
-
engine.subscribe(*ADDRESSES) do |*values|
|
27
|
-
Datadog.logger.debug { "reacted to #{ADDRESSES.inspect}: #{values.inspect}" }
|
28
|
-
path_params = values[0]
|
29
|
-
|
30
|
-
persistent_data = {
|
31
|
-
'server.request.path_params' => path_params,
|
32
|
-
}
|
33
|
-
|
34
|
-
waf_timeout = Datadog.configuration.appsec.waf_timeout
|
35
|
-
result = context.run_waf(persistent_data, {}, waf_timeout)
|
36
|
-
|
37
|
-
next unless result.match?
|
38
|
-
|
39
|
-
yield result
|
40
|
-
throw(:block, true) unless result.actions.empty?
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Datadog
|
4
|
-
module AppSec
|
5
|
-
module Monitor
|
6
|
-
module Reactive
|
7
|
-
# Dispatch data from Datadog::Kit::Identity.set_user to the WAF context
|
8
|
-
module SetUser
|
9
|
-
ADDRESSES = [
|
10
|
-
'usr.id',
|
11
|
-
].freeze
|
12
|
-
private_constant :ADDRESSES
|
13
|
-
|
14
|
-
def self.publish(engine, user)
|
15
|
-
catch(:block) do
|
16
|
-
engine.publish('usr.id', user.id)
|
17
|
-
|
18
|
-
nil
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.subscribe(engine, context)
|
23
|
-
engine.subscribe(*ADDRESSES) do |*values|
|
24
|
-
Datadog.logger.debug { "reacted to #{ADDRESSES.inspect}: #{values.inspect}" }
|
25
|
-
|
26
|
-
user_id = values[0]
|
27
|
-
|
28
|
-
persistent_data = {
|
29
|
-
'usr.id' => user_id,
|
30
|
-
}
|
31
|
-
|
32
|
-
waf_timeout = Datadog.configuration.appsec.waf_timeout
|
33
|
-
result = context.run_waf(persistent_data, {}, waf_timeout)
|
34
|
-
|
35
|
-
next unless result.match?
|
36
|
-
|
37
|
-
yield result
|
38
|
-
throw(:block, true) unless result.actions.empty?
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Datadog
|
4
|
-
module AppSec
|
5
|
-
module Reactive
|
6
|
-
# AddressHash for Reactive Engine
|
7
|
-
class AddressHash < Hash
|
8
|
-
def self.new(*arguments, &block)
|
9
|
-
super { |h, k| h[k] = [] }
|
10
|
-
end
|
11
|
-
|
12
|
-
def addresses
|
13
|
-
keys.flatten
|
14
|
-
end
|
15
|
-
|
16
|
-
def with(address)
|
17
|
-
keys.select { |k| k.include?(address) }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'address_hash'
|
4
|
-
require_relative 'subscriber'
|
5
|
-
|
6
|
-
module Datadog
|
7
|
-
module AppSec
|
8
|
-
module Reactive
|
9
|
-
# Reactive Engine
|
10
|
-
class Engine
|
11
|
-
def initialize
|
12
|
-
@data = {}
|
13
|
-
@subscribers = AddressHash.new
|
14
|
-
end
|
15
|
-
|
16
|
-
def subscribe(*addresses, &block)
|
17
|
-
@subscribers[addresses.freeze] << Subscriber.new(&block)
|
18
|
-
end
|
19
|
-
|
20
|
-
def publish(address, value)
|
21
|
-
# check if someone has address subscribed
|
22
|
-
if @subscribers.addresses.include?(address)
|
23
|
-
|
24
|
-
# someone will be interested, set value
|
25
|
-
@data[address] = value
|
26
|
-
|
27
|
-
# find candidates i.e address groups that contain the just posted address
|
28
|
-
@subscribers.with(address).each do |addresses|
|
29
|
-
# find targets to the address group containing the posted address
|
30
|
-
subscribers = @subscribers[addresses]
|
31
|
-
|
32
|
-
# is all data for the targets available?
|
33
|
-
if (addresses - @data.keys).empty?
|
34
|
-
hash = addresses.each_with_object({}) { |a, h| h[a] = @data[a] }
|
35
|
-
subscribers.each { |s| s.call(*hash.values) }
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
attr_reader :subscribers, :data
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Datadog
|
4
|
-
module AppSec
|
5
|
-
module Reactive
|
6
|
-
# Reactive Engine subscriber
|
7
|
-
class Subscriber
|
8
|
-
def initialize(&block)
|
9
|
-
@block = block
|
10
|
-
freeze
|
11
|
-
end
|
12
|
-
|
13
|
-
def call(*args)
|
14
|
-
@block.call(*args)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Datadog
|
4
|
-
module Core
|
5
|
-
module Remote
|
6
|
-
module Transport
|
7
|
-
module HTTP
|
8
|
-
module API
|
9
|
-
# An API configured with adapter and routes
|
10
|
-
class Instance
|
11
|
-
attr_reader \
|
12
|
-
:adapter,
|
13
|
-
:headers,
|
14
|
-
:spec
|
15
|
-
|
16
|
-
def initialize(spec, adapter, options = {})
|
17
|
-
@spec = spec
|
18
|
-
@adapter = adapter
|
19
|
-
@headers = options.fetch(:headers, {})
|
20
|
-
end
|
21
|
-
|
22
|
-
def encoder
|
23
|
-
spec.encoder
|
24
|
-
end
|
25
|
-
|
26
|
-
def call(env)
|
27
|
-
# Add headers to request env, unless empty.
|
28
|
-
env.headers.merge!(headers) unless headers.empty?
|
29
|
-
|
30
|
-
# Send request env to the adapter.
|
31
|
-
adapter.call(env)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Datadog
|
4
|
-
module Core
|
5
|
-
module Remote
|
6
|
-
module Transport
|
7
|
-
module HTTP
|
8
|
-
module API
|
9
|
-
# Specification for an HTTP API
|
10
|
-
# Defines behaviors without specific configuration details.
|
11
|
-
class Spec
|
12
|
-
def initialize
|
13
|
-
yield(self) if block_given?
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,219 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../../../configuration/agent_settings_resolver'
|
4
|
-
require_relative '../../../transport/http/adapters/registry'
|
5
|
-
require_relative '../../../transport/http/api/map'
|
6
|
-
|
7
|
-
# TODO: Decouple standard transport/http/api/instance
|
8
|
-
#
|
9
|
-
# Separate classes are needed because transport/http/trace includes
|
10
|
-
# Trace::API::Instance which closes over and uses a single spec, which is
|
11
|
-
# negotiated as either /v3 or /v4 for the whole API at the spec level, but we
|
12
|
-
# need an independent toplevel path at the endpoint level.
|
13
|
-
#
|
14
|
-
# Separate classes are needed because of `include Trace::API::Instance`.
|
15
|
-
#
|
16
|
-
# Below should be:
|
17
|
-
# require_relative '../../../../datadog/core/transport/http/api/instance'
|
18
|
-
require_relative 'api/instance'
|
19
|
-
|
20
|
-
# TODO: Decouple transport/http/client
|
21
|
-
#
|
22
|
-
# The standard one does `include Transport::HTTP::Statistics` and performs
|
23
|
-
# stats updates, which may or may not be desirable in general.
|
24
|
-
#
|
25
|
-
# Below should be:
|
26
|
-
# require_relative '../../../../datadog/core/transport/http/client'
|
27
|
-
require_relative 'client'
|
28
|
-
|
29
|
-
# TODO: Decouple transport/http/builder
|
30
|
-
#
|
31
|
-
# This class is duplicated even though it is tantalisingly close to the
|
32
|
-
# one in datadog/core/transport mostly because it refers to a different
|
33
|
-
# `API::Instance` in `#api_instance_class` but also because it operates on a
|
34
|
-
# different `HTTP::Client`, as well as de-hardcoding the transport class
|
35
|
-
# `Transport::Traces::Transport` in `#to_transport`
|
36
|
-
#
|
37
|
-
# Additionally, its design makes it so there can be only one (API, Client,
|
38
|
-
# Transport) triplet, requiring a new transport instance for any varying
|
39
|
-
# element of the triplet.
|
40
|
-
|
41
|
-
module Datadog
|
42
|
-
module Core
|
43
|
-
module Remote
|
44
|
-
module Transport
|
45
|
-
module HTTP
|
46
|
-
# Builds new instances of Transport::HTTP::Client
|
47
|
-
class Builder
|
48
|
-
REGISTRY = Datadog::Core::Transport::HTTP::Adapters::Registry.new
|
49
|
-
|
50
|
-
attr_reader \
|
51
|
-
:apis,
|
52
|
-
:api_options,
|
53
|
-
:default_adapter,
|
54
|
-
:default_api,
|
55
|
-
:default_headers
|
56
|
-
|
57
|
-
def initialize
|
58
|
-
# Global settings
|
59
|
-
@default_adapter = nil
|
60
|
-
@default_headers = {}
|
61
|
-
|
62
|
-
# Client settings
|
63
|
-
@apis = Datadog::Core::Transport::HTTP::API::Map.new
|
64
|
-
@default_api = nil
|
65
|
-
|
66
|
-
# API settings
|
67
|
-
@api_options = {}
|
68
|
-
|
69
|
-
yield(self) if block_given?
|
70
|
-
end
|
71
|
-
|
72
|
-
def adapter(config, *args, **kwargs)
|
73
|
-
@default_adapter = case config
|
74
|
-
when Core::Configuration::AgentSettingsResolver::AgentSettings
|
75
|
-
registry_klass = REGISTRY.get(config.adapter)
|
76
|
-
raise UnknownAdapterError, config.adapter if registry_klass.nil?
|
77
|
-
|
78
|
-
registry_klass.build(config)
|
79
|
-
when Symbol
|
80
|
-
registry_klass = REGISTRY.get(config)
|
81
|
-
raise UnknownAdapterError, config if registry_klass.nil?
|
82
|
-
|
83
|
-
registry_klass.new(*args, **kwargs)
|
84
|
-
else
|
85
|
-
config
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def headers(values = {})
|
90
|
-
@default_headers.merge!(values)
|
91
|
-
end
|
92
|
-
|
93
|
-
# Adds a new API to the client
|
94
|
-
# Valid options:
|
95
|
-
# - :adapter
|
96
|
-
# - :default
|
97
|
-
# - :fallback
|
98
|
-
# - :headers
|
99
|
-
def api(key, spec, options = {})
|
100
|
-
options = options.dup
|
101
|
-
|
102
|
-
# Copy spec into API map
|
103
|
-
@apis[key] = spec
|
104
|
-
|
105
|
-
# Apply as default API, if specified to do so.
|
106
|
-
@default_api = key if options.delete(:default) || @default_api.nil?
|
107
|
-
|
108
|
-
# Save all other settings for initialization
|
109
|
-
(@api_options[key] ||= {}).merge!(options)
|
110
|
-
end
|
111
|
-
|
112
|
-
def default_api=(key)
|
113
|
-
raise UnknownApiError, key unless @apis.key?(key)
|
114
|
-
|
115
|
-
@default_api = key
|
116
|
-
end
|
117
|
-
|
118
|
-
def to_transport(klass)
|
119
|
-
raise NoDefaultApiError if @default_api.nil?
|
120
|
-
|
121
|
-
klass.new(to_api_instances, @default_api)
|
122
|
-
end
|
123
|
-
|
124
|
-
def to_api_instances
|
125
|
-
raise NoApisError if @apis.empty?
|
126
|
-
|
127
|
-
@apis.inject(Datadog::Core::Transport::HTTP::API::Map.new) do |instances, (key, spec)|
|
128
|
-
instances.tap do
|
129
|
-
api_options = @api_options[key].dup
|
130
|
-
|
131
|
-
# Resolve the adapter to use for this API
|
132
|
-
adapter = api_options.delete(:adapter) || @default_adapter
|
133
|
-
raise NoAdapterForApiError, key if adapter.nil?
|
134
|
-
|
135
|
-
# Resolve fallback and merge headers
|
136
|
-
fallback = api_options.delete(:fallback)
|
137
|
-
api_options[:headers] = @default_headers.merge((api_options[:headers] || {}))
|
138
|
-
|
139
|
-
# Add API::Instance with all settings
|
140
|
-
instances[key] = api_instance_class.new(
|
141
|
-
spec,
|
142
|
-
adapter,
|
143
|
-
api_options
|
144
|
-
)
|
145
|
-
|
146
|
-
# Configure fallback, if provided.
|
147
|
-
instances.with_fallbacks(key => fallback) unless fallback.nil?
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
def api_instance_class
|
153
|
-
API::Instance
|
154
|
-
end
|
155
|
-
|
156
|
-
# Raised when the API key does not match known APIs.
|
157
|
-
class UnknownApiError < StandardError
|
158
|
-
attr_reader :key
|
159
|
-
|
160
|
-
def initialize(key)
|
161
|
-
super()
|
162
|
-
|
163
|
-
@key = key
|
164
|
-
end
|
165
|
-
|
166
|
-
def message
|
167
|
-
"Unknown transport API '#{key}'!"
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
# Raised when the identifier cannot be matched to an adapter.
|
172
|
-
class UnknownAdapterError < StandardError
|
173
|
-
attr_reader :type
|
174
|
-
|
175
|
-
def initialize(type)
|
176
|
-
super()
|
177
|
-
|
178
|
-
@type = type
|
179
|
-
end
|
180
|
-
|
181
|
-
def message
|
182
|
-
"Unknown transport adapter '#{type}'!"
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
# Raised when an adapter cannot be resolved for an API instance.
|
187
|
-
class NoAdapterForApiError < StandardError
|
188
|
-
attr_reader :key
|
189
|
-
|
190
|
-
def initialize(key)
|
191
|
-
super()
|
192
|
-
|
193
|
-
@key = key
|
194
|
-
end
|
195
|
-
|
196
|
-
def message
|
197
|
-
"No adapter resolved for transport API '#{key}'!"
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
# Raised when built without defining APIs.
|
202
|
-
class NoApisError < StandardError
|
203
|
-
def message
|
204
|
-
'No APIs configured for transport!'
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
# Raised when client built without defining a default API.
|
209
|
-
class NoDefaultApiError < StandardError
|
210
|
-
def message
|
211
|
-
'No default API configured for transport!'
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
data/lib/datadog/di/transport.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'error'
|
4
|
-
require_relative '../core/transport/http/adapters/net'
|
5
|
-
|
6
|
-
module Datadog
|
7
|
-
module DI
|
8
|
-
# Transport for sending probe statuses and snapshots to local agent.
|
9
|
-
#
|
10
|
-
# Handles encoding of the payloads into multipart posts if necessary,
|
11
|
-
# body formatting/encoding, setting correct headers, etc.
|
12
|
-
#
|
13
|
-
# The transport does not handle batching of statuses or snapshots -
|
14
|
-
# the batching should be implemented upstream of this class.
|
15
|
-
#
|
16
|
-
# Timeout settings are forwarded from agent settings to the Net adapter.
|
17
|
-
#
|
18
|
-
# The send_* methods raise Error::AgentCommunicationError on errors
|
19
|
-
# (network errors and HTTP protocol errors). It is the responsibility
|
20
|
-
# of upstream code to rescue these exceptions appropriately to prevent them
|
21
|
-
# from being propagated to the application.
|
22
|
-
#
|
23
|
-
# @api private
|
24
|
-
class Transport
|
25
|
-
DIAGNOSTICS_PATH = '/debugger/v1/diagnostics'
|
26
|
-
INPUT_PATH = '/debugger/v1/input'
|
27
|
-
|
28
|
-
def initialize(agent_settings)
|
29
|
-
# Note that this uses host, port, timeout and TLS flag from
|
30
|
-
# agent settings.
|
31
|
-
@client = Core::Transport::HTTP::Adapters::Net.new(agent_settings)
|
32
|
-
end
|
33
|
-
|
34
|
-
def send_diagnostics(payload)
|
35
|
-
event_payload = Core::Vendor::Multipart::Post::UploadIO.new(
|
36
|
-
StringIO.new(JSON.dump(payload)), 'application/json', 'event.json'
|
37
|
-
)
|
38
|
-
payload = {'event' => event_payload}
|
39
|
-
# Core transport unconditionally specifies headers to underlying
|
40
|
-
# Net::HTTP client, ends up passing 'nil' as headers if none are
|
41
|
-
# specified by us, which then causes Net::HTTP to die with an exception.
|
42
|
-
send_request('Probe status submission',
|
43
|
-
path: DIAGNOSTICS_PATH, form: payload, headers: {})
|
44
|
-
end
|
45
|
-
|
46
|
-
def send_input(payload)
|
47
|
-
send_request('Probe snapshot submission',
|
48
|
-
path: INPUT_PATH, body: payload.to_json,
|
49
|
-
headers: {'content-type' => 'application/json'},)
|
50
|
-
end
|
51
|
-
|
52
|
-
# TODO status should use either input or diagnostics endpoints
|
53
|
-
# depending on agent version.
|
54
|
-
alias_method :send_status, :send_diagnostics
|
55
|
-
|
56
|
-
alias_method :send_snapshot, :send_input
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
attr_reader :client
|
61
|
-
|
62
|
-
def send_request(desc, **options)
|
63
|
-
env = Core::Transport::HTTP::Env.new(nil, options)
|
64
|
-
response = client.post(env)
|
65
|
-
unless response.ok?
|
66
|
-
raise Error::AgentCommunicationError, "#{desc} failed: #{response.code}: #{response.payload}"
|
67
|
-
end
|
68
|
-
# Datadog::Core::Transport does not perform any exception mapping,
|
69
|
-
# therefore we could have any exception here from failure to parse
|
70
|
-
# agent URI for example.
|
71
|
-
# If we ever implement retries for network errors, we should distinguish
|
72
|
-
# actual network errors from non-network errors that are raised by
|
73
|
-
# transport code.
|
74
|
-
rescue => exc
|
75
|
-
raise Error::AgentCommunicationError, "#{desc} failed: #{exc.class}: #{exc}"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|