Skip to content

Commit 013fbb8

Browse files
committed
Hide Warp exceptions better in logs
1 parent 5848c2a commit 013fbb8

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

flora.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ common common-rts-options
6969
-rtsopts
7070
-threaded
7171
"-with-rtsopts=-N -Iw1 --disable-delayed-os-memory-return -T"
72+
7273
-- Use TCMalloc instead of glibc's malloc.
7374
if !(os(osx) && arch(aarch64))
7475
pkgconfig-depends: libtcmalloc

src/web/FloraWeb/Common/Tracing.hs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module FloraWeb.Common.Tracing where
22

33
import Control.Exception (AsyncException (..), Exception (..), SomeException, throw)
4+
import Control.Monad (when)
45
import Data.Aeson qualified as Aeson
56
import Data.ByteString.Char8 (unpack)
67
import Data.Maybe (isJust)
@@ -30,38 +31,38 @@ handleExceptions
3031
handleExceptions logger environment mltp mRequest e@(E.SomeException exception) = do
3132
Log.runLogT "flora-production" logger LogAttention $ do
3233
let context = E.displayExceptionContext $ E.someExceptionContext e
33-
Log.logAttention "Unhandled exception" $
34-
Aeson.object
35-
[ "exception" .= display (show exception)
36-
, "backtraces" .= context
37-
]
38-
case mltp.sentryDSN of
39-
Nothing -> throw exception
40-
Just sentryDSN ->
41-
if shouldDisplayException e && isJust mRequest
42-
then do
43-
sentryService <-
34+
when (shouldDisplayException e) $ do
35+
Log.logAttention "Unhandled exception" $
36+
Aeson.object
37+
[ "exception" .= display (show exception)
38+
, "backtraces" .= context
39+
]
40+
case mltp.sentryDSN of
41+
Nothing -> throw exception
42+
Just sentryDSN ->
43+
if isJust mRequest
44+
then do
45+
sentryService <-
46+
liftIO $
47+
initRaven
48+
sentryDSN
49+
(\defaultRecord -> defaultRecord{srEnvironment = Just $ show environment})
50+
sendRecord
51+
silentFallback
4452
liftIO $
45-
initRaven
46-
sentryDSN
47-
(\defaultRecord -> defaultRecord{srEnvironment = Just $ show environment})
48-
sendRecord
49-
silentFallback
50-
liftIO $
51-
register
52-
sentryService
53-
"flora-server"
54-
Error
55-
(formatMessage mRequest e)
56-
(recordUpdate mRequest e)
57-
liftIO $ defaultOnException mRequest e
58-
else liftIO $ defaultOnException mRequest e
53+
register
54+
sentryService
55+
"flora-server"
56+
Error
57+
(formatMessage mRequest e)
58+
(recordUpdate mRequest e)
59+
liftIO $ defaultOnException mRequest e
60+
else liftIO $ defaultOnException mRequest e
5961

6062
shouldDisplayException :: SomeException -> Bool
6163
shouldDisplayException exception
6264
| Just ThreadKilled <- fromException exception = False
6365
| Just TimeoutThread <- fromException exception = False
64-
| Just ConnectionClosedByPeer <- fromException exception = False
6566
| Just (_ :: InvalidRequest) <- fromException exception = False
6667
| Just (ioeGetErrorType -> et) <- fromException exception
6768
, et == ResourceVanished || et == InvalidArgument =

0 commit comments

Comments
 (0)