-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.hs
38 lines (29 loc) · 1.12 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
import Data.Text (Text)
import Network.Wai.Handler.Warp as Warp
import OpenTelemetry.Instrumentation.Servant (openTelemetryServantMiddleware)
import OpenTelemetry.Instrumentation.Wai (newOpenTelemetryWaiMiddleware)
import OpenTelemetry.Trace (TracerProvider, initializeGlobalTracerProvider, shutdownTracerProvider)
import Servant
import UnliftIO.Exception (bracket)
port :: Int
port = 4567
type Api = "hello" :> Capture "name" Text :> Get '[JSON] Text
api :: Proxy Api
api = Proxy
server :: Server Api
server name = return $ "hello, " <> name <> "!"
main :: IO ()
main = withTracerProvider $ \tracerProvider -> do
openTelemetryWaiMiddleware <- newOpenTelemetryWaiMiddleware
putStrLn $ "Starting server on port " <> show port
Warp.run port $
openTelemetryWaiMiddleware $
openTelemetryServantMiddleware tracerProvider api $
serve api server
withTracerProvider :: (TracerProvider -> IO a) -> IO a
withTracerProvider =
bracket initializeGlobalTracerProvider shutdownTracerProvider