Skip to content

Commit afe863e

Browse files
committed
apply redact in telemetry properties
1 parent ea1c1d7 commit afe863e

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/telemetry/telemetry.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Session } from "../common/session.js";
2-
import type { BaseEvent, CommonProperties } from "./types.js";
2+
import type { BaseEvent, CommonProperties, TelemetryEvent } from "./types.js";
33
import type { UserConfig } from "../common/config.js";
44
import { LogId } from "../common/logger.js";
55
import type { ApiClient } from "../common/atlas/apiClient.js";
@@ -8,6 +8,7 @@ import { EventCache } from "./eventCache.js";
88
import { detectContainerEnv } from "../helpers/container.js";
99
import type { DeviceId } from "../helpers/deviceId.js";
1010
import { EventEmitter } from "events";
11+
import { redact } from "mongodb-redact";
1112

1213
type EventResult = {
1314
success: boolean;
@@ -52,8 +53,8 @@ export class Telemetry {
5253
} = {}
5354
): Telemetry {
5455
const mergedProperties = {
55-
...MACHINE_METADATA,
56-
...commonProperties,
56+
...redact(MACHINE_METADATA, session.keychain.allSecrets),
57+
...redact(commonProperties, session.keychain.allSecrets),
5758
};
5859
const instance = new Telemetry(session, userConfig, mergedProperties, {
5960
eventCache,
@@ -123,7 +124,6 @@ export class Telemetry {
123124
this.events.emit("events-skipped");
124125
return;
125126
}
126-
127127
// Don't wait for events to be sent - we should not block regular server
128128
// operations on telemetry
129129
void this.emit(events);
@@ -135,11 +135,11 @@ export class Telemetry {
135135
*/
136136
public getCommonProperties(): CommonProperties {
137137
return {
138-
...this.commonProperties,
138+
...redact(this.commonProperties, this.session.keychain.allSecrets),
139139
transport: this.userConfig.transport,
140-
mcp_client_version: this.session.mcpClient?.version,
141-
mcp_client_name: this.session.mcpClient?.name,
142-
session_id: this.session.sessionId,
140+
mcp_client_version: redact(this.session.mcpClient?.version, this.session.keychain.allSecrets),
141+
mcp_client_name: redact(this.session.mcpClient?.name, this.session.keychain.allSecrets),
142+
session_id: redact(this.session.sessionId, this.session.keychain.allSecrets),
143143
config_atlas_auth: this.session.apiClient.hasCredentials() ? "true" : "false",
144144
config_connection_string: this.userConfig.connectionString ? "true" : "false",
145145
};
@@ -214,13 +214,17 @@ export class Telemetry {
214214

215215
/**
216216
* Attempts to send events through the provided API client
217+
* Events are redacted before being sent to ensure no sensitive data is transmitted
217218
*/
218219
private async sendEvents(client: ApiClient, events: BaseEvent[]): Promise<EventResult> {
219220
try {
220221
await client.sendEvents(
221222
events.map((event) => ({
222223
...event,
223-
properties: { ...this.getCommonProperties(), ...event.properties },
224+
properties: {
225+
...this.getCommonProperties(),
226+
...redact(event.properties, this.session.keychain.allSecrets),
227+
},
224228
}))
225229
);
226230
return { success: true };

0 commit comments

Comments
 (0)