mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
This PR adds filtering of git repository properties from telemetry data and includes git info in telemetry properties, with comprehensive tests. Behavior: PostHogTelemetryClient now filters out repositoryUrl, repositoryName, and defaultBranch from telemetry events. ClineProvider includes git repository information in telemetry properties, filtered by clients. Functions: Added isPropertyCapturable() in BaseTelemetryClient to allow property filtering. Implemented getGitRepositoryInfo() and getWorkspaceGitInfo() in git.ts to extract git info. Tests: Added tests for isPropertyCapturable() in PostHogTelemetryClient.test.ts. Added tests for getGitRepositoryInfo() and getWorkspaceGitInfo() in git.spec.ts.
73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
import {
|
|
TelemetryEvent,
|
|
TelemetryEventName,
|
|
TelemetryClient,
|
|
TelemetryPropertiesProvider,
|
|
TelemetryEventSubscription,
|
|
} from "@roo-code/types"
|
|
|
|
export abstract class BaseTelemetryClient implements TelemetryClient {
|
|
protected providerRef: WeakRef<TelemetryPropertiesProvider> | null = null
|
|
protected telemetryEnabled: boolean = false
|
|
|
|
constructor(
|
|
public readonly subscription?: TelemetryEventSubscription,
|
|
protected readonly debug = false,
|
|
) {}
|
|
|
|
protected isEventCapturable(eventName: TelemetryEventName): boolean {
|
|
if (!this.subscription) {
|
|
return true
|
|
}
|
|
|
|
return this.subscription.type === "include"
|
|
? this.subscription.events.includes(eventName)
|
|
: !this.subscription.events.includes(eventName)
|
|
}
|
|
|
|
/**
|
|
* Determines if a specific property should be included in telemetry events
|
|
* Override in subclasses to filter specific properties
|
|
*/
|
|
protected isPropertyCapturable(_propertyName: string): boolean {
|
|
return true
|
|
}
|
|
|
|
protected async getEventProperties(event: TelemetryEvent): Promise<TelemetryEvent["properties"]> {
|
|
let providerProperties: TelemetryEvent["properties"] = {}
|
|
const provider = this.providerRef?.deref()
|
|
|
|
if (provider) {
|
|
try {
|
|
// Get properties from the provider
|
|
providerProperties = await provider.getTelemetryProperties()
|
|
} catch (error) {
|
|
// Log error but continue with capturing the event.
|
|
console.error(
|
|
`Error getting telemetry properties: ${error instanceof Error ? error.message : String(error)}`,
|
|
)
|
|
}
|
|
}
|
|
|
|
// Merge provider properties with event-specific properties.
|
|
// Event properties take precedence in case of conflicts.
|
|
const mergedProperties = { ...providerProperties, ...(event.properties || {}) }
|
|
|
|
// Filter out properties that shouldn't be captured by this client
|
|
return Object.fromEntries(Object.entries(mergedProperties).filter(([key]) => this.isPropertyCapturable(key)))
|
|
}
|
|
|
|
public abstract capture(event: TelemetryEvent): Promise<void>
|
|
|
|
public setProvider(provider: TelemetryPropertiesProvider): void {
|
|
this.providerRef = new WeakRef(provider)
|
|
}
|
|
|
|
public abstract updateTelemetryState(didUserOptIn: boolean): void
|
|
|
|
public isTelemetryEnabled(): boolean {
|
|
return this.telemetryEnabled
|
|
}
|
|
|
|
public abstract shutdown(): Promise<void>
|
|
}
|