ddtrace 1.14.0 → 1.16.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 +146 -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 +67 -2
- data/lib/datadog/appsec/contrib/rack/gateway/request.rb +6 -2
- data/lib/datadog/appsec/contrib/rack/gateway/response.rb +46 -0
- 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 +7 -5
- data/lib/datadog/appsec/contrib/rack/request_body_middleware.rb +3 -2
- data/lib/datadog/appsec/contrib/rack/request_middleware.rb +34 -10
- 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/remote/worker.rb +3 -1
- 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 +14 -19
- 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 +36 -13
- data/lib/datadog/profiling/scheduler.rb +16 -9
- 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 +106 -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/concurrent_ruby/context_composite_executor_service.rb +14 -14
- data/lib/datadog/tracing/contrib/concurrent_ruby/future_patch.rb +3 -10
- data/lib/datadog/tracing/contrib/concurrent_ruby/integration.rb +2 -1
- data/lib/datadog/tracing/contrib/concurrent_ruby/patcher.rb +8 -1
- data/lib/datadog/tracing/contrib/concurrent_ruby/promises_future_patch.rb +22 -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/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/redis/instrumentation.rb +3 -38
- data/lib/datadog/tracing/contrib/redis/tags.rb +7 -2
- data/lib/datadog/tracing/contrib/redis/trace_middleware.rb +46 -33
- 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/diagnostics/environment_logger.rb +6 -0
- 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 +73 -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,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'set'
|
4
|
+
|
3
5
|
module Datadog
|
4
6
|
module Core
|
5
7
|
module Environment
|
@@ -10,14 +12,29 @@ module Datadog
|
|
10
12
|
# This can be used to make decisions about when to enable
|
11
13
|
# background systems like worker threads or telemetry.
|
12
14
|
def development?
|
13
|
-
!!(repl? || test? || rails_development?)
|
15
|
+
!!(webmock_enabled? || repl? || test? || rails_development?)
|
16
|
+
end
|
17
|
+
|
18
|
+
# WebMock stores the reference to `Net::HTTP` with constant `OriginalNetHTTP`, and when WebMock enables,
|
19
|
+
# the adapter swaps `Net::HTTP` reference to its mock object, @webMockNetHTTP.
|
20
|
+
#
|
21
|
+
# Hence, we can detect by
|
22
|
+
# 1. Checking if `Net::HTTP` is referring to mock object
|
23
|
+
# => ::Net::HTTP.equal?(::WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_get(:@webMockNetHTTP))
|
24
|
+
#
|
25
|
+
# 2. Checking if `Net::HTTP` is referring to the original one
|
26
|
+
# => ::Net::HTTP.equal?(::WebMock::HttpLibAdapters::NetHttpAdapter::OriginalNetHTTP)
|
27
|
+
def webmock_enabled?
|
28
|
+
defined?(::WebMock::HttpLibAdapters::NetHttpAdapter) &&
|
29
|
+
defined?(::Net::HTTP) &&
|
30
|
+
::Net::HTTP.equal?(::WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_get(:@webMockNetHTTP))
|
14
31
|
end
|
15
32
|
|
16
33
|
private
|
17
34
|
|
18
35
|
# Is this process running a test?
|
19
36
|
def test?
|
20
|
-
rspec? || minitest?
|
37
|
+
rspec? || minitest? || cucumber?
|
21
38
|
end
|
22
39
|
|
23
40
|
# Is this process running inside on a Read–eval–print loop?
|
@@ -49,14 +66,35 @@ module Datadog
|
|
49
66
|
::Minitest::Unit.class_variable_get(:@@installed_at_exit))
|
50
67
|
end
|
51
68
|
|
52
|
-
#
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
#
|
69
|
+
# Check if we are running from `bin/cucumber` or `cucumber/rake/task`.
|
70
|
+
def cucumber?
|
71
|
+
defined?(::Cucumber::Cli)
|
72
|
+
end
|
73
|
+
|
74
|
+
# If this is a Rails application, use different heuristics to detect
|
75
|
+
# whether this is a development environment or not.
|
58
76
|
def rails_development?
|
59
|
-
|
77
|
+
# A Rails Spring Ruby process is a bit peculiar: the process is agnostic
|
78
|
+
# whether the application is running as a console or server.
|
79
|
+
# Luckily, the Spring gem *must not* be installed in a production environment so
|
80
|
+
# detecting its presence is enough to deduct if this is a development environment.
|
81
|
+
#
|
82
|
+
# @see https://github.com/rails/spring/blob/48b299348ace2188444489a0c216a6f3e9687281/README.md?plain=1#L204-L207
|
83
|
+
defined?(::Spring) || rails_env_development?
|
84
|
+
end
|
85
|
+
|
86
|
+
RAILS_ENV_DEVELOPMENT = Set['development', 'test'].freeze
|
87
|
+
private_constant :RAILS_ENV_DEVELOPMENT
|
88
|
+
|
89
|
+
# By default, every Rails application has three environments: `development`, `test`, and `production`.
|
90
|
+
# This has been the case since Rails 3.0.0:
|
91
|
+
# https://github.com/rails/rails/blob/3e48484ff16ea07ffe5db232bf43c14992e273c1/railties/doc/guides/getting_started_with_rails/getting_started_with_rails.txt#L144
|
92
|
+
#
|
93
|
+
# Instead of checking for "not production", we instead check for "development" and "test" because
|
94
|
+
# it's common to have a custom "staging" environment, and such environment normally want to run as close
|
95
|
+
# to production as possible.
|
96
|
+
def rails_env_development?
|
97
|
+
defined?(::Rails.env) && RAILS_ENV_DEVELOPMENT.include?(::Rails.env)
|
60
98
|
end
|
61
99
|
end
|
62
100
|
end
|
@@ -29,75 +29,6 @@ module Datadog
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
# Reads an environment variable as an Integer.
|
33
|
-
#
|
34
|
-
# @param [String] var environment variable
|
35
|
-
# @param [Array<String>] var list of environment variables
|
36
|
-
# @param [Integer] default the default value if the keys in `var` are not present in the environment
|
37
|
-
# @param [Boolean] deprecation_warning when `var` is a list, record a deprecation log when
|
38
|
-
# the first key in `var` is not used.
|
39
|
-
# @return [Integer] if the environment value is a valid Integer
|
40
|
-
# @return [default] if the environment value is not found
|
41
|
-
def env_to_int(var, default = nil, deprecation_warning: true)
|
42
|
-
var = decode_array(var, deprecation_warning)
|
43
|
-
var && ENV.key?(var) ? ENV[var].to_i : default
|
44
|
-
end
|
45
|
-
|
46
|
-
# Reads an environment variable as a Float.
|
47
|
-
#
|
48
|
-
# @param [String] var environment variable
|
49
|
-
# @param [Array<String>] var list of environment variables
|
50
|
-
# @param [Float] default the default value if the keys in `var` are not present in the environment
|
51
|
-
# @param [Boolean] deprecation_warning when `var` is a list, record a deprecation log when
|
52
|
-
# the first key in `var` is not used.
|
53
|
-
# @return [Float] if the environment value is a valid Float
|
54
|
-
# @return [default] if the environment value is not found
|
55
|
-
def env_to_float(var, default = nil, deprecation_warning: true)
|
56
|
-
var = decode_array(var, deprecation_warning)
|
57
|
-
var && ENV.key?(var) ? ENV[var].to_f : default
|
58
|
-
end
|
59
|
-
|
60
|
-
# Parses comma- or space-separated lists.
|
61
|
-
#
|
62
|
-
# If a comma is present, then the list is considered comma-separated.
|
63
|
-
# Otherwise, it is considered space-separated.
|
64
|
-
#
|
65
|
-
# After the entries are separated, commas and whitespaces that are
|
66
|
-
# either trailing or leading are trimmed.
|
67
|
-
#
|
68
|
-
# Empty entries, after trimmed, are also removed from the result.
|
69
|
-
#
|
70
|
-
# @param [String] var environment variable
|
71
|
-
# @param [Array<String>] var list of environment variables
|
72
|
-
# @param [Array<Object>] default the default value if the keys in `var` are not present in the environment
|
73
|
-
# @param [Boolean] deprecation_warning when `var` is a list, record a deprecation log when
|
74
|
-
# the first key in `var` is not used.
|
75
|
-
# @return [Array<Object>] if the environment value is a valid list
|
76
|
-
# @return [default] if the environment value is not found
|
77
|
-
def env_to_list(var, default = [], comma_separated_only:, deprecation_warning: true)
|
78
|
-
var = decode_array(var, deprecation_warning)
|
79
|
-
if var && ENV.key?(var)
|
80
|
-
value = ENV[var]
|
81
|
-
|
82
|
-
values = if value.include?(',') || comma_separated_only
|
83
|
-
value.split(',')
|
84
|
-
else
|
85
|
-
value.split(' ') # rubocop:disable Style/RedundantArgument
|
86
|
-
end
|
87
|
-
|
88
|
-
values.map! do |v|
|
89
|
-
v.gsub!(/\A[\s,]*|[\s,]*\Z/, '')
|
90
|
-
|
91
|
-
v.empty? ? nil : v
|
92
|
-
end
|
93
|
-
|
94
|
-
values.compact!
|
95
|
-
values
|
96
|
-
else
|
97
|
-
default
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
32
|
private
|
102
33
|
|
103
34
|
def decode_array(var, deprecation_warning)
|
data/lib/datadog/core/error.rb
CHANGED
data/lib/datadog/core/git/ext.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require_relative 'worker'
|
4
4
|
require_relative 'client/capabilities'
|
5
5
|
require_relative 'client'
|
6
|
-
require_relative '
|
6
|
+
require_relative 'transport/http'
|
7
7
|
require_relative '../remote'
|
8
8
|
require_relative 'negotiation'
|
9
9
|
|
@@ -22,7 +22,7 @@ module Datadog
|
|
22
22
|
transport_options[:agent_settings] = agent_settings if agent_settings
|
23
23
|
|
24
24
|
negotiation = Negotiation.new(settings, agent_settings)
|
25
|
-
transport_v7 = Datadog::Core::Transport::HTTP.v7(**transport_options.dup)
|
25
|
+
transport_v7 = Datadog::Core::Remote::Transport::HTTP.v7(**transport_options.dup)
|
26
26
|
|
27
27
|
@barrier = Barrier.new(BARRIER_TIMEOUT)
|
28
28
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '
|
3
|
+
require_relative 'transport/http'
|
4
4
|
|
5
5
|
module Datadog
|
6
6
|
module Core
|
@@ -11,7 +11,7 @@ module Datadog
|
|
11
11
|
transport_options = {}
|
12
12
|
transport_options[:agent_settings] = agent_settings if agent_settings
|
13
13
|
|
14
|
-
@transport_root = Datadog::Core::Transport::HTTP.root(**transport_options.dup)
|
14
|
+
@transport_root = Datadog::Core::Remote::Transport::HTTP.root(**transport_options.dup)
|
15
15
|
@logged = {}
|
16
16
|
end
|
17
17
|
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../core/transport/request'
|
4
|
+
require_relative '../../../core/transport/parcel'
|
5
|
+
|
6
|
+
module Datadog
|
7
|
+
module Core
|
8
|
+
module Remote
|
9
|
+
module Transport
|
10
|
+
module Config
|
11
|
+
# Data transfer object for encoded traces
|
12
|
+
class EncodedParcel
|
13
|
+
include Datadog::Core::Transport::Parcel
|
14
|
+
|
15
|
+
def count
|
16
|
+
data.length
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Config request
|
21
|
+
class Request < Datadog::Core::Transport::Request
|
22
|
+
end
|
23
|
+
|
24
|
+
# Config response
|
25
|
+
module Response
|
26
|
+
attr_reader :roots, :targets, :target_files, :client_configs
|
27
|
+
|
28
|
+
def empty?
|
29
|
+
@empty
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Config transport
|
34
|
+
class Transport
|
35
|
+
attr_reader :client, :apis, :default_api, :current_api_id
|
36
|
+
|
37
|
+
def initialize(apis, default_api)
|
38
|
+
@apis = apis
|
39
|
+
|
40
|
+
@client = HTTP::Client.new(current_api)
|
41
|
+
end
|
42
|
+
|
43
|
+
##### there is only one transport! it's negotiation!
|
44
|
+
def send_config(payload)
|
45
|
+
json = JSON.dump(payload)
|
46
|
+
parcel = EncodedParcel.new(json)
|
47
|
+
request = Request.new(parcel)
|
48
|
+
|
49
|
+
@client.send_config_payload(request)
|
50
|
+
end
|
51
|
+
|
52
|
+
def current_api
|
53
|
+
@apis[HTTP::API::V7]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,39 @@
|
|
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
|
@@ -0,0 +1,21 @@
|
|
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
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../encoding'
|
4
|
+
require_relative '../../../transport/http/api/map'
|
5
|
+
|
6
|
+
# TODO: Decouple standard transport/http/api/instance
|
7
|
+
#
|
8
|
+
# Separate classes are needed because transport/http/traces includes
|
9
|
+
# Trace::API::Instance which closes over and uses a single spec, which is
|
10
|
+
# negotiated as either /v3 or /v4 for the whole API at the spec level, but we
|
11
|
+
# need an independent toplevel path at the endpoint level.
|
12
|
+
#
|
13
|
+
# Separate classes are needed because of `include Trace::API::Instance`.
|
14
|
+
#
|
15
|
+
# Below should be:
|
16
|
+
# require_relative '../../../../ddtrace/transport/http/api/spec'
|
17
|
+
require_relative 'api/spec'
|
18
|
+
|
19
|
+
# TODO: only needed for Negotiation::API::Endpoint
|
20
|
+
require_relative 'negotiation'
|
21
|
+
|
22
|
+
# TODO: only needed for Config::API::Endpoint
|
23
|
+
require_relative 'config'
|
24
|
+
|
25
|
+
module Datadog
|
26
|
+
module Core
|
27
|
+
module Remote
|
28
|
+
module Transport
|
29
|
+
module HTTP
|
30
|
+
# Namespace for API components
|
31
|
+
module API
|
32
|
+
# Default API versions
|
33
|
+
ROOT = 'root'
|
34
|
+
V7 = 'v0.7'
|
35
|
+
|
36
|
+
module_function
|
37
|
+
|
38
|
+
def defaults
|
39
|
+
Datadog::Core::Transport::HTTP::API::Map[
|
40
|
+
ROOT => Spec.new do |s|
|
41
|
+
s.info = Negotiation::API::Endpoint.new(
|
42
|
+
'/info',
|
43
|
+
)
|
44
|
+
end,
|
45
|
+
V7 => Spec.new do |s|
|
46
|
+
s.config = Config::API::Endpoint.new(
|
47
|
+
'/v0.7/config',
|
48
|
+
Core::Encoding::JSONEncoder,
|
49
|
+
)
|
50
|
+
end,
|
51
|
+
]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,219 @@
|
|
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 '../../../../ddtrace/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 '../../../../ddtrace/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 ddtrace/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
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../../core/transport/http/env'
|
4
|
+
require_relative '../../../../core/transport/http/response'
|
5
|
+
|
6
|
+
# TODO: Decouple transport/http/client
|
7
|
+
#
|
8
|
+
# The standard one does `include Transport::HTTP::Statistics` and performs
|
9
|
+
# stats updates, which may or may not be desirable in general.
|
10
|
+
|
11
|
+
module Datadog
|
12
|
+
module Core
|
13
|
+
module Remote
|
14
|
+
module Transport
|
15
|
+
module HTTP
|
16
|
+
# Routes, encodes, and sends tracer data to the trace agent via HTTP.
|
17
|
+
class Client
|
18
|
+
attr_reader :api
|
19
|
+
|
20
|
+
def initialize(api)
|
21
|
+
@api = api
|
22
|
+
end
|
23
|
+
|
24
|
+
def send_request(request, &block)
|
25
|
+
# Build request into env
|
26
|
+
env = build_env(request)
|
27
|
+
|
28
|
+
# Get responses from API
|
29
|
+
yield(api, env)
|
30
|
+
rescue StandardError => e
|
31
|
+
message =
|
32
|
+
"Internal error during #{self.class.name} request. Cause: #{e.class.name} #{e.message} " \
|
33
|
+
"Location: #{Array(e.backtrace).first}"
|
34
|
+
|
35
|
+
Datadog.logger.debug(message)
|
36
|
+
|
37
|
+
Datadog::Core::Transport::InternalErrorResponse.new(e)
|
38
|
+
end
|
39
|
+
|
40
|
+
def build_env(request)
|
41
|
+
Datadog::Core::Transport::HTTP::Env.new(request)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|