From a7c2c2bf08b08d418fb5a7b30dba72a041d3032f Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Thu, 16 Jul 2020 16:49:53 +0100 Subject: [PATCH] Create the session tracker after configure has run Create the session tracker if sessions are enabled to avoid the overhead of creating it on the first request By requiring the concurrent gem in the session tracker's initialize method, we shifted the overhead from startup to the first request. This caused the first request to go from ~10ms to ~70ms (in the Sinatra example app run locally), which is quite alot of overhead --- lib/bugsnag.rb | 6 ++++++ 1 file changed, 6 insertions(+) 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