ddtrace 1.13.1 → 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 +207 -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 -1
- 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 +68 -3
- 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 +9 -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/diagnostics/environment_logger.rb +130 -234
- data/lib/datadog/core/environment/execution.rb +50 -2
- 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 +13 -4
- 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 +34 -99
- data/lib/datadog/profiling/diagnostics/environment_logger.rb +39 -0
- data/lib/datadog/profiling/exporter.rb +4 -4
- data/lib/datadog/profiling/ext.rb +0 -12
- data/lib/datadog/profiling/flush.rb +2 -7
- 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 +9 -81
- data/lib/datadog/tracing/component.rb +12 -5
- 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/configuration/resolver.rb +18 -11
- data/lib/datadog/tracing/contrib/active_record/events/sql.rb +4 -0
- data/lib/datadog/tracing/contrib/active_record/utils.rb +1 -1
- 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 +104 -102
- 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/lograge/instrumentation.rb +1 -17
- 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/semantic_logger/instrumentation.rb +3 -20
- 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 +11 -11
- data/lib/datadog/tracing/correlation.rb +20 -0
- data/lib/datadog/tracing/diagnostics/environment_logger.rb +159 -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 +6 -4
- 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 +2 -2
- data/lib/ddtrace.rb +1 -1
- metadata +74 -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,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'date'
|
2
4
|
require 'json'
|
3
5
|
require 'rbconfig'
|
@@ -5,280 +7,174 @@ require 'rbconfig'
|
|
5
7
|
module Datadog
|
6
8
|
module Core
|
7
9
|
module Diagnostics
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
class << self
|
13
|
-
# Outputs environment information to {Datadog.logger}.
|
14
|
-
# Executes only once for the lifetime of the program.
|
15
|
-
def log!(transport_responses)
|
16
|
-
return if (defined?(@executed) && @executed) || !log?
|
17
|
-
|
18
|
-
@executed = true
|
19
|
-
|
20
|
-
data = EnvironmentCollector.new.collect!(transport_responses)
|
21
|
-
data.reject! { |_, v| v.nil? } # Remove empty values from hash output
|
22
|
-
|
23
|
-
log_environment!(data.to_json)
|
24
|
-
log_error!('Agent Error'.freeze, data[:agent_error]) if data[:agent_error]
|
25
|
-
rescue => e
|
26
|
-
Datadog.logger.warn("Failed to collect environment information: #{e} Location: #{Array(e.backtrace).first}")
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def log_environment!(line)
|
32
|
-
Datadog.logger.info("DATADOG CONFIGURATION - #{line}")
|
33
|
-
end
|
34
|
-
|
35
|
-
def log_error!(type, error)
|
36
|
-
Datadog.logger.warn("DATADOG DIAGNOSTIC - #{type}: #{error}")
|
37
|
-
end
|
38
|
-
|
39
|
-
# Are we logging the environment data?
|
40
|
-
def log?
|
41
|
-
startup_logs_enabled = Datadog.configuration.diagnostics.startup_logs.enabled
|
42
|
-
if startup_logs_enabled.nil?
|
43
|
-
!repl? # Suppress logs if we running in a REPL
|
44
|
-
else
|
45
|
-
startup_logs_enabled
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
REPL_PROGRAM_NAMES = %w[irb pry].freeze
|
50
|
-
|
51
|
-
def repl?
|
52
|
-
REPL_PROGRAM_NAMES.include?($PROGRAM_NAME)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# Collects environment information for diagnostic logging
|
58
|
-
class EnvironmentCollector
|
59
|
-
# @return [String] current time in ISO8601 format
|
60
|
-
def date
|
61
|
-
DateTime.now.iso8601
|
62
|
-
end
|
63
|
-
|
64
|
-
# Best portable guess of OS information.
|
65
|
-
# @return [String] platform string
|
66
|
-
def os_name
|
67
|
-
RbConfig::CONFIG['host'.freeze]
|
10
|
+
# Base class for EnvironmentLoggers - should allow for easy reporting by users to Datadog support.
|
11
|
+
module EnvironmentLogging
|
12
|
+
def log_configuration!(prefix, data)
|
13
|
+
logger.info("DATADOG CONFIGURATION - #{prefix} - #{data}")
|
68
14
|
end
|
69
15
|
|
70
|
-
|
71
|
-
|
72
|
-
DDTrace::VERSION::STRING
|
16
|
+
def log_error!(prefix, type, error)
|
17
|
+
logger.warn("DATADOG ERROR - #{prefix} - #{type}: #{error}")
|
73
18
|
end
|
74
19
|
|
75
|
-
|
76
|
-
def lang
|
77
|
-
Core::Environment::Ext::LANG
|
78
|
-
end
|
20
|
+
protected
|
79
21
|
|
80
|
-
|
81
|
-
|
82
|
-
# @return [String]
|
83
|
-
def lang_version
|
84
|
-
Core::Environment::Ext::LANG_VERSION
|
22
|
+
def logger
|
23
|
+
Datadog.logger
|
85
24
|
end
|
86
25
|
|
87
|
-
#
|
88
|
-
def
|
89
|
-
|
90
|
-
|
26
|
+
# If logger should log and hasn't logged already, then output environment configuration and possible errors.
|
27
|
+
def log_once!
|
28
|
+
# Check if already been executed
|
29
|
+
return false if (defined?(@executed) && @executed) || !log?
|
91
30
|
|
92
|
-
|
93
|
-
def enabled
|
94
|
-
Datadog.configuration.tracing.enabled
|
95
|
-
end
|
31
|
+
yield if block_given?
|
96
32
|
|
97
|
-
|
98
|
-
def service
|
99
|
-
Datadog.configuration.service
|
33
|
+
@executed = true
|
100
34
|
end
|
101
35
|
|
102
|
-
#
|
103
|
-
def
|
104
|
-
Datadog.configuration.
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
transport = Tracing.send(:tracer).writer.transport
|
111
|
-
|
112
|
-
# return `nil` with IO transport
|
113
|
-
return unless transport.respond_to?(:client)
|
114
|
-
|
115
|
-
adapter = transport.client.api.adapter
|
116
|
-
adapter.url
|
36
|
+
# Are we logging the environment data?
|
37
|
+
def log?
|
38
|
+
startup_logs_enabled = Datadog.configuration.diagnostics.startup_logs.enabled
|
39
|
+
if startup_logs_enabled.nil?
|
40
|
+
!repl? && !rspec? # Suppress logs if we are running in a REPL or rspec
|
41
|
+
else
|
42
|
+
startup_logs_enabled
|
43
|
+
end
|
117
44
|
end
|
118
45
|
|
119
|
-
|
120
|
-
# @return [String] concatenated list of transport errors
|
121
|
-
def agent_error(transport_responses)
|
122
|
-
error_responses = transport_responses.reject(&:ok?)
|
46
|
+
REPL_PROGRAM_NAMES = %w[irb pry].freeze
|
123
47
|
|
124
|
-
|
125
|
-
|
126
|
-
error_responses.map(&:inspect).join(','.freeze)
|
127
|
-
end
|
128
|
-
|
129
|
-
# @return [Boolean, nil] debug mode enabled in configuration
|
130
|
-
def debug
|
131
|
-
!!Datadog.configuration.diagnostics.debug
|
48
|
+
def repl?
|
49
|
+
REPL_PROGRAM_NAMES.include?($PROGRAM_NAME)
|
132
50
|
end
|
133
51
|
|
134
|
-
|
135
|
-
|
136
|
-
!!Datadog.configuration.tracing.analytics.enabled
|
52
|
+
def rspec?
|
53
|
+
$PROGRAM_NAME.end_with?('rspec')
|
137
54
|
end
|
55
|
+
end
|
138
56
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
return nil unless sampler
|
57
|
+
# Collects and logs Core diagnostic information
|
58
|
+
module EnvironmentLogger
|
59
|
+
extend EnvironmentLogging
|
143
60
|
|
144
|
-
|
61
|
+
def self.collect_and_log!
|
62
|
+
log_once! do
|
63
|
+
data = EnvironmentCollector.collect_config!
|
64
|
+
log_configuration!('CORE', data.to_json)
|
65
|
+
end
|
66
|
+
rescue => e
|
67
|
+
logger.warn("Failed to collect core environment information: #{e} Location: #{Array(e.backtrace).first}")
|
145
68
|
end
|
69
|
+
end
|
146
70
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
#
|
152
|
-
# @return [Hash, nil] sample rules configured
|
153
|
-
def sampling_rules
|
154
|
-
sampler = Datadog.configuration.tracing.sampler
|
155
|
-
return nil unless sampler.is_a?(Tracing::Sampling::PrioritySampler) &&
|
156
|
-
sampler.priority_sampler.is_a?(Tracing::Sampling::RuleSampler)
|
157
|
-
|
158
|
-
sampler.priority_sampler.rules.map do |rule|
|
159
|
-
next unless rule.is_a?(Tracing::Sampling::SimpleRule)
|
160
|
-
|
71
|
+
# Collects environment information for Core diagnostic logging
|
72
|
+
module EnvironmentCollector
|
73
|
+
class << self
|
74
|
+
def collect_config!
|
161
75
|
{
|
162
|
-
|
163
|
-
|
164
|
-
|
76
|
+
date: date,
|
77
|
+
os_name: os_name,
|
78
|
+
version: version,
|
79
|
+
lang: lang,
|
80
|
+
lang_version: lang_version,
|
81
|
+
env: env,
|
82
|
+
service: service,
|
83
|
+
dd_version: dd_version,
|
84
|
+
debug: debug,
|
85
|
+
tags: tags,
|
86
|
+
runtime_metrics_enabled: runtime_metrics_enabled,
|
87
|
+
vm: vm,
|
88
|
+
health_metrics_enabled: health_metrics_enabled
|
165
89
|
}
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
# @return [Hash, nil] concatenated list of global tracer tags configured
|
170
|
-
def tags
|
171
|
-
tags = Datadog.configuration.tags
|
172
|
-
return nil if tags.empty?
|
90
|
+
end
|
173
91
|
|
174
|
-
|
175
|
-
|
92
|
+
# @return [String] current time in ISO8601 format
|
93
|
+
def date
|
94
|
+
DateTime.now.iso8601
|
95
|
+
end
|
176
96
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
97
|
+
# Best portable guess of OS information.
|
98
|
+
# @return [String] platform string
|
99
|
+
def os_name
|
100
|
+
RbConfig::CONFIG['host']
|
101
|
+
end
|
181
102
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
def integrations_loaded
|
187
|
-
integrations = instrumented_integrations
|
188
|
-
return if integrations.empty?
|
103
|
+
# @return [String] ddtrace version
|
104
|
+
def version
|
105
|
+
DDTrace::VERSION::STRING
|
106
|
+
end
|
189
107
|
|
190
|
-
|
191
|
-
|
108
|
+
# @return [String] "ruby"
|
109
|
+
def lang
|
110
|
+
Core::Environment::Ext::LANG
|
111
|
+
end
|
192
112
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
# will differ from RUBY_VERSION for non-mri VMs.
|
199
|
-
if defined?(RUBY_ENGINE_VERSION)
|
200
|
-
"#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION}"
|
201
|
-
else
|
202
|
-
# Ruby < 2.3 doesn't support RUBY_ENGINE_VERSION
|
203
|
-
"#{RUBY_ENGINE}-#{RUBY_VERSION}"
|
113
|
+
# Supported Ruby language version.
|
114
|
+
# Will be distinct from VM version for non-MRI environments.
|
115
|
+
# @return [String]
|
116
|
+
def lang_version
|
117
|
+
Core::Environment::Ext::LANG_VERSION
|
204
118
|
end
|
205
|
-
end
|
206
119
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
120
|
+
# @return [String] configured application environment
|
121
|
+
def env
|
122
|
+
Datadog.configuration.env
|
123
|
+
end
|
211
124
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
125
|
+
# @return [String] configured application service name
|
126
|
+
def service
|
127
|
+
Datadog.configuration.service
|
128
|
+
end
|
216
129
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
130
|
+
# @return [String] configured application version
|
131
|
+
def dd_version
|
132
|
+
Datadog.configuration.version
|
133
|
+
end
|
221
134
|
|
222
|
-
|
223
|
-
|
224
|
-
|
135
|
+
# @return [Boolean, nil] debug mode enabled in configuration
|
136
|
+
def debug
|
137
|
+
!!Datadog.configuration.diagnostics.debug
|
138
|
+
end
|
225
139
|
|
226
|
-
|
227
|
-
|
228
|
-
|
140
|
+
# @return [Hash, nil] concatenated list of global tracer tags configured
|
141
|
+
def tags
|
142
|
+
tags = Datadog.configuration.tags
|
143
|
+
return nil if tags.empty?
|
229
144
|
|
230
|
-
|
231
|
-
|
232
|
-
{
|
233
|
-
date: date,
|
234
|
-
os_name: os_name,
|
235
|
-
version: version,
|
236
|
-
lang: lang,
|
237
|
-
lang_version: lang_version,
|
238
|
-
env: env,
|
239
|
-
enabled: enabled,
|
240
|
-
service: service,
|
241
|
-
dd_version: dd_version,
|
242
|
-
agent_url: agent_url,
|
243
|
-
agent_error: agent_error(transport_responses),
|
244
|
-
debug: debug,
|
245
|
-
analytics_enabled: analytics_enabled,
|
246
|
-
sample_rate: sample_rate,
|
247
|
-
sampling_rules: sampling_rules,
|
248
|
-
tags: tags,
|
249
|
-
runtime_metrics_enabled: runtime_metrics_enabled,
|
250
|
-
integrations_loaded: integrations_loaded,
|
251
|
-
vm: vm,
|
252
|
-
partial_flushing_enabled: partial_flushing_enabled,
|
253
|
-
priority_sampling_enabled: priority_sampling_enabled,
|
254
|
-
health_metrics_enabled: health_metrics_enabled,
|
255
|
-
profiling_enabled: profiling_enabled,
|
256
|
-
**instrumented_integrations_settings
|
257
|
-
}
|
258
|
-
end
|
145
|
+
hash_serializer(tags)
|
146
|
+
end
|
259
147
|
|
260
|
-
|
148
|
+
# @return [Boolean, nil] runtime metrics enabled in configuration
|
149
|
+
def runtime_metrics_enabled
|
150
|
+
Datadog.configuration.runtime_metrics.enabled
|
151
|
+
end
|
261
152
|
|
262
|
-
|
263
|
-
|
264
|
-
|
153
|
+
# Ruby VM name and version.
|
154
|
+
# Examples: "ruby-2.7.1", "jruby-9.2.11.1", "truffleruby-20.1.0"
|
155
|
+
# @return [String, nil]
|
156
|
+
def vm
|
157
|
+
# RUBY_ENGINE_VERSION returns the VM version, which
|
158
|
+
# will differ from RUBY_VERSION for non-mri VMs.
|
159
|
+
if defined?(RUBY_ENGINE_VERSION)
|
160
|
+
"#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION}"
|
161
|
+
else
|
162
|
+
# Ruby < 2.3 doesn't support RUBY_ENGINE_VERSION
|
163
|
+
"#{RUBY_ENGINE}-#{RUBY_VERSION}"
|
164
|
+
end
|
165
|
+
end
|
265
166
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
next [] if setting == :tracer # Skip internal Ruby objects
|
167
|
+
# @return [Boolean, nil] health metrics enabled in configuration
|
168
|
+
def health_metrics_enabled
|
169
|
+
!!Datadog.configuration.diagnostics.health_metrics.enabled
|
170
|
+
end
|
271
171
|
|
272
|
-
|
273
|
-
# handlers possibly causing errors.
|
274
|
-
[[:"integration_#{name}_#{setting}", value.to_s]]
|
275
|
-
end
|
276
|
-
end.to_h
|
277
|
-
end
|
172
|
+
private
|
278
173
|
|
279
|
-
|
280
|
-
|
281
|
-
|
174
|
+
# Outputs "k1:v1,k2:v2,..."
|
175
|
+
def hash_serializer(h)
|
176
|
+
h.map { |k, v| "#{k}:#{v}" }.join(',')
|
177
|
+
end
|
282
178
|
end
|
283
179
|
end
|
284
180
|
end
|
@@ -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?)
|
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?
|
@@ -48,6 +65,37 @@ module Datadog
|
|
48
65
|
::Minitest::Unit.class_variable_defined?(:@@installed_at_exit) &&
|
49
66
|
::Minitest::Unit.class_variable_get(:@@installed_at_exit))
|
50
67
|
end
|
68
|
+
|
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.
|
76
|
+
def rails_development?
|
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)
|
98
|
+
end
|
51
99
|
end
|
52
100
|
end
|
53
101
|
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
|
|