mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-31 08:20:54 -07:00
Refine onboarding metrics to log the duration explicitly and use the tier name. (#23678)
This commit is contained in:
@@ -15,8 +15,20 @@ import { CodeAssistServer } from '../code_assist/server.js';
|
||||
import type { OAuth2Client } from 'google-auth-library';
|
||||
import { UserTierId, type GeminiUserTier } from './types.js';
|
||||
import type { Config } from '../config/config.js';
|
||||
import {
|
||||
logOnboardingSuccess,
|
||||
OnboardingSuccessEvent,
|
||||
} from '../telemetry/index.js';
|
||||
|
||||
vi.mock('../code_assist/server.js');
|
||||
vi.mock('../telemetry/index.js', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('../telemetry/index.js')>();
|
||||
return {
|
||||
...actual,
|
||||
logOnboardingStart: vi.fn(),
|
||||
logOnboardingSuccess: vi.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
const mockPaidTier: GeminiUserTier = {
|
||||
id: UserTierId.STANDARD,
|
||||
@@ -214,7 +226,20 @@ describe('setupUser', () => {
|
||||
mockLoad.mockResolvedValue({
|
||||
allowedTiers: [mockPaidTier],
|
||||
});
|
||||
const userData = await setupUser({} as OAuth2Client, mockConfig);
|
||||
mockOnboardUser.mockImplementation(async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1500));
|
||||
return {
|
||||
done: true,
|
||||
response: {
|
||||
cloudaicompanionProject: {
|
||||
id: 'server-project',
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
const userDataPromise = setupUser({} as OAuth2Client, mockConfig);
|
||||
await vi.advanceTimersByTimeAsync(1500);
|
||||
const userData = await userDataPromise;
|
||||
expect(mockOnboardUser).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
tierId: UserTierId.STANDARD,
|
||||
@@ -227,6 +252,13 @@ describe('setupUser', () => {
|
||||
userTierName: 'paid',
|
||||
hasOnboardedPreviously: false,
|
||||
});
|
||||
expect(logOnboardingSuccess).toHaveBeenCalledWith(
|
||||
mockConfig,
|
||||
expect.any(OnboardingSuccessEvent),
|
||||
);
|
||||
const event = vi.mocked(logOnboardingSuccess).mock.calls[0][1];
|
||||
expect(event.userTier).toBe('paid');
|
||||
expect(event.duration_ms).toBeGreaterThanOrEqual(1500);
|
||||
});
|
||||
|
||||
it('should onboard a new free user when project ID is not set', async () => {
|
||||
|
||||
@@ -251,6 +251,7 @@ async function _doSetupUser(
|
||||
}
|
||||
|
||||
logOnboardingStart(config, new OnboardingStartEvent());
|
||||
const onboardingStartTime = Date.now();
|
||||
|
||||
let lroRes = await caServer.onboardUser(onboardReq);
|
||||
if (!lroRes.done && lroRes.name) {
|
||||
@@ -261,8 +262,10 @@ async function _doSetupUser(
|
||||
}
|
||||
}
|
||||
|
||||
const userTier = tier.id ?? UserTierId.STANDARD;
|
||||
logOnboardingSuccess(config, new OnboardingSuccessEvent(userTier));
|
||||
logOnboardingSuccess(
|
||||
config,
|
||||
new OnboardingSuccessEvent(tier.name, Date.now() - onboardingStartTime),
|
||||
);
|
||||
|
||||
if (!lroRes.response?.cloudaicompanionProject?.id) {
|
||||
if (projectId) {
|
||||
|
||||
Reference in New Issue
Block a user