{-|
Module      : Instana.Wai.Middleware.Entry.Internal
Description : Internals of the WAI Instana Tracing Middleware

Automatically creates entry spans for all incoming HTTP requests in a WAI
application.
-}
module Instana.Wai.Middleware.Entry.Internal
  ( traceHttpEntries
  ) where


import           Network.Wai     (Application)

import           Instana.SDK.SDK (InstanaContext, withHttpEntry)


-- |Run the tracing middleware given an initialized Instana SDK context.
traceHttpEntries :: InstanaContext -> Application -> Application
traceHttpEntries :: InstanaContext -> Application -> Application
traceHttpEntries instana :: InstanaContext
instana app :: Application
app request :: Request
request respond :: Response -> IO ResponseReceived
respond = do
  InstanaContext
-> Request -> IO ResponseReceived -> IO ResponseReceived
forall (m :: * -> *) a.
MonadIO m =>
InstanaContext -> Request -> m a -> m a
withHttpEntry InstanaContext
instana Request
request (IO ResponseReceived -> IO ResponseReceived)
-> IO ResponseReceived -> IO ResponseReceived
forall a b. (a -> b) -> a -> b
$
    Application
app Request
request Response -> IO ResponseReceived
respond