Skip to content

Commit

Permalink
[APPSEC-56128] Replace telemetry error with report
Browse files Browse the repository at this point in the history
  • Loading branch information
Strech committed Dec 12, 2024
1 parent 3c0de7d commit 413066f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 7 additions & 2 deletions lib/datadog/appsec/processor/context.rb
Original file line number Diff line number Diff line change
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-rb internal low-level error')
@telemetry.report(e, description: "#{@libddwaf_debug_tag} internal low-level error")

[:err_internal, WAF::Result.new(:err_internal, [], 0.0, false, [], [])]
end
Expand All @@ -92,8 +92,13 @@ def report_execution(result)
else
message = "#{@libddwaf_debug_tag} execution error: #{result.status.inspect}"

# NOTE: Ruby 3.4.0 allows to pass way faster `Thread::Backtrace::Location`
# via `caller_locations` method
error = WAF::LibDDWAF::Error.new(message)
error.set_backtrace(caller)

Datadog.logger.debug { message }
@telemetry.error(message)
@telemetry.report(error, description: message)
end
end

Expand Down
12 changes: 9 additions & 3 deletions spec/datadog/appsec/processor/context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@
end

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

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

it 'sends telemetry report' do
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-rb internal low-level error')
.with(kind_of(Datadog::AppSec::WAF::LibDDWAF::Error),
description: /libddwaf:[\d.]+ method:ddwaf_run execution error: :err_internal/)

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

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

0 comments on commit 413066f

Please sign in to comment.