ddtrace 1.12.1 → 1.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +129 -9
- data/ext/ddtrace_profiling_native_extension/collectors_thread_context.c +97 -14
- data/ext/ddtrace_profiling_native_extension/extconf.rb +6 -0
- data/ext/ddtrace_profiling_native_extension/http_transport.c +19 -6
- data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +1 -1
- data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +41 -2
- data/ext/ddtrace_profiling_native_extension/private_vm_api_access.h +6 -0
- data/ext/ddtrace_profiling_native_extension/stack_recorder.c +6 -10
- data/ext/ddtrace_profiling_native_extension/time_helpers.c +40 -4
- data/ext/ddtrace_profiling_native_extension/time_helpers.h +14 -0
- data/lib/datadog/appsec/component.rb +9 -0
- data/lib/datadog/appsec/configuration/settings.rb +104 -195
- data/lib/datadog/appsec/configuration.rb +0 -79
- data/lib/datadog/appsec/contrib/auto_instrument.rb +2 -4
- data/lib/datadog/appsec/contrib/devise/event.rb +57 -0
- data/lib/datadog/appsec/contrib/devise/ext.rb +13 -0
- data/lib/datadog/appsec/contrib/devise/integration.rb +42 -0
- data/lib/datadog/appsec/contrib/devise/patcher/authenticatable_patch.rb +76 -0
- data/lib/datadog/appsec/contrib/devise/patcher/registration_controller_patch.rb +52 -0
- data/lib/datadog/appsec/contrib/devise/patcher.rb +45 -0
- data/lib/datadog/appsec/contrib/devise/resource.rb +35 -0
- data/lib/datadog/appsec/contrib/devise/tracking.rb +49 -0
- data/lib/datadog/appsec/contrib/rack/ext.rb +2 -1
- data/lib/datadog/appsec/contrib/rack/reactive/request.rb +1 -1
- data/lib/datadog/appsec/contrib/rack/reactive/request_body.rb +1 -1
- data/lib/datadog/appsec/contrib/rack/reactive/response.rb +1 -1
- data/lib/datadog/appsec/contrib/rack/request_middleware.rb +12 -7
- data/lib/datadog/appsec/contrib/rails/ext.rb +3 -2
- data/lib/datadog/appsec/contrib/rails/framework.rb +1 -3
- data/lib/datadog/appsec/contrib/rails/patcher.rb +8 -8
- data/lib/datadog/appsec/contrib/rails/reactive/action.rb +1 -1
- data/lib/datadog/appsec/contrib/sinatra/ext.rb +2 -1
- data/lib/datadog/appsec/contrib/sinatra/framework.rb +1 -3
- data/lib/datadog/appsec/contrib/sinatra/reactive/routed.rb +1 -1
- data/lib/datadog/appsec/event.rb +1 -1
- data/lib/datadog/appsec/extensions.rb +1 -130
- data/lib/datadog/appsec/monitor/reactive/set_user.rb +1 -1
- data/lib/datadog/appsec/processor.rb +1 -1
- data/lib/datadog/appsec/rate_limiter.rb +1 -1
- data/lib/datadog/appsec/remote.rb +1 -1
- data/lib/datadog/appsec.rb +1 -2
- data/lib/datadog/ci/configuration/settings.rb +6 -8
- data/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +7 -5
- data/lib/datadog/ci/contrib/cucumber/ext.rb +10 -8
- data/lib/datadog/ci/contrib/minitest/configuration/settings.rb +35 -0
- data/lib/datadog/ci/contrib/minitest/ext.rb +21 -0
- data/lib/datadog/ci/contrib/minitest/integration.rb +49 -0
- data/lib/datadog/ci/contrib/minitest/patcher.rb +27 -0
- data/lib/datadog/ci/contrib/minitest/test_helper.rb +68 -0
- data/lib/datadog/ci/contrib/rspec/configuration/settings.rb +7 -5
- data/lib/datadog/ci/contrib/rspec/ext.rb +9 -7
- data/lib/datadog/ci.rb +1 -0
- data/lib/datadog/core/backport.rb +51 -0
- data/lib/datadog/core/configuration/agent_settings_resolver.rb +9 -5
- data/lib/datadog/core/configuration/base.rb +5 -5
- data/lib/datadog/core/configuration/components.rb +6 -1
- data/lib/datadog/core/configuration/ext.rb +7 -5
- data/lib/datadog/core/configuration/option.rb +269 -19
- data/lib/datadog/core/configuration/option_definition.rb +76 -11
- data/lib/datadog/core/configuration/options.rb +22 -10
- data/lib/datadog/core/configuration/settings.rb +139 -61
- data/lib/datadog/core/environment/execution.rb +55 -0
- data/lib/datadog/core/environment/ext.rb +13 -11
- data/lib/datadog/core/environment/yjit.rb +58 -0
- data/lib/datadog/core/git/ext.rb +24 -22
- data/lib/datadog/core/logging/ext.rb +3 -1
- data/lib/datadog/core/metrics/ext.rb +7 -5
- data/lib/datadog/core/remote/client/capabilities.rb +5 -0
- data/lib/datadog/core/remote/client.rb +3 -0
- data/lib/datadog/core/remote/component.rb +25 -34
- data/lib/datadog/core/remote/configuration/content.rb +28 -1
- data/lib/datadog/core/remote/configuration/repository.rb +3 -1
- data/lib/datadog/core/remote/ext.rb +1 -1
- data/lib/datadog/core/remote/negotiation.rb +17 -4
- data/lib/datadog/core/runtime/ext.rb +22 -12
- data/lib/datadog/core/runtime/metrics.rb +43 -0
- data/lib/datadog/core/telemetry/client.rb +12 -2
- data/lib/datadog/core/telemetry/emitter.rb +4 -2
- data/lib/datadog/core/telemetry/event.rb +19 -4
- data/lib/datadog/core/telemetry/ext.rb +4 -1
- data/lib/datadog/core/telemetry/heartbeat.rb +2 -4
- data/lib/datadog/core/telemetry/http/ext.rb +10 -8
- data/lib/datadog/core/telemetry/http/transport.rb +1 -0
- data/lib/datadog/core/telemetry/v2/app_client_configuration_change.rb +41 -0
- data/lib/datadog/core/telemetry/v2/request.rb +29 -0
- data/lib/datadog/core/transport/http/client.rb +1 -1
- data/lib/datadog/core/transport/http/config.rb +10 -0
- data/lib/datadog/core/utils/duration.rb +52 -0
- data/lib/datadog/core/utils/hash.rb +47 -0
- data/lib/datadog/core/utils/network.rb +1 -1
- data/lib/datadog/core/utils/safe_dup.rb +27 -20
- data/lib/datadog/core/utils.rb +1 -1
- data/lib/datadog/core/workers/async.rb +2 -2
- data/lib/datadog/kit/appsec/events.rb +139 -89
- data/lib/datadog/kit/identity.rb +80 -65
- data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +3 -0
- data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +1 -0
- data/lib/datadog/profiling/collectors/thread_context.rb +9 -2
- data/lib/datadog/profiling/component.rb +41 -9
- data/lib/datadog/profiling/exporter.rb +5 -1
- data/lib/datadog/profiling/flush.rb +9 -2
- data/lib/datadog/profiling/http_transport.rb +13 -3
- data/lib/datadog/profiling/load_native_extension.rb +7 -1
- data/lib/datadog/profiling.rb +11 -1
- data/lib/datadog/tracing/component.rb +58 -6
- data/lib/datadog/tracing/configuration/dynamic/option.rb +71 -0
- data/lib/datadog/tracing/configuration/dynamic.rb +64 -0
- data/lib/datadog/tracing/configuration/ext.rb +35 -32
- data/lib/datadog/tracing/configuration/http.rb +74 -0
- data/lib/datadog/tracing/configuration/settings.rb +106 -92
- data/lib/datadog/tracing/contrib/action_cable/configuration/settings.rb +9 -6
- data/lib/datadog/tracing/contrib/action_cable/ext.rb +20 -18
- data/lib/datadog/tracing/contrib/action_mailer/configuration/settings.rb +9 -6
- data/lib/datadog/tracing/contrib/action_mailer/ext.rb +20 -18
- data/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +8 -6
- data/lib/datadog/tracing/contrib/action_pack/ext.rb +10 -8
- data/lib/datadog/tracing/contrib/action_view/configuration/settings.rb +9 -6
- data/lib/datadog/tracing/contrib/action_view/ext.rb +12 -10
- data/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +13 -7
- data/lib/datadog/tracing/contrib/active_job/ext.rb +25 -23
- data/lib/datadog/tracing/contrib/active_job/log_injection.rb +1 -1
- data/lib/datadog/tracing/contrib/active_job/patcher.rb +1 -1
- data/lib/datadog/tracing/contrib/active_model_serializers/configuration/settings.rb +9 -6
- data/lib/datadog/tracing/contrib/active_model_serializers/ext.rb +12 -10
- data/lib/datadog/tracing/contrib/active_record/configuration/settings.rb +9 -7
- data/lib/datadog/tracing/contrib/active_record/events/sql.rb +0 -8
- data/lib/datadog/tracing/contrib/active_record/ext.rb +17 -15
- data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +0 -5
- data/lib/datadog/tracing/contrib/active_support/configuration/settings.rb +9 -7
- data/lib/datadog/tracing/contrib/active_support/ext.rb +18 -16
- data/lib/datadog/tracing/contrib/aws/configuration/settings.rb +14 -7
- data/lib/datadog/tracing/contrib/aws/ext.rb +37 -24
- data/lib/datadog/tracing/contrib/aws/instrumentation.rb +9 -5
- data/lib/datadog/tracing/contrib/concurrent_ruby/configuration/settings.rb +3 -2
- data/lib/datadog/tracing/contrib/concurrent_ruby/ext.rb +4 -2
- data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +14 -7
- data/lib/datadog/tracing/contrib/dalli/ext.rb +19 -11
- data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +8 -6
- data/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +13 -7
- data/lib/datadog/tracing/contrib/delayed_job/ext.rb +16 -14
- data/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +14 -7
- data/lib/datadog/tracing/contrib/elasticsearch/ext.rb +21 -15
- data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +8 -5
- data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +16 -9
- data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +43 -3
- data/lib/datadog/tracing/contrib/ethon/ext.rb +19 -11
- data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +0 -5
- data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +19 -10
- data/lib/datadog/tracing/contrib/excon/ext.rb +16 -8
- data/lib/datadog/tracing/contrib/excon/middleware.rb +20 -5
- data/lib/datadog/tracing/contrib/ext.rb +23 -1
- data/lib/datadog/tracing/contrib/extensions.rb +32 -0
- data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +20 -10
- data/lib/datadog/tracing/contrib/faraday/ext.rb +16 -8
- data/lib/datadog/tracing/contrib/faraday/middleware.rb +16 -5
- data/lib/datadog/tracing/contrib/grape/configuration/settings.rb +8 -6
- data/lib/datadog/tracing/contrib/grape/ext.rb +16 -14
- data/lib/datadog/tracing/contrib/graphql/configuration/settings.rb +8 -6
- data/lib/datadog/tracing/contrib/graphql/ext.rb +7 -5
- data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +19 -9
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +29 -20
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +21 -20
- data/lib/datadog/tracing/contrib/grpc/ext.rb +16 -13
- data/lib/datadog/tracing/contrib/grpc/formatting.rb +127 -0
- data/lib/datadog/tracing/contrib/hanami/configuration/settings.rb +3 -2
- data/lib/datadog/tracing/contrib/hanami/ext.rb +10 -8
- data/lib/datadog/tracing/contrib/http/circuit_breaker.rb +4 -7
- data/lib/datadog/tracing/contrib/http/configuration/settings.rb +33 -11
- data/lib/datadog/tracing/contrib/http/ext.rb +16 -9
- data/lib/datadog/tracing/contrib/http/instrumentation.rb +22 -7
- data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +33 -11
- data/lib/datadog/tracing/contrib/httpclient/ext.rb +17 -9
- data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +17 -5
- data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +33 -11
- data/lib/datadog/tracing/contrib/httprb/ext.rb +16 -9
- data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +17 -5
- data/lib/datadog/tracing/contrib/kafka/configuration/settings.rb +9 -6
- data/lib/datadog/tracing/contrib/kafka/ext.rb +42 -39
- data/lib/datadog/tracing/contrib/lograge/configuration/settings.rb +3 -2
- data/lib/datadog/tracing/contrib/lograge/ext.rb +3 -1
- data/lib/datadog/tracing/contrib/lograge/instrumentation.rb +1 -0
- data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +14 -7
- data/lib/datadog/tracing/contrib/mongodb/ext.rb +20 -16
- data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +9 -5
- data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +17 -14
- data/lib/datadog/tracing/contrib/mysql2/ext.rb +15 -10
- data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +9 -5
- data/lib/datadog/tracing/contrib/opensearch/configuration/settings.rb +52 -0
- data/lib/datadog/tracing/contrib/opensearch/ext.rb +37 -0
- data/lib/datadog/tracing/contrib/opensearch/integration.rb +44 -0
- data/lib/datadog/tracing/contrib/opensearch/patcher.rb +128 -0
- data/lib/datadog/tracing/contrib/opensearch/quantize.rb +81 -0
- data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +17 -14
- data/lib/datadog/tracing/contrib/pg/ext.rb +22 -19
- data/lib/datadog/tracing/contrib/pg/instrumentation.rb +9 -5
- data/lib/datadog/tracing/contrib/presto/configuration/settings.rb +14 -7
- data/lib/datadog/tracing/contrib/presto/ext.rb +25 -20
- data/lib/datadog/tracing/contrib/presto/instrumentation.rb +9 -5
- data/lib/datadog/tracing/contrib/propagation/sql_comment/ext.rb +12 -10
- data/lib/datadog/tracing/contrib/qless/configuration/settings.rb +12 -8
- data/lib/datadog/tracing/contrib/qless/ext.rb +14 -12
- data/lib/datadog/tracing/contrib/que/configuration/settings.rb +21 -12
- data/lib/datadog/tracing/contrib/racecar/configuration/settings.rb +9 -7
- data/lib/datadog/tracing/contrib/racecar/event.rb +0 -5
- data/lib/datadog/tracing/contrib/racecar/ext.rb +20 -18
- data/lib/datadog/tracing/contrib/rack/configuration/settings.rb +16 -12
- data/lib/datadog/tracing/contrib/rack/ext.rb +18 -16
- data/lib/datadog/tracing/contrib/rack/header_collection.rb +3 -0
- data/lib/datadog/tracing/contrib/rack/header_tagging.rb +53 -0
- data/lib/datadog/tracing/contrib/rack/middlewares.rb +8 -49
- data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +15 -11
- data/lib/datadog/tracing/contrib/rails/ext.rb +7 -5
- data/lib/datadog/tracing/contrib/rails/log_injection.rb +7 -10
- data/lib/datadog/tracing/contrib/rails/patcher.rb +10 -41
- data/lib/datadog/tracing/contrib/rails/railtie.rb +3 -3
- data/lib/datadog/tracing/contrib/rake/configuration/settings.rb +12 -9
- data/lib/datadog/tracing/contrib/rake/ext.rb +14 -12
- data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +17 -9
- data/lib/datadog/tracing/contrib/redis/ext.rb +22 -15
- data/lib/datadog/tracing/contrib/redis/tags.rb +9 -5
- data/lib/datadog/tracing/contrib/resque/configuration/settings.rb +13 -7
- data/lib/datadog/tracing/contrib/resque/ext.rb +9 -7
- data/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +16 -9
- data/lib/datadog/tracing/contrib/rest_client/ext.rb +15 -8
- data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +20 -5
- data/lib/datadog/tracing/contrib/roda/configuration/settings.rb +9 -6
- data/lib/datadog/tracing/contrib/semantic_logger/configuration/settings.rb +3 -2
- data/lib/datadog/tracing/contrib/semantic_logger/ext.rb +3 -1
- data/lib/datadog/tracing/contrib/semantic_logger/instrumentation.rb +1 -0
- data/lib/datadog/tracing/contrib/sequel/configuration/settings.rb +9 -6
- data/lib/datadog/tracing/contrib/sequel/ext.rb +10 -8
- data/lib/datadog/tracing/contrib/sequel/utils.rb +2 -7
- data/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +14 -8
- data/lib/datadog/tracing/contrib/shoryuken/ext.rb +14 -12
- data/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +18 -11
- data/lib/datadog/tracing/contrib/sidekiq/ext.rb +32 -30
- data/lib/datadog/tracing/contrib/sinatra/configuration/settings.rb +11 -9
- data/lib/datadog/tracing/contrib/sinatra/env.rb +0 -17
- data/lib/datadog/tracing/contrib/sinatra/ext.rb +21 -19
- data/lib/datadog/tracing/contrib/sinatra/tracer_middleware.rb +3 -14
- data/lib/datadog/tracing/contrib/sneakers/configuration/settings.rb +14 -8
- data/lib/datadog/tracing/contrib/sneakers/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/sneakers/tracer.rb +1 -1
- data/lib/datadog/tracing/contrib/span_attribute_schema.rb +74 -10
- data/lib/datadog/tracing/contrib/stripe/configuration/settings.rb +9 -6
- data/lib/datadog/tracing/contrib/sucker_punch/configuration/settings.rb +9 -6
- data/lib/datadog/tracing/contrib/sucker_punch/ext.rb +15 -13
- data/lib/datadog/tracing/contrib/utils/database.rb +5 -3
- data/lib/datadog/tracing/contrib.rb +1 -0
- data/lib/datadog/tracing/correlation.rb +9 -12
- data/lib/datadog/tracing/diagnostics/ext.rb +21 -19
- data/lib/datadog/tracing/distributed/b3_multi.rb +2 -2
- data/lib/datadog/tracing/distributed/b3_single.rb +1 -1
- data/lib/datadog/tracing/distributed/trace_context.rb +52 -17
- data/lib/datadog/tracing/metadata/ext.rb +9 -6
- data/lib/datadog/tracing/remote.rb +78 -0
- data/lib/datadog/tracing/sampling/rule_sampler.rb +29 -0
- data/lib/datadog/tracing/span_operation.rb +3 -15
- data/lib/datadog/tracing/trace_operation.rb +16 -3
- data/lib/datadog/tracing/trace_segment.rb +5 -2
- data/lib/datadog/tracing/tracer.rb +10 -1
- data/lib/ddtrace/transport/ext.rb +15 -9
- data/lib/ddtrace/transport/trace_formatter.rb +9 -0
- data/lib/ddtrace/version.rb +8 -11
- metadata +36 -7
- data/lib/datadog/tracing/contrib/sinatra/headers.rb +0 -35
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module AppSec
|
5
|
+
module Contrib
|
6
|
+
module Devise
|
7
|
+
# Class to extract event information from the resource
|
8
|
+
class Event
|
9
|
+
UUID_REGEX = /^\h{8}-\h{4}-\h{4}-\h{4}-\h{12}$/.freeze
|
10
|
+
|
11
|
+
SAFE_MODE = 'safe'
|
12
|
+
EXTENDED_MODE = 'extended'
|
13
|
+
|
14
|
+
attr_reader :user_id
|
15
|
+
|
16
|
+
def initialize(resource, mode)
|
17
|
+
@resource = resource
|
18
|
+
@mode = mode
|
19
|
+
@user_id = nil
|
20
|
+
@email = nil
|
21
|
+
@username = nil
|
22
|
+
|
23
|
+
extract if @resource
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_h
|
27
|
+
return @event if defined?(@event)
|
28
|
+
|
29
|
+
@event = {}
|
30
|
+
@event[:email] = @email if @email
|
31
|
+
@event[:username] = @username if @username
|
32
|
+
@event
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def extract
|
38
|
+
@user_id = @resource.id
|
39
|
+
|
40
|
+
case @mode
|
41
|
+
when EXTENDED_MODE
|
42
|
+
@email = @resource.email
|
43
|
+
@username = @resource.username
|
44
|
+
when SAFE_MODE
|
45
|
+
@user_id = nil unless @user_id && @user_id.to_s =~ UUID_REGEX
|
46
|
+
else
|
47
|
+
Datadog.logger.warn(
|
48
|
+
"Invalid automated user evenst mode: `#{@mode}`. "\
|
49
|
+
'Supported modes are: `safe` and `extended`.'
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../integration'
|
4
|
+
|
5
|
+
require_relative 'patcher'
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
module AppSec
|
9
|
+
module Contrib
|
10
|
+
module Devise
|
11
|
+
# Description of Devise integration
|
12
|
+
class Integration
|
13
|
+
include Datadog::AppSec::Contrib::Integration
|
14
|
+
|
15
|
+
MINIMUM_VERSION = Gem::Version.new('3.2.1')
|
16
|
+
|
17
|
+
register_as :devise, auto_patch: true
|
18
|
+
|
19
|
+
def self.version
|
20
|
+
Gem.loaded_specs['devise'] && Gem.loaded_specs['devise'].version
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.loaded?
|
24
|
+
!defined?(::Devise).nil?
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.compatible?
|
28
|
+
super && version >= MINIMUM_VERSION
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.auto_instrument?
|
32
|
+
true
|
33
|
+
end
|
34
|
+
|
35
|
+
def patcher
|
36
|
+
Patcher
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../tracking'
|
4
|
+
require_relative '../resource'
|
5
|
+
require_relative '../event'
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
module AppSec
|
9
|
+
module Contrib
|
10
|
+
module Devise
|
11
|
+
module Patcher
|
12
|
+
# Hook in devise validate method
|
13
|
+
module AuthenticatablePatch
|
14
|
+
# rubocop:disable Metrics/MethodLength
|
15
|
+
def validate(resource, &block)
|
16
|
+
result = super
|
17
|
+
return result unless AppSec.enabled?
|
18
|
+
|
19
|
+
track_user_events_configuration = Datadog.configuration.appsec.track_user_events
|
20
|
+
|
21
|
+
return result unless track_user_events_configuration.enabled
|
22
|
+
|
23
|
+
automated_track_user_events_mode = track_user_events_configuration.mode
|
24
|
+
|
25
|
+
appsec_scope = Datadog::AppSec.active_scope
|
26
|
+
|
27
|
+
return result unless appsec_scope
|
28
|
+
|
29
|
+
devise_resource = resource ? Resource.new(resource) : nil
|
30
|
+
|
31
|
+
event_information = Event.new(devise_resource, automated_track_user_events_mode)
|
32
|
+
|
33
|
+
if result
|
34
|
+
if event_information.user_id
|
35
|
+
Datadog.logger.debug { 'User Login Event success' }
|
36
|
+
else
|
37
|
+
Datadog.logger.debug { 'User Login Event success, but can\'t extract user ID. Tracking empty event' }
|
38
|
+
end
|
39
|
+
|
40
|
+
Tracking.track_login_success(
|
41
|
+
appsec_scope.trace,
|
42
|
+
appsec_scope.service_entry_span,
|
43
|
+
user_id: event_information.user_id,
|
44
|
+
**event_information.to_h
|
45
|
+
)
|
46
|
+
|
47
|
+
return result
|
48
|
+
end
|
49
|
+
|
50
|
+
user_exists = nil
|
51
|
+
|
52
|
+
if resource
|
53
|
+
user_exists = true
|
54
|
+
Datadog.logger.debug { 'User Login Event failure users exists' }
|
55
|
+
else
|
56
|
+
user_exists = false
|
57
|
+
Datadog.logger.debug { 'User Login Event failure user do not exists' }
|
58
|
+
end
|
59
|
+
|
60
|
+
Tracking.track_login_failure(
|
61
|
+
appsec_scope.trace,
|
62
|
+
appsec_scope.service_entry_span,
|
63
|
+
user_id: event_information.user_id,
|
64
|
+
user_exists: user_exists,
|
65
|
+
**event_information.to_h
|
66
|
+
)
|
67
|
+
|
68
|
+
result
|
69
|
+
end
|
70
|
+
# rubocop:enable Metrics/MethodLength
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../tracking'
|
4
|
+
require_relative '../resource'
|
5
|
+
require_relative '../event'
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
module AppSec
|
9
|
+
module Contrib
|
10
|
+
module Devise
|
11
|
+
module Patcher
|
12
|
+
# Hook in devise registration controller
|
13
|
+
module RegistrationControllerPatch
|
14
|
+
def create
|
15
|
+
return super unless AppSec.enabled?
|
16
|
+
|
17
|
+
track_user_events_configuration = Datadog.configuration.appsec.track_user_events
|
18
|
+
|
19
|
+
return super unless track_user_events_configuration.enabled
|
20
|
+
|
21
|
+
automated_track_user_events_mode = track_user_events_configuration.mode
|
22
|
+
|
23
|
+
appsec_scope = Datadog::AppSec.active_scope
|
24
|
+
return super unless appsec_scope
|
25
|
+
|
26
|
+
super do |resource|
|
27
|
+
if resource.persisted?
|
28
|
+
devise_resource = Resource.new(resource)
|
29
|
+
|
30
|
+
event_information = Event.new(devise_resource, automated_track_user_events_mode)
|
31
|
+
|
32
|
+
if event_information.user_id
|
33
|
+
Datadog.logger.debug { 'User Signup Event' }
|
34
|
+
else
|
35
|
+
Datadog.logger.warn { 'User Signup Event, but can\'t extract user ID. Tracking empty event' }
|
36
|
+
end
|
37
|
+
|
38
|
+
Tracking.track_signup(
|
39
|
+
appsec_scope.trace,
|
40
|
+
appsec_scope.service_entry_span,
|
41
|
+
user_id: event_information.user_id,
|
42
|
+
**event_information.to_h
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../patcher'
|
4
|
+
require_relative 'patcher/authenticatable_patch'
|
5
|
+
require_relative 'patcher/registration_controller_patch'
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
module AppSec
|
9
|
+
module Contrib
|
10
|
+
module Devise
|
11
|
+
# Patcher for AppSec on Devise
|
12
|
+
module Patcher
|
13
|
+
include Datadog::AppSec::Contrib::Patcher
|
14
|
+
|
15
|
+
module_function
|
16
|
+
|
17
|
+
def patched?
|
18
|
+
Patcher.instance_variable_get(:@patched)
|
19
|
+
end
|
20
|
+
|
21
|
+
def target_version
|
22
|
+
Integration.version
|
23
|
+
end
|
24
|
+
|
25
|
+
def patch
|
26
|
+
patch_authenticable_strategy
|
27
|
+
patch_registration_controller
|
28
|
+
|
29
|
+
Patcher.instance_variable_set(:@patched, true)
|
30
|
+
end
|
31
|
+
|
32
|
+
def patch_authenticable_strategy
|
33
|
+
::Devise::Strategies::Authenticatable.prepend(AuthenticatablePatch)
|
34
|
+
end
|
35
|
+
|
36
|
+
def patch_registration_controller
|
37
|
+
::ActiveSupport.on_load(:after_initialize) do
|
38
|
+
::Devise::RegistrationsController.prepend(RegistrationControllerPatch)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module AppSec
|
5
|
+
module Contrib
|
6
|
+
module Devise
|
7
|
+
# Class to encpasulate extracting information from a Devise resource
|
8
|
+
# Normally a devise resource would be an Active::Record instance
|
9
|
+
class Resource
|
10
|
+
def initialize(resource)
|
11
|
+
@resource = resource
|
12
|
+
end
|
13
|
+
|
14
|
+
def id
|
15
|
+
extract(:id) || extract(:uuid)
|
16
|
+
end
|
17
|
+
|
18
|
+
def email
|
19
|
+
extract(:email)
|
20
|
+
end
|
21
|
+
|
22
|
+
def username
|
23
|
+
extract(:username)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def extract(method)
|
29
|
+
@resource.send(method) if @resource.respond_to?(method)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../kit/identity'
|
4
|
+
|
5
|
+
module Datadog
|
6
|
+
module AppSec
|
7
|
+
module Contrib
|
8
|
+
module Devise
|
9
|
+
# Internal module to track user events
|
10
|
+
module Tracking
|
11
|
+
LOGIN_SUCCESS_EVENT = 'users.login.success'
|
12
|
+
LOGIN_FAILURE_EVENT = 'users.login.failure'
|
13
|
+
SIGNUP_EVENT = 'users.signup'
|
14
|
+
|
15
|
+
def self.track_login_success(trace, span, user_id:, **others)
|
16
|
+
track(LOGIN_SUCCESS_EVENT, trace, span, **others)
|
17
|
+
|
18
|
+
Kit::Identity.set_user(trace, span, id: user_id.to_s, **others) if user_id
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.track_login_failure(trace, span, user_id:, user_exists:, **others)
|
22
|
+
track(LOGIN_FAILURE_EVENT, trace, span, **others)
|
23
|
+
|
24
|
+
span.set_tag('appsec.events.users.login.failure.usr.id', user_id) if user_id
|
25
|
+
span.set_tag('appsec.events.users.login.failure.usr.exists', user_exists)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.track_signup(trace, span, user_id:, **others)
|
29
|
+
track(SIGNUP_EVENT, trace, span, **others)
|
30
|
+
Kit::Identity.set_user(trace, id: user_id.to_s, **others) if user_id
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.track(event, trace, span, **others)
|
34
|
+
span.set_tag("appsec.events.#{event}.track", 'true')
|
35
|
+
span.set_tag("_dd.appsec.events.#{event}.auto.mode", Datadog.configuration.appsec.track_user_events.mode)
|
36
|
+
|
37
|
+
others.each do |k, v|
|
38
|
+
raise ArgumentError, 'key cannot be :track' if k.to_sym == :track
|
39
|
+
|
40
|
+
span.set_tag("appsec.events.#{event}.#{k}", v) unless v.nil?
|
41
|
+
end
|
42
|
+
|
43
|
+
trace.keep!
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -52,7 +52,7 @@ module Datadog
|
|
52
52
|
'server.request.method' => request_method,
|
53
53
|
}
|
54
54
|
|
55
|
-
waf_timeout = Datadog
|
55
|
+
waf_timeout = Datadog.configuration.appsec.waf_timeout
|
56
56
|
result = waf_context.run(waf_args, waf_timeout)
|
57
57
|
|
58
58
|
Datadog.logger.debug { "WAF TIMEOUT: #{result.inspect}" } if result.timeout
|
@@ -30,7 +30,7 @@ module Datadog
|
|
30
30
|
'server.request.body' => body,
|
31
31
|
}
|
32
32
|
|
33
|
-
waf_timeout = Datadog
|
33
|
+
waf_timeout = Datadog.configuration.appsec.waf_timeout
|
34
34
|
result = waf_context.run(waf_args, waf_timeout)
|
35
35
|
|
36
36
|
Datadog.logger.debug { "WAF TIMEOUT: #{result.inspect}" } if result.timeout
|
@@ -36,7 +36,7 @@ module Datadog
|
|
36
36
|
'server.response.headers.no_cookies' => response_headers_no_cookies,
|
37
37
|
}
|
38
38
|
|
39
|
-
waf_timeout = Datadog
|
39
|
+
waf_timeout = Datadog.configuration.appsec.waf_timeout
|
40
40
|
result = waf_context.run(waf_args, waf_timeout)
|
41
41
|
|
42
42
|
Datadog.logger.debug { "WAF TIMEOUT: #{result.inspect}" } if result.timeout
|
@@ -53,7 +53,7 @@ module Datadog
|
|
53
53
|
|
54
54
|
gateway_request = Gateway::Request.new(env)
|
55
55
|
|
56
|
-
add_appsec_tags(processor, scope
|
56
|
+
add_appsec_tags(processor, scope, env)
|
57
57
|
|
58
58
|
request_return, request_response = catch(::Datadog::AppSec::Ext::INTERRUPT) do
|
59
59
|
Instrumentation.gateway.push('rack.request', gateway_request) do
|
@@ -88,7 +88,7 @@ module Datadog
|
|
88
88
|
request_return
|
89
89
|
ensure
|
90
90
|
if scope
|
91
|
-
add_waf_runtime_tags(scope
|
91
|
+
add_waf_runtime_tags(scope)
|
92
92
|
Datadog::AppSec::Scope.deactivate_scope
|
93
93
|
end
|
94
94
|
end
|
@@ -116,8 +116,11 @@ module Datadog
|
|
116
116
|
Datadog::Tracing.active_span
|
117
117
|
end
|
118
118
|
|
119
|
-
def add_appsec_tags(processor,
|
120
|
-
|
119
|
+
def add_appsec_tags(processor, scope, env)
|
120
|
+
span = scope.service_entry_span
|
121
|
+
trace = scope.trace
|
122
|
+
|
123
|
+
return unless trace && span
|
121
124
|
|
122
125
|
span.set_tag('_dd.appsec.enabled', 1)
|
123
126
|
span.set_tag('_dd.runtime_family', 'ruby')
|
@@ -157,9 +160,11 @@ module Datadog
|
|
157
160
|
end
|
158
161
|
end
|
159
162
|
|
160
|
-
def add_waf_runtime_tags(
|
161
|
-
|
162
|
-
|
163
|
+
def add_waf_runtime_tags(scope)
|
164
|
+
span = scope.service_entry_span
|
165
|
+
context = scope.processor_context
|
166
|
+
|
167
|
+
return unless span && context
|
163
168
|
|
164
169
|
span.set_tag('_dd.appsec.waf.timeouts', context.timeouts)
|
165
170
|
|
@@ -33,19 +33,19 @@ module Datadog
|
|
33
33
|
|
34
34
|
def patch
|
35
35
|
Gateway::Watcher.watch
|
36
|
-
|
37
|
-
|
36
|
+
patch_before_initialize
|
37
|
+
patch_after_initialize
|
38
38
|
|
39
39
|
Patcher.instance_variable_set(:@patched, true)
|
40
40
|
end
|
41
41
|
|
42
|
-
def
|
42
|
+
def patch_before_initialize
|
43
43
|
::ActiveSupport.on_load(:before_initialize) do
|
44
|
-
Datadog::AppSec::Contrib::Rails::Patcher.
|
44
|
+
Datadog::AppSec::Contrib::Rails::Patcher.before_initialize(self)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
48
|
+
def before_initialize(app)
|
49
49
|
BEFORE_INITIALIZE_ONLY_ONCE_PER_APP[app].run do
|
50
50
|
# Middleware must be added before the application is initialized.
|
51
51
|
# Otherwise the middleware stack will be frozen.
|
@@ -134,13 +134,13 @@ module Datadog
|
|
134
134
|
Datadog.logger.debug { 'Rails middlewares: ' << app.middleware.map(&:inspect).inspect }
|
135
135
|
end
|
136
136
|
|
137
|
-
def
|
137
|
+
def patch_after_initialize
|
138
138
|
::ActiveSupport.on_load(:after_initialize) do
|
139
|
-
Datadog::AppSec::Contrib::Rails::Patcher.
|
139
|
+
Datadog::AppSec::Contrib::Rails::Patcher.after_initialize(self)
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
-
def
|
143
|
+
def after_initialize(app)
|
144
144
|
AFTER_INITIALIZE_ONLY_ONCE_PER_APP[app].run do
|
145
145
|
# Finish configuring the tracer after the application is initialized.
|
146
146
|
# We need to wait for some things, like application name, middleware stack, etc.
|
@@ -36,7 +36,7 @@ module Datadog
|
|
36
36
|
'server.request.path_params' => path_params,
|
37
37
|
}
|
38
38
|
|
39
|
-
waf_timeout = Datadog
|
39
|
+
waf_timeout = Datadog.configuration.appsec.waf_timeout
|
40
40
|
result = waf_context.run(waf_args, waf_timeout)
|
41
41
|
|
42
42
|
Datadog.logger.debug { "WAF TIMEOUT: #{result.inspect}" } if result.timeout
|
@@ -11,9 +11,7 @@ module Datadog
|
|
11
11
|
module Framework
|
12
12
|
# Configure Rack from Sinatra, but only if Rack has not been configured manually beforehand
|
13
13
|
def self.setup
|
14
|
-
Datadog
|
15
|
-
datadog_config.instrument(:rack)
|
16
|
-
end
|
14
|
+
Datadog.configuration.appsec.instrument(:rack)
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
@@ -31,7 +31,7 @@ module Datadog
|
|
31
31
|
'server.request.path_params' => path_params,
|
32
32
|
}
|
33
33
|
|
34
|
-
waf_timeout = Datadog
|
34
|
+
waf_timeout = Datadog.configuration.appsec.waf_timeout
|
35
35
|
result = waf_context.run(waf_args, waf_timeout)
|
36
36
|
|
37
37
|
Datadog.logger.debug { "WAF TIMEOUT: #{result.inspect}" } if result.timeout
|
data/lib/datadog/appsec/event.rb
CHANGED
@@ -40,7 +40,7 @@ module Datadog
|
|
40
40
|
# to properly apply
|
41
41
|
def self.record(span, *events)
|
42
42
|
# ensure rate limiter is called only when there are events to record
|
43
|
-
return if events.empty?
|
43
|
+
return if events.empty? || span.nil?
|
44
44
|
|
45
45
|
Datadog::AppSec::RateLimiter.limit(:traces) do
|
46
46
|
record_via_span(span, *events)
|