Open
Description
Here is the current code for creating the top level span:
getTopLevelSpan :: IO Span
getTopLevelSpan = do
traceParent <- lookupEnv "TRACEPARENT"
traceState_ <- lookupEnv "TRACESTATE"
case W3CTraceContext.decodeSpanContext traceParent traceState_ of
Just spanContext ->
pure (Trace.Core.wrapSpanContext spanContext)
Nothing -> do
-- If we're not inheriting a span from
-- `TRACEPARENT`/`TRACESTATE`, then create a zero-duration span
-- whose sole purpose is to be a parent span for each module's
-- spans.
--
-- Ideally we'd like this span's duration to last for the
-- entirety of compilation, but there isn't a good way to end
-- the span when compilation is done. Also, we still need
-- *some* parent span for each module's spans, otherwise an
-- entirely new trace will be created for each new span.
-- Creating a zero-duration span is the least-worst solution.
--
-- Note that there aren't any issues with the child spans
-- lasting longer than the parent span. This is supported by
-- open telemetry and the Haskell API.
timestamp <- Trace.Core.getTimestamp
let arguments =
Trace.defaultSpanArguments
{ startTime = Just timestamp }
span <- Trace.createSpan tracer Context.empty "opentelemetry GHC plugin" arguments
Trace.endSpan span (Just timestamp)
pure span
I think we should always create a top-level span for the Haskell code. That allows us to attach attributes to the span, like the count of modules in project and the count of modules built. We cannot do that now with the first thing, because the span is a FrozenSpan
since it is created from external process. This also allows us to provide a consistent name and trace structure for traces regardless of whether there's a parent.
Metadata
Assignees
Labels
No labels
Activity