Skip to content

Commit dac1b2d

Browse files
committed
chore: minor improvements
1 parent 3b9e002 commit dac1b2d

File tree

3 files changed

+32
-27
lines changed

3 files changed

+32
-27
lines changed

src/session.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class Session extends EventEmitter<{
2626
username: string;
2727
projectId: string;
2828
clusterName: string;
29+
organizationId?: string;
2930
expiryDate: Date;
3031
};
3132

src/telemetry/telemetry.ts

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

14-
export class Telemetry {
15-
private readonly commonProperties: CommonProperties;
16-
17-
constructor(
18-
private readonly session: Session,
19-
private readonly eventCache: EventCache = EventCache.getInstance()
20-
) {
21-
this.commonProperties = {
22-
...MACHINE_METADATA,
23-
};
24-
}
25-
26-
/**
14+
/**
2715
* Checks if telemetry is currently enabled
2816
* This is a method rather than a constant to capture runtime config changes
2917
*
3018
* Follows the Console Do Not Track standard (https://consoledonottrack.com/)
3119
* by respecting the DO_NOT_TRACK environment variable
3220
*/
33-
private static isTelemetryEnabled(): boolean {
34-
// Check if telemetry is explicitly disabled in config
35-
if (config.telemetry === "disabled") {
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 = process.env.DO_NOT_TRACK;
28+
if (doNotTrack) {
29+
const value = doNotTrack.toLowerCase();
30+
// Telemetry should be disabled if DO_NOT_TRACK is "1", "true", or "yes"
31+
if (value === "1" || value === "true" || value === "yes") {
3632
return false;
3733
}
34+
}
3835

39-
const doNotTrack = process.env.DO_NOT_TRACK;
40-
if (doNotTrack) {
41-
const value = doNotTrack.toLowerCase();
42-
// Telemetry should be disabled if DO_NOT_TRACK is "1", "true", or "yes"
43-
if (value === "1" || value === "true" || value === "yes") {
44-
return false;
45-
}
46-
}
36+
return true;
37+
}
38+
39+
export class Telemetry {
40+
private readonly commonProperties: CommonProperties;
4741

48-
return true;
42+
constructor(
43+
private readonly session: Session,
44+
private readonly eventCache: EventCache = EventCache.getInstance()
45+
) {
46+
this.commonProperties = {
47+
...MACHINE_METADATA,
48+
};
4949
}
5050

5151
/**
@@ -54,7 +54,8 @@ export class Telemetry {
5454
*/
5555
public async emitEvents(events: BaseEvent[]): Promise<void> {
5656
try {
57-
if (!Telemetry.isTelemetryEnabled()) {
57+
if (!isTelemetryEnabled()) {
58+
logger.info(LogId.telemetryEmitFailure, "telemetry", `Telemetry is disabled.`);
5859
return;
5960
}
6061

src/tools/tool.ts

Lines changed: 4 additions & 1 deletion
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 } from "../telemetry/telemetry.js";
6+
import { Telemetry, isTelemetryEnabled } from "../telemetry/telemetry.js";
77
import { type ToolEvent } from "../telemetry/types.js";
88
import { UserConfig } from "../config.js";
99

@@ -38,6 +38,9 @@ export abstract class ToolBase {
3838
* @param error - Optional error if the command failed
3939
*/
4040
private async emitToolEvent(startTime: number, result: CallToolResult): Promise<void> {
41+
if (!isTelemetryEnabled()) {
42+
return;
43+
}
4144
const duration = Date.now() - startTime;
4245
const event: ToolEvent = {
4346
timestamp: new Date().toISOString(),

0 commit comments

Comments
 (0)