diff --git a/lib/bugsnag.rb b/lib/bugsnag.rb index 178ce0efc..7d215b3d6 100644 --- a/lib/bugsnag.rb +++ b/lib/bugsnag.rb @@ -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 diff --git a/lib/bugsnag/session_tracker.rb b/lib/bugsnag/session_tracker.rb index d57e227c7..65c0f98a5 100644 --- a/lib/bugsnag/session_tracker.rb +++ b/lib/bugsnag/session_tracker.rb @@ -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 @@ -27,6 +25,8 @@ def self.get_current_session ## # Initializes the session tracker. def initialize + require 'concurrent' + @session_counts = Concurrent::Hash.new(0) end @@ -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 \ No newline at end of file +end