AstroTelemetry Class — astro Architecture
Architecture documentation for the AstroTelemetry class in index.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD aa586462_b436_2ea0_2f45_107a3d7bae01["AstroTelemetry"] 71f3a511_b4a5_d013_3649_d4e84069becc["index.ts"] aa586462_b436_2ea0_2f45_107a3d7bae01 -->|defined in| 71f3a511_b4a5_d013_3649_d4e84069becc 9bb89beb_9da1_ded5_5406_22a8b09bf0c4["astroVersion()"] aa586462_b436_2ea0_2f45_107a3d7bae01 -->|method| 9bb89beb_9da1_ded5_5406_22a8b09bf0c4 24d5dbff_f735_3c25_fee7_f6883a139860["viteVersion()"] aa586462_b436_2ea0_2f45_107a3d7bae01 -->|method| 24d5dbff_f735_3c25_fee7_f6883a139860 bee6947c_ca0c_94ea_753a_4228b7f53d83["ASTRO_TELEMETRY_DISABLED()"] aa586462_b436_2ea0_2f45_107a3d7bae01 -->|method| bee6947c_ca0c_94ea_753a_4228b7f53d83 112856fe_5192_127f_1c3b_86f54d717b29["TELEMETRY_DISABLED()"] aa586462_b436_2ea0_2f45_107a3d7bae01 -->|method| 112856fe_5192_127f_1c3b_86f54d717b29 08a6b8c3_a743_2a16_a384_9ebc91242924["constructor()"] aa586462_b436_2ea0_2f45_107a3d7bae01 -->|method| 08a6b8c3_a743_2a16_a384_9ebc91242924 fe2c05fb_e168_3d3e_067e_79fe7e234b35["getConfigWithFallback()"] aa586462_b436_2ea0_2f45_107a3d7bae01 -->|method| fe2c05fb_e168_3d3e_067e_79fe7e234b35 eb8b7aa4_58e0_c90f_b7c3_177db81b292e["enabled()"] aa586462_b436_2ea0_2f45_107a3d7bae01 -->|method| eb8b7aa4_58e0_c90f_b7c3_177db81b292e d2c36394_50eb_07fc_771b_f58b743a9e4a["notifyDate()"] aa586462_b436_2ea0_2f45_107a3d7bae01 -->|method| d2c36394_50eb_07fc_771b_f58b743a9e4a 4971db9e_d1b5_05a1_a10c_7048e3f2eda5["anonymousId()"] aa586462_b436_2ea0_2f45_107a3d7bae01 -->|method| 4971db9e_d1b5_05a1_a10c_7048e3f2eda5 24d9f83c_b801_8b2d_38e2_a1cec12f8f32["anonymousSessionId()"] aa586462_b436_2ea0_2f45_107a3d7bae01 -->|method| 24d9f83c_b801_8b2d_38e2_a1cec12f8f32 4ca5b560_8802_4457_edf0_d3977118051a["anonymousProjectInfo()"] aa586462_b436_2ea0_2f45_107a3d7bae01 -->|method| 4ca5b560_8802_4457_edf0_d3977118051a 37b57fa3_e219_5e93_937d_e1627a2b179f["isDisabled()"] aa586462_b436_2ea0_2f45_107a3d7bae01 -->|method| 37b57fa3_e219_5e93_937d_e1627a2b179f f5002ce3_9aa8_2b3f_1cc4_c0dcc5ba8f83["setEnabled()"] aa586462_b436_2ea0_2f45_107a3d7bae01 -->|method| f5002ce3_9aa8_2b3f_1cc4_c0dcc5ba8f83
Relationship Graph
Source Code
packages/telemetry/src/index.ts lines 21–172
export class AstroTelemetry {
private _anonymousSessionId: string | undefined;
private _anonymousProjectInfo: ProjectInfo | undefined;
private config = new GlobalConfig({ name: 'astro' });
private debug = debug('astro:telemetry');
private isCI = isCI;
private env = process.env;
private get astroVersion() {
return this.opts.astroVersion;
}
private get viteVersion() {
return this.opts.viteVersion;
}
private get ASTRO_TELEMETRY_DISABLED() {
return this.env.ASTRO_TELEMETRY_DISABLED;
}
private get TELEMETRY_DISABLED() {
return this.env.TELEMETRY_DISABLED;
}
constructor(private opts: AstroTelemetryOptions) {
// TODO: When the process exits, flush any queued promises
// This caused a "cannot exist astro" error when it ran, so it was removed.
// process.on('SIGINT', () => this.flush());
}
/**
* Get value from either the global config or the provided fallback.
* If value is not set, the fallback is saved to the global config,
* persisted for later sessions.
*/
private getConfigWithFallback<T>(key: string, getValue: () => T): T {
const currentValue = this.config.get(key);
if (currentValue !== undefined) {
return currentValue;
}
const newValue = getValue();
this.config.set(key, newValue);
return newValue;
}
private get enabled(): boolean {
return this.getConfigWithFallback(KEY.TELEMETRY_ENABLED, () => true);
}
private get notifyDate(): string {
return this.getConfigWithFallback(KEY.TELEMETRY_NOTIFY_DATE, () => '');
}
private get anonymousId(): string {
return this.getConfigWithFallback(KEY.TELEMETRY_ID, () => randomBytes(32).toString('hex'));
}
private get anonymousSessionId(): string {
// NOTE(fks): this value isn't global, so it can't use getConfigWithFallback().
this._anonymousSessionId = this._anonymousSessionId || randomBytes(32).toString('hex');
return this._anonymousSessionId;
}
private get anonymousProjectInfo(): ProjectInfo {
// NOTE(fks): this value isn't global, so it can't use getConfigWithFallback().
this._anonymousProjectInfo = this._anonymousProjectInfo || getProjectInfo(this.isCI);
return this._anonymousProjectInfo;
}
private get isDisabled(): boolean {
if (Boolean(this.ASTRO_TELEMETRY_DISABLED || this.TELEMETRY_DISABLED)) {
return true;
}
return this.enabled === false;
}
setEnabled(value: boolean) {
this.config.set(KEY.TELEMETRY_ENABLED, value);
}
clear() {
return this.config.clear();
}
Domain
Defined In
Source
Frequently Asked Questions
What is the AstroTelemetry class?
AstroTelemetry is a class in the astro codebase, defined in packages/telemetry/src/index.ts.
Where is AstroTelemetry defined?
AstroTelemetry is defined in packages/telemetry/src/index.ts at line 21.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free