File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ def initialize(configuration, client)
1010 @pending_aggregates = { }
1111 @release = configuration . release
1212 @environment = configuration . environment
13+ @mutex = Mutex . new
1314
1415 log_debug ( "[Sessions] Sessions won't be captured without a valid release" ) unless @release
1516 end
@@ -18,7 +19,6 @@ def flush
1819 return if @pending_aggregates . empty?
1920
2021 @client . capture_envelope ( pending_envelope )
21- @pending_aggregates = { }
2222 end
2323
2424 alias_method :run , :flush
@@ -42,11 +42,15 @@ def init_aggregates(aggregation_key)
4242 end
4343
4444 def pending_envelope
45- envelope = Envelope . new
45+ aggregates = @mutex . synchronize do
46+ aggregates = @pending_aggregates . values
47+ @pending_aggregates = { }
48+ aggregates
49+ end
4650
51+ envelope = Envelope . new
4752 header = { type : "sessions" }
48- payload = { attrs : attrs , aggregates : @pending_aggregates . values }
49-
53+ payload = { attrs : attrs , aggregates : aggregates }
5054 envelope . add_item ( header , payload )
5155 envelope
5256 end
You can’t perform that action at this time.
0 commit comments