From 99c0e5fc745314fa75943156a62c771dd1bedd30 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Tue, 5 Nov 2024 10:28:56 +0100 Subject: [PATCH] Add method name into telemetry in Context#run --- lib/datadog/appsec/processor/context.rb | 4 ++-- spec/datadog/appsec/processor/context_spec.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/datadog/appsec/processor/context.rb b/lib/datadog/appsec/processor/context.rb index ea196d9984..7750d43dba 100644 --- a/lib/datadog/appsec/processor/context.rb +++ b/lib/datadog/appsec/processor/context.rb @@ -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) @@ -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 diff --git a/spec/datadog/appsec/processor/context_spec.rb b/spec/datadog/appsec/processor/context_spec.rb index a482c410ef..debb2a4fc5 100644 --- a/spec/datadog/appsec/processor/context_spec.rb +++ b/spec/datadog/appsec/processor/context_spec.rb @@ -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 @@ -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