Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export class Server {

if (command === "start") {
event.properties.startup_time_ms = commandDuration;
event.properties.read_only_mode = this.userConfig.readOnly || false;
event.properties.read_only_mode = this.userConfig.readOnly ? "true" : "false";
event.properties.disabled_tools = this.userConfig.disabledTools || [];
event.properties.confirmation_required_tools = this.userConfig.confirmationRequiredTools || [];
}
Expand Down
22 changes: 13 additions & 9 deletions src/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { detectContainerEnv } from "../helpers/container.js";
import type { DeviceId } from "../helpers/deviceId.js";
import { EventEmitter } from "events";
import { redact } from "mongodb-redact";

type EventResult = {
success: boolean;
Expand Down Expand Up @@ -52,8 +53,8 @@
} = {}
): Telemetry {
const mergedProperties = {
...MACHINE_METADATA,
...commonProperties,
...redact(MACHINE_METADATA, session.keychain.allSecrets),

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (macos-latest)

tests/unit/telemetry.test.ts > Telemetry > when DO_NOT_TRACK environment variable is set > should not send events

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (macos-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is disabled > should not send events

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (macos-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > device ID resolution > should handle device ID timeout gracefully

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (macos-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > device ID resolution > should handle device ID resolution failure gracefully

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (macos-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > device ID resolution > should successfully resolve the device ID

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (macos-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > should add hostingMode to events if set

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (macos-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > should correctly add common properties to events

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (macos-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > should include cached events when sending

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (macos-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > should cache events when sending fails

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (macos-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > should send events successfully

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (ubuntu-latest)

tests/unit/telemetry.test.ts > Telemetry > when DO_NOT_TRACK environment variable is set > should not send events

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (ubuntu-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is disabled > should not send events

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (ubuntu-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > device ID resolution > should handle device ID timeout gracefully

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (ubuntu-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > device ID resolution > should handle device ID resolution failure gracefully

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (ubuntu-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > device ID resolution > should successfully resolve the device ID

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (ubuntu-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > should add hostingMode to events if set

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (ubuntu-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > should correctly add common properties to events

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (ubuntu-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > should include cached events when sending

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (ubuntu-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > should cache events when sending fails

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (ubuntu-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > should send events successfully

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (windows-latest)

tests/unit/telemetry.test.ts > Telemetry > when DO_NOT_TRACK environment variable is set > should not send events

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (windows-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is disabled > should not send events

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (windows-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > device ID resolution > should handle device ID timeout gracefully

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (windows-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > device ID resolution > should handle device ID resolution failure gracefully

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (windows-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > device ID resolution > should successfully resolve the device ID

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (windows-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > should add hostingMode to events if set

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (windows-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > should correctly add common properties to events

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (windows-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > should include cached events when sending

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (windows-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > should cache events when sending fails

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31

Check failure on line 56 in src/telemetry/telemetry.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (windows-latest)

tests/unit/telemetry.test.ts > Telemetry > when telemetry is enabled > should send events successfully

TypeError: Cannot read properties of undefined (reading 'allSecrets') ❯ Function.create src/telemetry/telemetry.ts:56:58 ❯ tests/unit/telemetry.test.ts:145:31
...redact(commonProperties, session.keychain.allSecrets),
};
const instance = new Telemetry(session, userConfig, mergedProperties, {
eventCache,
Expand All @@ -79,7 +80,7 @@
const [deviceIdValue, containerEnv] = await this.setupPromise;

this.commonProperties.device_id = deviceIdValue;
this.commonProperties.is_container_env = containerEnv;
this.commonProperties.is_container_env = containerEnv ? "true" : "false";

this.isBufferingEvents = false;
}
Expand Down Expand Up @@ -123,7 +124,6 @@
this.events.emit("events-skipped");
return;
}

// Don't wait for events to be sent - we should not block regular server
// operations on telemetry
void this.emit(events);
Expand All @@ -135,11 +135,11 @@
*/
public getCommonProperties(): CommonProperties {
return {
...this.commonProperties,
...redact(this.commonProperties, this.session.keychain.allSecrets),
transport: this.userConfig.transport,
mcp_client_version: this.session.mcpClient?.version,
mcp_client_name: this.session.mcpClient?.name,
session_id: this.session.sessionId,
mcp_client_version: redact(this.session.mcpClient?.version, this.session.keychain.allSecrets),
mcp_client_name: redact(this.session.mcpClient?.name, this.session.keychain.allSecrets),
session_id: redact(this.session.sessionId, this.session.keychain.allSecrets),
config_atlas_auth: this.session.apiClient.hasCredentials() ? "true" : "false",
config_connection_string: this.userConfig.connectionString ? "true" : "false",
};
Expand Down Expand Up @@ -214,13 +214,17 @@

/**
* Attempts to send events through the provided API client
* Events are redacted before being sent to ensure no sensitive data is transmitted
*/
private async sendEvents(client: ApiClient, events: BaseEvent[]): Promise<EventResult> {
try {
await client.sendEvents(
events.map((event) => ({
...event,
properties: { ...this.getCommonProperties(), ...event.properties },
properties: {
...this.getCommonProperties(),
...redact(event.properties, this.session.keychain.allSecrets),
},
}))
);
return { success: true };
Expand Down
4 changes: 2 additions & 2 deletions src/telemetry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type ServerEventProperties = {
reason?: string;
startup_time_ms?: number;
runtime_duration_ms?: number;
read_only_mode?: boolean;
read_only_mode?: TelemetryBoolSet;
disabled_tools?: string[];
confirmation_required_tools?: string[];
};
Expand Down Expand Up @@ -97,7 +97,7 @@ export type CommonProperties = {
/**
* A boolean indicating whether the server is running in a container environment.
*/
is_container_env?: boolean;
is_container_env?: TelemetryBoolSet;

/**
* The version of the MCP client as reported by the client on session establishment.
Expand Down
28 changes: 28 additions & 0 deletions tests/integration/telemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,32 @@ describe("Telemetry", () => {
expect(telemetry.getCommonProperties().device_id).toBe(actualDeviceId);
expect(telemetry["isBufferingEvents"]).toBe(false);
});

it("should redact sensitive data", async () => {
const logger = new CompositeLogger();
const deviceId = DeviceId.create(logger);

// configure keychain with a secret that would show up in random properties
const keychain = new Keychain();
keychain.register(process.platform, "url");

const telemetry = Telemetry.create(
new Session({
apiBaseUrl: "",
logger,
exportsManager: ExportsManager.init(config, logger),
connectionManager: new MCPConnectionManager(config, driverOptions, logger, deviceId),
keychain: keychain,
}),
config,
deviceId
);

await telemetry.setupPromise;

// expect the platform to be redacted
const commonProperties = telemetry.getCommonProperties();
expect(commonProperties.platform).toBe("<url>");
expect(telemetry["isBufferingEvents"]).toBe(false);
});
});
Loading