Skip to content

Commit

Permalink
Add method name into telemetry in Context#run
Browse files Browse the repository at this point in the history
  • Loading branch information
Strech committed Nov 12, 2024
1 parent d84be25 commit 99c0e5f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/datadog/appsec/processor/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(handle, telemetry:)
@events = []
@run_mutex = Mutex.new

@libddwaf_debug_tag = "libddwaf:#{WAF::VERSION::STRING}"
@libddwaf_debug_tag = "libddwaf:#{WAF::VERSION::STRING} method:ddwaf_run"
end

def run(persistent_data, ephemeral_data, timeout = WAF::LibDDWAF::DDWAF_RUN_TIMEOUT)
Expand Down Expand Up @@ -79,7 +79,7 @@ def try_run(persistent_data, ephemeral_data, timeout)
@context.run(persistent_data, ephemeral_data, timeout)
rescue WAF::LibDDWAF::Error => e
Datadog.logger.debug { "#{@libddwaf_debug_tag} execution error: #{e} backtrace: #{e.backtrace&.first(3)}" }
@telemetry.report(e, description: 'libddwaf internal low-level error')
@telemetry.report(e, description: 'libddwaf-rb internal low-level error')

[:err_internal, WAF::Result.new(:err_internal, [], 0.0, false, [], [])]
end
Expand Down
6 changes: 3 additions & 3 deletions spec/datadog/appsec/processor/context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
end

it 'sends telemetry error' do
expect(telemetry).to receive(:error).with(/libddwaf:[\d.]+ execution error: :err_invalid_object/)
expect(telemetry).to receive(:error).with(/libddwaf:[\d.]+ method:ddwaf_run execution error: :err_invalid_object/)

context.run(input, {}, timeout)
end
Expand All @@ -269,9 +269,9 @@
let(:result) { context.run(input, {}, timeout) }

it 'sends telemetry report' do
expect(telemetry).to receive(:error).with(/libddwaf:[\d.]+ execution error: :err_internal/)
expect(telemetry).to receive(:error).with(/libddwaf:[\d.]+ method:ddwaf_run execution error: :err_internal/)
expect(telemetry).to receive(:report)
.with(kind_of(Datadog::AppSec::WAF::LibDDWAF::Error), description: 'libddwaf internal low-level error')
.with(kind_of(Datadog::AppSec::WAF::LibDDWAF::Error), description: 'libddwaf-rb internal low-level error')

expect(result.status).to eq(:err_internal)
end
Expand Down

0 comments on commit 99c0e5f

Please sign in to comment.