forked from mtth/tracing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [CORE-6093] Add abstract implementation for MonadTrace * [CORE-6093] Add effectful package * PoC for monomorphic traceWith and addSpanEntryWith * [CORE-6093] Clean up implementation and cabal file * [CORE-6093] Use monomorphized version of traceWith and addSpanEntryWith * [CORE-6093] Add CI to additional package * [CORE-6093] Satisfy CI by adding bounds Also apply cabal-fmt to our cabal files while we're at it --------- Co-authored-by: Andrzej Rybczak <[email protected]>
- Loading branch information
Showing
11 changed files
with
293 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
packages: . | ||
packages: | ||
. | ||
tracing-effectful |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Copyright (c) 2024, Adrien Duclos | ||
|
||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
|
||
* Neither the name of Adrien Duclos nor the names of other | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
packages: | ||
. | ||
../ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{-# LANGUAGE UndecidableInstances #-} | ||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
module Effectful.Tracing | ||
( | ||
-- * Effect | ||
Trace | ||
|
||
-- * Handler | ||
, runTracing | ||
, runTracingMaybe | ||
|
||
-- * Zipkin utilities | ||
, runZipkinTracing | ||
, withZipkin | ||
|
||
-- * Reexport | ||
, module Monitor.Tracing | ||
) where | ||
|
||
import Effectful | ||
import Effectful.Dispatch.Static | ||
import Control.Monad.Trace | ||
import Control.Monad.Trace.Class | ||
import Control.Monad.Catch (finally) | ||
import Monitor.Tracing | ||
import Monitor.Tracing.Zipkin (Zipkin(zipkinTracer), Settings, new, publish) | ||
|
||
-- | Provides the ability to send traces to a backend | ||
data Trace :: Effect | ||
|
||
type instance DispatchOf Trace = Static WithSideEffects | ||
newtype instance StaticRep Trace = Trace (Maybe Scope) | ||
|
||
-- | Run the 'Tracing' effect. | ||
-- | ||
-- /Note:/ this is the @effectful@ version of 'runTracingT'. | ||
runTracing | ||
:: IOE :> es | ||
=> Eff (Trace : es) a | ||
-> Tracer | ||
-> Eff es a | ||
runTracing actn = runTracingMaybe actn . pure | ||
|
||
runTracingMaybe | ||
:: IOE :> es | ||
=> Eff (Trace : es) a | ||
-> Maybe Tracer | ||
-> Eff es a | ||
runTracingMaybe actn mbTracer = | ||
let scope = fmap (\tracer -> Scope tracer Nothing Nothing Nothing) mbTracer | ||
in evalStaticRep (Trace scope) actn | ||
|
||
-- | Convenience method to start a 'Zipkin', run an action, and publish all spans before returning. | ||
withZipkin :: (IOE :> es) => Settings -> (Zipkin -> Eff es a) -> Eff es a | ||
withZipkin settings f = do | ||
zipkin <- unsafeEff_ $ new settings | ||
f zipkin `finally` publish zipkin | ||
|
||
-- | Runs a 'TraceT' action, sampling spans appropriately. Note that this method does not publish | ||
-- spans on its own; to do so, either call 'publish' manually or specify a positive | ||
-- 'settingsPublishPeriod' to publish in the background. | ||
runZipkinTracing :: (IOE :> es) => Eff (Trace : es) a -> Zipkin -> Eff es a | ||
runZipkinTracing actn zipkin = runTracing actn (zipkinTracer zipkin) | ||
|
||
-- | Orphan, canonical instance. | ||
instance Trace :> es => MonadTrace (Eff es) where | ||
trace bldr f = getStaticRep >>= \case | ||
Trace Nothing -> f | ||
Trace (Just scope) -> unsafeSeqUnliftIO $ \unlift -> do | ||
traceWith bldr scope $ \childScope -> do | ||
unlift $ localStaticRep (const . Trace $ Just childScope) f | ||
|
||
activeSpan = do | ||
Trace scope <- getStaticRep | ||
pure (scope >>= scopeSpan) | ||
|
||
addSpanEntry key value = do | ||
Trace scope <- getStaticRep | ||
unsafeEff_ $ addSpanEntryWith scope key value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Main (main) where | ||
|
||
main :: IO () | ||
main = putStrLn "Test suite not yet implemented." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
cabal-version: 3.0 | ||
name: tracing-effectful | ||
version: 0.1.0.0 | ||
license: BSD-3-Clause | ||
license-file: LICENSE | ||
author: Adrien Duclos | ||
maintainer: [email protected] | ||
category: Development | ||
synopsis: Distributed tracing in Eff | ||
description: | ||
Adaptation of the tracing library for the Effectful ecosystem | ||
|
||
build-type: Simple | ||
extra-doc-files: CHANGELOG.md | ||
tested-with: | ||
GHC ==8.10.7 || ==9.0.2 || ==9.2.8 || ==9.4.8 || ==9.6.4 || ==9.8.2 | ||
|
||
common language | ||
ghc-options: -Wall -Wcompat -Wno-unticked-promoted-constructors | ||
default-language: Haskell2010 | ||
default-extensions: | ||
DataKinds | ||
FlexibleContexts | ||
KindSignatures | ||
LambdaCase | ||
TypeFamilies | ||
TypeOperators | ||
|
||
library | ||
import: language | ||
exposed-modules: Effectful.Tracing | ||
build-depends: | ||
, base <5 | ||
, effectful-core >=1.0.0.0 && <3.0.0.0 | ||
, exceptions <0.11 | ||
, tracing >=0.0.7 && <1.0.0.0 | ||
|
||
hs-source-dirs: src | ||
|
||
test-suite tracing-effectful-test | ||
import: language | ||
default-language: Haskell2010 | ||
type: exitcode-stdio-1.0 | ||
hs-source-dirs: test | ||
main-is: Main.hs | ||
build-depends: | ||
, base <5 | ||
, tracing-effectful |
Oops, something went wrong.