Changesets · Branches · Tags · Compare
| Changeset | 2a0d7f0fdeadbac93ecd5bb3f9ac1ec932a075f939a633b4b67b3b39d2a3d3e6 |
|---|---|
| Author | Nate <sestinj@gmail.com> · 2025-09-12 16:08 -07:00 |
| Committer | Nate <sestinj@gmail.com> · 2025-09-12 16:08 -07:00 |
| Parents | 36bac28d80cf |
2 files changed
modified extensions/cli/src/stream/streamChatResponse.helpers.ts +12 −0
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | import { toolPermissionManager } from "../permissions/permissionManager.js"; |
| 7 | 7 | import { ToolCallRequest } from "../permissions/types.js"; |
| 8 | 8 | import { services } from "../services/index.js"; |
| 9 | +import { posthogService } from "../telemetry/posthogService.js"; | |
| 9 | 10 | import { telemetryService } from "../telemetry/telemetryService.js"; |
| 10 | 11 | import { calculateTokenCost } from "../telemetry/utils.js"; |
| 11 | 12 | import { |
| @@ -290,6 +291,17 @@ | ||
| 290 | 291 | costUsd: cost, |
| 291 | 292 | }); |
| 292 | 293 | |
| 294 | + // Mirror core metrics to PostHog for product analytics | |
| 295 | + try { | |
| 296 | + posthogService.capture("apiRequest", { | |
| 297 | + model: model.model, | |
| 298 | + durationMs: totalDuration, | |
| 299 | + inputTokens, | |
| 300 | + outputTokens, | |
| 301 | + costUsd: cost, | |
| 302 | + }); | |
| 303 | + } catch {} | |
| 304 | + | |
| 293 | 305 | return cost; |
| 294 | 306 | } |
| 295 | 307 |
modified extensions/cli/src/stream/streamChatResponse.ts +10 −0
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | import { getServiceSync, SERVICE_NAMES, services } from "../services/index.js"; |
| 12 | 12 | import { systemMessageService } from "../services/SystemMessageService.js"; |
| 13 | 13 | import type { ToolPermissionServiceState } from "../services/ToolPermissionService.js"; |
| 14 | +import { posthogService } from "../telemetry/posthogService.js"; | |
| 14 | 15 | import { telemetryService } from "../telemetry/telemetryService.js"; |
| 15 | 16 | import { ToolCall } from "../tools/index.js"; |
| 16 | 17 | import { |
| @@ -258,6 +259,15 @@ | ||
| 258 | 259 | error: error.message || String(error), |
| 259 | 260 | }); |
| 260 | 261 | |
| 262 | + try { | |
| 263 | + posthogService.capture("apiRequest", { | |
| 264 | + model: model.model, | |
| 265 | + durationMs: errorDuration, | |
| 266 | + success: false, | |
| 267 | + error: error.message || String(error), | |
| 268 | + }); | |
| 269 | + } catch {} | |
| 270 | + | |
| 261 | 271 | if (error.name === "AbortError" || abortController?.signal.aborted) { |
| 262 | 272 | logger.debug("Stream aborted by user"); |
| 263 | 273 | return { |