feat(agent): add anonymous event: Connected. (#349)
parent
61a885ddd8
commit
b6ce85733f
|
|
@ -15,6 +15,8 @@ export class AnonymousUsageLogger {
|
|||
? undefined
|
||||
: `${process.version} ${process.platform} ${require("os").arch()} ${require("os").release()}`,
|
||||
};
|
||||
private properties: { [key: string]: any } = {};
|
||||
private emittedUniqueEvent: string[] = [];
|
||||
private dataStore: DataStore | null = null;
|
||||
private anonymousId: string;
|
||||
|
||||
|
|
@ -52,19 +54,37 @@ export class AnonymousUsageLogger {
|
|||
}
|
||||
}
|
||||
|
||||
async event(event: string, data: any) {
|
||||
addProperties(properties: { [key: string]: any }) {
|
||||
// not a deep merge
|
||||
this.properties = { ...this.properties, ...properties };
|
||||
}
|
||||
|
||||
async uniqueEvent(event: string, data: { [key: string]: any } = {}) {
|
||||
await this.event(event, data, true);
|
||||
}
|
||||
|
||||
async event(event: string, data: { [key: string]: any } = {}, unique = false) {
|
||||
if (this.disabled) {
|
||||
return;
|
||||
}
|
||||
if (unique && this.emittedUniqueEvent.indexOf(event) >= 0) {
|
||||
return;
|
||||
}
|
||||
await this.anonymousUsageTrackingApi.api
|
||||
.usage({
|
||||
distinctId: this.anonymousId,
|
||||
event,
|
||||
properties: {
|
||||
...this.systemData,
|
||||
...this.properties,
|
||||
...data,
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
if (unique) {
|
||||
this.emittedUniqueEvent.push(event);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
this.logger.error({ error }, "Error when sending anonymous usage data");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -86,6 +86,9 @@ export class TabbyAgent extends EventEmitter implements Agent {
|
|||
const event: AgentEvent = { event: "statusChanged", status };
|
||||
this.logger.debug({ event }, "Status changed");
|
||||
super.emit("statusChanged", event);
|
||||
if (this.status == "ready") {
|
||||
this.anonymousUsageLogger.uniqueEvent("Connected");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -146,6 +149,7 @@ export class TabbyAgent extends EventEmitter implements Agent {
|
|||
// Client info is only used in logging for now
|
||||
// `pino.Logger.setBindings` is not present in the browser
|
||||
allLoggers.forEach((logger) => logger.setBindings?.({ client: options.client }));
|
||||
this.anonymousUsageLogger.addProperties({ client: options.client });
|
||||
}
|
||||
if (userAgentConfig) {
|
||||
await userAgentConfig.load();
|
||||
|
|
@ -164,9 +168,7 @@ export class TabbyAgent extends EventEmitter implements Agent {
|
|||
const event: AgentEvent = { event: "authRequired", server: this.config.server };
|
||||
super.emit("authRequired", event);
|
||||
}
|
||||
await this.anonymousUsageLogger.event("AgentInitialized", {
|
||||
client: options.client,
|
||||
});
|
||||
await this.anonymousUsageLogger.uniqueEvent("AgentInitialized");
|
||||
this.logger.debug({ options }, "Initialized");
|
||||
return this.status !== "notInitialized";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue