Skip to content

Commit

Permalink
Add mutex sync to SessionFlusher aggregates (#2469)
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py authored Nov 28, 2024
1 parent a9b3687 commit f225138
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
- Fix `send_default_pii` handling in rails controller spans [#2443](https://github.com/getsentry/sentry-ruby/pull/2443)
- Fixes [#2438](https://github.com/getsentry/sentry-ruby/issues/2438)
- Fix `RescuedExceptionInterceptor` to handle an empty configuration [#2428](https://github.com/getsentry/sentry-ruby/pull/2428)
- Add mutex sync to `SessionFlusher` aggregates [#2469](https://github.com/getsentry/sentry-ruby/pull/2469)
- Fixes [#2468](https://github.com/getsentry/sentry-ruby/issues/2468)

## 5.21.0

Expand Down
12 changes: 8 additions & 4 deletions sentry-ruby/lib/sentry/session_flusher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def initialize(configuration, client)
@pending_aggregates = {}
@release = configuration.release
@environment = configuration.environment
@mutex = Mutex.new

log_debug("[Sessions] Sessions won't be captured without a valid release") unless @release
end
Expand All @@ -18,7 +19,6 @@ def flush
return if @pending_aggregates.empty?

@client.capture_envelope(pending_envelope)
@pending_aggregates = {}
end

alias_method :run, :flush
Expand All @@ -42,11 +42,15 @@ def init_aggregates(aggregation_key)
end

def pending_envelope
envelope = Envelope.new
aggregates = @mutex.synchronize do
aggregates = @pending_aggregates.values
@pending_aggregates = {}
aggregates
end

envelope = Envelope.new
header = { type: "sessions" }
payload = { attrs: attrs, aggregates: @pending_aggregates.values }

payload = { attrs: attrs, aggregates: aggregates }
envelope.add_item(header, payload)
envelope
end
Expand Down

0 comments on commit f225138

Please sign in to comment.