Skip to content

Commit 7997c54

Browse files
committed
address comment: isolate machine data
1 parent 6d92021 commit 7997c54

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ const mergedUserConfig = {
4040
...getCliConfig(),
4141
};
4242

43-
const machineMetadata = {
43+
// Machine-specific metadata that isn't configurable
44+
export const machineMetadata = {
4445
device_id: "id", // TODO: use @mongodb-js/machine-id
4546
platform: process.platform,
4647
arch: process.arch,
@@ -50,7 +51,6 @@ const machineMetadata = {
5051

5152
const config = {
5253
...mergedUserConfig,
53-
...machineMetadata,
5454
version: packageJson.version,
5555
mcpServerName: "MdbMcpServer",
5656
isTelemetryEnabled: true,

src/telemetry/telemetry.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { Session } from "../session.js";
22
import { BaseEvent, type ToolEvent } from "./types.js";
3-
import pkg from "../../package.json" with { type: "json" };
43
import config from "../config.js";
54
import logger from "../logger.js";
65
import { mongoLogId } from "mongodb-log-writer";
76
import { ApiClient } from "../common/atlas/apiClient.js";
87
import fs from "fs/promises";
98
import path from "path";
9+
import { MACHINE_METADATA } from "./constants.js";
1010

11-
const TELEMETRY_ENABLED = config.telemetry !== "disabled";
1211
const CACHE_FILE = path.join(process.cwd(), ".telemetry-cache.json");
1312

1413
interface TelemetryError extends Error {
@@ -39,24 +38,26 @@ export class Telemetry {
3938
constructor(private readonly session: Session) {
4039
// Ensure all required properties are present
4140
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,
4542
mcp_client_version: this.session.agentRunner?.version,
4643
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,
5144
});
5245
}
5346

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+
5455
/**
5556
* Emits events through the telemetry pipeline
5657
* @param events - The events to emit
5758
*/
5859
public async emitEvents(events: BaseEvent[]): Promise<void> {
59-
if (!TELEMETRY_ENABLED) {
60+
if (!Telemetry.isTelemetryEnabled()) {
6061
logger.debug(mongoLogId(1_000_000), "telemetry", "Telemetry is disabled, skipping events.");
6162
return;
6263
}

0 commit comments

Comments
 (0)