Skip to content

Commit

Permalink
Extract duration conversion in Metrics::Exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
Strech committed Jan 21, 2025
1 parent 037c474 commit 728e95d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/datadog/appsec/metrics/exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,24 @@ module Exporter
def export_waf_metrics(metrics, span)
return if metrics.evals.zero?

# expected time is in us
span.set_tag('_dd.appsec.waf.timeouts', metrics.timeouts)
span.set_tag('_dd.appsec.waf.duration', metrics.duration_ns / 1000.0)
span.set_tag('_dd.appsec.waf.duration_ext', metrics.duration_ext_ns / 1000.0)
span.set_tag('_dd.appsec.waf.duration', convert_ns_to_us(metrics.duration_ns))
span.set_tag('_dd.appsec.waf.duration_ext', convert_ns_to_us(metrics.duration_ext_ns))
end

def export_rasp_metrics(metrics, span)
return if metrics.evals.zero?

span.set_tag('_dd.appsec.rasp.rule.eval', metrics.evals)
span.set_tag('_dd.appsec.rasp.timeout', 1) unless metrics.timeouts.zero?
span.set_tag('_dd.appsec.rasp.duration', metrics.duration_ns / 1000.0)
span.set_tag('_dd.appsec.rasp.duration_ext', metrics.duration_ext_ns / 1000.0)
span.set_tag('_dd.appsec.rasp.duration', convert_ns_to_us(metrics.duration_ns))
span.set_tag('_dd.appsec.rasp.duration_ext', convert_ns_to_us(metrics.duration_ext_ns))
end

# private

def convert_ns_to_us(value)
value / 1000.0
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/appsec/metrics/exporter.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Datadog
def self?.export_waf_metrics: (Metrics::Collector::Store metrics, Tracing::SpanOperation span) -> void

def self?.export_rasp_metrics: (Metrics::Collector::Store metrics, Tracing::SpanOperation span) -> void

def self?.convert_ns_to_us: (::Integer value) -> ::Float
end
end
end
Expand Down

0 comments on commit 728e95d

Please sign in to comment.