PosthogExporter
Sends Tracing data to PostHog for AI observability and analytics.
ConstructorDirect link to Constructor
new PosthogExporter(config: PosthogExporterConfig)
PosthogExporterConfigDirect link to PosthogExporterConfig
interface PosthogExporterConfig extends BaseExporterConfig {
apiKey: string;
host?: string;
flushAt?: number;
flushInterval?: number;
serverless?: boolean;
defaultDistinctId?: string;
enablePrivacyMode?: boolean;
}
Extends BaseExporterConfig, which includes:
logger?: IMastraLogger- Logger instancelogLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error'- Log level (default: INFO)
MethodsDirect link to Methods
exportTracingEventDirect link to exportTracingEvent
async exportTracingEvent(event: TracingEvent): Promise<void>
Exports a tracing event to PostHog.
shutdownDirect link to shutdown
async shutdown(): Promise<void>
Flushes pending batched events and shuts down the PostHog client.
UsageDirect link to Usage
import { PosthogExporter } from "@mastra/posthog";
const exporter = new PosthogExporter({
apiKey: process.env.POSTHOG_API_KEY!,
host: "https://us.i.posthog.com",
serverless: true,
});
Span Type MappingDirect link to Span Type Mapping
| Mastra Span Type | PostHog Event Type |
|---|---|
MODEL_GENERATION | $ai_generation |
MODEL_STEP | $ai_generation |
MODEL_CHUNK | $ai_span |
TOOL_CALL | $ai_span |
MCP_TOOL_CALL | $ai_span |
PROCESSOR_RUN | $ai_span |
AGENT_RUN | $ai_span |
WORKFLOW_RUN | $ai_span |
| All other workflows | $ai_span |
GENERIC | $ai_span |