git.iko.soy/typeable/katip-rollbar
on master help sign in
5 files changed+82−72
since splitsnapshots
unifiedsplit
.gitignore+1−3 katip-rollbar.cabal+44 package.yaml−24 src/Katip/Scribes/Rollbar.hs+26−42 stack.yaml+11−3
.gitignore+1−3
@@ -1,7 +1,5 @@
11### Project specific ###
22
3−*.cabal
4−
53# Created by https://www.gitignore.io/api/vim,osx,linux,macos,emacs,windows,haskell,visualstudiocode
64
75### Emacs ###
@@ -184,4 +182,4 @@ $RECYCLE.BIN/
184182*.lnk
185183
186184
187−# End of https://www.gitignore.io/api/vim,osx,linux,macos,emacs,windows,haskell,visualstudiocode
185+# End of https://www.gitignore.io/api/vim,osx,linux,macos,emacs,windows,haskell,visualstudiocode
katip-rollbar.cabalnew file+44
@@ -0,0 +1,44 @@
1+cabal-version: 1.12
2+
3+-- This file has been generated from package.yaml by hpack version 0.35.1.
4+--
5+-- see: https://github.com/sol/hpack
6+
7+name: katip-rollbar
8+version: 0.3.0.1
9+synopsis: Katip scribe that logs to Rollbar
10+category: Logging
11+homepage: https://github.com/joneshf/katip-rollbar#readme
12+bug-reports: https://github.com/joneshf/katip-rollbar/issues
13+author: Hardy Jones
14+maintainer: jones3.hardy@gmail.com
15+copyright: 2018 Hardy Jones
16+license: BSD3
17+license-file: LICENSE
18+build-type: Simple
19+extra-source-files:
20+ README.md
21+
22+source-repository head
23+ type: git
24+ location: https://github.com/joneshf/katip-rollbar
25+
26+library
27+ exposed-modules:
28+ Katip.Scribes.Rollbar
29+ other-modules:
30+ Paths_katip_rollbar
31+ hs-source-dirs:
32+ src
33+ build-depends:
34+ aeson >=1.2
35+ , async >=2.1
36+ , base >=4.7
37+ , hostname >=1.0
38+ , http-client >=0.5.10
39+ , katip >=0.8
40+ , rollbar-hs >=0.2
41+ , stm-chans >=3.0
42+ , text >=1.2
43+ , time >=1.8
44+ default-language: Haskell2010
package.yamldeleted−24
@@ -1,24 +0,0 @@
1−author: Hardy Jones
2−category: Logging
3−copyright: 2018 Hardy Jones
4−extra-source-files:
5− - README.md
6−github: joneshf/katip-rollbar
7−library:
8− dependencies:
9− - aeson >= 1.2 && < 1.3
10− - async >= 2.1 && < 2.2
11− - base >= 4.7 && < 5
12− - hostname >= 1.0 && < 1.1
13− - http-client >= 0.5.10
14− - katip >= 0.5 && < 0.6
15− - rollbar-hs >= 0.2 && < 0.3
16− - stm-chans >= 3.0 && < 3.1
17− - text >= 1.2 && < 1.3
18− - time >= 1.8 && < 1.9
19− source-dirs: src
20−license: BSD3
21−maintainer: jones3.hardy@gmail.com
22−name: katip-rollbar
23−synopsis: Katip scribe that logs to Rollbar
24−version: '0.2.0.0'
src/Katip/Scribes/Rollbar.hs+26−42
@@ -3,6 +3,7 @@
33{-# LANGUAGE NamedFieldPuns #-}
44{-# LANGUAGE OverloadedStrings #-}
55{-# LANGUAGE PackageImports #-}
6+{-# LANGUAGE RankNTypes #-}
67{-# LANGUAGE ScopedTypeVariables #-}
78{-# LANGUAGE TypeOperators #-}
89
@@ -12,11 +13,10 @@ module Katip.Scribes.Rollbar
1213
1314import Prelude hiding (error)
1415
15−import "base" Control.Concurrent.MVar (MVar, newEmptyMVar, putMVar, takeMVar)
16−import "base" Control.Monad (replicateM, when)
17−import "base" Data.Foldable (for_)
18−import "base" Data.Functor (void)
19−import "base" GHC.Conc (atomically)
16+import "base" Control.Monad (replicateM, when)
17+import "base" Data.Foldable (for_)
18+import "base" Data.Functor (void)
19+import "base" GHC.Conc (atomically)
2020
2121import "async" Control.Concurrent.Async (async, waitCatch)
2222import "stm-chans" Control.Concurrent.STM.TBMQueue
@@ -32,8 +32,8 @@ import "text" Data.Text.Lazy.Builder (toLazyText)
3232import "time" Data.Time.Clock (UTCTime)
3333import "katip" Katip
3434 ( LogItem
35− , Scribe(Scribe, liPush, scribeFinalizer)
36− , Severity(DebugS, ErrorS, InfoS, NoticeS, WarningS)
35+ , Scribe(..)
36+ , Severity(..)
3737 , Verbosity
3838 , getEnvironment
3939 , itemJson
@@ -45,6 +45,7 @@ import "katip" Katip
4545 , _itemSeverity
4646 , _itemTime
4747 )
48+import "katip" Katip.Core (PermitFunc)
4849import "hostname" Network.HostName (HostName)
4950import "http-client" Network.HTTP.Client (Manager)
5051import "rollbar-hs" Rollbar.AccessToken (AccessToken)
@@ -72,32 +73,31 @@ import "rollbar-hs" Rollbar.Item.Server
7273import qualified "katip" Katip
7374
7475queueSize :: Int
75−queueSize = 10
76+queueSize = 4096
7677
7778workerSize :: Int
78−workerSize = 3
79+workerSize = 10
7980
80−mkRollbarScribe ::
81− RemoveHeaders headers =>
82− proxy headers ->
83− AccessToken ->
84− Maybe Branch ->
85− Maybe CodeVersion ->
86− Manager ->
87− Severity ->
88− Verbosity ->
89− IO Scribe
90−mkRollbarScribe proxy accessToken branch codeVersion manager severity verbosity = do
81+mkRollbarScribe
82+ :: RemoveHeaders headers
83+ => proxy headers
84+ -> AccessToken
85+ -> Maybe Branch
86+ -> Maybe CodeVersion
87+ -> Manager -- ^ Must support TLS
88+ -> PermitFunc
89+ -> Verbosity
90+ -> IO Scribe
91+mkRollbarScribe proxy accessToken branch codeVersion manager scribePermitItem verbosity = do
9192 queue <- newTBMQueueIO queueSize
92− finalize <- newEmptyMVar
93− setupWorkers proxy queue finalize manager
94− let liPush item = when (permitItem severity item) $
93+ workers <- replicateM workerSize (async $ mkWorker proxy manager queue)
94+ let liPush item =
9595 atomically (writeTBMQueue queue $ rollbarItem' item)
9696 rollbarItem' item = rollbarItem proxy accessToken branch codeVersion verbosity item
9797 scribeFinalizer = do
98− putMVar finalize ()
99− takeMVar finalize
100− pure Scribe { liPush, scribeFinalizer }
98+ atomically (closeTBMQueue queue)
99+ for_ workers waitCatch
100+ pure Scribe { liPush, scribeFinalizer, scribePermitItem }
101101
102102rollbarItem ::
103103 (LogItem a, RemoveHeaders headers) =>
@@ -141,22 +141,6 @@ rollbarItem _ accessToken branch serverCodeVersion verbosity item =
141141 value :: Value
142142 value = itemJson verbosity item
143143
144−-- | Setup the workers and wait until the finalizer is evaluated.
145−-- Then, close the queueu, wait for the workers and continue finalization.
146−setupWorkers ::
147− RemoveHeaders headers =>
148− proxy headers ->
149− TBMQueue (Item Value ("Authorization" ': headers)) ->
150− MVar () ->
151− Manager ->
152− IO ()
153−setupWorkers proxy queue finalize manager = void $ async $ do
154− workers <- replicateM workerSize (async $ mkWorker proxy manager queue)
155− takeMVar finalize
156− atomically (closeTBMQueue queue)
157− for_ workers waitCatch
158− putMVar finalize ()
159−
160144mkWorker ::
161145 (RemoveHeaders headers) =>
162146 proxy headers ->
stack.yaml+11−3
@@ -1,6 +1,14 @@
1−flags: {}
1+resolver: lts-20.5
2+
23packages:
34- .
5+
46extra-deps:
5−- rollbar-hs-0.2.0.0
6−resolver: lts-10.5
7+- git: https://github.com/typeable/rollbar-hs.git
8+ commit: cf2e2a5df04b9d1e30dba18d2219b645c3c7b051
9+
10+nix:
11+ packages:
12+ - zlib
13+
14+flags: {}