Skip to content

Commit

Permalink
Migrate from sentry-raven to sentry-ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMagee committed Jan 18, 2024
1 parent 825e2f0 commit 9c2a457
Show file tree
Hide file tree
Showing 18 changed files with 189 additions and 138 deletions.
23 changes: 0 additions & 23 deletions sorbet/rbi/shims/sentry-raven.rbi

This file was deleted.

52 changes: 52 additions & 0 deletions sorbet/rbi/shims/sentry-ruby.rbi
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# typed: strong
# frozen_string_literal: true

module Sentry
class << self
sig { params(_blk: T.proc.params(arg0: Sentry::Configuration).void).void }
def init(&_blk); end

sig { params(exception: Exception, options: T.untyped).void }
def capture_exception(exception, **options); end
end

class Configuration
sig { returns(T.nilable(::Logger)) }
attr_accessor :logger

sig { returns(T.nilable(String)) }
attr_accessor :project_root

sig { returns(T.nilable(::Regexp)) }
attr_accessor :app_dirs_pattern

sig do
params(
value: T.proc
.params(
event: ::Sentry::Event,
hint: T::Hash[Symbol, T.untyped]
)
.returns(::Sentry::Event)
).void
end
def before_send=(value); end
end

class Event; end

class ErrorEvent < ::Sentry::Event
sig { returns(::Sentry::ExceptionInterface) }
attr_reader :exception
end

class ExceptionInterface
sig { returns(T::Array[::Sentry::SingleExceptionInterface]) }
attr_reader :values
end

class SingleExceptionInterface
sig { returns(String) }
attr_accessor :value
end
end
2 changes: 0 additions & 2 deletions sorbet/rbi/todo.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
# typed: false

module ::Azure::Error::NotFound; end
module ::Raven; end
class ::Raven::Processor; end
module Bundler::CompactIndexClient::Updater; end
module Bundler::SolveFailure; end
module Dependabot::NpmAndYarn::FileFetcher::Pysch::SyntaxError; end
Expand Down
2 changes: 1 addition & 1 deletion updater/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ gem "opentelemetry-instrumentation-excon", "~> 0.21"
gem "opentelemetry-instrumentation-faraday", "~> 0.23"
gem "opentelemetry-instrumentation-http", "~> 0.23"
gem "opentelemetry-sdk", "~> 1.3"
gem "sentry-raven", "~> 3.1"
gem "sentry-ruby", "~> 5.1"
gem "terminal-table", "~> 3.0.2"

group :test do
Expand Down
7 changes: 4 additions & 3 deletions updater/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ GEM
base64 (0.1.1)
citrus (3.0.2)
commonmarker (0.23.10)
concurrent-ruby (1.2.3)
crack (0.4.5)
rexml
debug (1.8.0)
Expand Down Expand Up @@ -311,8 +312,8 @@ GEM
sawyer (0.9.2)
addressable (>= 2.3.5)
faraday (>= 0.17.3, < 3)
sentry-raven (3.1.2)
faraday (>= 1.0)
sentry-ruby (5.16.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
sorbet-runtime (0.5.11193)
stackprof (0.2.25)
stringio (3.0.8)
Expand Down Expand Up @@ -372,7 +373,7 @@ DEPENDENCIES
rubocop (~> 1.58.0)
rubocop-performance (~> 1.19.0)
rubocop-sorbet (~> 0.7.3)
sentry-raven (~> 3.1)
sentry-ruby (~> 5.1)
stackprof (~> 0.2.16)
terminal-table (~> 3.0.2)
turbo_tests (~> 2.2.0)
Expand Down
10 changes: 6 additions & 4 deletions updater/bin/fetch_files.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# typed: false
# typed: strict
# frozen_string_literal: true

$LOAD_PATH.unshift(__dir__ + "/../lib")
require "sorbet-runtime"

$LOAD_PATH.unshift(T.must(__dir__) + "/../lib")

$stdout.sync = true

require "raven"
require "sentry-ruby"
require "dependabot/setup"
require "dependabot/file_fetcher_command"
require "debug" if ENV["DEBUG"]
Expand All @@ -16,7 +18,7 @@ class UpdaterKilledError < StandardError; end
puts "Received SIGTERM"
error = UpdaterKilledError.new("Updater process killed with SIGTERM")
tags = { "gh.dependabot_api.update_job.id": ENV.fetch("DEPENDABOT_JOB_ID", nil) }
Raven.capture_exception(error, tags: tags)
Sentry.capture_exception(error, tags: tags)
exit
end

Expand Down
4 changes: 2 additions & 2 deletions updater/bin/update_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

$stdout.sync = true

require "raven"
require "sentry-ruby"
require "dependabot/setup"
require "dependabot/update_files_command"
require "debug" if ENV["DEBUG"]
Expand All @@ -16,7 +16,7 @@ class UpdaterKilledError < StandardError; end
puts "Received SIGTERM"
error = UpdaterKilledError.new("Updater process killed with SIGTERM")
tags = { "gh.dependabot_api.update_job.id": ENV.fetch("DEPENDABOT_JOB_ID", nil) }
Raven.capture_exception(error, tags: tags)
Sentry.capture_exception(error, tags: tags)
exit
end

Expand Down
1 change: 0 additions & 1 deletion updater/lib/dependabot/base_command.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# typed: true
# frozen_string_literal: true

require "raven"
require "dependabot/api_client"
require "dependabot/service"
require "dependabot/logger"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# typed: strong
# frozen_string_literal: true

require "raven"
require "sentry-ruby"
require "sorbet-runtime"
require "dependabot/sentry/processor"

# ExceptionSanitizer filters potential secrets/PII from exception payloads
class ExceptionSanitizer < Raven::Processor
class ExceptionSanitizer < ::Dependabot::Sentry::Processor
extend T::Sig

REPO = %r{[\w.\-]+/([\w.\-]+)}
Expand All @@ -18,21 +19,24 @@ class ExceptionSanitizer < Raven::Processor
)

sig do
params(data: T::Hash[Symbol, T.nilable(T::Hash[Symbol, T::Array[T::Hash[Symbol, String]]])])
.returns(T::Hash[Symbol, T.untyped])
override
.params(
event: ::Sentry::Event,
_hint: T::Hash[Symbol, T.untyped]
)
.returns(::Sentry::Event)
end
def process(data)
return data unless data.dig(:exception, :values)
def process(event, _hint)
return event unless event.is_a?(::Sentry::ErrorEvent)

T.must(data[:exception])[:values] = T.must(data.dig(:exception, :values)).map do |e|
event.exception.values.each do |e|
PATTERNS.each do |key, regex|
e[:value] = T.must(e[:value]).gsub(regex) do |match|
e.value = e.value.gsub(regex) do |match|
match.sub(/#{T.must(Regexp.last_match).captures.compact.first}\z/, "[FILTERED_#{key.to_s.upcase}]")
end
end
e
end

data
event
end
end
35 changes: 35 additions & 0 deletions updater/lib/dependabot/sentry/processor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# typed: strong
# frozen_string_literal: true

require "sorbet-runtime"

module Dependabot
module Sentry
class Processor
extend T::Sig
extend T::Helpers

abstract!

# Process an event before it is sent to Sentry
sig do
abstract
.params(
event: ::Sentry::Event,
hint: T::Hash[Symbol, T.untyped]
)
.returns(::Sentry::Event)
end
def process(event, hint); end

# The default processor chain.
# This chain is applied in the order of the array.
sig { params(event: ::Sentry::Event, hint: T::Hash[Symbol, T.untyped]).returns(::Sentry::Event) }
def self.process_chain(event, hint)
[ExceptionSanitizer].reduce(event) do |acc, processor|
processor.new.process(acc, hint)
end
end
end
end
end
33 changes: 16 additions & 17 deletions updater/lib/dependabot/service.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# typed: strict
# frozen_string_literal: true

require "raven"
require "sentry-ruby"
require "sorbet-runtime"
require "terminal-table"

require "dependabot/api_client"
require "dependabot/opentelemetry"
require "sorbet-runtime"

# This class provides an output adapter for the Dependabot Service which manages
# communication with the private API as well as consolidated error handling.
Expand Down Expand Up @@ -83,7 +84,7 @@ def update_dependency_list(dependency_snapshot:)
client.update_dependency_list(dependency_payload, dependency_file_paths)
end

# This method wraps the Raven client as the Application error tracker
# This method wraps the Sentry client as the Application error tracker
# the service uses to notice errors.
#
# This should be called as an alternative/in addition to record_update_job_error
Expand All @@ -100,21 +101,19 @@ def update_dependency_list(dependency_snapshot:)
end
def capture_exception(error:, job: nil, dependency: nil, dependency_group: nil, tags: {}, extra: {})
::Dependabot::OpenTelemetry.record_exception(error: error, job: job, tags: tags)
T.unsafe(Raven).capture_exception(
::Sentry.capture_exception(
error,
{
tags: tags.merge({
"gh.dependabot_api.update_job.id": job&.id,
"gh.dependabot_api.update_config.package_manager": job&.package_manager,
"gh.repo.is_private": job&.repo_private?
}.compact),
extra: extra.merge({
dependency_name: dependency&.name,
dependency_group: dependency_group&.name
}.compact),
user: {
id: job&.repo_owner
}
tags: tags.merge({
"gh.dependabot_api.update_job.id": job&.id,
"gh.dependabot_api.update_config.package_manager": job&.package_manager,
"gh.repo.is_private": job&.repo_private?
}.compact),
extra: extra.merge({
dependency_name: dependency&.name,
dependency_group: dependency_group&.name
}.compact),
user: {
id: job&.repo_owner
}
)
end
Expand Down
10 changes: 6 additions & 4 deletions updater/lib/dependabot/setup.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# typed: strict
# frozen_string_literal: true

require "sentry-ruby"

require "dependabot/environment"
require "dependabot/logger"
require "dependabot/logger/formats"
require "dependabot/environment"
require "dependabot/sentry/processor"

Dependabot.logger = Logger.new($stdout).tap do |logger|
logger.level = Dependabot::Environment.log_level
logger.formatter = Dependabot::Logger::BasicFormatter.new
end

require "dependabot/sentry"
Raven.configure do |config|
Sentry.init do |config|
config.logger = Dependabot.logger
config.project_root = File.expand_path("../../..", __dir__)

Expand Down Expand Up @@ -39,7 +41,7 @@
swift
)}x

config.processors += [ExceptionSanitizer]
config.before_send = ->(event, hint) { Dependabot::Sentry::Processor.process_chain(event, hint) }
end

require "dependabot/opentelemetry"
Expand Down
2 changes: 1 addition & 1 deletion updater/spec/dependabot/file_fetcher_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
end

it "retries the job when the rate-limit is reset and reports api error" do
expect(Raven).not_to receive(:capture_exception)
expect(Sentry).not_to receive(:capture_exception)
expect(api_client)
.to receive(:record_update_job_error)
.with(
Expand Down
Loading

0 comments on commit 9c2a457

Please sign in to comment.