-
-
Notifications
You must be signed in to change notification settings - Fork 476
Open
Description
Summary
I'd like to request an API to intercept span creation events without having to monkey-patch the tracer. Currently, to track span metadata (like building a span path/tree), the only option is to patch tracer.span() directly, which feels hacky and fragile.
Use Case
In our UI framework, we wrap user effects with Effect.withSpan('ui.effect', { root: true }) and want to log the "deepest" span path when the effect completes. For example:
[handleClick → fetchData → processResult] Trace URL: https://...
Since Effect.ensuring() runs after inner spans have closed, we can't access the span hierarchy at that point. Our current workaround patches the tracer to track the deepest span path in a root span attribute as spans are created.
Current Workaround
const ensureTracerPatched = (tracer: Tracer.Tracer) => {
const originalSpan = tracer.span
tracer.span = function (name, parent, context, links, startTime, kind, options) {
const span = originalSpan.apply(this, arguments)
// Track span path in root span attribute...
return span
}
}Proposed Solutions
Any of these would help:
- Tracer hook/callback: An official API to register callbacks for span lifecycle events (create, end)
- In-memory span tree: A way to query the current span hierarchy from within an effect
- Span creation interceptor: A composable way to wrap span creation similar to how layers work
Environment
- Effect version: 3.x
- Platform: Browser (Electron renderer)
Happy to provide more context or help with implementation if needed!
higherorderfunctor
Metadata
Metadata
Assignees
Labels
No labels