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

Make Trace a dynamically dispatched effect #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

arybczak
Copy link

@arybczak arybczak commented Apr 10, 2024

After some thinking I decided that Trace should be dynamic since currently it has two interpretations crammed into it based on whether the Scope is there or not (another design flaw of the original library). I also renamed Tracing to Trace to keep naming consistent with TraceT and MonadTrace.

I also don't think addSpanEntry should do anything in the no-op handler.

EDIT: I'll rename Effectful.Tracing to Effectful.Trace before merging, I didn't do it yet because then GitHub generates a bad diff.

After some thinking I decided that `Trace` should be dynamic since currently it
has two interpretations crammed into it based on whether the `Scope` is there or
not (another design flaw of the original library). I also renamed `Tracing` to
`Trace` to keep naming consistent with TraceT and MonadTrace.

I also don't think `addSpanEntry` should do anything in the no-op handler.
Copy link

@Raveline Raveline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. It's interesting to see a dynamic dispatch implementation.

Just an aside: you changed the order of parameters in runTrace (formerly runTracing) and runZipkinTracing; though I understand that the new order makes more sense, I had kept the order of the equivalent MonadTrace functions mostly because I thought it would avoid some headscratching when switching a project from MonadTrace to Effectful.

withZipkin :: (IOE :> es) => Settings -> (Zipkin -> Eff es a) -> Eff es a
withZipkin settings f = do
zipkin <- unsafeEff_ $ new settings
zipkin <- liftIO $ new settings

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my general understanding of effectful: are liftIO and unsafeEff_ exchangeable in general (or at least when es is mostly IOE ?) or is this a specific case ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite - liftIO requires IOE effect to be in scope and unsafeEff_ doesn't - that's why it's called unsafe ;)

It's an escape hatch mostly for statically dispatched effect operations which shouldn't require IOE (only the runner should), but I was unable to find a more satisfying solution to this problem so far.

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)
runZipkinTracing :: (IOE :> es) => Zipkin -> Eff (Trace : es) a -> Eff es a

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For naming coherence, it should probably renamed as runZipkinTrace.

@arybczak arybczak force-pushed the dynamic-dispatch branch 2 times, most recently from a11e7a8 to f58c2f7 Compare April 11, 2024 13:46
withZipkin is Monitor.Tracing.Zipkin.with and runZipkinTrace is somewhat unnecessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants