Skip to content

Commit

Permalink
Pass user info to Sentry (dependabot#8188)
Browse files Browse the repository at this point in the history
It could be useful to be able to prioritize errors by the number of
repos affected.
  • Loading branch information
deivid-rodriguez authored Oct 27, 2023
1 parent 8071217 commit cb578cf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
4 changes: 4 additions & 0 deletions updater/lib/dependabot/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ def repo_private?
@repo_private
end

def repo_owner
source&.organization
end

def updating_a_pull_request?
@updating_a_pull_request
end
Expand Down
5 changes: 4 additions & 1 deletion updater/lib/dependabot/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ def capture_exception(error:, job: nil, dependency: nil, dependency_group: nil,
extra: extra.merge({
dependency_name: dependency&.name,
dependency_group: dependency_group&.name
}.compact)
}.compact),
user: {
id: job&.repo_owner
}
}
)
end
Expand Down
27 changes: 23 additions & 4 deletions updater/spec/dependabot/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,24 @@
Dependabot::DependabotError.new("Something went wrong")
end

it "delegates error capture to Sentry (Raven)" do
it "delegates error capture to Sentry (Raven), adding user info if any" do
service.capture_exception(error: error, tags: { foo: "bar" }, extra: { baz: "qux" })

expect(Raven).to have_received(:capture_exception).with(error, tags: { foo: "bar" }, extra: { baz: "qux" })
expect(Raven).to have_received(:capture_exception)
.with(error,
tags: {
foo: "bar"
},
extra: {
baz: "qux"
},
user: {
id: nil
})
end

it "extracts information from a job if provided" do
job = OpenStruct.new(id: 1234, package_manager: "bundler", repo_private?: false)
job = OpenStruct.new(id: 1234, package_manager: "bundler", repo_private?: false, repo_owner: "foo")
service.capture_exception(error: error, job: job)

expect(Raven).to have_received(:capture_exception)
Expand All @@ -267,7 +277,10 @@
package_manager: "bundler",
repo_private: false
},
extra: {})
extra: {},
user: {
id: "foo"
})
end

it "extracts information from a dependency if provided" do
Expand All @@ -279,6 +292,9 @@
tags: {},
extra: {
dependency_name: "lodash"
},
user: {
id: nil
})
end

Expand All @@ -292,6 +308,9 @@
tags: {},
extra: {
dependency_group: "all-the-things"
},
user: {
id: nil
})
end
end
Expand Down

0 comments on commit cb578cf

Please sign in to comment.