|
1 | 1 | import { Session } from "../session.js"; |
2 | 2 | import { BaseEvent, type ToolEvent } from "./types.js"; |
3 | | -import pkg from "../../package.json" with { type: "json" }; |
4 | 3 | import config from "../config.js"; |
5 | 4 | import logger from "../logger.js"; |
6 | 5 | import { mongoLogId } from "mongodb-log-writer"; |
7 | 6 | import { ApiClient } from "../common/atlas/apiClient.js"; |
8 | 7 | import fs from "fs/promises"; |
9 | 8 | import path from "path"; |
| 9 | +import { MACHINE_METADATA } from "./constants.js"; |
10 | 10 |
|
11 | | -const TELEMETRY_ENABLED = config.telemetry !== "disabled"; |
12 | 11 | const CACHE_FILE = path.join(process.cwd(), ".telemetry-cache.json"); |
13 | 12 |
|
14 | 13 | interface TelemetryError extends Error { |
@@ -39,24 +38,26 @@ export class Telemetry { |
39 | 38 | constructor(private readonly session: Session) { |
40 | 39 | // Ensure all required properties are present |
41 | 40 | this.commonProperties = Object.freeze({ |
42 | | - device_id: config.device_id, |
43 | | - mcp_server_version: pkg.version, |
44 | | - mcp_server_name: config.mcpServerName, |
| 41 | + ...MACHINE_METADATA, |
45 | 42 | mcp_client_version: this.session.agentRunner?.version, |
46 | 43 | mcp_client_name: this.session.agentRunner?.name, |
47 | | - platform: config.platform, |
48 | | - arch: config.arch, |
49 | | - os_type: config.os_type, |
50 | | - os_version: config.os_version, |
51 | 44 | }); |
52 | 45 | } |
53 | 46 |
|
| 47 | + /** |
| 48 | + * Checks if telemetry is currently enabled |
| 49 | + * This is a method rather than a constant to capture runtime config changes |
| 50 | + */ |
| 51 | + private static isTelemetryEnabled(): boolean { |
| 52 | + return config.telemetry !== "disabled"; |
| 53 | + } |
| 54 | + |
54 | 55 | /** |
55 | 56 | * Emits events through the telemetry pipeline |
56 | 57 | * @param events - The events to emit |
57 | 58 | */ |
58 | 59 | public async emitEvents(events: BaseEvent[]): Promise<void> { |
59 | | - if (!TELEMETRY_ENABLED) { |
| 60 | + if (!Telemetry.isTelemetryEnabled()) { |
60 | 61 | logger.debug(mongoLogId(1_000_000), "telemetry", "Telemetry is disabled, skipping events."); |
61 | 62 | return; |
62 | 63 | } |
|
0 commit comments