diff --git a/lib/datadog/core/telemetry/logging.rb b/lib/datadog/core/telemetry/logging.rb index 174fc2fe21a..8fadeafb623 100644 --- a/lib/datadog/core/telemetry/logging.rb +++ b/lib/datadog/core/telemetry/logging.rb @@ -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,' diff --git a/spec/datadog/core/telemetry/logging_spec.rb b/spec/datadog/core/telemetry/logging_spec.rb index ad811d742f6..880c7c90a71 100644 --- a/spec/datadog/core/telemetry/logging_spec.rb +++ b/spec/datadog/core/telemetry/logging_spec.rb @@ -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'