git.iko.soy/typeable/katip-rollbar
on master help sign in
6 files changed+86−80
since splitsnapshots
unifiedsplit
.gitignore+1−3 katip-rollbar.cabal+44 package.yaml−23 src/Katip/Scribes/Rollbar.hs+30−45 src/Lib.hs−6 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−23
@@ -1,23 +0,0 @@
1−author: Hardy Jones
2−category: Web
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−version: '0.1.0.0'
src/Katip/Scribes/Rollbar.hs+30−45
@@ -3,20 +3,22 @@
33{-# LANGUAGE NamedFieldPuns #-}
44{-# LANGUAGE OverloadedStrings #-}
55{-# LANGUAGE PackageImports #-}
6+{-# LANGUAGE RankNTypes #-}
67{-# LANGUAGE ScopedTypeVariables #-}
78{-# LANGUAGE TypeOperators #-}
89
9−module Katip.Scribes.Rollbar where
10+module Katip.Scribes.Rollbar
11+ ( mkRollbarScribe
12+ ) where
1013
1114import Prelude hiding (error)
1215
13−import "base" Control.Concurrent.MVar (MVar, newEmptyMVar, putMVar, takeMVar)
14−import "base" Control.Monad (replicateM, when)
15−import "base" Data.Foldable (for_)
16−import "base" Data.Functor (void)
17−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)
1820
19−import "async" Control.Concurrent.Async (async, waitCatchSTM)
21+import "async" Control.Concurrent.Async (async, waitCatch)
2022import "stm-chans" Control.Concurrent.STM.TBMQueue
2123 ( TBMQueue
2224 , closeTBMQueue
@@ -30,8 +32,8 @@ import "text" Data.Text.Lazy.Builder (toLazyText)
3032import "time" Data.Time.Clock (UTCTime)
3133import "katip" Katip
3234 ( LogItem
33− , Scribe(Scribe, liPush, scribeFinalizer)
34− , Severity(DebugS, ErrorS, InfoS, NoticeS, WarningS)
35+ , Scribe(..)
36+ , Severity(..)
3537 , Verbosity
3638 , getEnvironment
3739 , itemJson
@@ -43,6 +45,7 @@ import "katip" Katip
4345 , _itemSeverity
4446 , _itemTime
4547 )
48+import "katip" Katip.Core (PermitFunc)
4649import "hostname" Network.HostName (HostName)
4750import "http-client" Network.HTTP.Client (Manager)
4851import "rollbar-hs" Rollbar.AccessToken (AccessToken)
@@ -70,32 +73,31 @@ import "rollbar-hs" Rollbar.Item.Server
7073import qualified "katip" Katip
7174
7275queueSize :: Int
73−queueSize = 10
76+queueSize = 4096
7477
7578workerSize :: Int
76−workerSize = 3
79+workerSize = 10
7780
78−mkRollbarScribe ::
79− RemoveHeaders headers =>
80− proxy headers ->
81− AccessToken ->
82− Maybe Branch ->
83− Maybe CodeVersion ->
84− Manager ->
85− Severity ->
86− Verbosity ->
87− IO Scribe
88−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
8992 queue <- newTBMQueueIO queueSize
90− finalize <- newEmptyMVar
91− setupWorkers proxy queue finalize manager
92− let liPush item = when (permitItem severity item) $
93+ workers <- replicateM workerSize (async $ mkWorker proxy manager queue)
94+ let liPush item =
9395 atomically (writeTBMQueue queue $ rollbarItem' item)
9496 rollbarItem' item = rollbarItem proxy accessToken branch codeVersion verbosity item
9597 scribeFinalizer = do
96− putMVar finalize ()
97− takeMVar finalize
98− pure Scribe { liPush, scribeFinalizer }
98+ atomically (closeTBMQueue queue)
99+ for_ workers waitCatch
100+ pure Scribe { liPush, scribeFinalizer, scribePermitItem }
99101
100102rollbarItem ::
101103 (LogItem a, RemoveHeaders headers) =>
@@ -139,23 +141,6 @@ rollbarItem _ accessToken branch serverCodeVersion verbosity item =
139141 value :: Value
140142 value = itemJson verbosity item
141143
142−-- | Setup the workers and wait until the finalizer is evaluated.
143−-- Then, close the queueu, wait for the workers and continue finalization.
144−setupWorkers ::
145− RemoveHeaders headers =>
146− proxy headers ->
147− TBMQueue (Item Value ("Authorization" ': headers)) ->
148− MVar () ->
149− Manager ->
150− IO ()
151−setupWorkers proxy queue finalize manager = void $ async $ do
152− workers <- replicateM workerSize (async $ mkWorker proxy manager queue)
153− takeMVar finalize
154− atomically $ do
155− closeTBMQueue queue
156− for_ workers waitCatchSTM
157− putMVar finalize ()
158−
159144mkWorker ::
160145 (RemoveHeaders headers) =>
161146 proxy headers ->
src/Lib.hsdeleted−6
@@ -1,6 +0,0 @@
1−module Lib
2− ( someFunc
3− ) where
4−
5−someFunc :: IO ()
6−someFunc = putStrLn "someFunc"
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: {}