mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
chore(telemetry): Add various surface detection to determineSurface for logging. (#6074)
Co-authored-by: christine betts <chrstn@uw.edu> Co-authored-by: Jacob Richman <jacob314@gmail.com> Co-authored-by: matt korwel <matt.korwel@gmail.com>
This commit is contained in:
@@ -47,7 +47,6 @@ describe('ClearcutLogger', () => {
|
||||
const CLEARCUT_URL = 'https://play.googleapis.com/log';
|
||||
const MOCK_DATE = new Date('2025-01-02T00:00:00.000Z');
|
||||
const EXAMPLE_RESPONSE = `["${NEXT_WAIT_MS}",null,[[["ANDROID_BACKUP",0],["BATTERY_STATS",0],["SMART_SETUP",0],["TRON",0]],-3334737594024971225],[]]`;
|
||||
|
||||
// A helper to get the internal events array for testing
|
||||
const getEvents = (l: ClearcutLogger): LogEventEntry[][] =>
|
||||
l['events'].toArray() as LogEventEntry[][];
|
||||
@@ -57,6 +56,10 @@ describe('ClearcutLogger', () => {
|
||||
const requeueFailedEvents = (l: ClearcutLogger, events: LogEventEntry[][]) =>
|
||||
l['requeueFailedEvents'](events);
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
function setup({
|
||||
config = {} as Partial<ConfigParameters>,
|
||||
lifetimeGoogleAccounts = 1,
|
||||
@@ -135,16 +138,84 @@ describe('ClearcutLogger', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('logs the current surface', () => {
|
||||
it('logs the current surface from a github action', () => {
|
||||
const { logger } = setup({});
|
||||
|
||||
vi.stubEnv('GITHUB_SHA', '8675309');
|
||||
|
||||
const event = logger?.createLogEvent('abc', []);
|
||||
|
||||
expect(event?.event_metadata[0][1]).toEqual({
|
||||
gemini_cli_key: EventMetadataKey.GEMINI_CLI_SURFACE,
|
||||
value: 'SURFACE_NOT_SET',
|
||||
value: 'GitHub',
|
||||
});
|
||||
});
|
||||
|
||||
it('honors the value from env.SURFACE over all others', () => {
|
||||
const { logger } = setup({});
|
||||
|
||||
vi.stubEnv('TERM_PROGRAM', 'vscode');
|
||||
vi.stubEnv('SURFACE', 'ide-1234');
|
||||
|
||||
const event = logger?.createLogEvent('abc', []);
|
||||
|
||||
expect(event?.event_metadata[0][1]).toEqual({
|
||||
gemini_cli_key: EventMetadataKey.GEMINI_CLI_SURFACE,
|
||||
value: 'ide-1234',
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
env: {
|
||||
CURSOR_TRACE_ID: 'abc123',
|
||||
GITHUB_SHA: undefined,
|
||||
},
|
||||
expectedValue: 'cursor',
|
||||
},
|
||||
{
|
||||
env: {
|
||||
TERM_PROGRAM: 'vscode',
|
||||
GITHUB_SHA: undefined,
|
||||
},
|
||||
expectedValue: 'vscode',
|
||||
},
|
||||
{
|
||||
env: {
|
||||
MONOSPACE_ENV: 'true',
|
||||
GITHUB_SHA: undefined,
|
||||
},
|
||||
expectedValue: 'firebasestudio',
|
||||
},
|
||||
{
|
||||
env: {
|
||||
__COG_BASHRC_SOURCED: 'true',
|
||||
GITHUB_SHA: undefined,
|
||||
},
|
||||
expectedValue: 'devin',
|
||||
},
|
||||
{
|
||||
env: {
|
||||
CLOUD_SHELL: 'true',
|
||||
GITHUB_SHA: undefined,
|
||||
},
|
||||
expectedValue: 'cloudshell',
|
||||
},
|
||||
])(
|
||||
'logs the current surface for as $expectedValue, preempting vscode detection',
|
||||
({ env, expectedValue }) => {
|
||||
const { logger } = setup({});
|
||||
for (const [key, value] of Object.entries(env)) {
|
||||
vi.stubEnv(key, value);
|
||||
}
|
||||
vi.stubEnv('TERM_PROGRAM', 'vscode');
|
||||
const event = logger?.createLogEvent('abc', []);
|
||||
expect(event?.event_metadata[0][1]).toEqual({
|
||||
gemini_cli_key: EventMetadataKey.GEMINI_CLI_SURFACE,
|
||||
value: expectedValue,
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe('enqueueLogEvent', () => {
|
||||
|
||||
Reference in New Issue
Block a user