Skip to content

Commit 43e5c75

Browse files
committed
address comment: telemetry enabled check
1 parent 72539ab commit 43e5c75

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/telemetry/telemetry.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,6 @@ type EventResult = {
1111
error?: Error;
1212
};
1313

14-
/**
15-
* Checks if telemetry is currently enabled
16-
* This is a method rather than a constant to capture runtime config changes
17-
*
18-
* Follows the Console Do Not Track standard (https://consoledonottrack.com/)
19-
* by respecting the DO_NOT_TRACK environment variable
20-
*/
21-
export function isTelemetryEnabled(): boolean {
22-
// Check if telemetry is explicitly disabled in config
23-
if (config.telemetry === "disabled") {
24-
return false;
25-
}
26-
27-
const doNotTrack = "DO_NOT_TRACK" in process.env;
28-
return !doNotTrack;
29-
}
30-
3114
export class Telemetry {
3215
private readonly commonProperties: CommonProperties;
3316

@@ -46,7 +29,7 @@ export class Telemetry {
4629
*/
4730
public async emitEvents(events: BaseEvent[]): Promise<void> {
4831
try {
49-
if (!isTelemetryEnabled()) {
32+
if (!this.isTelemetryEnabled()) {
5033
logger.info(LogId.telemetryEmitFailure, "telemetry", `Telemetry is disabled.`);
5134
return;
5235
}
@@ -72,6 +55,23 @@ export class Telemetry {
7255
};
7356
}
7457

58+
/**
59+
* Checks if telemetry is currently enabled
60+
* This is a method rather than a constant to capture runtime config changes
61+
*
62+
* Follows the Console Do Not Track standard (https://consoledonottrack.com/)
63+
* by respecting the DO_NOT_TRACK environment variable
64+
*/
65+
public isTelemetryEnabled(): boolean {
66+
// Check if telemetry is explicitly disabled in config
67+
if (config.telemetry === "disabled") {
68+
return false;
69+
}
70+
71+
const doNotTrack = "DO_NOT_TRACK" in process.env;
72+
return !doNotTrack;
73+
}
74+
7575
/**
7676
* Attempts to emit events through authenticated and unauthenticated clients
7777
* Falls back to caching if both attempts fail

src/tools/tool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { McpServer, RegisteredTool, ToolCallback } from "@modelcontextproto
33
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
44
import { Session } from "../session.js";
55
import logger, { LogId } from "../logger.js";
6-
import { Telemetry, isTelemetryEnabled } from "../telemetry/telemetry.js";
6+
import { Telemetry } from "../telemetry/telemetry.js";
77
import { type ToolEvent } from "../telemetry/types.js";
88
import { UserConfig } from "../config.js";
99

@@ -185,7 +185,7 @@ export abstract class ToolBase {
185185
result: CallToolResult,
186186
...args: Parameters<ToolCallback<typeof this.argsShape>>
187187
): Promise<void> {
188-
if (!isTelemetryEnabled()) {
188+
if (!this.telemetry.isTelemetryEnabled()) {
189189
return;
190190
}
191191
const duration = Date.now() - startTime;

0 commit comments

Comments
 (0)