@@ -8,6 +8,11 @@ import { PostHog } from "posthog-node"
88import { type TelemetryPropertiesProvider , TelemetryEventName , ApiProviderError } from "@roo-code/types"
99
1010import { PostHogTelemetryClient } from "../PostHogTelemetryClient"
11+ import { hashDistinctId } from "../distinct-id"
12+
13+ // The client must use the salted hash as its PostHog distinct ID, never the raw
14+ // VS Code machine ID (issue #830).
15+ const hashedMachineId = hashDistinctId ( "test-machine-id" )
1116
1217vi . mock ( "posthog-node" )
1318
@@ -277,7 +282,7 @@ describe("PostHogTelemetryClient", () => {
277282 } )
278283
279284 expect ( mockPostHogClient . capture ) . toHaveBeenCalledWith ( {
280- distinctId : "test-machine-id" ,
285+ distinctId : hashedMachineId ,
281286 event : TelemetryEventName . TASK_CREATED ,
282287 properties : expect . objectContaining ( {
283288 appVersion : "1.0.0" ,
@@ -286,6 +291,22 @@ describe("PostHogTelemetryClient", () => {
286291 } )
287292 } )
288293
294+ it ( "never uses the raw VS Code machine ID as the PostHog distinct ID" , async ( ) => {
295+ const client = new PostHogTelemetryClient ( )
296+ client . updateTelemetryState ( true )
297+
298+ await client . capture ( {
299+ event : TelemetryEventName . TASK_CREATED ,
300+ properties : { test : "value" } ,
301+ } )
302+
303+ expect ( mockPostHogClient . capture ) . toHaveBeenCalledTimes ( 1 )
304+ const captureCall = mockPostHogClient . capture . mock . calls [ 0 ] [ 0 ]
305+ expect ( captureCall . distinctId ) . toBe ( hashedMachineId )
306+ expect ( captureCall . distinctId ) . not . toBe ( "test-machine-id" )
307+ expect ( captureCall . distinctId ) . not . toContain ( "test-machine-id" )
308+ } )
309+
289310 it ( "should filter out git repository properties when capturing events" , async ( ) => {
290311 const client = new PostHogTelemetryClient ( )
291312 client . updateTelemetryState ( true )
@@ -313,7 +334,7 @@ describe("PostHogTelemetryClient", () => {
313334 } )
314335
315336 expect ( mockPostHogClient . capture ) . toHaveBeenCalledWith ( {
316- distinctId : "test-machine-id" ,
337+ distinctId : hashedMachineId ,
317338 event : TelemetryEventName . TASK_CREATED ,
318339 properties : expect . objectContaining ( {
319340 appVersion : "1.0.0" ,
@@ -402,7 +423,7 @@ describe("PostHogTelemetryClient", () => {
402423
403424 expect ( mockPostHogClient . captureException ) . toHaveBeenCalledWith (
404425 error ,
405- "test-machine-id" ,
426+ hashedMachineId ,
406427 expect . objectContaining ( {
407428 customProp : "value" ,
408429 $app_version : "1.0.0" ,
@@ -417,7 +438,7 @@ describe("PostHogTelemetryClient", () => {
417438 const error = new Error ( "Test error" )
418439 await client . captureException ( error )
419440
420- expect ( mockPostHogClient . captureException ) . toHaveBeenCalledWith ( error , "test-machine-id" , {
441+ expect ( mockPostHogClient . captureException ) . toHaveBeenCalledWith ( error , hashedMachineId , {
421442 $app_version : undefined ,
422443 } )
423444 } )
@@ -485,7 +506,7 @@ describe("PostHogTelemetryClient", () => {
485506 const error = new Error ( "Internal server error" )
486507 client . captureException ( error )
487508
488- expect ( mockPostHogClient . captureException ) . toHaveBeenCalledWith ( error , "test-machine-id" , {
509+ expect ( mockPostHogClient . captureException ) . toHaveBeenCalledWith ( error , hashedMachineId , {
489510 $app_version : undefined ,
490511 } )
491512 } )
@@ -497,7 +518,7 @@ describe("PostHogTelemetryClient", () => {
497518 const error = Object . assign ( new Error ( "Internal server error" ) , { status : 500 } )
498519 client . captureException ( error )
499520
500- expect ( mockPostHogClient . captureException ) . toHaveBeenCalledWith ( error , "test-machine-id" , {
521+ expect ( mockPostHogClient . captureException ) . toHaveBeenCalledWith ( error , hashedMachineId , {
501522 $app_version : undefined ,
502523 } )
503524 } )
@@ -537,7 +558,7 @@ describe("PostHogTelemetryClient", () => {
537558
538559 // The implementation overrides error.message with the extracted message from getErrorMessage
539560 expect ( error . message ) . toBe ( "Upstream provider error: model overloaded" )
540- expect ( mockPostHogClient . captureException ) . toHaveBeenCalledWith ( error , "test-machine-id" , {
561+ expect ( mockPostHogClient . captureException ) . toHaveBeenCalledWith ( error , hashedMachineId , {
541562 $app_version : undefined ,
542563 } )
543564 } )
@@ -558,7 +579,7 @@ describe("PostHogTelemetryClient", () => {
558579
559580 // The implementation overrides error.message with the extracted message from getErrorMessage
560581 expect ( error . message ) . toBe ( "Upstream provider: connection timeout" )
561- expect ( mockPostHogClient . captureException ) . toHaveBeenCalledWith ( error , "test-machine-id" , {
582+ expect ( mockPostHogClient . captureException ) . toHaveBeenCalledWith ( error , hashedMachineId , {
562583 $app_version : undefined ,
563584 } )
564585 } )
@@ -576,7 +597,7 @@ describe("PostHogTelemetryClient", () => {
576597
577598 // Verify error message remains the primary message
578599 expect ( error . message ) . toBe ( "Primary error message" )
579- expect ( mockPostHogClient . captureException ) . toHaveBeenCalledWith ( error , "test-machine-id" , {
600+ expect ( mockPostHogClient . captureException ) . toHaveBeenCalledWith ( error , hashedMachineId , {
580601 $app_version : undefined ,
581602 } )
582603 } )
@@ -589,7 +610,7 @@ describe("PostHogTelemetryClient", () => {
589610 client . captureException ( error )
590611
591612 // The implementation auto-extracts properties from ApiProviderError
592- expect ( mockPostHogClient . captureException ) . toHaveBeenCalledWith ( error , "test-machine-id" , {
613+ expect ( mockPostHogClient . captureException ) . toHaveBeenCalledWith ( error , hashedMachineId , {
593614 provider : "OpenRouter" ,
594615 modelId : "gpt-4" ,
595616 operation : "createMessage" ,
@@ -606,7 +627,7 @@ describe("PostHogTelemetryClient", () => {
606627 client . captureException ( error , { customProperty : "value" } )
607628
608629 // additionalProperties take precedence over auto-extracted properties
609- expect ( mockPostHogClient . captureException ) . toHaveBeenCalledWith ( error , "test-machine-id" , {
630+ expect ( mockPostHogClient . captureException ) . toHaveBeenCalledWith ( error , hashedMachineId , {
610631 provider : "OpenRouter" ,
611632 modelId : "gpt-4" ,
612633 operation : "createMessage" ,
@@ -622,7 +643,7 @@ describe("PostHogTelemetryClient", () => {
622643 const error = new Error ( "Regular error" )
623644 client . captureException ( error , { customProperty : "value" } )
624645
625- expect ( mockPostHogClient . captureException ) . toHaveBeenCalledWith ( error , "test-machine-id" , {
646+ expect ( mockPostHogClient . captureException ) . toHaveBeenCalledWith ( error , hashedMachineId , {
626647 customProperty : "value" ,
627648 $app_version : undefined ,
628649 } )
0 commit comments