Skip to content

Commit

Permalink
[#1401] add sentryenv field to backend config
Browse files Browse the repository at this point in the history
  • Loading branch information
jankun4 committed Jun 26, 2024
1 parent fa1c0dd commit 52404b8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ changes.

## [Unreleased]

- Added 'sentryenv' field in backend config file [Issue 1401](https://github.com/IntersectMBO/govtool/issues/1401)
- Add wallet connector package [Issue 898](https://github.com/IntersectMBO/govtool/issues/898)
- Change DRep without metadata name from "Sole Voter" to "Direct Voter" [Issue 880](https://github.com/IntersectMBO/govtool/issues/880)
- Inicialize Usersnap into App [Issue 546](https://github.com/IntersectMBO/govtool/issues/546)
Expand Down
12 changes: 7 additions & 5 deletions govtool/backend/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ exceptionHandler vvaConfig mRequest exception = do
print exception
guard (show exception /= "Thread killed by timeout manager")
guard (show exception /= "Warp: Client closed connection prematurely")
let env = sentryEnv vvaConfig
sentryService <-
initRaven
(sentryDSN vvaConfig)
Expand All @@ -156,20 +157,21 @@ exceptionHandler vvaConfig mRequest exception = do
"vva.be"
Error
(formatMessage mRequest exception)
(recordUpdate mRequest exception)
(recordUpdate env mRequest exception)



formatMessage :: Maybe Request -> SomeException -> String
formatMessage Nothing exception = "Exception before request could be parsed: " ++ show exception
formatMessage (Just request) exception = "Exception " ++ show exception ++ " while handling request " ++ show request

recordUpdate :: Maybe Request -> SomeException -> SentryRecord -> SentryRecord
recordUpdate Nothing exception record = record
recordUpdate (Just request) exception record =
recordUpdate :: String -> Maybe Request -> SomeException -> SentryRecord -> SentryRecord
recordUpdate env Nothing exception record = record { srEnvironment = Just env }
recordUpdate env (Just request) exception record =
record
{ srCulprit = Just $ unpack $ rawPathInfo request,
srServerName = unpack <$> requestHeaderHost request
srServerName = unpack <$> requestHeaderHost request,
srEnvironment = Just env
}

shouldDisplayException :: SomeException -> Bool
Expand Down
1 change: 1 addition & 0 deletions govtool/backend/example-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"host" : "localhost",
"cachedurationseconds": 20,
"sentrydsn": "https://username:[email protected]/id",
"sentryenv": "development",
"metadatavalidationhost": "localhost",
"metadatavalidationport": 3001,
"metadatavalidationmaxconcurrentrequests": 10
Expand Down
6 changes: 6 additions & 0 deletions govtool/backend/src/VVA/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ data VVAConfigInternal
, vVaConfigInternalCacheDurationSeconds :: Int
-- | Sentry DSN
, vVAConfigInternalSentrydsn :: String
-- | Sentry environment
, vVAConfigInternalSentryEnv :: String
-- | Metadata validation service host
, vVAConfigInternalMetadataValidationHost :: Text
-- | Metadata validation service port
Expand All @@ -97,6 +99,7 @@ instance DefaultConfig VVAConfigInternal where
vVAConfigInternalHost = "localhost",
vVaConfigInternalCacheDurationSeconds = 20,
vVAConfigInternalSentrydsn = "https://username:[email protected]/id",
vVAConfigInternalSentryEnv = "development",
vVAConfigInternalMetadataValidationHost = "localhost",
vVAConfigInternalMetadataValidationPort = 3001,
vVAConfigInternalMetadataValidationMaxConcurrentRequests = 10
Expand All @@ -115,6 +118,8 @@ data VVAConfig
, cacheDurationSeconds :: Int
-- | Sentry DSN
, sentryDSN :: String
-- | Sentry environment
, sentryEnv :: String
-- | Metadata validation service host
, metadataValidationHost :: Text
-- | Metadata validation service port
Expand Down Expand Up @@ -161,6 +166,7 @@ convertConfig VVAConfigInternal {..} =
serverHost = vVAConfigInternalHost,
cacheDurationSeconds = vVaConfigInternalCacheDurationSeconds,
sentryDSN = vVAConfigInternalSentrydsn,
sentryEnv = vVAConfigInternalSentryEnv,
metadataValidationHost = vVAConfigInternalMetadataValidationHost,
metadataValidationPort = vVAConfigInternalMetadataValidationPort,
metadataValidationMaxConcurrentRequests = vVAConfigInternalMetadataValidationMaxConcurrentRequests
Expand Down
1 change: 1 addition & 0 deletions scripts/govtool/config/templates/backend-config.json.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"host" : "0.0.0.0",
"cachedurationseconds": 20,
"sentrydsn": "<SENTRY_DSN>",
"sentryenv": "<SENTRY_ENV>",
"metadatavalidationhost": "http://metadata-validation",
"metadatavalidationport": "3000",
"metadatavalidationmaxconcurrentrequests": 10
Expand Down

0 comments on commit 52404b8

Please sign in to comment.