mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-24 03:54:43 -07:00
feat(billing): implement G1 AI credits overage flow with billing telemetry (#18590)
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user