Skip to content

Commit

Permalink
[#2450] Initialize Sentry service at application start
Browse files Browse the repository at this point in the history
Updated the application to initialize the Sentry service at the
beginning of the app lifecycle rather than during each exception
occurrence. This change ensures that the Sentry service is set up once
when the application starts, saving resources and potentially increasing
the application's performance by avoiding repetitive initializations.
The Sentry service is passed to the exception handler during setup and
is used consistently throughout the application's uptime. This aligns
with the user story's requirement to optimize exception handling
efficiency by centralizing Sentry service initialization.
  • Loading branch information
placek committed Dec 4, 2024
1 parent e78f6e6 commit 8c2c67b
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions govtool/backend/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import System.Clock (TimeSpec (TimeSpec))
import System.IO (stderr)
import System.Log.Raven (initRaven, register, silentFallback)
import System.Log.Raven.Transport.HttpConduit (sendRecord)
import System.Log.Raven.Types (SentryLevel (Error), SentryRecord (..))
import System.Log.Raven.Types (SentryLevel (Error), SentryRecord (..), SentryService)
import System.TimeManager (TimeoutThread (..))

import VVA.API
Expand All @@ -71,12 +71,18 @@ main :: IO ()
main = do
commandLineConfig <- execParser cmdParser
vvaConfig <- loadVVAConfig (clcConfigPath commandLineConfig)
sentryService <-
initRaven
(sentryDSN vvaConfig)
id
sendRecord
silentFallback
case clcCommand commandLineConfig of
StartApp -> startApp vvaConfig
StartApp -> startApp vvaConfig sentryService
ShowConfig -> Text.putStrLn $ vvaConfigToText vvaConfig

startApp :: VVAConfig -> IO ()
startApp vvaConfig = do
startApp :: VVAConfig -> SentryService -> IO ()
startApp vvaConfig sentryService = do
let vvaPort = serverPort vvaConfig
vvaHost = fromString (Text.unpack (serverHost vvaConfig))
settings =
Expand All @@ -92,7 +98,7 @@ startApp vvaConfig = do
++ show vvaPort
)
)
$ setOnException (exceptionHandler vvaConfig) defaultSettings
$ setOnException (exceptionHandler vvaConfig sentryService) defaultSettings
cacheEnv <- do
let newCache = Cache.newCache (Just $ TimeSpec (fromIntegral (cacheDurationSeconds vvaConfig)) 0)
proposalListCache <- newCache
Expand Down Expand Up @@ -122,8 +128,8 @@ startApp vvaConfig = do
server' <- mkVVAServer appEnv
runSettings settings server'

exceptionHandler :: VVAConfig -> Maybe Request -> SomeException -> IO ()
exceptionHandler vvaConfig mRequest exception = do
exceptionHandler :: VVAConfig -> SentryService -> Maybe Request -> SomeException -> IO ()
exceptionHandler vvaConfig sentryService mRequest exception = do
print mRequest
print exception
let isNotTimeoutThread x = case fromException x of
Expand All @@ -135,12 +141,6 @@ exceptionHandler vvaConfig mRequest exception = do
guard . isNotTimeoutThread $ exception
guard . isNotConnectionClosedByPeer $ exception
let env = sentryEnv vvaConfig
sentryService <-
initRaven
(sentryDSN vvaConfig)
id
sendRecord
silentFallback
register
sentryService
"vva.be"
Expand Down

0 comments on commit 8c2c67b

Please sign in to comment.