-
Notifications
You must be signed in to change notification settings - Fork 955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate from sentry-raven
to sentry-ruby
#8818
Changes from all commits
85251aa
e890388
196c312
b1b9dd1
4ed2b1a
d719fc2
b9a9ca0
428e8a9
b3d05b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# 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 { returns(T::Boolean) } | ||
attr_accessor :propagate_traces | ||
|
||
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 |
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, SentryContext].reduce(event) do |acc, processor| | ||
processor.new.process(acc, hint) | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
require "sorbet-runtime" | ||
|
||
require "dependabot/sentry/processor" | ||
|
||
class SentryContext < ::Dependabot::Sentry::Processor | ||
sig do | ||
override | ||
.params( | ||
event: Sentry::Event, | ||
hint: T::Hash[Symbol, T.untyped] | ||
) | ||
.returns(Sentry::Event) | ||
end | ||
def process(event, hint) | ||
if (exception = hint[:exception]) | ||
exception.raven_context.each do |key, value| | ||
event.send("#{key}=", value) | ||
end | ||
end | ||
Comment on lines
+18
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copied from the migration guide here: https://docs.sentry.io/platforms/ruby/migration/#exceptionraven_context |
||
event | ||
end | ||
end |
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. | ||
|
@@ -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 | ||
|
@@ -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 | ||
Comment on lines
+106
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
) | ||
end | ||
|
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__) | ||
|
||
|
@@ -40,7 +42,8 @@ | |
devcontainers | ||
)}x | ||
|
||
config.processors += [ExceptionSanitizer] | ||
config.before_send = ->(event, hint) { Dependabot::Sentry::Processor.process_chain(event, hint) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I had to migrate |
||
config.propagate_traces = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This prevents Sentry adding If we want to get this distributed trace information, we'll need to ignore these headers in our updater proxy. References: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think disabling is the right call as Dependabot makes most calls to external endpoints that don't care about our tracing. |
||
end | ||
|
||
require "dependabot/opentelemetry" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tapioca gem sentry-ruby
generates an empty file, so this is minimal handwritten types for our uses.