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
@@ -0,0 +1,224 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../core/chunker'
|
4
|
+
require_relative '../../core/transport/parcel'
|
5
|
+
require_relative '../../core/transport/request'
|
6
|
+
require_relative 'serializable_trace'
|
7
|
+
require_relative 'trace_formatter'
|
8
|
+
|
9
|
+
module Datadog
|
10
|
+
module Tracing
|
11
|
+
module Transport
|
12
|
+
module Traces
|
13
|
+
# Data transfer object for encoded traces
|
14
|
+
class EncodedParcel
|
15
|
+
include Datadog::Core::Transport::Parcel
|
16
|
+
|
17
|
+
attr_reader :trace_count
|
18
|
+
|
19
|
+
def initialize(data, trace_count)
|
20
|
+
super(data)
|
21
|
+
@trace_count = trace_count
|
22
|
+
end
|
23
|
+
|
24
|
+
def count
|
25
|
+
data.length
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Traces request
|
30
|
+
class Request < Datadog::Core::Transport::Request
|
31
|
+
end
|
32
|
+
|
33
|
+
# Traces response
|
34
|
+
module Response
|
35
|
+
attr_reader :service_rates, :trace_count
|
36
|
+
end
|
37
|
+
|
38
|
+
# Traces chunker
|
39
|
+
class Chunker
|
40
|
+
# Trace agent limit payload size of 10 MiB (since agent v5.11.0):
|
41
|
+
# https://github.com/DataDog/datadog-agent/blob/6.14.1/pkg/trace/api/api.go#L46
|
42
|
+
#
|
43
|
+
# We set the value to a conservative 5 MiB, in case network speed is slow.
|
44
|
+
DEFAULT_MAX_PAYLOAD_SIZE = 5 * 1024 * 1024
|
45
|
+
|
46
|
+
attr_reader :encoder, :max_size
|
47
|
+
|
48
|
+
#
|
49
|
+
# Single traces larger than +max_size+ will be discarded.
|
50
|
+
#
|
51
|
+
# @param encoder [Datadog::Core::Encoding::Encoder]
|
52
|
+
# @param max_size [String] maximum acceptable payload size
|
53
|
+
def initialize(encoder, max_size: DEFAULT_MAX_PAYLOAD_SIZE)
|
54
|
+
@encoder = encoder
|
55
|
+
@max_size = max_size
|
56
|
+
end
|
57
|
+
|
58
|
+
# Encodes a list of traces in chunks.
|
59
|
+
# Before serializing, all traces are normalized. Trace nesting is not changed.
|
60
|
+
#
|
61
|
+
# @param traces [Enumerable<Trace>] list of traces
|
62
|
+
# @return [Enumerable[Array[Bytes,Integer]]] list of encoded chunks: each containing a byte array and
|
63
|
+
# number of traces
|
64
|
+
def encode_in_chunks(traces)
|
65
|
+
encoded_traces = if traces.respond_to?(:filter_map)
|
66
|
+
# DEV Supported since Ruby 2.7, saves an intermediate object creation
|
67
|
+
traces.filter_map { |t| encode_one(t) }
|
68
|
+
else
|
69
|
+
traces.map { |t| encode_one(t) }.reject(&:nil?)
|
70
|
+
end
|
71
|
+
|
72
|
+
Datadog::Core::Chunker.chunk_by_size(encoded_traces, max_size).map do |chunk|
|
73
|
+
[encoder.join(chunk), chunk.size]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def encode_one(trace)
|
80
|
+
encoded = Encoder.encode_trace(encoder, trace)
|
81
|
+
|
82
|
+
if encoded.size > max_size
|
83
|
+
# This single trace is too large, we can't flush it
|
84
|
+
Datadog.logger.debug { "Dropping trace. Payload too large: '#{trace.inspect}'" }
|
85
|
+
Datadog.health_metrics.transport_trace_too_large(1)
|
86
|
+
|
87
|
+
return nil
|
88
|
+
end
|
89
|
+
|
90
|
+
encoded
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Encodes traces using {Datadog::Core::Encoding::Encoder} instances.
|
95
|
+
module Encoder
|
96
|
+
module_function
|
97
|
+
|
98
|
+
def encode_trace(encoder, trace)
|
99
|
+
# Format the trace for transport
|
100
|
+
TraceFormatter.format!(trace)
|
101
|
+
|
102
|
+
# Make the trace serializable
|
103
|
+
serializable_trace = SerializableTrace.new(trace)
|
104
|
+
|
105
|
+
Datadog.logger.debug { "Flushing trace: #{JSON.dump(serializable_trace)}" }
|
106
|
+
|
107
|
+
# Encode the trace
|
108
|
+
encoder.encode(serializable_trace)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Sends traces based on transport API configuration.
|
113
|
+
#
|
114
|
+
# This class initializes the HTTP client, breaks down large
|
115
|
+
# batches of traces into smaller chunks and handles
|
116
|
+
# API version downgrade handshake.
|
117
|
+
class Transport
|
118
|
+
attr_reader :client, :apis, :default_api, :current_api_id
|
119
|
+
|
120
|
+
def initialize(apis, default_api)
|
121
|
+
@apis = apis
|
122
|
+
@default_api = default_api
|
123
|
+
|
124
|
+
change_api!(default_api)
|
125
|
+
end
|
126
|
+
|
127
|
+
def send_traces(traces)
|
128
|
+
encoder = current_api.encoder
|
129
|
+
chunker = Datadog::Tracing::Transport::Traces::Chunker.new(encoder)
|
130
|
+
|
131
|
+
responses = chunker.encode_in_chunks(traces.lazy).map do |encoded_traces, trace_count|
|
132
|
+
request = Request.new(EncodedParcel.new(encoded_traces, trace_count))
|
133
|
+
|
134
|
+
client.send_traces_payload(request).tap do |response|
|
135
|
+
if downgrade?(response)
|
136
|
+
downgrade!
|
137
|
+
return send_traces(traces)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Force resolution of lazy enumerator.
|
143
|
+
#
|
144
|
+
# The "correct" method to call here would be `#force`,
|
145
|
+
# as this method was created to force the eager loading
|
146
|
+
# of a lazy enumerator.
|
147
|
+
#
|
148
|
+
# Unfortunately, JRuby < 9.2.9.0 erroneously eagerly loads
|
149
|
+
# the lazy Enumerator during intermediate steps.
|
150
|
+
# This forces us to use `#to_a`, as this method works for both
|
151
|
+
# lazy and regular Enumerators.
|
152
|
+
# Using `#to_a` can mask the fact that we expect a lazy
|
153
|
+
# Enumerator.
|
154
|
+
responses = responses.to_a
|
155
|
+
|
156
|
+
Datadog.health_metrics.transport_chunked(responses.size)
|
157
|
+
|
158
|
+
responses
|
159
|
+
end
|
160
|
+
|
161
|
+
def stats
|
162
|
+
@client.stats
|
163
|
+
end
|
164
|
+
|
165
|
+
def current_api
|
166
|
+
apis[@current_api_id]
|
167
|
+
end
|
168
|
+
|
169
|
+
private
|
170
|
+
|
171
|
+
def downgrade?(response)
|
172
|
+
return false unless apis.fallbacks.key?(@current_api_id)
|
173
|
+
|
174
|
+
response.not_found? || response.unsupported?
|
175
|
+
end
|
176
|
+
|
177
|
+
def downgrade!
|
178
|
+
downgrade_api_id = apis.fallbacks[@current_api_id]
|
179
|
+
raise NoDowngradeAvailableError, @current_api_id if downgrade_api_id.nil?
|
180
|
+
|
181
|
+
change_api!(downgrade_api_id)
|
182
|
+
end
|
183
|
+
|
184
|
+
def change_api!(api_id)
|
185
|
+
raise UnknownApiVersionError, api_id unless apis.key?(api_id)
|
186
|
+
|
187
|
+
@current_api_id = api_id
|
188
|
+
@client = HTTP::Client.new(current_api)
|
189
|
+
end
|
190
|
+
|
191
|
+
# Raised when configured with an unknown API version
|
192
|
+
class UnknownApiVersionError < StandardError
|
193
|
+
attr_reader :version
|
194
|
+
|
195
|
+
def initialize(version)
|
196
|
+
super
|
197
|
+
|
198
|
+
@version = version
|
199
|
+
end
|
200
|
+
|
201
|
+
def message
|
202
|
+
"No matching transport API for version #{version}!"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
# Raised when configured with an unknown API version
|
207
|
+
class NoDowngradeAvailableError < StandardError
|
208
|
+
attr_reader :version
|
209
|
+
|
210
|
+
def initialize(version)
|
211
|
+
super
|
212
|
+
|
213
|
+
@version = version
|
214
|
+
end
|
215
|
+
|
216
|
+
def message
|
217
|
+
"No downgrade from transport API version #{version} is available!"
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
@@ -7,7 +7,7 @@ require_relative '../buffer'
|
|
7
7
|
require_relative '../pipeline'
|
8
8
|
require_relative '../event'
|
9
9
|
|
10
|
-
require_relative '
|
10
|
+
require_relative '../transport/http'
|
11
11
|
|
12
12
|
module Datadog
|
13
13
|
module Tracing
|
@@ -24,7 +24,7 @@ module Datadog
|
|
24
24
|
transport_options[:agent_settings] = options[:agent_settings] if options.key?(:agent_settings)
|
25
25
|
|
26
26
|
@transport = options.fetch(:transport) do
|
27
|
-
Transport::HTTP.default(**transport_options)
|
27
|
+
Datadog::Tracing::Transport::HTTP.default(**transport_options)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
# rubocop:enable Lint/MissingSuper
|
@@ -104,6 +104,8 @@ module Datadog
|
|
104
104
|
# Workers::Queue settings
|
105
105
|
@buffer_size = options.fetch(:buffer_size, DEFAULT_BUFFER_MAX_SIZE)
|
106
106
|
self.buffer = TraceBuffer.new(@buffer_size)
|
107
|
+
|
108
|
+
@shutdown_timeout = options.fetch(:shutdown_timeout, Core::Workers::Polling::DEFAULT_SHUTDOWN_TIMEOUT)
|
107
109
|
end
|
108
110
|
|
109
111
|
# NOTE: #perform is wrapped by other modules:
|
@@ -119,7 +121,7 @@ module Datadog
|
|
119
121
|
nil
|
120
122
|
end
|
121
123
|
|
122
|
-
def stop(
|
124
|
+
def stop(force_stop = false, timeout = @shutdown_timeout)
|
123
125
|
buffer.close if running?
|
124
126
|
super
|
125
127
|
end
|
@@ -14,7 +14,7 @@ module Datadog
|
|
14
14
|
DEFAULT_TIMEOUT = 5
|
15
15
|
BACK_OFF_RATIO = 1.2
|
16
16
|
BACK_OFF_MAX = 5
|
17
|
-
|
17
|
+
DEFAULT_SHUTDOWN_TIMEOUT = 1
|
18
18
|
|
19
19
|
attr_reader \
|
20
20
|
:trace_buffer
|
@@ -36,6 +36,7 @@ module Datadog
|
|
36
36
|
|
37
37
|
# Threading
|
38
38
|
@shutdown = ConditionVariable.new
|
39
|
+
@shutdown_timeout = options.fetch(:shutdown_timeout, DEFAULT_SHUTDOWN_TIMEOUT)
|
39
40
|
@mutex = Mutex.new
|
40
41
|
@worker = nil
|
41
42
|
@run = false
|
@@ -89,7 +90,7 @@ module Datadog
|
|
89
90
|
|
90
91
|
# Block until executor shutdown is complete or until timeout seconds have passed.
|
91
92
|
def join
|
92
|
-
@worker.join(
|
93
|
+
@worker.join(@shutdown_timeout)
|
93
94
|
end
|
94
95
|
|
95
96
|
# Enqueue an item in the trace internal buffer. This operation is thread-safe
|
@@ -2,7 +2,7 @@ require_relative 'event'
|
|
2
2
|
require_relative 'runtime/metrics'
|
3
3
|
require_relative 'workers'
|
4
4
|
|
5
|
-
require_relative '
|
5
|
+
require_relative 'transport/http'
|
6
6
|
|
7
7
|
module Datadog
|
8
8
|
module Tracing
|
@@ -28,6 +28,8 @@ module Datadog
|
|
28
28
|
Transport::HTTP.default(**transport_options)
|
29
29
|
end
|
30
30
|
|
31
|
+
@shutdown_timeout = options.fetch(:shutdown_timeout, Workers::AsyncTransport::DEFAULT_SHUTDOWN_TIMEOUT)
|
32
|
+
|
31
33
|
# handles the thread creation after an eventual fork
|
32
34
|
@mutex_after_fork = Mutex.new
|
33
35
|
@pid = nil
|
@@ -72,7 +74,8 @@ module Datadog
|
|
72
74
|
transport: @transport,
|
73
75
|
buffer_size: @buff_size,
|
74
76
|
on_trace: @trace_handler,
|
75
|
-
interval: @flush_interval
|
77
|
+
interval: @flush_interval,
|
78
|
+
shutdown_timeout: @shutdown_timeout
|
76
79
|
)
|
77
80
|
|
78
81
|
@worker.start
|
@@ -1,44 +1,46 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative '../../datadog/core/transport/ext'
|
4
|
+
# DEV(2.0): This file should be replaced by /datadog/core/transport/ext.rb.
|
3
5
|
module Datadog
|
4
6
|
module Transport
|
5
7
|
# @public_api
|
6
8
|
module Ext
|
7
9
|
# @public_api
|
8
10
|
module HTTP
|
9
|
-
ADAPTER =
|
10
|
-
DEFAULT_HOST =
|
11
|
-
DEFAULT_PORT =
|
11
|
+
ADAPTER = Datadog::Core::Transport::Ext::HTTP::ADAPTER
|
12
|
+
DEFAULT_HOST = Datadog::Core::Transport::Ext::HTTP::DEFAULT_HOST
|
13
|
+
DEFAULT_PORT = Datadog::Core::Transport::Ext::HTTP::DEFAULT_PORT
|
12
14
|
|
13
|
-
HEADER_CONTAINER_ID =
|
14
|
-
HEADER_DD_API_KEY =
|
15
|
+
HEADER_CONTAINER_ID = Datadog::Core::Transport::Ext::HTTP::HEADER_CONTAINER_ID
|
16
|
+
HEADER_DD_API_KEY = Datadog::Core::Transport::Ext::HTTP::HEADER_DD_API_KEY
|
15
17
|
# Tells agent that `_dd.top_level` metrics have been set by the tracer.
|
16
18
|
# The agent will not calculate top-level spans but instead trust the tracer tagging.
|
17
19
|
#
|
18
20
|
# This prevents partially flushed traces being mistakenly marked as top-level.
|
19
21
|
#
|
20
22
|
# Setting this header to any non-empty value enables this feature.
|
21
|
-
HEADER_CLIENT_COMPUTED_TOP_LEVEL =
|
22
|
-
HEADER_META_LANG =
|
23
|
-
HEADER_META_LANG_VERSION =
|
24
|
-
HEADER_META_LANG_INTERPRETER =
|
25
|
-
HEADER_META_TRACER_VERSION =
|
23
|
+
HEADER_CLIENT_COMPUTED_TOP_LEVEL = Datadog::Core::Transport::Ext::HTTP::HEADER_CLIENT_COMPUTED_TOP_LEVEL
|
24
|
+
HEADER_META_LANG = Datadog::Core::Transport::Ext::HTTP::HEADER_META_LANG
|
25
|
+
HEADER_META_LANG_VERSION = Datadog::Core::Transport::Ext::HTTP::HEADER_META_LANG_VERSION
|
26
|
+
HEADER_META_LANG_INTERPRETER = Datadog::Core::Transport::Ext::HTTP::HEADER_META_LANG_INTERPRETER
|
27
|
+
HEADER_META_TRACER_VERSION = Datadog::Core::Transport::Ext::HTTP::HEADER_META_TRACER_VERSION
|
26
28
|
|
27
29
|
# Header that prevents the Net::HTTP integration from tracing internal trace requests.
|
28
30
|
# Set it to any value to skip tracing.
|
29
|
-
HEADER_DD_INTERNAL_UNTRACED_REQUEST =
|
31
|
+
HEADER_DD_INTERNAL_UNTRACED_REQUEST = Datadog::Core::Transport::Ext::HTTP::HEADER_DD_INTERNAL_UNTRACED_REQUEST
|
30
32
|
end
|
31
33
|
|
32
34
|
# @public_api
|
33
35
|
module Test
|
34
|
-
ADAPTER =
|
36
|
+
ADAPTER = Datadog::Core::Transport::Ext::Test::ADAPTER
|
35
37
|
end
|
36
38
|
|
37
39
|
# @public_api
|
38
40
|
module UnixSocket
|
39
|
-
ADAPTER =
|
40
|
-
DEFAULT_PATH =
|
41
|
-
DEFAULT_TIMEOUT_SECONDS =
|
41
|
+
ADAPTER = Datadog::Core::Transport::Ext::UnixSocket::ADAPTER
|
42
|
+
DEFAULT_PATH = Datadog::Core::Transport::Ext::UnixSocket::DEFAULT_PATH
|
43
|
+
DEFAULT_TIMEOUT_SECONDS = Datadog::Core::Transport::Ext::UnixSocket::DEFAULT_TIMEOUT_SECONDS
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
data/lib/ddtrace/version.rb
CHANGED
data/lib/ddtrace.rb
CHANGED