Skip to content

Commit

Permalink
Improve regex
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Aug 29, 2024
1 parent 4aae539 commit 5a132b7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions lib/datadog/core/telemetry/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@ module Logging

# Extract datadog stack trace from the exception
module DatadogStackTrace
REGEX = %r{datadog-.*?/lib/datadog/}.freeze
# Typically, `lib` is under `#{gem_name}-#{version}/`
# but not the case when providing a bundler custom path in `Gemfile`
REGEX = %r{/lib/datadog/}.freeze

def self.from(exception)
return unless exception.backtrace
backtrace = exception.backtrace

return unless backtrace
return if backtrace.empty?

stack_trace = +''
(exception.backtrace || []).each do |line|
backtrace.each do |line|
stack_trace << if line.match?(REGEX)
# Removing host related information
line.sub(/^.*?(#{REGEX})/o, '\1') << ','
else
'REDACTED,'
Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/core/telemetry/logging_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@

expect(result).to eq(
[
'datadog-2.3.0.beta1/lib/datadog/core/telemetry/logging.rb:1 in `report`',
'/lib/datadog/core/telemetry/logging.rb:1 in `report`',
'REDACTED',
'REDACTED',
'REDACTED'
Expand Down

0 comments on commit 5a132b7

Please sign in to comment.