summaryrefslogtreecommitdiff
path: root/packages/core/src/tools/read-many-files.ts
diff options
context:
space:
mode:
authorJerop Kipruto <[email protected]>2025-06-15 16:24:53 -0400
committerGitHub <[email protected]>2025-06-15 13:24:53 -0700
commit714421c2da4f5d6b9c1c7060fdf5c47ba1c965ca (patch)
tree488459669757dda99eda46b621a030ece38842dd /packages/core/src/tools/read-many-files.ts
parent4421ef126fc6a2de89132aa35c261bf78cd481d2 (diff)
Add file operation telemetry (#1068)
Introduces telemetry for file create, read, and update operations. This change adds the `gemini_cli.file.operation.count` metric, recorded by the `read-file`, `read-many-files`, and `write-file` tools. The metric includes the following attributes: - `operation` (string: `create`, `read`, `update`): The type of file operation. - `lines` (optional, Int): Number of lines in the file. - `mimetype` (optional, string): Mimetype of the file. - `extension` (optional, string): File extension of the file. Here is a stacked bar chart of file operations by extension (`js`, `ts`, `md`): ![image](https://github.com/user-attachments/assets/3e8f8ea9-6155-4186-863c-075cc47647c5) Here is a stacked bar chart of file operations by type (`create`, `read`, `update`): ![image](https://github.com/user-attachments/assets/3fcf491d-31d0-4ba8-80e6-7fd2bd9c7c27) #750 cc @allenhutchison as discussed
Diffstat (limited to 'packages/core/src/tools/read-many-files.ts')
-rw-r--r--packages/core/src/tools/read-many-files.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/packages/core/src/tools/read-many-files.ts b/packages/core/src/tools/read-many-files.ts
index 107e16b3..62430c10 100644
--- a/packages/core/src/tools/read-many-files.ts
+++ b/packages/core/src/tools/read-many-files.ts
@@ -14,9 +14,14 @@ import {
detectFileType,
processSingleFileContent,
DEFAULT_ENCODING,
+ getSpecificMimeType,
} from '../utils/fileUtils.js';
import { PartListUnion } from '@google/genai';
import { Config } from '../config/config.js';
+import {
+ recordFileOperationMetric,
+ FileOperation,
+} from '../telemetry/metrics.js';
/**
* Parameters for the ReadManyFilesTool.
@@ -420,6 +425,18 @@ Use this tool when the user's query implies needing the content of several files
contentParts.push(fileReadResult.llmContent); // This is a Part for image/pdf
}
processedFilesRelativePaths.push(relativePathForDisplay);
+ const lines =
+ typeof fileReadResult.llmContent === 'string'
+ ? fileReadResult.llmContent.split('\n').length
+ : undefined;
+ const mimetype = getSpecificMimeType(filePath);
+ recordFileOperationMetric(
+ this.config,
+ FileOperation.READ,
+ lines,
+ mimetype,
+ path.extname(filePath),
+ );
}
}