| 51 | } |
| 52 | |
| 53 | export class Telemetry { |
| 54 | private telemetryDisabledRecorded = false; |
| 55 | private id: string; |
| 56 | |
| 57 | constructor() { |
| 58 | this.id = getUserId(); |
| 59 | void this.identify(); |
| 60 | } |
| 61 | |
| 62 | private getPersonProperties(ciFlag: boolean) { |
| 63 | const personProperties = { |
| 64 | ...getUserAuthInfo(), |
| 65 | isRunningInCi: ciFlag, |
| 66 | }; |
| 67 | return personProperties; |
| 68 | } |
| 69 | |
| 70 | async identify() { |
| 71 | if (this.disabled || getEnvBool('IS_TESTING')) { |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | const client = getPostHogClient(); |
| 76 | if (client) { |
| 77 | try { |
| 78 | const personProperties = this.getPersonProperties(isCI()); |
| 79 | client.identify({ |
| 80 | distinctId: this.id, |
| 81 | properties: personProperties, |
| 82 | }); |
| 83 | client.flush().catch(() => { |
| 84 | // Silently ignore flush errors |
| 85 | }); |
| 86 | } catch (error) { |
| 87 | logger.debug(`PostHog identify error: ${error}`); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | get disabled() { |
| 93 | return getEnvBool('PROMPTFOO_DISABLE_TELEMETRY'); |
| 94 | } |
| 95 | |
| 96 | private recordTelemetryDisabled() { |
| 97 | if (!this.telemetryDisabledRecorded) { |
| 98 | this.sendEvent('feature_used', { feature: 'telemetry disabled' }); |
| 99 | this.telemetryDisabledRecorded = true; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | record(eventName: TelemetryEventTypes, properties: EventProperties): void { |
| 104 | if (this.disabled) { |
| 105 | this.recordTelemetryDisabled(); |
| 106 | } else { |
| 107 | this.sendEvent(eventName, properties); |
| 108 | } |
| 109 | } |
| 110 |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…