Skip to content

Commit

Permalink
Merge pull request #606 from bugsnag/reduce-memory-overhead
Browse files Browse the repository at this point in the history
Reduce the memory overhead of Bugsnag when session tracking isn't enabled
  • Loading branch information
imjoehaines committed Jul 23, 2020
2 parents d3c6d2b + a7c2c2b commit 84aac9d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions lib/bugsnag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ class << self
def configure(validate_api_key=true)
yield(configuration) if block_given?

# Create the session tracker if sessions are enabled to avoid the overhead
# of creating it on the first request. We skip this if we're not validating
# the API key as we use this internally before the user's configure block
# has run, so we don't know if sessions are enabled yet.
session_tracker if validate_api_key && configuration.auto_capture_sessions

check_key_valid if validate_api_key
check_endpoint_setup

Expand Down
6 changes: 3 additions & 3 deletions lib/bugsnag/session_tracker.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
require 'thread'
require 'time'
require 'securerandom'
require 'concurrent'

module Bugsnag
class SessionTracker

THREAD_SESSION = "bugsnag_session"
SESSION_PAYLOAD_VERSION = "1.0"
MUTEX = Mutex.new
Expand All @@ -27,6 +25,8 @@ def self.get_current_session
##
# Initializes the session tracker.
def initialize
require 'concurrent'

@session_counts = Concurrent::Hash.new(0)
end

Expand Down Expand Up @@ -139,4 +139,4 @@ def deliver(session_payload)
Bugsnag::Delivery[Bugsnag.configuration.delivery_method].deliver(Bugsnag.configuration.session_endpoint, payload, Bugsnag.configuration, options)
end
end
end
end

0 comments on commit 84aac9d

Please sign in to comment.