git.iko.soy/typeable/katip-rollbar
on master help sign in
First pass at a Rollbar scribe

We should handle finalization properly. We can follow the algorithm that the ES scribe uses. Seems a safe bet anyway.

commitbcfc7e78406dbfb26b0fefb5633268c38ee00c51 authorjoneshf <jones3.hardy@gmail.com> dateSun 18 Feb 2018, 23:38 (9 years ago)
9 files changed+566
.gitignore+187 .stylish-haskell.yaml+224 LICENSE+30 README.md+1 Setup.hs+2 package.yaml+19 src/Katip/Scribes/Rollbar.hs+91 src/Lib.hs+6 stack.yaml+6
.gitignorenew file+187
@@ -0,0 +1,187 @@
1+### Project specific ###
2+
3+*.cabal
4+
5+# Created by https://www.gitignore.io/api/vim,osx,linux,macos,emacs,windows,haskell,visualstudiocode
6+
7+### Emacs ###
8+# -*- mode: gitignore; -*-
9+*~
10+\#*\#
11+/.emacs.desktop
12+/.emacs.desktop.lock
13+*.elc
14+auto-save-list
15+tramp
16+.\#*
17+
18+# Org-mode
19+.org-id-locations
20+*_archive
21+
22+# flymake-mode
23+*_flymake.*
24+
25+# eshell files
26+/eshell/history
27+/eshell/lastdir
28+
29+# elpa packages
30+/elpa/
31+
32+# reftex files
33+*.rel
34+
35+# AUCTeX auto folder
36+/auto/
37+
38+# cask packages
39+.cask/
40+dist/
41+
42+# Flycheck
43+flycheck_*.el
44+
45+# server auth directory
46+/server/
47+
48+# projectiles files
49+.projectile
50+projectile-bookmarks.eld
51+
52+# directory configuration
53+.dir-locals.el
54+
55+# saveplace
56+places
57+
58+# url cache
59+url/cache/
60+
61+# cedet
62+ede-projects.el
63+
64+# smex
65+smex-items
66+
67+# company-statistics
68+company-statistics-cache.el
69+
70+# anaconda-mode
71+anaconda-mode/
72+
73+### Haskell ###
74+dist
75+dist-*
76+cabal-dev
77+*.o
78+*.hi
79+*.chi
80+*.chs.h
81+*.dyn_o
82+*.dyn_hi
83+.hpc
84+.hsenv
85+.cabal-sandbox/
86+cabal.sandbox.config
87+*.prof
88+*.aux
89+*.hp
90+*.eventlog
91+.stack-work/
92+cabal.project.local
93+.HTF/
94+
95+### Linux ###
96+
97+# temporary files which can be created if a process still has a handle open of a deleted file
98+.fuse_hidden*
99+
100+# KDE directory preferences
101+.directory
102+
103+# Linux trash folder which might appear on any partition or disk
104+.Trash-*
105+
106+# .nfs files are created when an open file is removed but is still being accessed
107+.nfs*
108+
109+### macOS ###
110+*.DS_Store
111+.AppleDouble
112+.LSOverride
113+
114+# Icon must end with two \r
115+Icon
116+
117+# Thumbnails
118+._*
119+
120+# Files that might appear in the root of a volume
121+.DocumentRevisions-V100
122+.fseventsd
123+.Spotlight-V100
124+.TemporaryItems
125+.Trashes
126+.VolumeIcon.icns
127+.com.apple.timemachine.donotpresent
128+
129+# Directories potentially created on remote AFP share
130+.AppleDB
131+.AppleDesktop
132+Network Trash Folder
133+Temporary Items
134+.apdisk
135+
136+### OSX ###
137+
138+# Icon must end with two \r
139+
140+# Thumbnails
141+
142+# Files that might appear in the root of a volume
143+
144+# Directories potentially created on remote AFP share
145+
146+### Vim ###
147+# swap
148+.sw[a-p]
149+.*.sw[a-p]
150+# session
151+Session.vim
152+# temporary
153+.netrwhist
154+# auto-generated tag files
155+tags
156+
157+### VisualStudioCode ###
158+.vscode/*
159+!.vscode/settings.json
160+!.vscode/tasks.json
161+!.vscode/launch.json
162+!.vscode/extensions.json
163+.history
164+
165+### Windows ###
166+# Windows thumbnail cache files
167+Thumbs.db
168+ehthumbs.db
169+ehthumbs_vista.db
170+
171+# Folder config file
172+Desktop.ini
173+
174+# Recycle Bin used on file shares
175+$RECYCLE.BIN/
176+
177+# Windows Installer files
178+*.cab
179+*.msi
180+*.msm
181+*.msp
182+
183+# Windows shortcuts
184+*.lnk
185+
186+
187+# End of https://www.gitignore.io/api/vim,osx,linux,macos,emacs,windows,haskell,visualstudiocode
.stylish-haskell.yamlnew file+224
@@ -0,0 +1,224 @@
1+# stylish-haskell configuration file
2+# ==================================
3+
4+# The stylish-haskell tool is mainly configured by specifying steps. These steps
5+# are a list, so they have an order, and one specific step may appear more than
6+# once (if needed). Each file is processed by these steps in the given order.
7+steps:
8+ # Convert some ASCII sequences to their Unicode equivalents. This is disabled
9+ # by default.
10+ # - unicode_syntax:
11+ # # In order to make this work, we also need to insert the UnicodeSyntax
12+ # # language pragma. If this flag is set to true, we insert it when it's
13+ # # not already present. You may want to disable it if you configure
14+ # # language extensions using some other method than pragmas. Default:
15+ # # true.
16+ # add_language_pragma: true
17+
18+ # Align the right hand side of some elements. This is quite conservative
19+ # and only applies to statements where each element occupies a single
20+ # line.
21+ - simple_align:
22+ cases: true
23+ top_level_patterns: true
24+ records: true
25+
26+ # Import cleanup
27+ - imports:
28+ # There are different ways we can align names and lists.
29+ #
30+ # - global: Align the import names and import list throughout the entire
31+ # file.
32+ #
33+ # - file: Like global, but don't add padding when there are no qualified
34+ # imports in the file.
35+ #
36+ # - group: Only align the imports per group (a group is formed by adjacent
37+ # import lines).
38+ #
39+ # - none: Do not perform any alignment.
40+ #
41+ # Default: global.
42+ align: group
43+
44+ # The following options affect only import list alignment.
45+ #
46+ # List align has following options:
47+ #
48+ # - after_alias: Import list is aligned with end of import including
49+ # 'as' and 'hiding' keywords.
50+ #
51+ # > import qualified Data.List as List (concat, foldl, foldr, head,
52+ # > init, last, length)
53+ #
54+ # - with_alias: Import list is aligned with start of alias or hiding.
55+ #
56+ # > import qualified Data.List as List (concat, foldl, foldr, head,
57+ # > init, last, length)
58+ #
59+ # - new_line: Import list starts always on new line.
60+ #
61+ # > import qualified Data.List as List
62+ # > (concat, foldl, foldr, head, init, last, length)
63+ #
64+ # Default: after_alias
65+ list_align: with_alias
66+
67+ # Right-pad the module names to align imports in a group:
68+ #
69+ # - true: a little more readable
70+ #
71+ # > import qualified Data.List as List (concat, foldl, foldr,
72+ # > init, last, length)
73+ # > import qualified Data.List.Extra as List (concat, foldl, foldr,
74+ # > init, last, length)
75+ #
76+ # - false: diff-safe
77+ #
78+ # > import qualified Data.List as List (concat, foldl, foldr, init,
79+ # > last, length)
80+ # > import qualified Data.List.Extra as List (concat, foldl, foldr,
81+ # > init, last, length)
82+ #
83+ # Default: true
84+ pad_module_names: true
85+
86+ # Long list align style takes effect when import is too long. This is
87+ # determined by 'columns' setting.
88+ #
89+ # - inline: This option will put as much specs on same line as possible.
90+ #
91+ # - new_line: Import list will start on new line.
92+ #
93+ # - new_line_multiline: Import list will start on new line when it's
94+ # short enough to fit to single line. Otherwise it'll be multiline.
95+ #
96+ # - multiline: One line per import list entry.
97+ # Type with constructor list acts like single import.
98+ #
99+ # > import qualified Data.Map as M
100+ # > ( empty
101+ # > , singleton
102+ # > , ...
103+ # > , delete
104+ # > )
105+ #
106+ # Default: inline
107+ long_list_align: multiline
108+
109+ # Align empty list (importing instances)
110+ #
111+ # Empty list align has following options
112+ #
113+ # - inherit: inherit list_align setting
114+ #
115+ # - right_after: () is right after the module name:
116+ #
117+ # > import Vector.Instances ()
118+ #
119+ # Default: inherit
120+ empty_list_align: inherit
121+
122+ # List padding determines indentation of import list on lines after import.
123+ # This option affects 'long_list_align'.
124+ #
125+ # - <integer>: constant value
126+ #
127+ # - module_name: align under start of module name.
128+ # Useful for 'file' and 'group' align settings.
129+ list_padding: 4
130+
131+ # Separate lists option affects formatting of import list for type
132+ # or class. The only difference is single space between type and list
133+ # of constructors, selectors and class functions.
134+ #
135+ # - true: There is single space between Foldable type and list of it's
136+ # functions.
137+ #
138+ # > import Data.Foldable (Foldable (fold, foldl, foldMap))
139+ #
140+ # - false: There is no space between Foldable type and list of it's
141+ # functions.
142+ #
143+ # > import Data.Foldable (Foldable(fold, foldl, foldMap))
144+ #
145+ # Default: true
146+ separate_lists: false
147+
148+ # Space surround option affects formatting of import lists on a single
149+ # line. The only difference is single space after the initial
150+ # parenthesis and a single space before the terminal parenthesis.
151+ #
152+ # - true: There is single space associated with the enclosing
153+ # parenthesis.
154+ #
155+ # > import Data.Foo ( foo )
156+ #
157+ # - false: There is no space associated with the enclosing parenthesis
158+ #
159+ # > import Data.Foo (foo)
160+ #
161+ # Default: false
162+ space_surround: false
163+
164+ # Language pragmas
165+ - language_pragmas:
166+ # We can generate different styles of language pragma lists.
167+ #
168+ # - vertical: Vertical-spaced language pragmas, one per line.
169+ #
170+ # - compact: A more compact style.
171+ #
172+ # - compact_line: Similar to compact, but wrap each line with
173+ # `{-#LANGUAGE #-}'.
174+ #
175+ # Default: vertical.
176+ style: vertical
177+
178+ # Align affects alignment of closing pragma brackets.
179+ #
180+ # - true: Brackets are aligned in same column.
181+ #
182+ # - false: Brackets are not aligned together. There is only one space
183+ # between actual import and closing bracket.
184+ #
185+ # Default: true
186+ align: true
187+
188+ # stylish-haskell can detect redundancy of some language pragmas. If this
189+ # is set to true, it will remove those redundant pragmas. Default: true.
190+ remove_redundant: true
191+
192+ # Replace tabs by spaces. This is disabled by default.
193+ # - tabs:
194+ # # Number of spaces to use for each tab. Default: 8, as specified by the
195+ # # Haskell report.
196+ # spaces: 8
197+
198+ # Remove trailing whitespace
199+ - trailing_whitespace: {}
200+
201+# A common setting is the number of columns (parts of) code will be wrapped
202+# to. Different steps take this into account. Default: 80.
203+columns: 80
204+
205+# By default, line endings are converted according to the OS. You can override
206+# preferred format here.
207+#
208+# - native: Native newline format. CRLF on Windows, LF on other OSes.
209+#
210+# - lf: Convert to LF ("\n").
211+#
212+# - crlf: Convert to CRLF ("\r\n").
213+#
214+# Default: native.
215+newline: native
216+
217+# Sometimes, language extensions are specified in a cabal file or from the
218+# command line instead of using language pragmas in the file. stylish-haskell
219+# needs to be aware of these, so it can parse the file correctly.
220+#
221+# No language extensions are enabled by default.
222+# language_extensions:
223+ # - TemplateHaskell
224+ # - QuasiQuotes
LICENSEnew file+30
@@ -0,0 +1,30 @@
1+Copyright Hardy Jones (c) 2018
2+
3+All rights reserved.
4+
5+Redistribution and use in source and binary forms, with or without
6+modification, are permitted provided that the following conditions are met:
7+
8+ * Redistributions of source code must retain the above copyright
9+ notice, this list of conditions and the following disclaimer.
10+
11+ * Redistributions in binary form must reproduce the above
12+ copyright notice, this list of conditions and the following
13+ disclaimer in the documentation and/or other materials provided
14+ with the distribution.
15+
16+ * Neither the name of Hardy Jones nor the names of other
17+ contributors may be used to endorse or promote products derived
18+ from this software without specific prior written permission.
19+
20+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
README.mdnew file+1
@@ -0,0 +1 @@
1+# katip-rollbar
Setup.hsnew file+2
@@ -0,0 +1,2 @@
1+import Distribution.Simple
2+main = defaultMain
package.yamlnew file+19
@@ -0,0 +1,19 @@
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+ - base >= 4.7 && < 5
11+ - http-client >= 0.5.10
12+ - katip >= 0.5 && < 0.6
13+ - rollbar-hs >= 0.1 && < 0.2
14+ - text >= 1.2 && < 1.3
15+ source-dirs: src
16+license: BSD3
17+maintainer: jones3.hardy@gmail.com
18+name: katip-rollbar
19+version: '0.1.0.0'
src/Katip/Scribes/Rollbar.hsnew file+91
@@ -0,0 +1,91 @@
1+{-# LANGUAGE ScopedTypeVariables #-}
2+{-# LANGUAGE DataKinds #-}
3+{-# LANGUAGE LambdaCase #-}
4+{-# LANGUAGE NamedFieldPuns #-}
5+{-# LANGUAGE PackageImports #-}
6+{-# LANGUAGE TypeOperators #-}
7+
8+module Katip.Scribes.Rollbar where
9+
10+import Prelude hiding (error)
11+
12+import "base" Control.Exception (SomeException, Exception, catch)
13+import "base" Control.Monad (when)
14+import "base" Data.Functor (void)
15+
16+import "aeson" Data.Aeson (Value)
17+import "text" Data.Text.Lazy (toStrict)
18+import "text" Data.Text.Lazy.Builder (toLazyText)
19+import "katip" Katip
20+ ( LogItem
21+ , Scribe(Scribe, liPush, scribeFinalizer)
22+ , Severity(DebugS, ErrorS, InfoS, NoticeS, WarningS)
23+ , Verbosity
24+ , getEnvironment
25+ , itemJson
26+ , payloadObject
27+ , permitItem
28+ , unLogStr
29+ , _itemEnv
30+ , _itemMessage
31+ , _itemSeverity
32+ )
33+import "http-client" Network.HTTP.Client (Manager)
34+import "rollbar-hs" Rollbar.AccessToken (AccessToken)
35+import "rollbar-hs" Rollbar.API (itemsPOST')
36+import "rollbar-hs" Rollbar.Item
37+ ( Item(Item, accessToken, itemData)
38+ , critical
39+ , debug
40+ , error
41+ , info
42+ , warning
43+ )
44+import "rollbar-hs" Rollbar.Item.Body (MessageBody(MessageBody))
45+import "rollbar-hs" Rollbar.Item.Data (Data)
46+import "rollbar-hs" Rollbar.Item.Environment (Environment(Environment))
47+import "rollbar-hs" Rollbar.Item.MissingHeaders (RemoveHeaders)
48+
49+import qualified "katip" Katip
50+
51+mkRollbarScribe ::
52+ RemoveHeaders headers =>
53+ proxy headers ->
54+ AccessToken ->
55+ Manager ->
56+ Severity ->
57+ Verbosity ->
58+ IO Scribe
59+mkRollbarScribe proxy accessToken manager severity verbosity = do
60+ let liPush item = when (permitItem severity item) $ do
61+ void (itemsPOST' manager $ rollbarItem' item)
62+ rollbarItem' item = rollbarItem proxy accessToken item verbosity
63+ scribeFinalizer = pure ()
64+ pure Scribe { liPush, scribeFinalizer }
65+
66+rollbarItem ::
67+ (LogItem a, RemoveHeaders headers) =>
68+ proxy headers ->
69+ AccessToken ->
70+ Katip.Item a ->
71+ Verbosity ->
72+ Item Value ("Authorization" ': headers)
73+rollbarItem _ accessToken item verbosity = Item { accessToken, itemData }
74+ where
75+ environment :: Environment
76+ environment = Environment (getEnvironment $ _itemEnv item)
77+ itemData :: Data Value ("Authorization" ': headers)
78+ itemData = case severity of
79+ DebugS -> debug environment (Just messageBody) value
80+ InfoS -> info environment (Just messageBody) value
81+ NoticeS -> info environment (Just messageBody) value
82+ WarningS -> warning environment (Just messageBody) value
83+ ErrorS -> error environment (Just messageBody) value
84+ _ -> critical environment (Just messageBody) value
85+ messageBody :: MessageBody
86+ messageBody =
87+ MessageBody (toStrict $ toLazyText $ unLogStr $ _itemMessage item)
88+ severity :: Severity
89+ severity = _itemSeverity item
90+ value :: Value
91+ value = itemJson verbosity item
src/Lib.hsnew file+6
@@ -0,0 +1,6 @@
1+module Lib
2+ ( someFunc
3+ ) where
4+
5+someFunc :: IO ()
6+someFunc = putStrLn "someFunc"
stack.yamlnew file+6
@@ -0,0 +1,6 @@
1+flags: {}
2+packages:
3+- .
4+extra-deps:
5+- rollbar-hs-0.1.0.1
6+resolver: lts-10.5