1
1
import type { Session } from "../common/session.js" ;
2
- import type { BaseEvent , CommonProperties } from "./types.js" ;
2
+ import type { BaseEvent , CommonProperties , TelemetryEvent } from "./types.js" ;
3
3
import type { UserConfig } from "../common/config.js" ;
4
4
import { LogId } from "../common/logger.js" ;
5
5
import type { ApiClient } from "../common/atlas/apiClient.js" ;
@@ -8,6 +8,7 @@ import { EventCache } from "./eventCache.js";
8
8
import { detectContainerEnv } from "../helpers/container.js" ;
9
9
import type { DeviceId } from "../helpers/deviceId.js" ;
10
10
import { EventEmitter } from "events" ;
11
+ import { redact } from "mongodb-redact" ;
11
12
12
13
type EventResult = {
13
14
success : boolean ;
@@ -52,8 +53,8 @@ export class Telemetry {
52
53
} = { }
53
54
) : Telemetry {
54
55
const mergedProperties = {
55
- ...MACHINE_METADATA ,
56
- ...commonProperties ,
56
+ ...redact ( MACHINE_METADATA , session . keychain . allSecrets ) ,
57
+ ...redact ( commonProperties , session . keychain . allSecrets ) ,
57
58
} ;
58
59
const instance = new Telemetry ( session , userConfig , mergedProperties , {
59
60
eventCache,
@@ -123,7 +124,6 @@ export class Telemetry {
123
124
this . events . emit ( "events-skipped" ) ;
124
125
return ;
125
126
}
126
-
127
127
// Don't wait for events to be sent - we should not block regular server
128
128
// operations on telemetry
129
129
void this . emit ( events ) ;
@@ -135,11 +135,11 @@ export class Telemetry {
135
135
*/
136
136
public getCommonProperties ( ) : CommonProperties {
137
137
return {
138
- ...this . commonProperties ,
138
+ ...redact ( this . commonProperties , this . session . keychain . allSecrets ) ,
139
139
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 ) ,
143
143
config_atlas_auth : this . session . apiClient . hasCredentials ( ) ? "true" : "false" ,
144
144
config_connection_string : this . userConfig . connectionString ? "true" : "false" ,
145
145
} ;
@@ -214,13 +214,17 @@ export class Telemetry {
214
214
215
215
/**
216
216
* Attempts to send events through the provided API client
217
+ * Events are redacted before being sent to ensure no sensitive data is transmitted
217
218
*/
218
219
private async sendEvents ( client : ApiClient , events : BaseEvent [ ] ) : Promise < EventResult > {
219
220
try {
220
221
await client . sendEvents (
221
222
events . map ( ( event ) => ( {
222
223
...event ,
223
- properties : { ...this . getCommonProperties ( ) , ...event . properties } ,
224
+ properties : {
225
+ ...this . getCommonProperties ( ) ,
226
+ ...redact ( event . properties , this . session . keychain . allSecrets ) ,
227
+ } ,
224
228
} ) )
225
229
) ;
226
230
return { success : true } ;
0 commit comments