Skip to content

Commit 8bd4054

Browse files
authored
Sentry.with_child_span should check SDK's initialization state (#1819)
* Sentry.with_child_span should check SDK's initialization state * Update changelog
1 parent 0fe8d27 commit 8bd4054

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- Don't require a DB connection, but release one if it is acquired [#1812](https://github.com/getsentry/sentry-ruby/pull/1812)
66
- Fixes [#1808](https://github.com/getsentry/sentry-ruby/issues/1808)
7+
- `Sentry.with_child_span` should check SDK's initialization state [#1819](https://github.com/getsentry/sentry-ruby/pull/1819)
8+
- Fixes [#1818](https://github.com/getsentry/sentry-ruby/issues/1818)
79

810
### Miscellaneous
911

sentry-ruby/lib/sentry-ruby.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,7 @@ def start_transaction(**options)
399399
# end
400400
#
401401
def with_child_span(**attributes, &block)
402-
current_span = get_current_scope.get_span
403-
404-
if current_span
402+
if Sentry.initialized? && current_span = get_current_scope.get_span
405403
result = nil
406404

407405
begin

sentry-ruby/spec/initialization_check_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,10 @@
2525
it do
2626
expect { Sentry.with_scope { raise "foo" } }.not_to raise_error(RuntimeError)
2727
end
28+
29+
it do
30+
result = Sentry.with_child_span { "foo" }
31+
expect(result).to eq("foo")
32+
end
2833
end
2934

0 commit comments

Comments
 (0)