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,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../transport/traces'
|
4
|
+
require_relative '../../../core/transport/parcel'
|
5
|
+
require_relative 'response'
|
6
|
+
require_relative 'client'
|
7
|
+
|
8
|
+
module Datadog
|
9
|
+
module Tracing
|
10
|
+
module Transport
|
11
|
+
module IO
|
12
|
+
# IO transport behavior for traces
|
13
|
+
module Traces
|
14
|
+
# Response from HTTP transport for traces
|
15
|
+
class Response < IO::Response
|
16
|
+
include Transport::Traces::Response
|
17
|
+
|
18
|
+
def initialize(result, trace_count = 1)
|
19
|
+
super(result)
|
20
|
+
@trace_count = trace_count
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Extensions for HTTP client
|
25
|
+
module Client
|
26
|
+
def send_traces(traces)
|
27
|
+
# Build a request
|
28
|
+
req = Transport::Traces::Request.new(Parcel.new(traces))
|
29
|
+
|
30
|
+
[send_request(req) do |out, request|
|
31
|
+
# Encode trace data
|
32
|
+
data = encode_data(encoder, request)
|
33
|
+
|
34
|
+
# Write to IO
|
35
|
+
result = if block_given?
|
36
|
+
yield(out, data)
|
37
|
+
else
|
38
|
+
write_data(out, data)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Generate response
|
42
|
+
Traces::Response.new(result)
|
43
|
+
end]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Encoder for IO-specific trace encoding
|
48
|
+
# API compliant when used with {JSONEncoder}.
|
49
|
+
module Encoder
|
50
|
+
ENCODED_IDS = [
|
51
|
+
:trace_id,
|
52
|
+
:span_id,
|
53
|
+
:parent_id
|
54
|
+
].freeze
|
55
|
+
|
56
|
+
# Encodes a list of traces
|
57
|
+
def encode_traces(encoder, traces)
|
58
|
+
trace_hashes = traces.map do |trace|
|
59
|
+
encode_trace(trace)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Wrap traces & encode them
|
63
|
+
encoder.encode(traces: trace_hashes)
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def encode_trace(trace)
|
69
|
+
# Convert each trace to hash
|
70
|
+
trace.spans.map(&:to_hash).tap do |spans|
|
71
|
+
# Convert IDs to hexadecimal
|
72
|
+
spans.each do |span|
|
73
|
+
ENCODED_IDS.each do |id|
|
74
|
+
span[id] = span[id].to_s(16) if span.key?(id)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Transfer object for list of traces
|
82
|
+
class Parcel
|
83
|
+
include Datadog::Core::Transport::Parcel
|
84
|
+
include Encoder
|
85
|
+
|
86
|
+
def count
|
87
|
+
data.length
|
88
|
+
end
|
89
|
+
|
90
|
+
def encode_with(encoder)
|
91
|
+
encode_traces(encoder, data)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Add traces behavior to transport components
|
96
|
+
IO::Client.include(Traces::Client)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../core/encoding'
|
4
|
+
require_relative 'io/client'
|
5
|
+
require_relative 'io/traces'
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
module Tracing
|
9
|
+
module Transport
|
10
|
+
# Namespace for IO transport components
|
11
|
+
module IO
|
12
|
+
module_function
|
13
|
+
|
14
|
+
# Builds a new Transport::IO::Client
|
15
|
+
def new(out, encoder)
|
16
|
+
Client.new(out, encoder)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Builds a new Transport::IO::Client with default settings
|
20
|
+
# Pass options to override any settings.
|
21
|
+
def default(options = {})
|
22
|
+
new(
|
23
|
+
options.fetch(:out, $stdout),
|
24
|
+
options.fetch(:encoder, Core::Encoding::JSONEncoder)
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'msgpack'
|
5
|
+
require 'datadog/tracing/utils'
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
module Tracing
|
9
|
+
module Transport
|
10
|
+
# Adds serialization functions to a {Datadog::TraceSegment}
|
11
|
+
class SerializableTrace
|
12
|
+
attr_reader \
|
13
|
+
:trace
|
14
|
+
|
15
|
+
def initialize(trace)
|
16
|
+
@trace = trace
|
17
|
+
end
|
18
|
+
|
19
|
+
# MessagePack serializer interface. Making this object
|
20
|
+
# respond to `#to_msgpack` allows it to be automatically
|
21
|
+
# serialized by MessagePack.
|
22
|
+
#
|
23
|
+
# This is more efficient than doing +MessagePack.pack(span.to_hash)+
|
24
|
+
# as we don't have to create an intermediate Hash.
|
25
|
+
#
|
26
|
+
# @param packer [MessagePack::Packer] serialization buffer, can be +nil+ with JRuby
|
27
|
+
def to_msgpack(packer = nil)
|
28
|
+
# As of 1.3.3, JRuby implementation doesn't pass an existing packer
|
29
|
+
trace.spans.map { |s| SerializableSpan.new(s) }.to_msgpack(packer)
|
30
|
+
end
|
31
|
+
|
32
|
+
# JSON serializer interface.
|
33
|
+
# Used by older version of the transport.
|
34
|
+
def to_json(*args)
|
35
|
+
trace.spans.map { |s| SerializableSpan.new(s).to_hash }.to_json(*args)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Adds serialization functions to a {Datadog::Span}
|
40
|
+
class SerializableSpan
|
41
|
+
attr_reader \
|
42
|
+
:span
|
43
|
+
|
44
|
+
def initialize(span)
|
45
|
+
@span = span
|
46
|
+
@trace_id = Tracing::Utils::TraceId.to_low_order(span.trace_id)
|
47
|
+
end
|
48
|
+
|
49
|
+
# MessagePack serializer interface. Making this object
|
50
|
+
# respond to `#to_msgpack` allows it to be automatically
|
51
|
+
# serialized by MessagePack.
|
52
|
+
#
|
53
|
+
# This is more efficient than doing +MessagePack.pack(span.to_hash)+
|
54
|
+
# as we don't have to create an intermediate Hash.
|
55
|
+
#
|
56
|
+
# @param packer [MessagePack::Packer] serialization buffer, can be +nil+ with JRuby
|
57
|
+
# rubocop:disable Metrics/AbcSize
|
58
|
+
def to_msgpack(packer = nil)
|
59
|
+
packer ||= MessagePack::Packer.new
|
60
|
+
|
61
|
+
number_of_elements_to_write = 10
|
62
|
+
|
63
|
+
if span.stopped?
|
64
|
+
packer.write_map_header(number_of_elements_to_write + 2) # Set header with how many elements in the map
|
65
|
+
|
66
|
+
packer.write('start')
|
67
|
+
packer.write(time_nano(span.start_time))
|
68
|
+
|
69
|
+
packer.write('duration')
|
70
|
+
packer.write(duration_nano(span.duration))
|
71
|
+
else
|
72
|
+
packer.write_map_header(number_of_elements_to_write) # Set header with how many elements in the map
|
73
|
+
end
|
74
|
+
|
75
|
+
# DEV: We use strings as keys here, instead of symbols, as
|
76
|
+
# DEV: MessagePack will ultimately convert them to strings.
|
77
|
+
# DEV: By providing strings directly, we skip this indirection operation.
|
78
|
+
packer.write('span_id')
|
79
|
+
packer.write(span.id)
|
80
|
+
packer.write('parent_id')
|
81
|
+
packer.write(span.parent_id)
|
82
|
+
packer.write('trace_id')
|
83
|
+
packer.write(@trace_id)
|
84
|
+
packer.write('name')
|
85
|
+
packer.write(span.name)
|
86
|
+
packer.write('service')
|
87
|
+
packer.write(span.service)
|
88
|
+
packer.write('resource')
|
89
|
+
packer.write(span.resource)
|
90
|
+
packer.write('type')
|
91
|
+
packer.write(span.type)
|
92
|
+
packer.write('meta')
|
93
|
+
packer.write(span.meta)
|
94
|
+
packer.write('metrics')
|
95
|
+
packer.write(span.metrics)
|
96
|
+
packer.write('error')
|
97
|
+
packer.write(span.status)
|
98
|
+
packer
|
99
|
+
end
|
100
|
+
# rubocop:enable Metrics/AbcSize
|
101
|
+
|
102
|
+
# JSON serializer interface.
|
103
|
+
# Used by older version of the transport.
|
104
|
+
def to_json(*args)
|
105
|
+
to_hash.to_json(*args)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Used for serialization
|
109
|
+
# @return [Integer] in nanoseconds since Epoch
|
110
|
+
def time_nano(time)
|
111
|
+
time.to_i * 1000000000 + time.nsec
|
112
|
+
end
|
113
|
+
|
114
|
+
def to_hash
|
115
|
+
span.to_hash.merge(trace_id: @trace_id)
|
116
|
+
end
|
117
|
+
|
118
|
+
# Used for serialization
|
119
|
+
# @return [Integer] in nanoseconds since Epoch
|
120
|
+
def duration_nano(duration)
|
121
|
+
(duration * 1e9).to_i
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../core/metrics/metric'
|
4
|
+
require_relative '../../core/diagnostics/health'
|
5
|
+
|
6
|
+
module Datadog
|
7
|
+
module Tracing
|
8
|
+
module Transport
|
9
|
+
# Tracks statistics for transports
|
10
|
+
module Statistics
|
11
|
+
def stats
|
12
|
+
@stats ||= Counts.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def update_stats_from_response!(response)
|
16
|
+
if response.ok?
|
17
|
+
stats.success += 1
|
18
|
+
stats.consecutive_errors = 0
|
19
|
+
else
|
20
|
+
stats.client_error += 1 if response.client_error?
|
21
|
+
stats.server_error += 1 if response.server_error?
|
22
|
+
stats.internal_error += 1 if response.internal_error?
|
23
|
+
stats.consecutive_errors += 1
|
24
|
+
end
|
25
|
+
|
26
|
+
# Send health metrics
|
27
|
+
Datadog.health_metrics.send_metrics(
|
28
|
+
metrics_for_response(response).values
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def metrics_for_response(response)
|
33
|
+
{}.tap do |metrics|
|
34
|
+
metrics[:api_errors] = Core::Metrics::Metric.new(:api_errors, nil, 1) if response.internal_error?
|
35
|
+
metrics[:api_responses] = Core::Metrics::Metric.new(:api_responses, nil, 1) unless response.internal_error?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def update_stats_from_exception!(exception)
|
40
|
+
stats.internal_error += 1
|
41
|
+
stats.consecutive_errors += 1
|
42
|
+
|
43
|
+
# Send health metrics
|
44
|
+
Datadog.health_metrics.send_metrics(
|
45
|
+
metrics_for_exception(exception).values
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def metrics_for_exception(_exception)
|
50
|
+
{ api_errors: Core::Metrics::Metric.new(:api_errors, nil, 1) }
|
51
|
+
end
|
52
|
+
|
53
|
+
# Stat counts
|
54
|
+
class Counts
|
55
|
+
attr_accessor \
|
56
|
+
:success,
|
57
|
+
:client_error,
|
58
|
+
:server_error,
|
59
|
+
:internal_error,
|
60
|
+
:consecutive_errors
|
61
|
+
|
62
|
+
def initialize
|
63
|
+
reset!
|
64
|
+
end
|
65
|
+
|
66
|
+
def reset!
|
67
|
+
@success = 0
|
68
|
+
@client_error = 0
|
69
|
+
@server_error = 0
|
70
|
+
@internal_error = 0
|
71
|
+
@consecutive_errors = 0
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,209 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../core/environment/identity'
|
4
|
+
require_relative '../../core/environment/socket'
|
5
|
+
require_relative '../../core/runtime/ext'
|
6
|
+
require_relative '../metadata/ext'
|
7
|
+
require_relative '../trace_segment'
|
8
|
+
|
9
|
+
module Datadog
|
10
|
+
module Tracing
|
11
|
+
module Transport
|
12
|
+
# Prepares traces for transport
|
13
|
+
class TraceFormatter
|
14
|
+
attr_reader \
|
15
|
+
:root_span,
|
16
|
+
:trace
|
17
|
+
|
18
|
+
def self.format!(trace)
|
19
|
+
new(trace).format!
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(trace)
|
23
|
+
@trace = trace
|
24
|
+
@root_span = find_root_span(trace)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Modifies a trace so suitable for transport
|
28
|
+
def format!
|
29
|
+
return unless trace
|
30
|
+
return trace unless root_span
|
31
|
+
|
32
|
+
# Because the trace API does not support
|
33
|
+
# trace metadata, we must put our trace
|
34
|
+
# metadata on the root span. This "root span"
|
35
|
+
# is needed by the agent/API to ingest the trace.
|
36
|
+
|
37
|
+
# Apply generic trace tags. Any more specific value will be overridden
|
38
|
+
# by the subsequent calls below.
|
39
|
+
set_trace_tags!
|
40
|
+
|
41
|
+
set_resource!
|
42
|
+
|
43
|
+
tag_agent_sample_rate!
|
44
|
+
tag_hostname!
|
45
|
+
tag_lang!
|
46
|
+
tag_origin!
|
47
|
+
tag_process_id!
|
48
|
+
tag_rule_sample_rate!
|
49
|
+
tag_runtime_id!
|
50
|
+
tag_rate_limiter_rate!
|
51
|
+
tag_sample_rate!
|
52
|
+
tag_sampling_decision_maker!
|
53
|
+
tag_high_order_trace_id!
|
54
|
+
tag_sampling_priority!
|
55
|
+
tag_profiling_enabled!
|
56
|
+
|
57
|
+
trace
|
58
|
+
end
|
59
|
+
|
60
|
+
protected
|
61
|
+
|
62
|
+
def set_resource!
|
63
|
+
# If the trace resource is undefined, or the root span wasn't
|
64
|
+
# specified, don't set this. We don't want to overwrite the
|
65
|
+
# resource of a span that is in the middle of the trace.
|
66
|
+
return if trace.resource.nil? || partial?
|
67
|
+
|
68
|
+
root_span.resource = trace.resource
|
69
|
+
end
|
70
|
+
|
71
|
+
def set_trace_tags!
|
72
|
+
# If the root span wasn't specified, don't set this. We don't want to
|
73
|
+
# misset or overwrite the tags of a span that is in the middle of the
|
74
|
+
# trace.
|
75
|
+
return if partial?
|
76
|
+
|
77
|
+
root_span.set_tags(trace.send(:meta))
|
78
|
+
root_span.set_tags(trace.send(:metrics))
|
79
|
+
end
|
80
|
+
|
81
|
+
def tag_agent_sample_rate!
|
82
|
+
return unless trace.agent_sample_rate
|
83
|
+
|
84
|
+
root_span.set_tag(
|
85
|
+
Tracing::Metadata::Ext::Sampling::TAG_AGENT_RATE,
|
86
|
+
trace.agent_sample_rate
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
def tag_hostname!
|
91
|
+
return unless trace.hostname
|
92
|
+
|
93
|
+
root_span.set_tag(
|
94
|
+
Tracing::Metadata::Ext::NET::TAG_HOSTNAME,
|
95
|
+
trace.hostname
|
96
|
+
)
|
97
|
+
end
|
98
|
+
|
99
|
+
def tag_lang!
|
100
|
+
return if trace.lang.nil?
|
101
|
+
|
102
|
+
root_span.set_tag(
|
103
|
+
Core::Runtime::Ext::TAG_LANG,
|
104
|
+
trace.lang
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
def tag_origin!
|
109
|
+
return unless trace.origin
|
110
|
+
|
111
|
+
root_span.set_tag(
|
112
|
+
Tracing::Metadata::Ext::Distributed::TAG_ORIGIN,
|
113
|
+
trace.origin
|
114
|
+
)
|
115
|
+
end
|
116
|
+
|
117
|
+
def tag_process_id!
|
118
|
+
return unless trace.process_id
|
119
|
+
|
120
|
+
root_span.set_tag(Core::Runtime::Ext::TAG_PROCESS_ID, trace.process_id)
|
121
|
+
end
|
122
|
+
|
123
|
+
def tag_rate_limiter_rate!
|
124
|
+
return unless trace.rate_limiter_rate
|
125
|
+
|
126
|
+
root_span.set_tag(
|
127
|
+
Tracing::Metadata::Ext::Sampling::TAG_RATE_LIMITER_RATE,
|
128
|
+
trace.rate_limiter_rate
|
129
|
+
)
|
130
|
+
end
|
131
|
+
|
132
|
+
def tag_rule_sample_rate!
|
133
|
+
return unless trace.rule_sample_rate
|
134
|
+
|
135
|
+
root_span.set_tag(
|
136
|
+
Tracing::Metadata::Ext::Sampling::TAG_RULE_SAMPLE_RATE,
|
137
|
+
trace.rule_sample_rate
|
138
|
+
)
|
139
|
+
end
|
140
|
+
|
141
|
+
def tag_runtime_id!
|
142
|
+
return unless trace.runtime_id
|
143
|
+
|
144
|
+
root_span.set_tag(
|
145
|
+
Core::Runtime::Ext::TAG_ID,
|
146
|
+
trace.runtime_id
|
147
|
+
)
|
148
|
+
end
|
149
|
+
|
150
|
+
def tag_sample_rate!
|
151
|
+
return unless trace.sample_rate
|
152
|
+
|
153
|
+
root_span.set_tag(
|
154
|
+
Tracing::Metadata::Ext::Sampling::TAG_SAMPLE_RATE,
|
155
|
+
trace.sample_rate
|
156
|
+
)
|
157
|
+
end
|
158
|
+
|
159
|
+
def tag_sampling_decision_maker!
|
160
|
+
return unless (decision = trace.sampling_decision_maker)
|
161
|
+
|
162
|
+
root_span.set_tag(Tracing::Metadata::Ext::Distributed::TAG_DECISION_MAKER, decision)
|
163
|
+
end
|
164
|
+
|
165
|
+
def tag_sampling_priority!
|
166
|
+
return unless trace.sampling_priority
|
167
|
+
|
168
|
+
root_span.set_metric(
|
169
|
+
Tracing::Metadata::Ext::Distributed::TAG_SAMPLING_PRIORITY,
|
170
|
+
trace.sampling_priority
|
171
|
+
)
|
172
|
+
end
|
173
|
+
|
174
|
+
def tag_high_order_trace_id!
|
175
|
+
return unless (high_order_tid = trace.high_order_tid)
|
176
|
+
|
177
|
+
root_span.set_tag(Tracing::Metadata::Ext::Distributed::TAG_TID, high_order_tid)
|
178
|
+
end
|
179
|
+
|
180
|
+
def tag_profiling_enabled!
|
181
|
+
return if trace.profiling_enabled.nil?
|
182
|
+
|
183
|
+
root_span.set_tag(
|
184
|
+
Tracing::Metadata::Ext::TAG_PROFILING_ENABLED, trace.profiling_enabled ? 1 : 0
|
185
|
+
)
|
186
|
+
end
|
187
|
+
|
188
|
+
private
|
189
|
+
|
190
|
+
def partial?
|
191
|
+
!@found_root_span
|
192
|
+
end
|
193
|
+
|
194
|
+
def find_root_span(trace)
|
195
|
+
# TODO: Should we memoize this?
|
196
|
+
# Would be safe, but `spans` is mutable, so if
|
197
|
+
# the root span were removed, it would be a stale reference.
|
198
|
+
# Figure out a better way to deal with this.
|
199
|
+
root_span_id = trace.send(:root_span_id)
|
200
|
+
root_span = trace.spans.find { |s| s.id == root_span_id } if root_span_id
|
201
|
+
@found_root_span = !root_span.nil?
|
202
|
+
|
203
|
+
# when root span is not found, fall back to last span (partial flush)
|
204
|
+
root_span || trace.spans.last
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|