hs-opentelemetry-exporter-in-memory (empty) → 0.0.1.0
raw patch · 7 files changed
+136/−0 lines, 7 filesdep +asyncdep +basedep +hs-opentelemetry-apisetup-changed
Dependencies added: async, base, hs-opentelemetry-api, hs-opentelemetry-exporter-in-memory, unagi-chan
Files
- ChangeLog.md +3/−0
- LICENSE +30/−0
- README.md +1/−0
- Setup.hs +2/−0
- hs-opentelemetry-exporter-in-memory.cabal +55/−0
- src/OpenTelemetry/Exporter/InMemory.hs +43/−0
- test/Spec.hs +2/−0
+ ChangeLog.md view
@@ -0,0 +1,3 @@+# Changelog for hs-opentelemetry-exporter-in-memory++## Unreleased changes
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Ian Duncan (c) 2021++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 Ian Duncan 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.
+ README.md view
@@ -0,0 +1,1 @@+# hs-opentelemetry-exporter-in-memory
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ hs-opentelemetry-exporter-in-memory.cabal view
@@ -0,0 +1,55 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.34.4.+--+-- see: https://github.com/sol/hpack++name: hs-opentelemetry-exporter-in-memory+version: 0.0.1.0+description: Please see the README on GitHub at <https://github.com/iand675/hs-opentelemetry/tree/main/exporters/in-memory#readme>+homepage: https://github.com/iand675/hs-opentelemetry#readme+bug-reports: https://github.com/iand675/hs-opentelemetry/issues+author: Ian Duncan+maintainer: ian@iankduncan.com+copyright: 2021 Ian Duncan+license: BSD3+license-file: LICENSE+build-type: Simple+extra-source-files:+ README.md+ ChangeLog.md++source-repository head+ type: git+ location: https://github.com/iand675/hs-opentelemetry++library+ exposed-modules:+ OpenTelemetry.Exporter.InMemory+ other-modules:+ Paths_hs_opentelemetry_exporter_in_memory+ hs-source-dirs:+ src+ ghc-options: -Wall+ build-depends:+ async+ , base >=4.7 && <5+ , hs-opentelemetry-api+ , unagi-chan+ default-language: Haskell2010++test-suite hs-opentelemetry-exporter-in-memory-test+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ other-modules:+ Paths_hs_opentelemetry_exporter_in_memory+ hs-source-dirs:+ test+ ghc-options: -threaded -rtsopts -with-rtsopts=-N+ build-depends:+ async+ , base >=4.7 && <5+ , hs-opentelemetry-api+ , hs-opentelemetry-exporter-in-memory+ , unagi-chan+ default-language: Haskell2010
+ src/OpenTelemetry/Exporter/InMemory.hs view
@@ -0,0 +1,43 @@+module OpenTelemetry.Exporter.InMemory + ( inMemoryChannelExporter+ , inMemoryListExporter+ , module Control.Concurrent.Chan.Unagi+ ) where++import Control.Concurrent.Async+import Control.Concurrent.Chan.Unagi+import Control.Monad.IO.Class+import Data.IORef+import OpenTelemetry.Trace.Core+import OpenTelemetry.Processor++-- | Access exported spans via a concurrently accessible channel that produces spans. +-- The spans are exported in the order that the spans end.+inMemoryChannelExporter :: MonadIO m => m (Processor, OutChan ImmutableSpan)+inMemoryChannelExporter = liftIO $ do+ (inChan, outChan) <- newChan+ let processor = Processor + { processorOnStart = \_ _ -> pure () + , processorOnEnd = \ref -> do+ writeChan inChan =<< readIORef ref+ , processorShutdown = do+ async $ pure ShutdownSuccess+ , processorForceFlush = pure ()+ }+ pure (processor, outChan)++-- | Access exported spans via a mutable reference to a list of spans. The spans+-- are not guaranteed to be exported in a particular order.+inMemoryListExporter :: MonadIO m => m (Processor, IORef [ImmutableSpan])+inMemoryListExporter = liftIO $ do+ listRef <- newIORef []+ let processor = Processor + { processorOnStart = \_ _ -> pure () + , processorOnEnd = \ref -> do+ s <- readIORef ref+ atomicModifyIORef listRef (\l -> (s : l, ()))+ , processorShutdown = do+ async $ pure ShutdownSuccess+ , processorForceFlush = pure ()+ }+ pure (processor, listRef)
+ test/Spec.hs view
@@ -0,0 +1,2 @@+main :: IO ()+main = putStrLn "Test suite not yet implemented"