Skip to content
This repository was archived by the owner on Oct 19, 2024. It is now read-only.

Commit 10f299f

Browse files
authored
Add instrumentation to library example (#212)
1 parent dac53e0 commit 10f299f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Diff for: examples/library/mu-example-library.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ executable library
2525
, monad-logger >=0.3 && <0.4
2626
, mtl
2727
, mu-persistent >=0.3
28+
, mu-prometheus >=0.4
2829
, mu-graphql >=0.4
2930
, mu-rpc >=0.4
3031
, mu-schema >=0.3

Diff for: examples/library/src/Server.hs

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import Database.Persist.Sqlite
2020
import Mu.Adapter.Persistent (runDb)
2121
import Mu.GraphQL.Quasi
2222
import Mu.GraphQL.Server
23+
import Mu.Instrumentation.Prometheus
2324
import Mu.Schema
2425
import Mu.Server
2526
import Network.Wai.Handler.Warp (run)
@@ -30,19 +31,24 @@ import Schema
3031
main :: IO ()
3132
main = do
3233
putStrLn "starting GraphQL server on port 8000"
34+
-- Setup CORS
3335
let hm = addHeaders [
3436
("Access-Control-Allow-Origin", "*")
3537
, ("Access-Control-Allow-Headers", "Content-Type")
3638
]
39+
-- Set up Prometheus
40+
p <- initPrometheus "library"
41+
-- Run the whole thing
3742
runStderrLoggingT $
3843
withSqliteConn @(LoggingT IO) ":memory:" $ \conn -> do
3944
runDb conn $ runMigration migrateAll
4045
liftIO $ run 8000 $ hm $
41-
graphQLApp (libraryServer conn)
46+
graphQLApp (prometheus p $ libraryServer conn)
4247
(Proxy @('Just "Query"))
4348
(Proxy @('Just "Mutation"))
4449
(Proxy @('Just "Subscription"))
4550

51+
4652
type ObjectMapping = '[
4753
"Book" ':-> Entity Book
4854
, "Author" ':-> Entity Author

0 commit comments

Comments
 (0)