Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sentry-ruby/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- Correct type attribute's usages [#1354](https://github.com/getsentry/sentry-ruby/pull/1354)
- Fix sampling decision precedence [#1335](https://github.com/getsentry/sentry-ruby/pull/1335)
- Fix set_contexts [#1375](https://github.com/getsentry/sentry-ruby/pull/1375)
- Use thread variable instead of fiber variable to store the hub [#1380](https://github.com/getsentry/sentry-ruby/pull/1380)
- Fixes [#1374](https://github.com/getsentry/sentry-ruby/issues/1374)

## 4.3.1

Expand Down
6 changes: 3 additions & 3 deletions sentry-ruby/lib/sentry-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def init(&block)
client = Client.new(config)
scope = Scope.new(max_breadcrumbs: config.max_breadcrumbs)
hub = Hub.new(client, scope)
Thread.current[THREAD_LOCAL] = hub
Thread.current.thread_variable_set(THREAD_LOCAL, hub)
@main_hub = hub
@background_worker = Sentry::BackgroundWorker.new(config)
end
Expand All @@ -92,7 +92,7 @@ def get_current_hub
# ideally, we should do this proactively whenever a new thread is created
# but it's impossible for the SDK to keep track every new thread
# so we need to use this rather passive way to make sure the app doesn't crash
Thread.current[THREAD_LOCAL] || clone_hub_to_current_thread
Thread.current.thread_variable_get(THREAD_LOCAL) || clone_hub_to_current_thread
end

# Returns the current active client.
Expand All @@ -107,7 +107,7 @@ def get_current_scope

# Clones the main thread's active hub and stores it to the current thread.
def clone_hub_to_current_thread
Thread.current[THREAD_LOCAL] = get_main_hub.clone
Thread.current.thread_variable_set(THREAD_LOCAL, get_main_hub.clone)
end

# Takes a block and yields the current active scope.
Expand Down
12 changes: 12 additions & 0 deletions sentry-ruby/spec/sentry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@

new_thread.join
end

it "stores the hub in a thread variable (instead of just fiber variable)" do
Sentry.set_tags(outside_fiber: true)

fiber = Fiber.new do
Sentry.set_tags(inside_fiber: true)
end

fiber.resume

expect(Sentry.get_current_scope.tags).to eq({ outside_fiber: true, inside_fiber: true })
end
end

describe ".configure_scope" do
Expand Down