hs-opentelemetry-utils-exceptions 0.1.0.0 → 0.2.0.0
raw patch · 5 files changed
+63/−50 lines, 5 filesdep ~hs-opentelemetry-apisetup-changedPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: hs-opentelemetry-api
API changes (from Hackage documentation)
Files
- ChangeLog.md +6/−0
- Setup.hs +2/−0
- hs-opentelemetry-utils-exceptions.cabal +14/−14
- src/OpenTelemetry/Utils/Exceptions.hs +40/−36
- test/Spec.hs +1/−0
ChangeLog.md view
@@ -1,3 +1,9 @@ # Changelog for exceptions ## Unreleased changes++## 0.2.0.0++### Breaking changes++- Use `HashMap Text Attribute` instead of `[(Text, Attribute)]` as attributes
Setup.hs view
@@ -1,2 +1,4 @@ import Distribution.Simple++ main = defaultMain
hs-opentelemetry-utils-exceptions.cabal view
@@ -1,20 +1,20 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.34.5.+-- This file has been generated from package.yaml by hpack version 0.35.2. -- -- see: https://github.com/sol/hpack -name: hs-opentelemetry-utils-exceptions-version: 0.1.0.0-description: Please see the README on GitHub at <https://github.com/iand675/hs-opentelemetry/tree/main/utils/exceptions#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+name: hs-opentelemetry-utils-exceptions+version: 0.2.0.0+description: Please see the README on GitHub at <https://github.com/iand675/hs-opentelemetry/tree/main/utils/exceptions#readme>+homepage: https://github.com/iand675/hs-opentelemetry#readme+bug-reports: https://github.com/iand675/hs-opentelemetry/issues+author: Ian Duncan, Jade Lovelace+maintainer: ian@iankduncan.com+copyright: 2023 Ian Duncan, Mercury Technologies+license: BSD3+license-file: LICENSE+build-type: Simple extra-source-files: README.md ChangeLog.md@@ -33,7 +33,7 @@ build-depends: base >=4.7 && <5 , exceptions- , hs-opentelemetry-api ==0.0.3.*+ , hs-opentelemetry-api ==0.1.* , hs-opentelemetry-sdk ==0.0.3.* , text default-language: Haskell2010@@ -49,7 +49,7 @@ build-depends: base >=4.7 && <5 , exceptions- , hs-opentelemetry-api ==0.0.3.*+ , hs-opentelemetry-api ==0.1.* , hs-opentelemetry-sdk ==0.0.3.* , text default-language: Haskell2010
src/OpenTelemetry/Utils/Exceptions.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE OverloadedLists #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} @@ -12,7 +13,6 @@ import GHC.Exception (SrcLoc (..), getCallStack) import GHC.Stack (CallStack, callStack) import GHC.Stack.Types (HasCallStack)- import OpenTelemetry.Context (insertSpan, lookupSpan, removeSpan) import OpenTelemetry.Context.ThreadLocal (adjustContext) import qualified OpenTelemetry.Context.ThreadLocal as TraceCore.SpanContext@@ -20,7 +20,8 @@ import OpenTelemetry.Trace.Core (ToAttribute (..), endSpan, recordException, setStatus, whenSpanIsRecording) import qualified OpenTelemetry.Trace.Core as TraceCore -bracketError' :: MonadMask m => m a -> (Maybe SomeException -> a -> m b) -> (a -> m c) -> m c++bracketError' :: (MonadMask m) => m a -> (Maybe SomeException -> a -> m b) -> (a -> m c) -> m c bracketError' before after thing = MonadMask.mask $ \restore -> do x <- before res1 <- MonadMask.try $ restore $ thing x@@ -38,43 +39,46 @@ MonadMask.uninterruptibleMask_ $ after Nothing x return y + -- | The simplest function for annotating code with trace information.-inSpanM ::- (MonadIO m, MonadMask m, HasCallStack) =>- Trace.Tracer ->- -- | The name of the span. This may be updated later via 'updateName'- Text ->- -- | Additional options for creating the span, such as 'SpanKind',+inSpanM+ :: (MonadIO m, MonadMask m, HasCallStack)+ => Trace.Tracer+ -> Text+ -- ^ The name of the span. This may be updated later via 'updateName'+ -> Trace.SpanArguments+ -- ^ Additional options for creating the span, such as 'SpanKind', -- span links, starting attributes, etc.- Trace.SpanArguments ->- -- | The action to perform. 'inSpan' will record the time spent on the+ -> m a+ -- ^ The action to perform. 'inSpan' will record the time spent on the -- action without forcing strict evaluation of the result. Any uncaught -- exceptions will be recorded and rethrown.- m a ->- m a+ -> m a inSpanM t n args m = inSpanM'' t callStack n args (const m) -inSpanM' ::- (MonadIO m, MonadMask m, HasCallStack) =>- Trace.Tracer ->- -- | The name of the span. This may be updated later via 'updateName'- Text ->- Trace.SpanArguments ->- (Trace.Span -> m a) ->- m a++inSpanM'+ :: (MonadIO m, MonadMask m, HasCallStack)+ => Trace.Tracer+ -> Text+ -- ^ The name of the span. This may be updated later via 'updateName'+ -> Trace.SpanArguments+ -> (Trace.Span -> m a)+ -> m a inSpanM' t = inSpanM'' t callStack -inSpanM'' ::- (MonadMask m, HasCallStack, MonadIO m) =>- Trace.Tracer ->- -- | Record the location of the span in the codebase using the provided++inSpanM''+ :: (MonadMask m, HasCallStack, MonadIO m)+ => Trace.Tracer+ -> CallStack+ -- ^ Record the location of the span in the codebase using the provided -- callstack for source location info.- CallStack ->- -- | The name of the span. This may be updated later via 'updateName'- Text ->- Trace.SpanArguments ->- (Trace.Span -> m a) ->- m a+ -> Text+ -- ^ The name of the span. This may be updated later via 'updateName'+ -> Trace.SpanArguments+ -> (Trace.Span -> m a)+ -> m a inSpanM'' t cs n args f = bracketError' before after (f . snd) where before = do@@ -87,18 +91,18 @@ (fn, loc) : _ -> do TraceCore.addAttributes s- [ ("code.function", toAttribute $ T.pack fn),- ("code.namespace", toAttribute $ T.pack $ srcLocModule loc),- ("code.filepath", toAttribute $ T.pack $ srcLocFile loc),- ("code.lineno", toAttribute $ srcLocStartLine loc),- ("code.package", toAttribute $ T.pack $ srcLocPackage loc)+ [ ("code.function", toAttribute $ T.pack fn)+ , ("code.namespace", toAttribute $ T.pack $ srcLocModule loc)+ , ("code.filepath", toAttribute $ T.pack $ srcLocFile loc)+ , ("code.lineno", toAttribute $ srcLocStartLine loc)+ , ("code.package", toAttribute $ T.pack $ srcLocPackage loc) ] pure (lookupSpan ctx, s) after e (parent, s) = do forM_ e $ \(MonadMask.SomeException inner) -> do setStatus s $ Trace.Error $ T.pack $ MonadMask.displayException inner- recordException s [] Nothing inner+ recordException s [("exception.escaped", toAttribute True)] Nothing inner endSpan s Nothing adjustContext $ \ctx -> maybe (removeSpan ctx) (`insertSpan` ctx) parent
test/Spec.hs view
@@ -1,2 +1,3 @@+ main :: IO () main = putStrLn "Test suite not yet implemented"