aws-xray-client-persistent: A client for AWS X-Ray integration with Persistent.

[ library, mit, unclassified ] [ Propose Tags ]

Works with `aws-xray-client` to enable X-Ray tracing with Persistent.


[Skip to Readme]
Versions [RSS] [faq] 0.1.0.0, 0.1.0.1, 0.1.0.2
Change log CHANGELOG.md
Dependencies aws-xray-client (>=0.1.0.1), base (>=4.14.1.0 && <5), conduit (>=1.3.4.1), containers (>=0.6.2.1), lens (>=4.19.2), persistent (>=2.13.0.2), random (>=1.2.0), resourcet (>=1.2.4.2), text (>=1.2.4.1), time (>=1.9.3) [details]
License MIT
Copyright 2021 Renaissance Learning Inc
Author Freckle R&D
Maintainer engineering@freckle.com
Home page https://github.com/freckle/aws-xray-client#readme
Bug tracker https://github.com/freckle/aws-xray-client/issues
Source repo head: git clone https://github.com/freckle/aws-xray-client
Uploaded by PatrickBrisbin at 2021-07-01T16:00:36Z
Distributions NixOS:0.1.0.2
Downloads 355 total (68 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2021-07-01 [all 1 reports]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Candidates


Readme for aws-xray-client-persistent-0.1.0.2

[back to package description]

aws-xray-client-persistent

A Haskell client for integrating AWS X-Ray with Persistent.

To use this, you may want choose to define a helper to annotate traces


-- ...

import Data.Pool
import Database.Persist.Sql
import Network.AWS.XRayClient.Persistent

-- ...

runSqlPoolXRay
  :: (backend ~ SqlBackend, MonadUnliftIO m)
  => Text
  -- ^ Subsegment name
  --
  -- The top-level subsegment will be named @\"<this> runSqlPool\"@ and the,
  -- with a lower-level subsegment named @\"<this> query\"@.
  --
  -> XRayVaultData -- ^ Vault data to trace with
  -> ReaderT backend m a
  -> Pool backend
  -> m a
runSqlPoolXRay name vaultData action pool =
  traceXRaySubsegment' vaultData (name <> " runSqlPool") id
    $ withRunInIO
    $ \run -> withResource pool $ \backend -> do
        let
          sendTrace = atomicallyAddVaultDataSubsegment vaultData
          stdGenIORef = xrayVaultDataStdGen vaultData
          subsegmentName = name <> " query"
        run . runSqlConn action =<< liftIO
          (xraySqlBackend sendTrace stdGenIORef subsegmentName backend)

Then you can use this in your runDB definition to trace DB calls

-- ...
instance YesodPersist App where
  type YesodPersistBackend App = SqlBackend
  runDB action = do
    pool <- getsYesod appPool
    mVaultData <- vaultDataFromRequest <$> waiRequest
      
    -- ...

    maybe runSqlPool (runSqlPoolXRay "runDB") mVaultData action' pool