Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpanArguments with an exception handler #95

Open
parsonsmatt opened this issue Sep 19, 2023 · 2 comments
Open

SpanArguments with an exception handler #95

parsonsmatt opened this issue Sep 19, 2023 · 2 comments

Comments

@parsonsmatt
Copy link
Collaborator

SpanArguments should have a field for determining what happens with a thrown exception. The existing default behavior is to do this:

        forM_ e $ \(SomeException inner) -> do
          setStatus s $ Error $ T.pack $ displayException inner
          recordException s [] Nothing inner

I think that recordException s [] Nothing inner is probably good to leave in, and the "customizable' stuff will be the setStatus s $ Error $ T.pack $ displayException inner.

Related: #90

Comment: #91 (comment)

I think I'd like to see something like:

newtype SpanExceptionBehavior { unSpanExceptionBehavior :: SomeException -> Maybe (Span -> IO ()) }
  deriving newtype (Semigroup, Monoid)

spanExceptionSetStatusError :: SpanExceptionBehavior
spanExceptionSetStatusError = 
  SpanExceptionBehavior \(SomeException inner) ->  
    Just \s -> setStatus s $ Error $ T.pack displayException inner

addSpanExceptionBehavior :: SpanExceptionBehavior -> SpanArguments -> SpanArguments
addSpanExceptionBehavior new sa = sa { exceptionBehavior = new <> exceptionBehavior sa }

That allows you to compose and combine them. However, it does not allow you to override them. So I think we need something other than Maybe there -

data OverrideOrCombine a 
    = Override a
    | Combine a
    | Nothin

instance Semigroup a => Semigroup (OverrideOrCombine a) where
    Override a <> _ = Override a
    _ <> Override a = Override a
    Combine a <> Combine b = Combine (a <> b)
    Nothin <> r = r
    l <> Nothin = l

Then, for the ExitSuccess, we can do an override:

ignoreExitSuccess :: ExceptionBehavior
ignoreExitSuccess = ExceptionBehavior \exn ->
    case fromException exn of
        exitCode 
            | ExitSuccess <- exitCode -> 
                Override mempty
        _ -> 
            Nothin
@parsonsmatt
Copy link
Collaborator Author

I've run into this issue twice now: once for ExitSuccess and again for SIGINT parsonsmatt/hotel-california#8

So I am interested in providing some good work on this 😄

@michaelpj
Copy link
Collaborator

Another case: ki kills threads with exception when you leave a scope, but this can be totally fine and not bad at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants