> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ko/llms.txt # Posthog수출업자 AI Observability 및 분석을 위해 추적 데이터를 PostHog에 보냅니다. ## 건설자 ```typescript new PosthogExporter(config: PosthogExporterConfig) ``` ## `PosthogExporterConfig` ```typescript interface PosthogExporterConfig extends BaseExporterConfig { apiKey?: string host?: string flushAt?: number flushInterval?: number serverless?: boolean defaultDistinctId?: string enablePrivacyMode?: boolean } ``` `BaseExporterConfig`를 확장하며, 포함되는 항목은 다음과 같습니다. - `logger?: IMastraLogger`- 로거 인스턴스 - `logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error'`- 로그 수준(기본값: INFO) ## 행동 양식 ### `exportTracingEvent` ```typescript async exportTracingEvent(event: TracingEvent): Promise ``` 추적 이벤트를 PostHog로 내보냅니다. ### `onFeedbackEvent` ```typescript async onFeedbackEvent(event: FeedbackEvent): Promise ``` 피드백 이벤트를 PostHog로 내보냅니다. 보다[Feedback export](#feedback-export). ### 플러시 ```typescript async flush(): Promise ``` Force는 내보내기를 종료하지 않고 버퍼링된 이벤트를 PostHog로 플러시합니다. 런타임이 종료되기 전에 범위를 내보내야 하는 서버리스 환경에 유용합니다. ### 일시 휴업 ```typescript async shutdown(): Promise ``` 보류 중인 일괄 처리 이벤트를 플러시하고 PostHog 클라이언트를 종료합니다. ## 용법 ### Zero-Config(환경 변수 사용) ```typescript import { PosthogExporter } from '@mastra/posthog' // Reads from POSTHOG_API_KEY, POSTHOG_HOST const exporter = new PosthogExporter() ``` ### 명시적 구성 ```typescript import { PosthogExporter } from '@mastra/posthog' const exporter = new PosthogExporter({ apiKey: process.env.POSTHOG_API_KEY!, host: 'https://us.i.posthog.com', serverless: true, }) ``` ## 스팬 유형 매핑 | 마스트라 스팬 유형 | PostHog 이벤트 유형 | | -------------------- | ---------------- | | `MODEL_GENERATION` | `$ai_generation` | | `MODEL_STEP` | `$ai_generation` | | `MODEL_CHUNK` | `$ai_span` | | `TOOL_CALL` | `$ai_span` | | `MCP_TOOL_CALL` | `$ai_span` | | `PROVIDER_TOOL_CALL` | `$ai_span` | | `PROCESSOR_RUN` | `$ai_span` | | `AGENT_RUN` | `$ai_span` | | `WORKFLOW_RUN` | `$ai_span` | | 기타 모든 Workflow | `$ai_span` | | `GENERIC` | `$ai_span` | ## 피드백 내보내기 [`addFeedback()`](https://mastra.zisheng.pro/ko/docs/observability/feedback)으로 기록된 피드백은 PostHog에 네이티브 `$ai_feedback` 이벤트로 내보내집니다. PostHog는 연결된 Trace에 이를 **사용자 피드백**으로 표시합니다. 추가 구성은 필요하지 않습니다. ```typescript const trace = await mastra.observability.getRecordedTrace({ traceId }) await trace.addFeedback({ feedbackType: 'thumbs', value: 'down', comment: 'Wrong answer', }) ``` 피드백 이벤트는 다음 PostHog 속성에 매핑됩니다. | Mastra 피드백 필드 | PostHog 속성 | | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- | | `traceId` | `$ai_trace_id` | | `comment` (comment가 없으면 `value`) | `$ai_feedback_text` | | `feedbackId` | `feedback_id` | | `feedbackType` | `feedback_type` | | `value` | `feedback_value` | | `feedbackSource` | `feedback_source` | | `spanId` | `span_id` | | `sourceId` | `source_id` | | `metadata.sessionId` | `$ai_session_id` | | `metadata` (기타 키) | 사용자 정의 속성 | | PostHog는 `$ai_trace_id`를 통해 피드백을 Trace에 연결하므로 `traceId`가 없는 피드백은 삭제됩니다. 이벤트의 고유 ID는 `feedbackUserId`, `metadata.userId`, `defaultDistinctId`, `anonymous` 순서로 결정됩니다. | |