ddtrace 1.14.0 → 1.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +178 -2
- data/ext/ddtrace_profiling_native_extension/NativeExtensionDesign.md +3 -5
- data/ext/ddtrace_profiling_native_extension/clock_id.h +0 -3
- data/ext/ddtrace_profiling_native_extension/clock_id_from_pthread.c +0 -22
- data/ext/ddtrace_profiling_native_extension/clock_id_noop.c +0 -1
- data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +41 -6
- data/ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.c +3 -0
- data/ext/ddtrace_profiling_native_extension/collectors_stack.c +76 -24
- data/ext/ddtrace_profiling_native_extension/collectors_stack.h +1 -1
- data/ext/ddtrace_profiling_native_extension/collectors_thread_context.c +207 -32
- data/ext/ddtrace_profiling_native_extension/collectors_thread_context.h +1 -1
- data/ext/ddtrace_profiling_native_extension/extconf.rb +8 -2
- data/ext/ddtrace_profiling_native_extension/http_transport.c +26 -10
- data/ext/ddtrace_profiling_native_extension/libdatadog_helpers.c +42 -0
- data/ext/ddtrace_profiling_native_extension/libdatadog_helpers.h +6 -0
- data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +1 -16
- data/ext/ddtrace_profiling_native_extension/pid_controller.c +57 -0
- data/ext/ddtrace_profiling_native_extension/pid_controller.h +45 -0
- data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +17 -12
- data/ext/ddtrace_profiling_native_extension/profiling.c +0 -2
- data/ext/ddtrace_profiling_native_extension/stack_recorder.c +74 -37
- data/ext/ddtrace_profiling_native_extension/stack_recorder.h +13 -3
- data/lib/datadog/appsec/assets/waf_rules/processors.json +92 -0
- data/lib/datadog/appsec/assets/waf_rules/recommended.json +698 -75
- data/lib/datadog/appsec/assets/waf_rules/scanners.json +114 -0
- data/lib/datadog/appsec/assets/waf_rules/strict.json +98 -8
- data/lib/datadog/appsec/assets.rb +8 -0
- data/lib/datadog/appsec/component.rb +9 -2
- data/lib/datadog/appsec/configuration/settings.rb +61 -2
- data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +8 -6
- data/lib/datadog/appsec/contrib/rack/reactive/request.rb +2 -7
- data/lib/datadog/appsec/contrib/rack/reactive/request_body.rb +2 -5
- data/lib/datadog/appsec/contrib/rack/reactive/response.rb +2 -5
- data/lib/datadog/appsec/contrib/rack/request_body_middleware.rb +3 -2
- data/lib/datadog/appsec/contrib/rack/request_middleware.rb +23 -9
- data/lib/datadog/appsec/contrib/rails/gateway/watcher.rb +3 -2
- data/lib/datadog/appsec/contrib/rails/patcher.rb +9 -3
- data/lib/datadog/appsec/contrib/rails/reactive/action.rb +2 -5
- data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +6 -4
- data/lib/datadog/appsec/contrib/sinatra/patcher.rb +13 -7
- data/lib/datadog/appsec/contrib/sinatra/reactive/routed.rb +2 -5
- data/lib/datadog/appsec/event.rb +106 -50
- data/lib/datadog/appsec/monitor/gateway/watcher.rb +3 -3
- data/lib/datadog/appsec/monitor/reactive/set_user.rb +2 -5
- data/lib/datadog/appsec/processor/actions.rb +49 -0
- data/lib/datadog/appsec/processor/rule_merger.rb +22 -2
- data/lib/datadog/appsec/processor.rb +34 -6
- data/lib/datadog/appsec/remote.rb +4 -1
- data/lib/datadog/appsec/response.rb +82 -4
- data/lib/datadog/appsec/sample_rate.rb +21 -0
- data/lib/datadog/appsec.rb +2 -2
- data/lib/datadog/core/configuration/agent_settings_resolver.rb +29 -24
- data/lib/datadog/core/configuration/base.rb +1 -11
- data/lib/datadog/core/configuration/components.rb +7 -2
- data/lib/datadog/core/configuration/ext.rb +21 -0
- data/lib/datadog/core/configuration/option.rb +2 -4
- data/lib/datadog/core/configuration/option_definition.rb +17 -41
- data/lib/datadog/core/configuration/options.rb +5 -5
- data/lib/datadog/core/configuration/settings.rb +47 -45
- data/lib/datadog/core/environment/execution.rb +47 -9
- data/lib/datadog/core/environment/variable_helpers.rb +0 -69
- data/lib/datadog/core/error.rb +1 -0
- data/lib/datadog/core/git/ext.rb +2 -0
- data/lib/datadog/core/remote/client/capabilities.rb +1 -1
- data/lib/datadog/core/remote/component.rb +2 -2
- data/lib/datadog/core/remote/negotiation.rb +2 -2
- data/lib/datadog/core/remote/transport/config.rb +60 -0
- data/lib/datadog/core/remote/transport/http/api/instance.rb +39 -0
- data/lib/datadog/core/remote/transport/http/api/spec.rb +21 -0
- data/lib/datadog/core/remote/transport/http/api.rb +58 -0
- data/lib/datadog/core/remote/transport/http/builder.rb +219 -0
- data/lib/datadog/core/remote/transport/http/client.rb +48 -0
- data/lib/datadog/core/remote/transport/http/config.rb +280 -0
- data/lib/datadog/core/remote/transport/http/negotiation.rb +146 -0
- data/lib/datadog/core/remote/transport/http.rb +179 -0
- data/lib/datadog/core/{transport → remote/transport}/negotiation.rb +25 -23
- data/lib/datadog/core/telemetry/collector.rb +3 -2
- data/lib/datadog/core/telemetry/http/transport.rb +2 -1
- data/lib/datadog/core/transport/ext.rb +47 -0
- data/lib/datadog/core/transport/http/adapters/net.rb +168 -0
- data/lib/datadog/core/transport/http/adapters/registry.rb +29 -0
- data/lib/datadog/core/transport/http/adapters/test.rb +89 -0
- data/lib/datadog/core/transport/http/adapters/unix_socket.rb +83 -0
- data/lib/datadog/core/transport/http/api/endpoint.rb +31 -0
- data/lib/datadog/core/transport/http/api/fallbacks.rb +26 -0
- data/lib/datadog/core/transport/http/api/map.rb +18 -0
- data/lib/datadog/core/transport/http/env.rb +62 -0
- data/lib/datadog/core/transport/http/response.rb +60 -0
- data/lib/datadog/core/transport/parcel.rb +22 -0
- data/lib/datadog/core/transport/request.rb +17 -0
- data/lib/datadog/core/transport/response.rb +64 -0
- data/lib/datadog/core/workers/polling.rb +2 -2
- data/lib/datadog/opentelemetry/api/context.rb +10 -3
- data/lib/datadog/opentelemetry/sdk/propagator.rb +2 -1
- data/lib/datadog/opentelemetry/sdk/span_processor.rb +14 -2
- data/lib/datadog/opentelemetry/sdk/trace/span.rb +68 -0
- data/lib/datadog/opentelemetry/trace.rb +58 -0
- data/lib/datadog/opentelemetry.rb +1 -0
- data/lib/datadog/opentracer.rb +9 -0
- data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +12 -18
- data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +1 -1
- data/lib/datadog/profiling/collectors/thread_context.rb +9 -1
- data/lib/datadog/profiling/component.rb +24 -99
- data/lib/datadog/profiling/ext.rb +0 -12
- data/lib/datadog/profiling/flush.rb +0 -3
- data/lib/datadog/profiling/http_transport.rb +6 -3
- data/lib/datadog/profiling/native_extension.rb +0 -21
- data/lib/datadog/profiling/profiler.rb +11 -12
- data/lib/datadog/profiling.rb +8 -81
- data/lib/datadog/tracing/component.rb +10 -4
- data/lib/datadog/tracing/configuration/agent_settings_resolver.rb +13 -0
- data/lib/datadog/tracing/configuration/ext.rb +4 -2
- data/lib/datadog/tracing/configuration/settings.rb +14 -7
- data/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/active_record/events/sql.rb +4 -0
- data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +104 -197
- data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +3 -0
- data/lib/datadog/tracing/contrib/aws/instrumentation.rb +7 -0
- data/lib/datadog/tracing/contrib/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +6 -0
- data/lib/datadog/tracing/contrib/dalli/ext.rb +7 -0
- data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +9 -2
- data/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +5 -0
- data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +5 -0
- data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +8 -0
- data/lib/datadog/tracing/contrib/excon/middleware.rb +5 -0
- data/lib/datadog/tracing/contrib/ext.rb +3 -0
- data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/faraday/middleware.rb +5 -0
- data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +21 -1
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +11 -1
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +18 -0
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor.rb +0 -4
- data/lib/datadog/tracing/contrib/http/circuit_breaker.rb +3 -3
- data/lib/datadog/tracing/contrib/http/instrumentation.rb +5 -0
- data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +5 -0
- data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +5 -0
- data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +7 -0
- data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +13 -3
- data/lib/datadog/tracing/contrib/opensearch/integration.rb +2 -2
- data/lib/datadog/tracing/contrib/opensearch/patcher.rb +7 -0
- data/lib/datadog/tracing/contrib/pg/instrumentation.rb +5 -0
- data/lib/datadog/tracing/contrib/presto/instrumentation.rb +5 -0
- data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +1 -1
- data/lib/datadog/tracing/contrib/que/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/racecar/event.rb +5 -0
- data/lib/datadog/tracing/contrib/rack/header_tagging.rb +14 -4
- data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +4 -4
- data/lib/datadog/tracing/contrib/rake/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/redis/tags.rb +5 -0
- data/lib/datadog/tracing/contrib/resque/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +5 -0
- data/lib/datadog/tracing/contrib/sequel/utils.rb +5 -0
- data/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/sneakers/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/utils/quantization/http.rb +2 -2
- data/lib/datadog/tracing/distributed/propagation.rb +13 -33
- data/lib/datadog/tracing/metadata/tagging.rb +3 -3
- data/lib/datadog/tracing/sync_writer.rb +3 -3
- data/lib/datadog/tracing/tracer.rb +2 -0
- data/lib/datadog/{core → tracing}/transport/http/api/instance.rb +1 -1
- data/lib/datadog/{core → tracing}/transport/http/api/spec.rb +1 -1
- data/lib/datadog/tracing/transport/http/api.rb +43 -0
- data/lib/datadog/{core → tracing}/transport/http/builder.rb +13 -68
- data/lib/datadog/tracing/transport/http/client.rb +57 -0
- data/lib/datadog/tracing/transport/http/statistics.rb +47 -0
- data/lib/datadog/tracing/transport/http/traces.rb +152 -0
- data/lib/datadog/tracing/transport/http.rb +124 -0
- data/lib/datadog/tracing/transport/io/client.rb +89 -0
- data/lib/datadog/tracing/transport/io/response.rb +27 -0
- data/lib/datadog/tracing/transport/io/traces.rb +101 -0
- data/lib/datadog/tracing/transport/io.rb +30 -0
- data/lib/datadog/tracing/transport/serializable_trace.rb +126 -0
- data/lib/datadog/tracing/transport/statistics.rb +77 -0
- data/lib/datadog/tracing/transport/trace_formatter.rb +209 -0
- data/lib/datadog/tracing/transport/traces.rb +224 -0
- data/lib/datadog/tracing/workers/trace_writer.rb +5 -3
- data/lib/datadog/tracing/workers.rb +3 -2
- data/lib/datadog/tracing/writer.rb +5 -2
- data/lib/ddtrace/transport/ext.rb +17 -15
- data/lib/ddtrace/version.rb +1 -1
- data/lib/ddtrace.rb +1 -1
- metadata +72 -96
- data/lib/datadog/ci/configuration/components.rb +0 -32
- data/lib/datadog/ci/configuration/settings.rb +0 -51
- data/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +0 -35
- data/lib/datadog/ci/contrib/cucumber/ext.rb +0 -22
- data/lib/datadog/ci/contrib/cucumber/formatter.rb +0 -94
- data/lib/datadog/ci/contrib/cucumber/instrumentation.rb +0 -28
- data/lib/datadog/ci/contrib/cucumber/integration.rb +0 -47
- data/lib/datadog/ci/contrib/cucumber/patcher.rb +0 -27
- data/lib/datadog/ci/contrib/minitest/configuration/settings.rb +0 -35
- data/lib/datadog/ci/contrib/minitest/ext.rb +0 -21
- data/lib/datadog/ci/contrib/minitest/integration.rb +0 -49
- data/lib/datadog/ci/contrib/minitest/patcher.rb +0 -27
- data/lib/datadog/ci/contrib/minitest/test_helper.rb +0 -68
- data/lib/datadog/ci/contrib/rspec/configuration/settings.rb +0 -35
- data/lib/datadog/ci/contrib/rspec/example.rb +0 -68
- data/lib/datadog/ci/contrib/rspec/ext.rb +0 -21
- data/lib/datadog/ci/contrib/rspec/integration.rb +0 -48
- data/lib/datadog/ci/contrib/rspec/patcher.rb +0 -27
- data/lib/datadog/ci/ext/app_types.rb +0 -9
- data/lib/datadog/ci/ext/environment.rb +0 -575
- data/lib/datadog/ci/ext/settings.rb +0 -10
- data/lib/datadog/ci/ext/test.rb +0 -35
- data/lib/datadog/ci/extensions.rb +0 -19
- data/lib/datadog/ci/flush.rb +0 -38
- data/lib/datadog/ci/test.rb +0 -81
- data/lib/datadog/ci.rb +0 -21
- data/lib/datadog/core/configuration/dependency_resolver.rb +0 -28
- data/lib/datadog/core/configuration/option_definition_set.rb +0 -22
- data/lib/datadog/core/configuration/option_set.rb +0 -10
- data/lib/datadog/core/transport/config.rb +0 -58
- data/lib/datadog/core/transport/http/api.rb +0 -57
- data/lib/datadog/core/transport/http/client.rb +0 -45
- data/lib/datadog/core/transport/http/config.rb +0 -278
- data/lib/datadog/core/transport/http/negotiation.rb +0 -144
- data/lib/datadog/core/transport/http.rb +0 -169
- data/lib/datadog/core/utils/object_set.rb +0 -43
- data/lib/datadog/core/utils/string_table.rb +0 -47
- data/lib/datadog/profiling/backtrace_location.rb +0 -34
- data/lib/datadog/profiling/buffer.rb +0 -43
- data/lib/datadog/profiling/collectors/old_stack.rb +0 -301
- data/lib/datadog/profiling/encoding/profile.rb +0 -41
- data/lib/datadog/profiling/event.rb +0 -15
- data/lib/datadog/profiling/events/stack.rb +0 -82
- data/lib/datadog/profiling/old_recorder.rb +0 -107
- data/lib/datadog/profiling/pprof/builder.rb +0 -125
- data/lib/datadog/profiling/pprof/converter.rb +0 -102
- data/lib/datadog/profiling/pprof/message_set.rb +0 -16
- data/lib/datadog/profiling/pprof/payload.rb +0 -20
- data/lib/datadog/profiling/pprof/pprof.proto +0 -212
- data/lib/datadog/profiling/pprof/pprof_pb.rb +0 -81
- data/lib/datadog/profiling/pprof/stack_sample.rb +0 -139
- data/lib/datadog/profiling/pprof/string_table.rb +0 -12
- data/lib/datadog/profiling/pprof/template.rb +0 -118
- data/lib/datadog/profiling/trace_identifiers/ddtrace.rb +0 -43
- data/lib/datadog/profiling/trace_identifiers/helper.rb +0 -45
- data/lib/ddtrace/transport/http/adapters/net.rb +0 -168
- data/lib/ddtrace/transport/http/adapters/registry.rb +0 -27
- data/lib/ddtrace/transport/http/adapters/test.rb +0 -85
- data/lib/ddtrace/transport/http/adapters/unix_socket.rb +0 -77
- data/lib/ddtrace/transport/http/api/endpoint.rb +0 -29
- data/lib/ddtrace/transport/http/api/fallbacks.rb +0 -24
- data/lib/ddtrace/transport/http/api/instance.rb +0 -35
- data/lib/ddtrace/transport/http/api/map.rb +0 -16
- data/lib/ddtrace/transport/http/api/spec.rb +0 -17
- data/lib/ddtrace/transport/http/api.rb +0 -39
- data/lib/ddtrace/transport/http/builder.rb +0 -176
- data/lib/ddtrace/transport/http/client.rb +0 -52
- data/lib/ddtrace/transport/http/env.rb +0 -58
- data/lib/ddtrace/transport/http/response.rb +0 -58
- data/lib/ddtrace/transport/http/statistics.rb +0 -43
- data/lib/ddtrace/transport/http/traces.rb +0 -144
- data/lib/ddtrace/transport/http.rb +0 -117
- data/lib/ddtrace/transport/io/client.rb +0 -85
- data/lib/ddtrace/transport/io/response.rb +0 -25
- data/lib/ddtrace/transport/io/traces.rb +0 -99
- data/lib/ddtrace/transport/io.rb +0 -28
- data/lib/ddtrace/transport/parcel.rb +0 -20
- data/lib/ddtrace/transport/request.rb +0 -15
- data/lib/ddtrace/transport/response.rb +0 -60
- data/lib/ddtrace/transport/serializable_trace.rb +0 -122
- data/lib/ddtrace/transport/statistics.rb +0 -75
- data/lib/ddtrace/transport/trace_formatter.rb +0 -207
- data/lib/ddtrace/transport/traces.rb +0 -216
@@ -1,39 +0,0 @@
|
|
1
|
-
require_relative '../../../datadog/core/encoding'
|
2
|
-
|
3
|
-
require_relative 'api/map'
|
4
|
-
require_relative 'api/spec'
|
5
|
-
|
6
|
-
require_relative 'traces'
|
7
|
-
|
8
|
-
module Datadog
|
9
|
-
module Transport
|
10
|
-
module HTTP
|
11
|
-
# Namespace for API components
|
12
|
-
module API
|
13
|
-
# Default API versions
|
14
|
-
V4 = 'v0.4'.freeze
|
15
|
-
V3 = 'v0.3'.freeze
|
16
|
-
|
17
|
-
module_function
|
18
|
-
|
19
|
-
def defaults
|
20
|
-
Map[
|
21
|
-
V4 => Spec.new do |s|
|
22
|
-
s.traces = Traces::API::Endpoint.new(
|
23
|
-
'/v0.4/traces'.freeze,
|
24
|
-
Core::Encoding::MsgpackEncoder,
|
25
|
-
service_rates: true
|
26
|
-
)
|
27
|
-
end,
|
28
|
-
V3 => Spec.new do |s|
|
29
|
-
s.traces = Traces::API::Endpoint.new(
|
30
|
-
'/v0.3/traces'.freeze,
|
31
|
-
Core::Encoding::MsgpackEncoder
|
32
|
-
)
|
33
|
-
end,
|
34
|
-
].with_fallbacks(V4 => V3)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,176 +0,0 @@
|
|
1
|
-
require_relative '../../../datadog/core/configuration/agent_settings_resolver'
|
2
|
-
require_relative 'adapters/registry'
|
3
|
-
require_relative 'api/map'
|
4
|
-
require_relative 'api/instance'
|
5
|
-
require_relative 'client'
|
6
|
-
|
7
|
-
module Datadog
|
8
|
-
module Transport
|
9
|
-
module HTTP
|
10
|
-
# Builds new instances of Transport::HTTP::Client
|
11
|
-
class Builder
|
12
|
-
REGISTRY = Adapters::Registry.new
|
13
|
-
|
14
|
-
attr_reader \
|
15
|
-
:apis,
|
16
|
-
:api_options,
|
17
|
-
:default_adapter,
|
18
|
-
:default_api,
|
19
|
-
:default_headers
|
20
|
-
|
21
|
-
def initialize
|
22
|
-
# Global settings
|
23
|
-
@default_adapter = nil
|
24
|
-
@default_headers = {}
|
25
|
-
|
26
|
-
# Client settings
|
27
|
-
@apis = API::Map.new
|
28
|
-
@default_api = nil
|
29
|
-
|
30
|
-
# API settings
|
31
|
-
@api_options = {}
|
32
|
-
|
33
|
-
yield(self) if block_given?
|
34
|
-
end
|
35
|
-
|
36
|
-
def adapter(config, *args, **kwargs)
|
37
|
-
@default_adapter = case config
|
38
|
-
when Core::Configuration::AgentSettingsResolver::AgentSettings
|
39
|
-
registry_klass = REGISTRY.get(config.adapter)
|
40
|
-
raise UnknownAdapterError, config.adapter if registry_klass.nil?
|
41
|
-
|
42
|
-
registry_klass.build(config)
|
43
|
-
when Symbol
|
44
|
-
registry_klass = REGISTRY.get(config)
|
45
|
-
raise UnknownAdapterError, config if registry_klass.nil?
|
46
|
-
|
47
|
-
registry_klass.new(*args, **kwargs)
|
48
|
-
else
|
49
|
-
config
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def headers(values = {})
|
54
|
-
@default_headers.merge!(values)
|
55
|
-
end
|
56
|
-
|
57
|
-
# Adds a new API to the client
|
58
|
-
# Valid options:
|
59
|
-
# - :adapter
|
60
|
-
# - :default
|
61
|
-
# - :fallback
|
62
|
-
# - :headers
|
63
|
-
def api(key, spec, options = {})
|
64
|
-
options = options.dup
|
65
|
-
|
66
|
-
# Copy spec into API map
|
67
|
-
@apis[key] = spec
|
68
|
-
|
69
|
-
# Apply as default API, if specified to do so.
|
70
|
-
@default_api = key if options.delete(:default) || @default_api.nil?
|
71
|
-
|
72
|
-
# Save all other settings for initialization
|
73
|
-
(@api_options[key] ||= {}).merge!(options)
|
74
|
-
end
|
75
|
-
|
76
|
-
def default_api=(key)
|
77
|
-
raise UnknownApiError, key unless @apis.key?(key)
|
78
|
-
|
79
|
-
@default_api = key
|
80
|
-
end
|
81
|
-
|
82
|
-
def to_transport
|
83
|
-
raise NoDefaultApiError if @default_api.nil?
|
84
|
-
|
85
|
-
# DEV: Should not be specific to traces
|
86
|
-
Transport::Traces::Transport.new(to_api_instances, @default_api)
|
87
|
-
end
|
88
|
-
|
89
|
-
def to_api_instances
|
90
|
-
raise NoApisError if @apis.empty?
|
91
|
-
|
92
|
-
@apis.inject(API::Map.new) do |instances, (key, spec)|
|
93
|
-
instances.tap do
|
94
|
-
api_options = @api_options[key].dup
|
95
|
-
|
96
|
-
# Resolve the adapter to use for this API
|
97
|
-
adapter = api_options.delete(:adapter) || @default_adapter
|
98
|
-
raise NoAdapterForApiError, key if adapter.nil?
|
99
|
-
|
100
|
-
# Resolve fallback and merge headers
|
101
|
-
fallback = api_options.delete(:fallback)
|
102
|
-
api_options[:headers] = @default_headers.merge((api_options[:headers] || {}))
|
103
|
-
|
104
|
-
# Add API::Instance with all settings
|
105
|
-
instances[key] = api_instance_class.new(
|
106
|
-
spec,
|
107
|
-
adapter,
|
108
|
-
api_options
|
109
|
-
)
|
110
|
-
|
111
|
-
# Configure fallback, if provided.
|
112
|
-
instances.with_fallbacks(key => fallback) unless fallback.nil?
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def api_instance_class
|
118
|
-
API::Instance
|
119
|
-
end
|
120
|
-
|
121
|
-
# Raised when the API key does not match known APIs.
|
122
|
-
class UnknownApiError < StandardError
|
123
|
-
attr_reader :key
|
124
|
-
|
125
|
-
def initialize(key)
|
126
|
-
@key = key
|
127
|
-
end
|
128
|
-
|
129
|
-
def message
|
130
|
-
"Unknown transport API '#{key}'!"
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
# Raised when the identifier cannot be matched to an adapter.
|
135
|
-
class UnknownAdapterError < StandardError
|
136
|
-
attr_reader :type
|
137
|
-
|
138
|
-
def initialize(type)
|
139
|
-
@type = type
|
140
|
-
end
|
141
|
-
|
142
|
-
def message
|
143
|
-
"Unknown transport adapter '#{type}'!"
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
# Raised when an adapter cannot be resolved for an API instance.
|
148
|
-
class NoAdapterForApiError < StandardError
|
149
|
-
attr_reader :key
|
150
|
-
|
151
|
-
def initialize(key)
|
152
|
-
@key = key
|
153
|
-
end
|
154
|
-
|
155
|
-
def message
|
156
|
-
"No adapter resolved for transport API '#{key}'!"
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
# Raised when built without defining APIs.
|
161
|
-
class NoApisError < StandardError
|
162
|
-
def message
|
163
|
-
'No APIs configured for transport!'
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
# Raised when client built without defining a default API.
|
168
|
-
class NoDefaultApiError < StandardError
|
169
|
-
def message
|
170
|
-
'No default API configured for transport!'
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require_relative 'statistics'
|
2
|
-
require_relative 'env'
|
3
|
-
|
4
|
-
module Datadog
|
5
|
-
module Transport
|
6
|
-
module HTTP
|
7
|
-
# Routes, encodes, and sends tracer data to the trace agent via HTTP.
|
8
|
-
class Client
|
9
|
-
include Transport::HTTP::Statistics
|
10
|
-
|
11
|
-
attr_reader :api
|
12
|
-
|
13
|
-
def initialize(api)
|
14
|
-
@api = api
|
15
|
-
end
|
16
|
-
|
17
|
-
def send_request(request, &block)
|
18
|
-
# Build request into env
|
19
|
-
env = build_env(request)
|
20
|
-
|
21
|
-
# Get responses from API
|
22
|
-
response = yield(api, env)
|
23
|
-
|
24
|
-
# Update statistics
|
25
|
-
update_stats_from_response!(response)
|
26
|
-
|
27
|
-
response
|
28
|
-
rescue StandardError => e
|
29
|
-
message =
|
30
|
-
"Internal error during #{self.class.name} request. Cause: #{e.class.name} #{e.message} " \
|
31
|
-
"Location: #{Array(e.backtrace).first}"
|
32
|
-
|
33
|
-
# Log error
|
34
|
-
if stats.consecutive_errors > 0
|
35
|
-
Datadog.logger.debug(message)
|
36
|
-
else
|
37
|
-
Datadog.logger.error(message)
|
38
|
-
end
|
39
|
-
|
40
|
-
# Update statistics
|
41
|
-
update_stats_from_exception!(e)
|
42
|
-
|
43
|
-
InternalErrorResponse.new(e)
|
44
|
-
end
|
45
|
-
|
46
|
-
def build_env(request)
|
47
|
-
Env.new(request)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Datadog
|
4
|
-
module Transport
|
5
|
-
module HTTP
|
6
|
-
# Data structure for an HTTP request
|
7
|
-
class Env < Hash
|
8
|
-
attr_reader \
|
9
|
-
:request
|
10
|
-
|
11
|
-
def initialize(request, options = nil)
|
12
|
-
@request = request
|
13
|
-
merge!(options) unless options.nil?
|
14
|
-
end
|
15
|
-
|
16
|
-
def verb
|
17
|
-
self[:verb]
|
18
|
-
end
|
19
|
-
|
20
|
-
def verb=(value)
|
21
|
-
self[:verb] = value
|
22
|
-
end
|
23
|
-
|
24
|
-
def path
|
25
|
-
self[:path]
|
26
|
-
end
|
27
|
-
|
28
|
-
def path=(value)
|
29
|
-
self[:path] = value
|
30
|
-
end
|
31
|
-
|
32
|
-
def body
|
33
|
-
self[:body]
|
34
|
-
end
|
35
|
-
|
36
|
-
def body=(value)
|
37
|
-
self[:body] = value
|
38
|
-
end
|
39
|
-
|
40
|
-
def headers
|
41
|
-
self[:headers] ||= {}
|
42
|
-
end
|
43
|
-
|
44
|
-
def headers=(value)
|
45
|
-
self[:headers] = value
|
46
|
-
end
|
47
|
-
|
48
|
-
def form
|
49
|
-
self[:form] ||= {}
|
50
|
-
end
|
51
|
-
|
52
|
-
def form=(value)
|
53
|
-
self[:form] = value
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../response'
|
4
|
-
|
5
|
-
module Datadog
|
6
|
-
module Transport
|
7
|
-
module HTTP
|
8
|
-
# Wraps an HTTP response from an adapter.
|
9
|
-
#
|
10
|
-
# Used by endpoints to wrap responses from adapters with
|
11
|
-
# fields or behavior that's specific to that endpoint.
|
12
|
-
module Response
|
13
|
-
def initialize(http_response)
|
14
|
-
@http_response = http_response
|
15
|
-
end
|
16
|
-
|
17
|
-
# (see Datadog::Transport::Response#payload)
|
18
|
-
def payload
|
19
|
-
@http_response.payload
|
20
|
-
end
|
21
|
-
|
22
|
-
# (see Datadog::Transport::Response#internal_error?)
|
23
|
-
def internal_error?
|
24
|
-
@http_response.internal_error?
|
25
|
-
end
|
26
|
-
|
27
|
-
# (see Datadog::Transport::Response#unsupported?)
|
28
|
-
def unsupported?
|
29
|
-
@http_response.unsupported?
|
30
|
-
end
|
31
|
-
|
32
|
-
# (see Datadog::Transport::Response#ok?)
|
33
|
-
def ok?
|
34
|
-
@http_response.ok?
|
35
|
-
end
|
36
|
-
|
37
|
-
# (see Datadog::Transport::Response#not_found?)
|
38
|
-
def not_found?
|
39
|
-
@http_response.not_found?
|
40
|
-
end
|
41
|
-
|
42
|
-
# (see Datadog::Transport::Response#client_error?)
|
43
|
-
def client_error?
|
44
|
-
@http_response.client_error?
|
45
|
-
end
|
46
|
-
|
47
|
-
# (see Datadog::Transport::Response#server_error?)
|
48
|
-
def server_error?
|
49
|
-
@http_response.server_error?
|
50
|
-
end
|
51
|
-
|
52
|
-
def code
|
53
|
-
@http_response.respond_to?(:code) ? @http_response.code : nil
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require_relative '../statistics'
|
2
|
-
|
3
|
-
module Datadog
|
4
|
-
module Transport
|
5
|
-
module HTTP
|
6
|
-
# Tracks statistics for HTTP transports
|
7
|
-
module Statistics
|
8
|
-
def self.included(base)
|
9
|
-
base.include(Datadog::Transport::Statistics)
|
10
|
-
base.include(InstanceMethods)
|
11
|
-
end
|
12
|
-
|
13
|
-
# Instance methods for HTTP statistics
|
14
|
-
module InstanceMethods
|
15
|
-
# Decorate metrics for HTTP responses
|
16
|
-
def metrics_for_response(response)
|
17
|
-
super.tap do |metrics|
|
18
|
-
# Add status code tag to api.responses metric
|
19
|
-
if metrics.key?(:api_responses)
|
20
|
-
(metrics[:api_responses].options[:tags] ||= []).tap do |tags|
|
21
|
-
tags << metrics_tag_value(response.code)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
# The most common status code on a healthy tracer
|
30
|
-
STATUS_CODE_200 = 'status_code:200'.freeze
|
31
|
-
|
32
|
-
def metrics_tag_value(status_code)
|
33
|
-
if status_code == 200
|
34
|
-
STATUS_CODE_200 # DEV Saves string concatenation/creation for common case
|
35
|
-
else
|
36
|
-
"status_code:#{status_code}"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,144 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
require_relative '../traces'
|
4
|
-
require_relative 'client'
|
5
|
-
require_relative 'response'
|
6
|
-
require_relative 'api/endpoint'
|
7
|
-
require_relative 'api/instance'
|
8
|
-
|
9
|
-
module Datadog
|
10
|
-
module Transport
|
11
|
-
module HTTP
|
12
|
-
# HTTP transport behavior for traces
|
13
|
-
module Traces
|
14
|
-
# Response from HTTP transport for traces
|
15
|
-
class Response
|
16
|
-
include HTTP::Response
|
17
|
-
include Datadog::Transport::Traces::Response
|
18
|
-
|
19
|
-
def initialize(http_response, options = {})
|
20
|
-
super(http_response)
|
21
|
-
@service_rates = options.fetch(:service_rates, nil)
|
22
|
-
@trace_count = options.fetch(:trace_count, 0)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# Extensions for HTTP client
|
27
|
-
module Client
|
28
|
-
def send_traces_payload(request)
|
29
|
-
send_request(request) do |api, env|
|
30
|
-
api.send_traces(env)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
module API
|
36
|
-
# Extensions for HTTP API Spec
|
37
|
-
module Spec
|
38
|
-
attr_reader :traces
|
39
|
-
|
40
|
-
def traces=(endpoint)
|
41
|
-
@traces = endpoint
|
42
|
-
end
|
43
|
-
|
44
|
-
def send_traces(env, &block)
|
45
|
-
raise NoTraceEndpointDefinedError, self if traces.nil?
|
46
|
-
|
47
|
-
traces.call(env, &block)
|
48
|
-
end
|
49
|
-
|
50
|
-
def encoder
|
51
|
-
traces.encoder
|
52
|
-
end
|
53
|
-
|
54
|
-
# Raised when traces sent but no traces endpoint is defined
|
55
|
-
class NoTraceEndpointDefinedError < StandardError
|
56
|
-
attr_reader :spec
|
57
|
-
|
58
|
-
def initialize(spec)
|
59
|
-
@spec = spec
|
60
|
-
end
|
61
|
-
|
62
|
-
def message
|
63
|
-
'No trace endpoint is defined for API specification!'
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
# Extensions for HTTP API Instance
|
69
|
-
module Instance
|
70
|
-
def send_traces(env)
|
71
|
-
raise TracesNotSupportedError, spec unless spec.is_a?(Traces::API::Spec)
|
72
|
-
|
73
|
-
spec.send_traces(env) do |request_env|
|
74
|
-
call(request_env)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
# Raised when traces sent to API that does not support traces
|
79
|
-
class TracesNotSupportedError < StandardError
|
80
|
-
attr_reader :spec
|
81
|
-
|
82
|
-
def initialize(spec)
|
83
|
-
@spec = spec
|
84
|
-
end
|
85
|
-
|
86
|
-
def message
|
87
|
-
'Traces not supported for this API!'
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
# Endpoint for submitting trace data
|
93
|
-
class Endpoint < HTTP::API::Endpoint
|
94
|
-
HEADER_CONTENT_TYPE = 'Content-Type'.freeze
|
95
|
-
HEADER_TRACE_COUNT = 'X-Datadog-Trace-Count'.freeze
|
96
|
-
SERVICE_RATE_KEY = 'rate_by_service'.freeze
|
97
|
-
|
98
|
-
attr_reader \
|
99
|
-
:encoder
|
100
|
-
|
101
|
-
def initialize(path, encoder, options = {})
|
102
|
-
super(:post, path)
|
103
|
-
@encoder = encoder
|
104
|
-
@service_rates = options.fetch(:service_rates, false)
|
105
|
-
end
|
106
|
-
|
107
|
-
def service_rates?
|
108
|
-
@service_rates == true
|
109
|
-
end
|
110
|
-
|
111
|
-
def call(env, &block)
|
112
|
-
# Add trace count header
|
113
|
-
env.headers[HEADER_TRACE_COUNT] = env.request.parcel.trace_count.to_s
|
114
|
-
|
115
|
-
# Encode body & type
|
116
|
-
env.headers[HEADER_CONTENT_TYPE] = encoder.content_type
|
117
|
-
env.body = env.request.parcel.data
|
118
|
-
|
119
|
-
# Query for response
|
120
|
-
http_response = super(env, &block)
|
121
|
-
|
122
|
-
# Process the response
|
123
|
-
response_options = { trace_count: env.request.parcel.trace_count }.tap do |options|
|
124
|
-
# Parse service rates, if configured to do so.
|
125
|
-
if service_rates? && !http_response.payload.to_s.empty?
|
126
|
-
body = JSON.parse(http_response.payload)
|
127
|
-
options[:service_rates] = body[SERVICE_RATE_KEY] if body.is_a?(Hash) && body.key?(SERVICE_RATE_KEY)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
# Build and return a trace response
|
132
|
-
Traces::Response.new(http_response, response_options)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
# Add traces behavior to transport components
|
138
|
-
HTTP::Client.include(Traces::Client)
|
139
|
-
HTTP::API::Spec.include(Traces::API::Spec)
|
140
|
-
HTTP::API::Instance.include(Traces::API::Instance)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
@@ -1,117 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'uri'
|
4
|
-
|
5
|
-
require_relative '../../datadog/core/environment/container'
|
6
|
-
require_relative '../../datadog/core/environment/ext'
|
7
|
-
require_relative 'ext'
|
8
|
-
require_relative 'http/adapters/net'
|
9
|
-
require_relative 'http/adapters/test'
|
10
|
-
require_relative 'http/adapters/unix_socket'
|
11
|
-
require_relative 'http/api'
|
12
|
-
require_relative 'http/builder'
|
13
|
-
require_relative '../version'
|
14
|
-
|
15
|
-
module Datadog
|
16
|
-
module Transport
|
17
|
-
# Namespace for HTTP transport components
|
18
|
-
module HTTP
|
19
|
-
# NOTE: Due to... legacy reasons... This class likes having a default `AgentSettings` instance to fall back to.
|
20
|
-
# Because we generate this instance with an empty instance of `Settings`, the resulting `AgentSettings` below
|
21
|
-
# represents only settings specified via environment variables + the usual defaults.
|
22
|
-
#
|
23
|
-
# DO NOT USE THIS IN NEW CODE, as it ignores any settings specified by users via `Datadog.configure`.
|
24
|
-
DO_NOT_USE_ENVIRONMENT_AGENT_SETTINGS = Datadog::Core::Configuration::AgentSettingsResolver.call(
|
25
|
-
Datadog::Core::Configuration::Settings.new,
|
26
|
-
logger: nil,
|
27
|
-
)
|
28
|
-
|
29
|
-
module_function
|
30
|
-
|
31
|
-
# Builds a new Transport::HTTP::Client
|
32
|
-
def new(&block)
|
33
|
-
Builder.new(&block).to_transport
|
34
|
-
end
|
35
|
-
|
36
|
-
# Builds a new Transport::HTTP::Client with default settings
|
37
|
-
# Pass a block to override any settings.
|
38
|
-
def default(
|
39
|
-
agent_settings: DO_NOT_USE_ENVIRONMENT_AGENT_SETTINGS,
|
40
|
-
**options
|
41
|
-
)
|
42
|
-
new do |transport|
|
43
|
-
transport.adapter(agent_settings)
|
44
|
-
transport.headers default_headers
|
45
|
-
|
46
|
-
apis = API.defaults
|
47
|
-
|
48
|
-
transport.api API::V4, apis[API::V4], fallback: API::V3, default: true
|
49
|
-
transport.api API::V3, apis[API::V3]
|
50
|
-
|
51
|
-
# Apply any settings given by options
|
52
|
-
unless options.empty?
|
53
|
-
transport.default_api = options[:api_version] if options.key?(:api_version)
|
54
|
-
transport.headers options[:headers] if options.key?(:headers)
|
55
|
-
end
|
56
|
-
|
57
|
-
if agent_settings.deprecated_for_removal_transport_configuration_proc
|
58
|
-
agent_settings.deprecated_for_removal_transport_configuration_proc.call(transport)
|
59
|
-
end
|
60
|
-
|
61
|
-
# Call block to apply any customization, if provided
|
62
|
-
yield(transport) if block_given?
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def default_headers
|
67
|
-
{
|
68
|
-
Datadog::Transport::Ext::HTTP::HEADER_CLIENT_COMPUTED_TOP_LEVEL => '1',
|
69
|
-
Datadog::Transport::Ext::HTTP::HEADER_META_LANG => Datadog::Core::Environment::Ext::LANG,
|
70
|
-
Datadog::Transport::Ext::HTTP::HEADER_META_LANG_VERSION => Datadog::Core::Environment::Ext::LANG_VERSION,
|
71
|
-
Datadog::Transport::Ext::HTTP::HEADER_META_LANG_INTERPRETER => Datadog::Core::Environment::Ext::LANG_INTERPRETER,
|
72
|
-
Datadog::Transport::Ext::HTTP::HEADER_META_TRACER_VERSION => Datadog::Core::Environment::Ext::TRACER_VERSION
|
73
|
-
}.tap do |headers|
|
74
|
-
# Add container ID, if present.
|
75
|
-
container_id = Datadog::Core::Environment::Container.container_id
|
76
|
-
headers[Datadog::Transport::Ext::HTTP::HEADER_CONTAINER_ID] = container_id unless container_id.nil?
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def default_adapter
|
81
|
-
Transport::Ext::HTTP::ADAPTER
|
82
|
-
end
|
83
|
-
|
84
|
-
def default_hostname(logger: Datadog.logger)
|
85
|
-
logger.warn(
|
86
|
-
'Deprecated for removal: Using #default_hostname for configuration is deprecated and will ' \
|
87
|
-
'be removed on a future ddtrace release.'
|
88
|
-
)
|
89
|
-
|
90
|
-
DO_NOT_USE_ENVIRONMENT_AGENT_SETTINGS.hostname
|
91
|
-
end
|
92
|
-
|
93
|
-
def default_port(logger: Datadog.logger)
|
94
|
-
logger.warn(
|
95
|
-
'Deprecated for removal: Using #default_hostname for configuration is deprecated and will ' \
|
96
|
-
'be removed on a future ddtrace release.'
|
97
|
-
)
|
98
|
-
|
99
|
-
DO_NOT_USE_ENVIRONMENT_AGENT_SETTINGS.port
|
100
|
-
end
|
101
|
-
|
102
|
-
def default_url(logger: Datadog.logger)
|
103
|
-
logger.warn(
|
104
|
-
'Deprecated for removal: Using #default_url for configuration is deprecated and will ' \
|
105
|
-
'be removed on a future ddtrace release.'
|
106
|
-
)
|
107
|
-
|
108
|
-
nil
|
109
|
-
end
|
110
|
-
|
111
|
-
# Add adapters to registry
|
112
|
-
Builder::REGISTRY.set(Adapters::Net, Transport::Ext::HTTP::ADAPTER)
|
113
|
-
Builder::REGISTRY.set(Adapters::Test, Transport::Ext::Test::ADAPTER)
|
114
|
-
Builder::REGISTRY.set(Adapters::UnixSocket, Transport::Ext::UnixSocket::ADAPTER)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|