Skip to content

Commit

Permalink
Rename AppSec::Event.add_tags to AppSec::Event.tag_and_keep! and move…
Browse files Browse the repository at this point in the history
… trace.keep in it
  • Loading branch information
vpellan committed Oct 17, 2024
1 parent e24310e commit 73f8af2
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 14 deletions.
4 changes: 1 addition & 3 deletions lib/datadog/appsec/contrib/graphql/gateway/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ def watch_multiplex(gateway = Instrumentation.gateway)
actions: result.actions
}

# We want to keep the trace in case of security event
scope.trace.keep! if scope.trace
Datadog::AppSec::Event.add_tags(scope, result)
Datadog::AppSec::Event.tag_and_keep!(scope, result)
scope.processor_context.events << event
end

Expand Down
6 changes: 3 additions & 3 deletions lib/datadog/appsec/contrib/rack/gateway/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def watch_request(gateway = Instrumentation.gateway)

# We want to keep the trace in case of security event
scope.trace.keep! if scope.trace
Datadog::AppSec::Event.add_tags(scope, result)
Datadog::AppSec::Event.tag_and_keep!(scope, result)
scope.processor_context.events << event
end
end
Expand Down Expand Up @@ -85,7 +85,7 @@ def watch_response(gateway = Instrumentation.gateway)

# We want to keep the trace in case of security event
scope.trace.keep! if scope.trace
Datadog::AppSec::Event.add_tags(scope, result)
Datadog::AppSec::Event.tag_and_keep!(scope, result)
scope.processor_context.events << event
end
end
Expand Down Expand Up @@ -127,7 +127,7 @@ def watch_request_body(gateway = Instrumentation.gateway)

# We want to keep the trace in case of security event
scope.trace.keep! if scope.trace
Datadog::AppSec::Event.add_tags(scope, result)
Datadog::AppSec::Event.tag_and_keep!(scope, result)
scope.processor_context.events << event
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/appsec/contrib/rails/gateway/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def watch_request_action(gateway = Instrumentation.gateway)

# We want to keep the trace in case of security event
scope.trace.keep! if scope.trace
Datadog::AppSec::Event.add_tags(scope, result)
Datadog::AppSec::Event.tag_and_keep!(scope, result)
scope.processor_context.events << event
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def watch_request_dispatch(gateway = Instrumentation.gateway)

# We want to keep the trace in case of security event
scope.trace.keep! if scope.trace
Datadog::AppSec::Event.add_tags(scope, result)
Datadog::AppSec::Event.tag_and_keep!(scope, result)
scope.processor_context.events << event
end
end
Expand Down Expand Up @@ -84,7 +84,7 @@ def watch_request_routed(gateway = Instrumentation.gateway)

# We want to keep the trace in case of security event
scope.trace.keep! if scope.trace
Datadog::AppSec::Event.add_tags(scope, result)
Datadog::AppSec::Event.tag_and_keep!(scope, result)
scope.processor_context.events << event
end
end
Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/appsec/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ def build_service_entry_tags(event_group)
end
# rubocop:enable Metrics/MethodLength

def add_tags(scope, waf_result)
def tag_and_keep!(scope, waf_result)
# We want to keep the trace in case of security event
scope.trace.keep! if scope.trace

if scope.service_entry_span
scope.service_entry_span.set_tag('appsec.blocked', 'true') if waf_result.actions.include?('block')
scope.service_entry_span.set_tag('appsec.event', 'true')
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/appsec/monitor/gateway/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def watch_user_id(gateway = Instrumentation.gateway)

# We want to keep the trace in case of security event
scope.trace.keep! if scope.trace
Datadog::AppSec::Event.add_tags(scope, result)
Datadog::AppSec::Event.tag_and_keep!(scope, result)
scope.processor_context.events << event
end
end
Expand Down
2 changes: 1 addition & 1 deletion sig/datadog/appsec/event.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Datadog

def self.build_service_entry_tags: (Array[Hash[::Symbol, untyped]] event_group) -> Hash[::String, untyped]

def self.add_tags: (Datadog::AppSec::Scope scope, Datadog::AppSec::WAF::Result waf_result) -> void
def self.tag_and_keep!: (Datadog::AppSec::Scope scope, Datadog::AppSec::WAF::Result waf_result) -> void

private

Expand Down
4 changes: 2 additions & 2 deletions spec/datadog/appsec/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@
end
end

describe '.add_tags' do
describe '.tag_and_keep!' do
let(:with_trace) { true }
let(:with_span) { true }

Expand Down Expand Up @@ -397,7 +397,7 @@
# prevent rate limiter to bias tests
Datadog::AppSec::RateLimiter.reset!

described_class.add_tags(scope, waf_result)
described_class.tag_and_keep!(scope, waf_result)
end

context 'with no actions' do
Expand Down

0 comments on commit 73f8af2

Please sign in to comment.