Skip to content

Commit 92302a9

Browse files
authored
Merge 584a8f7 into 4712364
2 parents 4712364 + 584a8f7 commit 92302a9

4 files changed

Lines changed: 18 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
## Unreleased
1+
## 4.7.0
22

33
### Features
44

55
- Add `monotonic_active_support_logger` [#1531](https://github.com/getsentry/sentry-ruby/pull/1531)
66
- Support after-retry reporting to `sentry-sidekiq` [#1532](https://github.com/getsentry/sentry-ruby/pull/1532)
77
- Generate Security Header Endpoint with `Sentry.csp_report_uri` from dsn [#1507](https://github.com/getsentry/sentry-ruby/pull/1507)
8+
- Allow passing backtrace into `Sentry.capture_message` [#1550](https://github.com/getsentry/sentry-ruby/pull/1550)
89

910
### Bug Fixes
1011

sentry-ruby/lib/sentry/client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ def event_from_exception(exception, hint = {})
5757
end
5858
end
5959

60-
def event_from_message(message, hint = {})
60+
def event_from_message(message, hint = {}, backtrace: nil)
6161
integration_meta = Sentry.integrations[hint[:integration]]
6262
event = Event.new(configuration: configuration, integration_meta: integration_meta, message: message)
63-
event.add_threads_interface(backtrace: caller)
63+
event.add_threads_interface(backtrace: backtrace || caller)
6464
event
6565
end
6666

sentry-ruby/lib/sentry/hub.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ def capture_message(message, **options, &block)
108108

109109
options[:hint] ||= {}
110110
options[:hint][:message] = message
111-
event = current_client.event_from_message(message, options[:hint])
111+
backtrace = options.delete(:backtrace)
112+
event = current_client.event_from_message(message, options[:hint], backtrace: backtrace)
112113
capture_event(event, **options, &block)
113114
end
114115

sentry-ruby/spec/sentry/hub_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,18 @@
143143
end.to change { transport.events.count }.by(1)
144144
end
145145

146+
it "takes backtrace option" do
147+
event = subject.capture_message(message, backtrace: ["#{__FILE__}:10:in `foo'"])
148+
event_hash = event.to_hash
149+
expect(event_hash.dig(:threads, :values, 0, :stacktrace, :frames, 0, :function)).to eq("foo")
150+
end
151+
152+
it "assigns default backtrace with caller" do
153+
event = subject.capture_message(message)
154+
event_hash = event.to_hash
155+
expect(event_hash.dig(:threads, :values, 0, :stacktrace, :frames, 0, :function)).to eq("<main>")
156+
end
157+
146158
it_behaves_like "capture_helper" do
147159
let(:capture_helper) { :capture_message }
148160
let(:capture_subject) { message }

0 commit comments

Comments
 (0)