You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(observability): name AI traces in PostHog with a $ai_trace envelope (#10223)
PostHog's Traces view takes a trace's NAME from a trace-level $ai_trace event,
not from any property on the generations underneath it -- confirmed upstream in
PostHog/posthog#33179, where an $ai_span_name set on a generation does not
populate that column. This project emitted only generations, so every trace read
as an anonymous id with no way to tell a gate review from an embedding batch.
Emit the envelope from withReviewPipelineSpan, which already wraps a whole review
and carries the repo, PR and the ambient OTel trace id the generations group by.
It runs INSIDE the OTel span, because that id only exists once the span is open.
Two guards, both load-bearing:
- Outermost only. withReviewPipelineSpan is called from several sites that can
nest, and PostHog expects one $ai_trace per trace. A depth counter means inner
calls contribute nothing and the surviving name is the whole operation rather
than whichever leaf finished last.
- Only when generations exist. Not every pipeline span wraps an AI call -- the
gate does not. Emitting unconditionally would manufacture trace rows with
nothing under them, which reads worse than an unnamed trace.
A pass-through when PostHog is off or no ambient trace exists, so it never
changes what the wrapped work does or what it throws.
Closes#10221
Copy file name to clipboardExpand all lines: apps/loopover-ui/content/docs/self-hosting-operations.mdx
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -683,6 +683,11 @@ three standalone bindings (`AI_EMBED`, `AI_VISION`, `AI_ADVISORY`).
683
683
description:
684
684
"$ai_model is always the model the provider actually resolved — on the failure path too. The core passes a Workers-AI model id that every self-host provider discards, so it is resolved to the real one (or <provider>-default) before capture and never reported verbatim.",
685
685
},
686
+
{
687
+
title: "Trace naming",
688
+
description:
689
+
"$ai_trace names the whole review in PostHog's Traces view. Emitted once per trace, by the outermost pipeline span, and only when at least one AI call actually ran under it — a pipeline span with no generations is never given a trace row.",
0 commit comments