Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(aio): flush Convex telemetry before action return (#71433)

willwearingf7b4bb4aa2d3
diff --git a/docs/onboarding/ai-observability/convex.tsx b/docs/onboarding/ai-observability/convex.tsx
index 31db0a754af6..32329c71da5b 100644
--- a/docs/onboarding/ai-observability/convex.tsx
+++ b/docs/onboarding/ai-observability/convex.tsx
@@ -61,7 +61,8 @@ export const getConvexSteps = (ctx: OnboardingComponentsContext): StepDefinition
<Markdown>
Create a Convex action that initializes a `BasicTracerProvider` with PostHog's trace exporter
and enables telemetry on your AI SDK calls. The provider is initialized at module scope so it
- persists across warm V8 isolate invocations.
+ persists across warm V8 isolate invocations. Await `provider.forceFlush()` before returning
+ because Convex may finish the action while the OTLP export is still pending.
</Markdown>
<CodeBlock
@@ -111,6 +112,8 @@ export const getConvexSteps = (ctx: OnboardingComponentsContext): StepDefinition
},
})
+ await provider.forceFlush()
+
return { text: result.text, usage: result.usage }
},
})
@@ -192,6 +195,8 @@ export const getConvexSteps = (ctx: OnboardingComponentsContext): StepDefinition
},
})
+ await provider.forceFlush()
+
return { text: result.text, usage: result.totalUsage }
},
})