mirror of
https://github.com/hanzoai/insights-js.git
synced 2026-10-30 18:34:19 +00:00
## Problem
Our AI examples use PostHog's direct SDK wrappers (`@posthog/ai/openai`, `@posthog/ai/anthropic`, etc.) for tracking LLM calls. We want to silently deprecate these in favor of standard OpenTelemetry auto-instrumentation, which is more portable and follows industry conventions.
## Changes
Migrates 23 Node.js AI examples from PostHog direct wrappers to OpenTelemetry auto-instrumentation (or framework-native integrations where no OTel option exists):
- **15 OpenAI-compatible providers** (Groq, DeepSeek, Mistral, xAI, Together AI, Ollama, Cohere, Hugging Face, Perplexity, Cerebras, Fireworks AI, OpenRouter, Helicone, Vercel AI Gateway, Portkey) → `@opentelemetry/instrumentation-openai`
- **OpenAI** (all 7 files), **Azure OpenAI**, **Instructor** → `@opentelemetry/instrumentation-openai`
- **Anthropic** (chat + streaming) → `@traceloop/instrumentation-anthropic`
- **Vercel AI SDK** (8 files) → built-in `experimental_telemetry`
- **LangChain**, **LangGraph** → `@traceloop/instrumentation-langchain`
- **Mastra** → `@mastra/posthog` exporter (Mastra's native PostHog integration — no mature OTel path for Mastra yet)
All OTel-based examples set resource attributes to demonstrate the full feature set:
```ts
resource: resourceFromAttributes({
'service.name': 'example-groq-app',
'posthog.distinct_id': 'example-user',
foo: 'bar',
'conversation_id': 'abc-123',
}),
```
These map to `distinct_id` and custom event properties via PostHog's OTLP ingestion endpoint.
**Kept as-is:** Gemini (no Node.js OTel for `@google/genai`), AWS Bedrock/Convex/OTel (already OTel-based).
Key implementation details:
- Uses `SimpleSpanProcessor` instead of `BatchSpanProcessor` so spans export immediately without needing `sdk.shutdown()` (with an inline comment explaining why)
- Uses `resourceFromAttributes` from `@opentelemetry/resources` v2
- Static imports (no dynamic `await import()`)
- OTel deps at `^0.200.0` / `^2.0.0` for consistent resolution
- `example-ai-otel/package.json` bumped to matching OTel versions per reviewer feedback
## Release info Sub-libraries affected
### Libraries affected
- [ ] All of them
- [ ] posthog-js (web)
- [ ] posthog-js-lite (web lite)
- [ ] posthog-node
- [ ] posthog-react-native
- [ ] @posthog/react
- [ ] @posthog/ai
- [ ] @posthog/convex
- [ ] @posthog/next
- [ ] @posthog/nextjs-config
- [ ] @posthog/nuxt
- [ ] @posthog/rollup-plugin
- [ ] @posthog/webpack-plugin
- [ ] @posthog/types
No library version bumps — this only touches `examples/`.
## Checklist
- [ ] Tests for new code
- [x] Accounted for the impact of any changes across different platforms
- [x] Accounted for backwards compatibility of any changes (no breaking changes!)
- [x] Took care not to unnecessarily increase the bundle size
### If releasing new changes
- [ ] Ran `pnpm changeset` to generate a changeset file
- [ ] Added the "release" label to the PR to indicate we're publishing new versions for the affected packages
21 lines
410 B
JSON
21 lines
410 B
JSON
{
|
|
"name": "example-ai-mastra",
|
|
"version": "0.1.0",
|
|
"private": true,
|
|
"type": "module",
|
|
"packageManager": "[email protected]",
|
|
"scripts": {
|
|
"workflow": "tsx workflow.ts"
|
|
},
|
|
"dependencies": {
|
|
"@mastra/core": "^1.14.0",
|
|
"@mastra/observability": "^1.8.0",
|
|
"@mastra/posthog": "^1.0.16",
|
|
"zod": "^3.0.0"
|
|
},
|
|
"devDependencies": {
|
|
"tsx": "^4.0.0",
|
|
"typescript": "^5.0.0"
|
|
}
|
|
}
|