new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

AI SDK · Providers · all subjects

posthog/setup

5 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

PostHog setup overview

PostHog is an open source product analytics platform that integrates with the AI SDK through OpenTelemetry. The PostHogTraceExporter from the @posthog/ai package sends gen_ai.* spans to PostHog's OTLP ingestion endpoint, where they are automatically converted into $ai_generation events.

PostHog Node.js setup dependencies

For Node.js integration with PostHog, install: @posthog/ai, @opentelemetry/sdk-node, @opentelemetry/resources, and @ai-sdk/otel.

PostHog Next.js instrumentation file example

Create an instrumentation.ts file in the project root with the following code: ```ts import { registerTelemetry } from 'ai'; import { LegacyOpenTelemetry } from '@ai-sdk/otel'; import { NodeSDK } from '@opentelemetry/sdk-node'; import { resourceFromAttributes } from '@opentelemetry/resources'; import { PostHogTraceExporter } from '@posthog/ai/otel'; registerTelemetry(new LegacyOpenTelemetry()); export function register() { const sdk = new NodeSDK({ resource: resourceFromAttributes({ 'service.name': 'my-nextjs-app', }), traceExporter: new PostHogTraceExporter({ apiKey: process.env.POSTHOG_API_KEY!, host: 'https://us.i.posthog.com', // use https://eu.i.posthog.com for EU }), }); sdk.start(); } ```

PostHog Node.js tracing file example

Create a tracing.ts file with the following code: ```ts import { NodeSDK } from '@opentelemetry/sdk-node'; import { resourceFromAttributes } from '@opentelemetry/resources'; import { PostHogTraceExporter } from '@posthog/ai/otel'; import { registerTelemetry } from 'ai'; import { LegacyOpenTelemetry } from '@ai-sdk/otel'; const sdk = new NodeSDK({ resource: resourceFromAttributes({ 'service.name': 'my-ai-app', }), traceExporter: new PostHogTraceExporter({ apiKey: '<your-posthog-project-api-key>', host: 'https://us.i.posthog.com', // use https://eu.i.posthog.com for EU }), }); sdk.start(); registerTelemetry(new LegacyOpenTelemetry()); ```

PostHog telemetry with generateText example

This example shows how to use generateText with PostHog telemetry enabled: ```ts import { generateText } from 'ai'; import { openai } from '@ai-sdk/openai'; const result = await generateText({ model: openai('gpt-4o'), prompt: 'Tell me a fun fact about hedgehogs.', telemetry: { functionId: 'my-ai-function', metadata: { posthog_distinct_id: 'user_123', // optional: links events to a PostHog user }, }, }); ```

Give your agent this brain