datadog 2.12.2 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +36 -1
- data/ext/datadog_profiling_native_extension/collectors_thread_context.c +14 -13
- data/lib/datadog/appsec/actions_handler/serializable_backtrace.rb +89 -0
- data/lib/datadog/appsec/actions_handler.rb +22 -1
- data/lib/datadog/appsec/anonymizer.rb +16 -0
- data/lib/datadog/appsec/configuration/settings.rb +62 -10
- data/lib/datadog/appsec/contrib/auto_instrument.rb +1 -1
- data/lib/datadog/appsec/contrib/devise/configuration.rb +7 -31
- data/lib/datadog/appsec/contrib/devise/data_extractor.rb +79 -0
- data/lib/datadog/appsec/contrib/devise/ext.rb +21 -0
- data/lib/datadog/appsec/contrib/devise/integration.rb +0 -1
- data/lib/datadog/appsec/contrib/devise/patcher.rb +36 -23
- data/lib/datadog/appsec/contrib/devise/patches/signin_tracking_patch.rb +102 -0
- data/lib/datadog/appsec/contrib/devise/patches/signup_tracking_patch.rb +69 -0
- data/lib/datadog/appsec/contrib/devise/{patcher/rememberable_patch.rb → patches/skip_signin_tracking_patch.rb} +2 -2
- data/lib/datadog/appsec/contrib/devise/tracking_middleware.rb +93 -0
- data/lib/datadog/appsec/contrib/rack/ext.rb +14 -0
- data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +10 -3
- data/lib/datadog/appsec/contrib/rack/request_middleware.rb +0 -2
- data/lib/datadog/appsec/event.rb +1 -1
- data/lib/datadog/appsec/ext.rb +4 -2
- data/lib/datadog/appsec/instrumentation/gateway/argument.rb +4 -2
- data/lib/datadog/appsec/monitor/gateway/watcher.rb +8 -3
- data/lib/datadog/appsec/security_engine/runner.rb +2 -2
- data/lib/datadog/appsec/utils.rb +0 -2
- data/lib/datadog/core/configuration/components.rb +2 -1
- data/lib/datadog/core/configuration/ext.rb +4 -0
- data/lib/datadog/core/configuration/options.rb +2 -2
- data/lib/datadog/core/configuration/settings.rb +53 -30
- data/lib/datadog/core/environment/agent_info.rb +4 -3
- data/lib/datadog/core/remote/component.rb +3 -6
- data/lib/datadog/core/remote/configuration/repository.rb +2 -1
- data/lib/datadog/core/remote/negotiation.rb +9 -9
- data/lib/datadog/core/remote/transport/config.rb +4 -3
- data/lib/datadog/core/remote/transport/http/client.rb +4 -3
- data/lib/datadog/core/remote/transport/http/config.rb +6 -32
- data/lib/datadog/core/remote/transport/http/negotiation.rb +6 -32
- data/lib/datadog/core/remote/transport/http.rb +22 -57
- data/lib/datadog/core/remote/transport/negotiation.rb +4 -3
- data/lib/datadog/core/runtime/metrics.rb +8 -1
- data/lib/datadog/core/telemetry/http/adapters/net.rb +1 -1
- data/lib/datadog/core/transport/http/api/instance.rb +17 -0
- data/lib/datadog/core/transport/http/api/spec.rb +17 -0
- data/lib/datadog/core/transport/http/builder.rb +5 -3
- data/lib/datadog/core/transport/http.rb +39 -2
- data/lib/datadog/di/component.rb +0 -2
- data/lib/datadog/di/probe_notifier_worker.rb +16 -16
- data/lib/datadog/di/transport/diagnostics.rb +4 -3
- data/lib/datadog/di/transport/http/api.rb +2 -12
- data/lib/datadog/di/transport/http/client.rb +4 -3
- data/lib/datadog/di/transport/http/diagnostics.rb +7 -33
- data/lib/datadog/di/transport/http/input.rb +7 -33
- data/lib/datadog/di/transport/http.rb +14 -56
- data/lib/datadog/di/transport/input.rb +4 -3
- data/lib/datadog/di/utils.rb +5 -0
- data/lib/datadog/kit/appsec/events.rb +9 -0
- data/lib/datadog/kit/identity.rb +5 -1
- data/lib/datadog/opentelemetry/api/baggage.rb +90 -0
- data/lib/datadog/opentelemetry/api/baggage.rbs +26 -0
- data/lib/datadog/opentelemetry/api/context.rb +16 -2
- data/lib/datadog/opentelemetry/sdk/trace/span.rb +1 -1
- data/lib/datadog/opentelemetry.rb +2 -1
- data/lib/datadog/profiling/collectors/thread_context.rb +1 -1
- data/lib/datadog/profiling.rb +5 -2
- data/lib/datadog/tracing/component.rb +15 -12
- data/lib/datadog/tracing/configuration/ext.rb +7 -1
- data/lib/datadog/tracing/configuration/settings.rb +18 -2
- data/lib/datadog/tracing/context_provider.rb +1 -1
- data/lib/datadog/tracing/contrib/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +4 -5
- data/lib/datadog/tracing/contrib/excon/middleware.rb +5 -3
- data/lib/datadog/tracing/contrib/faraday/middleware.rb +5 -3
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +7 -1
- data/lib/datadog/tracing/contrib/grpc/distributed/propagation.rb +3 -0
- data/lib/datadog/tracing/contrib/http/circuit_breaker.rb +0 -15
- data/lib/datadog/tracing/contrib/http/distributed/propagation.rb +4 -1
- data/lib/datadog/tracing/contrib/http/instrumentation.rb +5 -5
- data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +5 -11
- data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +6 -10
- data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +5 -3
- data/lib/datadog/tracing/contrib/sidekiq/client_tracer.rb +6 -1
- data/lib/datadog/tracing/contrib/sidekiq/distributed/propagation.rb +3 -0
- data/lib/datadog/tracing/correlation.rb +9 -2
- data/lib/datadog/tracing/distributed/baggage.rb +131 -0
- data/lib/datadog/tracing/distributed/datadog.rb +2 -0
- data/lib/datadog/tracing/distributed/propagation.rb +25 -4
- data/lib/datadog/tracing/distributed/propagation_policy.rb +42 -0
- data/lib/datadog/tracing/metadata/ext.rb +5 -0
- data/lib/datadog/tracing/sampling/span/rule.rb +0 -1
- data/lib/datadog/tracing/span_operation.rb +2 -1
- data/lib/datadog/tracing/sync_writer.rb +1 -2
- data/lib/datadog/tracing/trace_digest.rb +9 -2
- data/lib/datadog/tracing/trace_operation.rb +29 -17
- data/lib/datadog/tracing/trace_segment.rb +6 -4
- data/lib/datadog/tracing/tracer.rb +38 -2
- data/lib/datadog/tracing/transport/http/api.rb +2 -10
- data/lib/datadog/tracing/transport/http/client.rb +5 -4
- data/lib/datadog/tracing/transport/http/traces.rb +13 -41
- data/lib/datadog/tracing/transport/http.rb +11 -44
- data/lib/datadog/tracing/transport/trace_formatter.rb +7 -0
- data/lib/datadog/tracing/transport/traces.rb +21 -9
- data/lib/datadog/tracing/workers/trace_writer.rb +2 -6
- data/lib/datadog/tracing/writer.rb +2 -6
- data/lib/datadog/tracing.rb +16 -3
- data/lib/datadog/version.rb +2 -2
- metadata +17 -13
- data/lib/datadog/appsec/contrib/devise/event.rb +0 -54
- data/lib/datadog/appsec/contrib/devise/patcher/authenticatable_patch.rb +0 -72
- data/lib/datadog/appsec/contrib/devise/patcher/registration_controller_patch.rb +0 -47
- data/lib/datadog/appsec/contrib/devise/resource.rb +0 -35
- data/lib/datadog/appsec/contrib/devise/tracking.rb +0 -57
- data/lib/datadog/appsec/utils/trace_operation.rb +0 -15
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative '../../../core/transport/http/api/instance'
|
4
|
+
require_relative '../../../core/transport/http/api/spec'
|
3
5
|
require_relative 'client'
|
4
6
|
|
5
7
|
module Datadog
|
@@ -16,52 +18,24 @@ module Datadog
|
|
16
18
|
end
|
17
19
|
|
18
20
|
module API
|
19
|
-
|
21
|
+
class Instance < Core::Transport::HTTP::API::Instance
|
20
22
|
def send_diagnostics(env)
|
21
|
-
raise
|
23
|
+
raise Core::Transport::HTTP::API::Instance::EndpointNotSupportedError.new('diagnostics', self) unless spec.is_a?(Diagnostics::API::Spec)
|
22
24
|
|
23
25
|
spec.send_diagnostics(env) do |request_env|
|
24
26
|
call(request_env)
|
25
27
|
end
|
26
28
|
end
|
27
|
-
|
28
|
-
class DiagnosticsNotSupportedError < StandardError
|
29
|
-
attr_reader :spec
|
30
|
-
|
31
|
-
def initialize(spec)
|
32
|
-
super
|
33
|
-
|
34
|
-
@spec = spec
|
35
|
-
end
|
36
|
-
|
37
|
-
def message
|
38
|
-
'Diagnostics not supported for this API!'
|
39
|
-
end
|
40
|
-
end
|
41
29
|
end
|
42
30
|
|
43
|
-
|
31
|
+
class Spec < Core::Transport::HTTP::API::Spec
|
44
32
|
attr_accessor :diagnostics
|
45
33
|
|
46
34
|
def send_diagnostics(env, &block)
|
47
|
-
raise
|
35
|
+
raise Core::Transport::HTTP::API::Spec::EndpointNotDefinedError.new('diagnostics', self) if diagnostics.nil?
|
48
36
|
|
49
37
|
diagnostics.call(env, &block)
|
50
38
|
end
|
51
|
-
|
52
|
-
class NoDiagnosticsEndpointDefinedError < StandardError
|
53
|
-
attr_reader :spec
|
54
|
-
|
55
|
-
def initialize(spec)
|
56
|
-
super
|
57
|
-
|
58
|
-
@spec = spec
|
59
|
-
end
|
60
|
-
|
61
|
-
def message
|
62
|
-
'No diagnostics endpoint is defined for API specification!'
|
63
|
-
end
|
64
|
-
end
|
65
39
|
end
|
66
40
|
|
67
41
|
# Endpoint for negotiation
|
@@ -79,7 +53,7 @@ module Datadog
|
|
79
53
|
)
|
80
54
|
env.form = {'event' => event_payload}
|
81
55
|
|
82
|
-
super
|
56
|
+
super
|
83
57
|
end
|
84
58
|
end
|
85
59
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative '../../../core/transport/http/api/instance'
|
4
|
+
require_relative '../../../core/transport/http/api/spec'
|
3
5
|
require_relative 'client'
|
4
6
|
|
5
7
|
module Datadog
|
@@ -16,52 +18,24 @@ module Datadog
|
|
16
18
|
end
|
17
19
|
|
18
20
|
module API
|
19
|
-
|
21
|
+
class Instance < Core::Transport::HTTP::API::Instance
|
20
22
|
def send_input(env)
|
21
|
-
raise
|
23
|
+
raise Core::Transport::HTTP::API::Instance::EndpointNotSupportedError.new('input', self) unless spec.is_a?(Input::API::Spec)
|
22
24
|
|
23
25
|
spec.send_input(env) do |request_env|
|
24
26
|
call(request_env)
|
25
27
|
end
|
26
28
|
end
|
27
|
-
|
28
|
-
class InputNotSupportedError < StandardError
|
29
|
-
attr_reader :spec
|
30
|
-
|
31
|
-
def initialize(spec)
|
32
|
-
super
|
33
|
-
|
34
|
-
@spec = spec
|
35
|
-
end
|
36
|
-
|
37
|
-
def message
|
38
|
-
'Input not supported for this API!'
|
39
|
-
end
|
40
|
-
end
|
41
29
|
end
|
42
30
|
|
43
|
-
|
31
|
+
class Spec < Core::Transport::HTTP::API::Spec
|
44
32
|
attr_accessor :input
|
45
33
|
|
46
34
|
def send_input(env, &block)
|
47
|
-
raise
|
35
|
+
raise Core::Transport::HTTP::API::Spec::EndpointNotDefinedError.new('input', self) if input.nil?
|
48
36
|
|
49
37
|
input.call(env, &block)
|
50
38
|
end
|
51
|
-
|
52
|
-
class NoInputEndpointDefinedError < StandardError
|
53
|
-
attr_reader :spec
|
54
|
-
|
55
|
-
def initialize(spec)
|
56
|
-
super
|
57
|
-
|
58
|
-
@spec = spec
|
59
|
-
end
|
60
|
-
|
61
|
-
def message
|
62
|
-
'No input endpoint is defined for API specification!'
|
63
|
-
end
|
64
|
-
end
|
65
39
|
end
|
66
40
|
|
67
41
|
# Endpoint for negotiation
|
@@ -81,7 +55,7 @@ module Datadog
|
|
81
55
|
env.headers[HEADER_CONTENT_TYPE] = encoder.content_type
|
82
56
|
env.body = env.request.parcel.data
|
83
57
|
|
84
|
-
super
|
58
|
+
super
|
85
59
|
end
|
86
60
|
end
|
87
61
|
end
|
@@ -18,86 +18,44 @@ module Datadog
|
|
18
18
|
module HTTP
|
19
19
|
module_function
|
20
20
|
|
21
|
-
# Builds a new Transport::HTTP::Client
|
22
|
-
def new(klass, &block)
|
23
|
-
Core::Transport::HTTP.build(
|
24
|
-
api_instance_class: API::Instance, &block
|
25
|
-
).to_transport(klass)
|
26
|
-
end
|
27
|
-
|
28
21
|
# Builds a new Transport::HTTP::Client with default settings
|
29
22
|
# Pass a block to override any settings.
|
30
23
|
def diagnostics(
|
31
24
|
agent_settings:,
|
32
|
-
|
25
|
+
logger:,
|
26
|
+
api_version: nil,
|
27
|
+
headers: nil
|
33
28
|
)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
29
|
+
Core::Transport::HTTP.build(api_instance_class: Diagnostics::API::Instance,
|
30
|
+
logger: logger,
|
31
|
+
agent_settings: agent_settings, api_version: api_version, headers: headers) do |transport|
|
38
32
|
apis = API.defaults
|
39
33
|
|
40
34
|
transport.api API::DIAGNOSTICS, apis[API::DIAGNOSTICS]
|
41
35
|
|
42
|
-
# Apply any settings given by options
|
43
|
-
unless options.empty?
|
44
|
-
transport.default_api = options[:api_version] if options.key?(:api_version)
|
45
|
-
transport.headers options[:headers] if options.key?(:headers)
|
46
|
-
end
|
47
|
-
|
48
36
|
# Call block to apply any customization, if provided
|
49
37
|
yield(transport) if block_given?
|
50
|
-
end
|
38
|
+
end.to_transport(DI::Transport::Diagnostics::Transport)
|
51
39
|
end
|
52
40
|
|
53
41
|
# Builds a new Transport::HTTP::Client with default settings
|
54
42
|
# Pass a block to override any settings.
|
55
43
|
def input(
|
56
44
|
agent_settings:,
|
57
|
-
|
45
|
+
logger:,
|
46
|
+
api_version: nil,
|
47
|
+
headers: nil
|
58
48
|
)
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
49
|
+
Core::Transport::HTTP.build(api_instance_class: Input::API::Instance,
|
50
|
+
logger: logger,
|
51
|
+
agent_settings: agent_settings, api_version: api_version, headers: headers) do |transport|
|
63
52
|
apis = API.defaults
|
64
53
|
|
65
54
|
transport.api API::INPUT, apis[API::INPUT]
|
66
55
|
|
67
|
-
# Apply any settings given by options
|
68
|
-
unless options.empty?
|
69
|
-
transport.default_api = options[:api_version] if options.key?(:api_version)
|
70
|
-
transport.headers options[:headers] if options.key?(:headers)
|
71
|
-
end
|
72
|
-
|
73
56
|
# Call block to apply any customization, if provided
|
74
57
|
yield(transport) if block_given?
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def default_headers
|
79
|
-
{
|
80
|
-
Datadog::Core::Transport::Ext::HTTP::HEADER_CLIENT_COMPUTED_TOP_LEVEL => '1',
|
81
|
-
Datadog::Core::Transport::Ext::HTTP::HEADER_META_LANG => Datadog::Core::Environment::Ext::LANG,
|
82
|
-
Datadog::Core::Transport::Ext::HTTP::HEADER_META_LANG_VERSION => Datadog::Core::Environment::Ext::LANG_VERSION,
|
83
|
-
Datadog::Core::Transport::Ext::HTTP::HEADER_META_LANG_INTERPRETER =>
|
84
|
-
Datadog::Core::Environment::Ext::LANG_INTERPRETER,
|
85
|
-
Datadog::Core::Transport::Ext::HTTP::HEADER_META_LANG_INTERPRETER_VENDOR => Core::Environment::Ext::LANG_ENGINE,
|
86
|
-
Datadog::Core::Transport::Ext::HTTP::HEADER_META_TRACER_VERSION =>
|
87
|
-
Datadog::Core::Environment::Ext::GEM_DATADOG_VERSION
|
88
|
-
}.tap do |headers|
|
89
|
-
# Add container ID, if present.
|
90
|
-
container_id = Datadog::Core::Environment::Container.container_id
|
91
|
-
headers[Datadog::Core::Transport::Ext::HTTP::HEADER_CONTAINER_ID] = container_id unless container_id.nil?
|
92
|
-
# Pretend that stats computation are already done by the client
|
93
|
-
if Datadog.configuration.appsec.standalone.enabled
|
94
|
-
headers[Datadog::Core::Transport::Ext::HTTP::HEADER_CLIENT_COMPUTED_STATS] = 'yes'
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def default_adapter
|
100
|
-
Datadog::Core::Configuration::Ext::Agent::HTTP::ADAPTER
|
58
|
+
end.to_transport(DI::Transport::Input::Transport)
|
101
59
|
end
|
102
60
|
end
|
103
61
|
end
|
@@ -15,12 +15,13 @@ module Datadog
|
|
15
15
|
end
|
16
16
|
|
17
17
|
class Transport
|
18
|
-
attr_reader :client, :apis, :default_api, :current_api_id
|
18
|
+
attr_reader :client, :apis, :default_api, :current_api_id, :logger
|
19
19
|
|
20
|
-
def initialize(apis, default_api)
|
20
|
+
def initialize(apis, default_api, logger)
|
21
21
|
@apis = apis
|
22
|
+
@logger = logger
|
22
23
|
|
23
|
-
@client = HTTP::Client.new(current_api)
|
24
|
+
@client = HTTP::Client.new(current_api, logger)
|
24
25
|
end
|
25
26
|
|
26
27
|
def current_api
|
data/lib/datadog/di/utils.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# standard gets itself into an infinite loop over this
|
4
|
+
# rubocop:disable Layout/SpaceAfterNot
|
5
|
+
|
3
6
|
module Datadog
|
4
7
|
module DI
|
5
8
|
module Utils
|
@@ -135,3 +138,5 @@ module Datadog
|
|
135
138
|
end
|
136
139
|
end
|
137
140
|
end
|
141
|
+
|
142
|
+
# rubocop:enable Layout/SpaceAfterNot
|
@@ -30,11 +30,14 @@ module Datadog
|
|
30
30
|
set_trace_and_span_context('track_login_success', trace, span) do |active_trace, active_span|
|
31
31
|
user_options = user.dup
|
32
32
|
user_id = user_options.delete(:id)
|
33
|
+
user_login = user_options[:login] || others[:'usr.login'] || user_id
|
33
34
|
|
34
35
|
raise ArgumentError, 'missing required key: :user => { :id }' if user_id.nil?
|
35
36
|
|
37
|
+
others[:'usr.login'] = user_login
|
36
38
|
track(LOGIN_SUCCESS_EVENT, active_trace, active_span, **others)
|
37
39
|
|
40
|
+
user_options[:login] = user_login
|
38
41
|
Kit::Identity.set_user(active_trace, active_span, id: user_id, **user_options)
|
39
42
|
end
|
40
43
|
end
|
@@ -55,6 +58,7 @@ module Datadog
|
|
55
58
|
# event information to attach to the trace.
|
56
59
|
def track_login_failure(trace = nil, span = nil, user_exists:, user_id: nil, **others)
|
57
60
|
set_trace_and_span_context('track_login_failure', trace, span) do |active_trace, active_span|
|
61
|
+
others[:'usr.login'] = user_id if user_id && !others.key?(:'usr.login')
|
58
62
|
track(LOGIN_FAILURE_EVENT, active_trace, active_span, **others)
|
59
63
|
|
60
64
|
active_span.set_tag('appsec.events.users.login.failure.usr.id', user_id) if user_id
|
@@ -80,11 +84,14 @@ module Datadog
|
|
80
84
|
set_trace_and_span_context('track_signup', trace, span) do |active_trace, active_span|
|
81
85
|
user_options = user.dup
|
82
86
|
user_id = user_options.delete(:id)
|
87
|
+
user_login = user_options[:login] || others[:'usr.login'] || user_id
|
83
88
|
|
84
89
|
raise ArgumentError, 'missing required key: :user => { :id }' if user_id.nil?
|
85
90
|
|
91
|
+
others[:'usr.login'] = user_login
|
86
92
|
track(SIGNUP_EVENT, active_trace, active_span, **others)
|
87
93
|
|
94
|
+
user_options[:login] = user_login
|
88
95
|
Kit::Identity.set_user(trace, id: user_id, **user_options)
|
89
96
|
end
|
90
97
|
end
|
@@ -131,6 +138,8 @@ module Datadog
|
|
131
138
|
active_trace.keep!
|
132
139
|
end
|
133
140
|
end
|
141
|
+
|
142
|
+
::Datadog::AppSec::Instrumentation.gateway.push('appsec.events.user_lifecycle', event)
|
134
143
|
end
|
135
144
|
|
136
145
|
private
|
data/lib/datadog/kit/identity.rb
CHANGED
@@ -33,6 +33,7 @@ module Datadog
|
|
33
33
|
# @param others [Hash<Symbol, String>] Additional free-form
|
34
34
|
# user information to attach to the trace.
|
35
35
|
#
|
36
|
+
# rubocop:disable Metrics/AbcSize
|
36
37
|
# rubocop:disable Metrics/CyclomaticComplexity
|
37
38
|
# rubocop:disable Metrics/PerceivedComplexity
|
38
39
|
def set_user(
|
@@ -67,11 +68,14 @@ module Datadog
|
|
67
68
|
end
|
68
69
|
|
69
70
|
if Datadog::AppSec.active_context
|
70
|
-
user
|
71
|
+
active_span.set_tag('_dd.appsec.user.collection_mode', 'sdk')
|
72
|
+
|
73
|
+
user = ::Datadog::AppSec::Instrumentation::Gateway::User.new(id, others[:login])
|
71
74
|
::Datadog::AppSec::Instrumentation.gateway.push('identity.set_user', user)
|
72
75
|
end
|
73
76
|
end
|
74
77
|
end
|
78
|
+
# rubocop:enable Metrics/AbcSize
|
75
79
|
# rubocop:enable Metrics/PerceivedComplexity
|
76
80
|
# rubocop:enable Metrics/CyclomaticComplexity
|
77
81
|
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'trace/span'
|
4
|
+
require_relative '../../tracing/trace_operation'
|
5
|
+
require_relative '../trace'
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
module OpenTelemetry
|
9
|
+
module API
|
10
|
+
# The Baggage module provides an implementation of the OpenTelemetry Baggage API.
|
11
|
+
#
|
12
|
+
# Baggage is a set of name/value pairs describing user-defined properties that can be
|
13
|
+
# propagated through a distributed trace. This implementation follows the W3C Baggage
|
14
|
+
# specification and the OpenTelemetry Baggage API.
|
15
|
+
#
|
16
|
+
# @see https://www.w3.org/TR/baggage/
|
17
|
+
# @see https://opentelemetry.io/docs/specs/otel/baggage/api/
|
18
|
+
module Baggage
|
19
|
+
def initialize(trace: nil)
|
20
|
+
@trace = trace
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns a new context with empty baggage
|
24
|
+
#
|
25
|
+
# @param [optional Context] context Context to clear baggage from. Defaults
|
26
|
+
# to ::OpenTelemetry::Context.current
|
27
|
+
# @return [Context]
|
28
|
+
def clear(context: ::OpenTelemetry::Context.current)
|
29
|
+
context.ensure_trace.baggage.clear
|
30
|
+
context
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns the corresponding value for key
|
34
|
+
#
|
35
|
+
# @param [String] key The lookup key
|
36
|
+
# @param [optional Context] context The context from which to retrieve
|
37
|
+
# the key. Defaults to ::OpenTelemetry::Context.current
|
38
|
+
# @return [String, nil]
|
39
|
+
def value(key, context: ::OpenTelemetry::Context.current)
|
40
|
+
trace = context.ensure_trace
|
41
|
+
return nil if trace.nil?
|
42
|
+
|
43
|
+
trace.baggage && trace.baggage[key]
|
44
|
+
end
|
45
|
+
|
46
|
+
# Returns all baggage values
|
47
|
+
#
|
48
|
+
# @param [optional Context] context The context from which to retrieve
|
49
|
+
# the baggage. Defaults to ::OpenTelemetry::Context.current
|
50
|
+
# @return [Hash<String, String>]
|
51
|
+
def values(context: ::OpenTelemetry::Context.current)
|
52
|
+
trace = context.ensure_trace
|
53
|
+
return {} if trace.nil?
|
54
|
+
|
55
|
+
trace.baggage ? trace.baggage.dup : {}
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns a new context with new key-value pair
|
59
|
+
#
|
60
|
+
# @param [String] key The key to store this value under
|
61
|
+
# @param [String] value String value to be stored under key
|
62
|
+
# @param [optional String] metadata This is here to store properties
|
63
|
+
# received from other W3C Baggage implementations but is not exposed in
|
64
|
+
# OpenTelemetry. This is considered private API and not for use by
|
65
|
+
# end-users.
|
66
|
+
# @param [optional Context] context The context to update with new
|
67
|
+
# value. Defaults to ::OpenTelemetry::Context.current
|
68
|
+
# @return [Context]
|
69
|
+
def set_value(key, value, metadata: nil, context: ::OpenTelemetry::Context.current)
|
70
|
+
# Delegate to the context to set the value because an active trace is not guaranteed
|
71
|
+
# set_values handles this logic
|
72
|
+
context.set_values({ ::OpenTelemetry::Baggage.const_get(:BAGGAGE_KEY) => { key => value } })
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns a new context with value at key removed
|
76
|
+
#
|
77
|
+
# @param [String] key The key to remove
|
78
|
+
# @param [optional Context] context The context to remove baggage
|
79
|
+
# from. Defaults to ::OpenTelemetry::Context.current
|
80
|
+
# @return [Context]
|
81
|
+
def remove_value(key, context: ::OpenTelemetry::Context.current)
|
82
|
+
# Delegate to the context to remove the value because an active trace is not guaranteed
|
83
|
+
# set_values handles this logic
|
84
|
+
context.set_values({ Context::BAGGAGE_REMOVE_KEY => key })
|
85
|
+
end
|
86
|
+
::OpenTelemetry::Baggage.singleton_class.prepend(self)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module OpenTelemetry
|
5
|
+
module API
|
6
|
+
module Baggage
|
7
|
+
def initialize: (?trace: Datadog::Tracing::TraceOperation?) -> void
|
8
|
+
|
9
|
+
# Returns a new context with empty baggage
|
10
|
+
def clear: (?context: OpenTelemetry::Context) -> OpenTelemetry::Context
|
11
|
+
|
12
|
+
# Returns the corresponding value for key
|
13
|
+
def value: (String key, ?context: OpenTelemetry::Context) -> String?
|
14
|
+
|
15
|
+
# Returns all baggage values
|
16
|
+
def values: (?context: OpenTelemetry::Context) -> Hash[String, String]
|
17
|
+
|
18
|
+
# Returns a new context with key-value pair
|
19
|
+
def set_value: (String key, String value, ?metadata: String?, ?context: OpenTelemetry::Context) -> OpenTelemetry::Context
|
20
|
+
|
21
|
+
# Returns a new context with value at key removed
|
22
|
+
def remove_value: (String key, ?context: OpenTelemetry::Context) -> OpenTelemetry::Context
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -21,11 +21,13 @@ module Datadog
|
|
21
21
|
module Context
|
22
22
|
CURRENT_SPAN_KEY = ::OpenTelemetry::Trace.const_get(:CURRENT_SPAN_KEY)
|
23
23
|
private_constant :CURRENT_SPAN_KEY
|
24
|
+
BAGGAGE_REMOVE_KEY = Object.new # sentinel object to indicate the deletion of a value in baggage
|
24
25
|
|
25
|
-
def initialize(entries, trace: nil)
|
26
|
+
def initialize(entries, trace: nil, baggage: nil)
|
26
27
|
@trace = trace || ::Datadog::Tracing.send(:tracer).send(:start_trace)
|
27
28
|
@trace.otel_values.merge!(entries) if entries
|
28
29
|
@trace.otel_context ||= self
|
30
|
+
@trace.baggage = baggage if baggage
|
29
31
|
end
|
30
32
|
|
31
33
|
# Because Context can be reused, we have to make sure we have
|
@@ -79,8 +81,20 @@ module Datadog
|
|
79
81
|
end
|
80
82
|
|
81
83
|
existing_values = @trace && @trace.otel_values || {}
|
84
|
+
existing_baggage = @trace && @trace.baggage || {}
|
82
85
|
|
83
|
-
|
86
|
+
# Retrieve the baggage removal sentinel and remove it from the values hash
|
87
|
+
existing_baggage.delete(values[BAGGAGE_REMOVE_KEY]) if values.key?(BAGGAGE_REMOVE_KEY)
|
88
|
+
|
89
|
+
# If the values hash contains a BAGGAGE_KEY, merge its contents with existing baggage
|
90
|
+
# Otherwise, keep the existing baggage unchanged
|
91
|
+
new_baggage = if values.key?(::OpenTelemetry::Baggage.const_get(:BAGGAGE_KEY))
|
92
|
+
existing_baggage.merge(values[::OpenTelemetry::Baggage.const_get(:BAGGAGE_KEY)])
|
93
|
+
else
|
94
|
+
existing_baggage
|
95
|
+
end
|
96
|
+
|
97
|
+
::OpenTelemetry::Context.new(existing_values.merge(values), trace: trace, baggage: new_baggage)
|
84
98
|
end
|
85
99
|
|
86
100
|
# The Datadog {TraceOperation} associated with this {Context}.
|
@@ -45,7 +45,7 @@ module Datadog
|
|
45
45
|
def add_attributes(attributes)
|
46
46
|
res = super
|
47
47
|
# Attributes can get dropped or their values truncated by `super`
|
48
|
-
attributes.
|
48
|
+
attributes.each_key { |key| datadog_set_attribute(key) }
|
49
49
|
res
|
50
50
|
end
|
51
51
|
|
@@ -13,6 +13,7 @@ require_relative 'tracing'
|
|
13
13
|
require_relative 'tracing/contrib'
|
14
14
|
|
15
15
|
require_relative 'opentelemetry/api/context'
|
16
|
+
require_relative 'opentelemetry/api/baggage'
|
16
17
|
|
17
18
|
# DEV: Should this be a Contrib integration, that depends on the `opentelemetry-sdk`
|
18
19
|
# DEV: and checks for compatibility?
|
@@ -29,7 +30,7 @@ module Datadog
|
|
29
30
|
|
30
31
|
# Use `Datadog.logger` as the default logger
|
31
32
|
def logger
|
32
|
-
|
33
|
+
::Datadog.logger
|
33
34
|
end
|
34
35
|
|
35
36
|
::OpenTelemetry.singleton_class.prepend(self)
|
data/lib/datadog/profiling.rb
CHANGED
@@ -78,8 +78,11 @@ module Datadog
|
|
78
78
|
end
|
79
79
|
|
80
80
|
private_class_method def self.replace_noop_allocation_count
|
81
|
-
|
82
|
-
|
81
|
+
class << self
|
82
|
+
remove_method :allocation_count
|
83
|
+
def allocation_count
|
84
|
+
Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_allocation_count
|
85
|
+
end
|
83
86
|
end
|
84
87
|
end
|
85
88
|
|
@@ -6,6 +6,7 @@ require_relative 'sync_writer'
|
|
6
6
|
require_relative 'sampling/span/rule_parser'
|
7
7
|
require_relative 'sampling/span/sampler'
|
8
8
|
require_relative 'diagnostics/environment_logger'
|
9
|
+
require_relative 'contrib/component'
|
9
10
|
|
10
11
|
module Datadog
|
11
12
|
module Tracing
|
@@ -74,18 +75,11 @@ module Datadog
|
|
74
75
|
return sampler
|
75
76
|
end
|
76
77
|
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
|
82
|
-
if settings.appsec.standalone.enabled
|
83
|
-
post_sampler = Tracing::Sampling::RuleSampler.new(
|
84
|
-
[Tracing::Sampling::SimpleRule.new(sample_rate: 1.0)],
|
85
|
-
rate_limiter: Datadog::Core::TokenBucket.new(1.0 / 60, 1.0),
|
86
|
-
default_sample_rate: 1.0 / 60
|
87
|
-
)
|
88
|
-
end
|
78
|
+
# APM Disablement means that we don't want to send traces that only contains APM data.
|
79
|
+
# Other products can then put the sampling priority to MANUAL_KEEP if they want to keep traces.
|
80
|
+
# (e.g.: AppSec will MANUAL_KEEP traces with AppSec events) and clients will be billed only for those traces.
|
81
|
+
# But to keep the service alive on the backend side, we need to send one trace per minute.
|
82
|
+
post_sampler = build_rate_limit_post_sampler(seconds: 60) unless settings.apm.tracing.enabled
|
89
83
|
|
90
84
|
# Sampling rules are provided
|
91
85
|
if (rules = settings.tracing.sampling.rules)
|
@@ -197,6 +191,15 @@ module Datadog
|
|
197
191
|
end
|
198
192
|
end
|
199
193
|
|
194
|
+
# Build a post-sampler that limits the rate of traces to one per `seconds`.
|
195
|
+
# E.g.: `build_rate_limit_post_sampler(seconds: 60)` will limit the rate to one trace per minute.
|
196
|
+
def build_rate_limit_post_sampler(seconds:)
|
197
|
+
Tracing::Sampling::RuleSampler.new(
|
198
|
+
rate_limiter: Datadog::Core::TokenBucket.new(1.0 / seconds, 1.0),
|
199
|
+
default_sample_rate: 1.0
|
200
|
+
)
|
201
|
+
end
|
202
|
+
|
200
203
|
def build_test_mode_trace_flush(settings)
|
201
204
|
# If context flush behavior is provided, use it instead.
|
202
205
|
settings.tracing.test_mode.trace_flush || build_trace_flush(settings)
|
@@ -12,6 +12,7 @@ module Datadog
|
|
12
12
|
ENV_OTEL_TRACES_EXPORTER = 'OTEL_TRACES_EXPORTER'
|
13
13
|
ENV_HEADER_TAGS = 'DD_TRACE_HEADER_TAGS'
|
14
14
|
ENV_TRACE_ID_128_BIT_GENERATION_ENABLED = 'DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED'
|
15
|
+
ENV_NATIVE_SPAN_EVENTS = 'DD_TRACE_NATIVE_SPAN_EVENTS'
|
15
16
|
|
16
17
|
# @public_api
|
17
18
|
module SpanAttributeSchema
|
@@ -41,8 +42,13 @@ module Datadog
|
|
41
42
|
# W3C Trace Context
|
42
43
|
PROPAGATION_STYLE_TRACE_CONTEXT = 'tracecontext'
|
43
44
|
|
45
|
+
# W3C Baggage
|
46
|
+
# @see https://www.w3.org/TR/baggage/
|
47
|
+
PROPAGATION_STYLE_BAGGAGE = 'baggage'
|
48
|
+
|
44
49
|
PROPAGATION_STYLE_SUPPORTED = [PROPAGATION_STYLE_DATADOG, PROPAGATION_STYLE_B3_MULTI_HEADER,
|
45
|
-
PROPAGATION_STYLE_B3_SINGLE_HEADER, PROPAGATION_STYLE_TRACE_CONTEXT
|
50
|
+
PROPAGATION_STYLE_B3_SINGLE_HEADER, PROPAGATION_STYLE_TRACE_CONTEXT,
|
51
|
+
PROPAGATION_STYLE_BAGGAGE].freeze
|
46
52
|
|
47
53
|
# Sets both extract and inject propagation style tho the provided value.
|
48
54
|
# Has lower precedence than `DD_TRACE_PROPAGATION_STYLE_INJECT` or
|