-
Notifications
You must be signed in to change notification settings - Fork 2.2k
chore: implement ClearcutLogger and ClearcutSender dummy #758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1323d09
chore: implement ClearcutLogger and ClearcutSender dummy
ergunsh a01c43f
chore: fix the license header year
ergunsh 6181a46
chore: fix formatting
ergunsh 0840ff0
chore: implement generic CLI flag usage reporting
ergunsh 8c12209
chore: remove the snapshot test
ergunsh 9360fff
Merge branch 'main' into telemetry/clearcut-logger-02
ergunsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
|
ergunsh marked this conversation as resolved.
Outdated
|
||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { | ||
| FlagUsage, | ||
| } from './types.js'; | ||
| import {ClearcutSender} from './clearcut-sender.js'; | ||
|
|
||
| export class ClearcutLogger { | ||
| #sender: ClearcutSender; | ||
|
|
||
| constructor(sender?: ClearcutSender) { | ||
| this.#sender = sender ?? new ClearcutSender(); | ||
| } | ||
|
|
||
| async logToolInvocation(args: { | ||
| toolName: string; | ||
| success: boolean; | ||
| latencyMs: number; | ||
| }): Promise<void> { | ||
| await this.#sender.send({ | ||
| tool_invocation: { | ||
| tool_name: args.toolName, | ||
| success: args.success, | ||
| latency_ms: args.latencyMs, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| async logServerStart(flagUsage: FlagUsage): Promise<void> { | ||
| await this.#sender.send({ | ||
| server_start: { | ||
| flag_usage: flagUsage, | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
|
ergunsh marked this conversation as resolved.
Outdated
|
||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import {ChromeDevToolsMcpExtension} from './types.js'; | ||
|
Check failure on line 7 in src/telemetry/clearcut-sender.ts
|
||
| import {logger} from '../logger.js'; | ||
|
|
||
| export class ClearcutSender { | ||
| async send(event: ChromeDevToolsMcpExtension): Promise<void> { | ||
| logger('Telemetry event', JSON.stringify(event, null, 2)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
|
ergunsh marked this conversation as resolved.
Outdated
|
||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| // Protobuf message interfaces | ||
| export interface ChromeDevToolsMcpExtension { | ||
| os_type?: OsType; | ||
| mcp_client?: McpClient; | ||
| app_version?: string; | ||
| session_id?: string; | ||
| tool_invocation?: ToolInvocation; | ||
| server_start?: ServerStart; | ||
| daily_active?: DailyActive; | ||
| first_time_installation?: FirstTimeInstallation; | ||
| } | ||
|
|
||
| export interface ToolInvocation { | ||
| tool_name: string; | ||
| success: boolean; | ||
| latency_ms: number; | ||
| } | ||
|
|
||
| export interface ServerStart { | ||
| flag_usage?: FlagUsage; | ||
| } | ||
|
|
||
| export interface DailyActive { | ||
| days_since_last_active: number; | ||
| } | ||
|
|
||
| export interface FirstTimeInstallation {} | ||
|
|
||
| export interface FlagUsage { | ||
| browser_url_present?: boolean; | ||
| headless?: boolean; | ||
| executable_path_present?: boolean; | ||
| isolated?: boolean; | ||
| channel?: ChromeChannel; | ||
| log_file_present?: boolean; | ||
| } | ||
|
|
||
| // Clearcut API interfaces | ||
| export interface LogRequest { | ||
| log_source: number; | ||
| request_time_ms: string; | ||
| client_info: { | ||
| client_type: number; | ||
| }; | ||
| log_event: Array<{ | ||
| event_time_ms: string; | ||
| source_extension_json: string; | ||
| }>; | ||
| } | ||
|
|
||
| // Enums | ||
| export enum OsType { | ||
| OS_TYPE_UNSPECIFIED = 0, | ||
| OS_TYPE_WINDOWS = 1, | ||
| OS_TYPE_MACOS = 2, | ||
| OS_TYPE_LINUX = 3, | ||
| } | ||
|
|
||
| export enum ChromeChannel { | ||
| CHROME_CHANNEL_UNSPECIFIED = 0, | ||
| CHROME_CHANNEL_CANARY = 1, | ||
| CHROME_CHANNEL_DEV = 2, | ||
| CHROME_CHANNEL_BETA = 3, | ||
| CHROME_CHANNEL_STABLE = 4, | ||
| } | ||
|
|
||
| export enum McpClient { | ||
| MCP_CLIENT_UNSPECIFIED = 0, | ||
| MCP_CLIENT_CLAUDE_CODE = 1, | ||
| MCP_CLIENT_GEMINI_CLI = 2, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
|
ergunsh marked this conversation as resolved.
Outdated
|
||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import assert from 'node:assert'; | ||
| import {describe, it, mock} from 'node:test'; | ||
| import {ClearcutLogger} from '../../src/telemetry/clearcut-logger.js'; | ||
| import {ClearcutSender} from '../../src/telemetry/clearcut-sender.js'; | ||
|
|
||
| describe('ClearcutLogger', () => { | ||
| it('should log tool invocation via sender', async () => { | ||
| const sender = new ClearcutSender(); | ||
| const sendSpy = mock.method(sender, 'send'); | ||
| const loggerInstance = new ClearcutLogger(sender); | ||
|
|
||
| await loggerInstance.logToolInvocation({ | ||
| toolName: 'test-tool', | ||
| success: true, | ||
| latencyMs: 100, | ||
| }); | ||
|
|
||
| assert.strictEqual(sendSpy.mock.callCount(), 1); | ||
| const event = sendSpy.mock.calls[0].arguments[0]; | ||
| assert.deepStrictEqual(event.tool_invocation, { | ||
| tool_name: 'test-tool', | ||
| success: true, | ||
| latency_ms: 100, | ||
| }); | ||
| }); | ||
|
|
||
| it('should log server start via sender', async () => { | ||
| const sender = new ClearcutSender(); | ||
| const sendSpy = mock.method(sender, 'send'); | ||
| const loggerInstance = new ClearcutLogger(sender); | ||
|
|
||
| await loggerInstance.logServerStart({headless: true}); | ||
|
|
||
| assert.strictEqual(sendSpy.mock.callCount(), 1); | ||
| const event = sendSpy.mock.calls[0].arguments[0]; | ||
| assert.deepStrictEqual(event.server_start, { | ||
| flag_usage: {headless: true}, | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.