Skip to content

Sentry.with_child_span didn't handle current scope is nil #1818

@elct9620

Description

@elct9620

Issue Description

def with_child_span(**attributes, &block)
current_span = get_current_scope.get_span
if current_span
result = nil
begin
current_span.with_child_span(**attributes) do |child_span|
get_current_scope.set_span(child_span)
result = yield(child_span)
end
ensure
get_current_scope.set_span(current_span)
end
result
else
yield(nil)
end
end

The get_current_scope will return nil before initialized then the with_child_span will failed.

Reproduction Steps

require 'sentry-ruby'

# May raise exception if Sentry not ready
Sentry.with_child_span do |child_span|
  # ...
end

Expected Behavior

Ignore the span until Sentry is ready.

Actual Behavior

Raised UndefinedMethod error

Ruby Version

2.7.6

SDK Version

5.3.0

Integration and Its Version

Sequel

Sentry Config

No response

Metadata

Metadata

Assignees

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions