feat(billing): implement G1 AI credits overage flow with billing telemetry (#18590)

This commit is contained in:
Gaurav
2026-02-27 10:15:06 -08:00
committed by GitHub
parent fdd844b405
commit b2d6844f9b
55 changed files with 3182 additions and 23 deletions
+52
View File
@@ -41,6 +41,8 @@ const EVENT_HOOK_CALL_COUNT = 'gemini_cli.hook_call.count';
const EVENT_HOOK_CALL_LATENCY = 'gemini_cli.hook_call.latency';
const KEYCHAIN_AVAILABILITY_COUNT = 'gemini_cli.keychain.availability.count';
const TOKEN_STORAGE_TYPE_COUNT = 'gemini_cli.token_storage.type.count';
const OVERAGE_OPTION_COUNT = 'gemini_cli.overage_option.count';
const CREDIT_PURCHASE_COUNT = 'gemini_cli.credit_purchase.count';
// Agent Metrics
const AGENT_RUN_COUNT = 'gemini_cli.agent.run.count';
@@ -259,6 +261,26 @@ const COUNTER_DEFINITIONS = {
forced: boolean;
},
},
[OVERAGE_OPTION_COUNT]: {
description: 'Counts overage option selections.',
valueType: ValueType.INT,
assign: (c: Counter) => (overageOptionCounter = c),
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
attributes: {} as {
selected_option: string;
model: string;
},
},
[CREDIT_PURCHASE_COUNT]: {
description: 'Counts credit purchase link clicks.',
valueType: ValueType.INT,
assign: (c: Counter) => (creditPurchaseCounter = c),
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
attributes: {} as {
source: string;
model: string;
},
},
} as const;
const HISTOGRAM_DEFINITIONS = {
@@ -597,6 +619,8 @@ let hookCallCounter: Counter | undefined;
let hookCallLatencyHistogram: Histogram | undefined;
let keychainAvailabilityCounter: Counter | undefined;
let tokenStorageTypeCounter: Counter | undefined;
let overageOptionCounter: Counter | undefined;
let creditPurchaseCounter: Counter | undefined;
// OpenTelemetry GenAI Semantic Convention Metrics
let genAiClientTokenUsageHistogram: Histogram | undefined;
@@ -1334,3 +1358,31 @@ export function recordTokenStorageInitialization(
forced: event.forced,
});
}
/**
* Records a metric for an overage option selection.
*/
export function recordOverageOptionSelected(
config: Config,
attributes: MetricDefinitions[typeof OVERAGE_OPTION_COUNT]['attributes'],
): void {
if (!overageOptionCounter || !isMetricsInitialized) return;
overageOptionCounter.add(1, {
...baseMetricDefinition.getCommonAttributes(config),
...attributes,
});
}
/**
* Records a metric for a credit purchase link click.
*/
export function recordCreditPurchaseClick(
config: Config,
attributes: MetricDefinitions[typeof CREDIT_PURCHASE_COUNT]['attributes'],
): void {
if (!creditPurchaseCounter || !isMetricsInitialized) return;
creditPurchaseCounter.add(1, {
...baseMetricDefinition.getCommonAttributes(config),
...attributes,
});
}