Merge pull request #10936 from continuedev/add-cache-telemetry-posthog
Add cache token data to PostHog telemetry events
This commit is contained in:
commit
a45888f5c2
1 changed files with 19 additions and 0 deletions
|
|
@ -367,6 +367,11 @@ export function recordStreamTelemetry(options: {
|
|||
});
|
||||
|
||||
// Mirror core metrics to PostHog for product analytics
|
||||
const cacheReadTokens =
|
||||
fullUsage?.prompt_tokens_details?.cache_read_tokens ?? 0;
|
||||
const cacheWriteTokens =
|
||||
fullUsage?.prompt_tokens_details?.cache_write_tokens ?? 0;
|
||||
|
||||
try {
|
||||
posthogService.capture("apiRequest", {
|
||||
model: model.model,
|
||||
|
|
@ -374,7 +379,21 @@ export function recordStreamTelemetry(options: {
|
|||
inputTokens: actualInputTokens,
|
||||
outputTokens: actualOutputTokens,
|
||||
costUsd: cost,
|
||||
cacheReadTokens,
|
||||
cacheWriteTokens,
|
||||
});
|
||||
|
||||
// Emit prompt_cache_metrics for the Prompt Cache Performance dashboard
|
||||
if (actualInputTokens > 0) {
|
||||
posthogService.capture("prompt_cache_metrics", {
|
||||
model: model.model,
|
||||
cache_read_tokens: cacheReadTokens,
|
||||
cache_write_tokens: cacheWriteTokens,
|
||||
total_prompt_tokens: actualInputTokens,
|
||||
cache_hit_rate: cacheReadTokens / actualInputTokens,
|
||||
tool_count: tools?.length ?? 0,
|
||||
});
|
||||
}
|
||||
} catch {}
|
||||
|
||||
// Report prompt cache metrics to PostHog
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue