(config: TelemetryConfig, stateDir: string, pluginVersion: string, log: Logger, pluginDir?: string)
| 73 | private platform: string; |
| 74 | |
| 75 | constructor(config: TelemetryConfig, stateDir: string, pluginVersion: string, log: Logger, pluginDir?: string) { |
| 76 | this.log = log; |
| 77 | this.pluginVersion = pluginVersion; |
| 78 | this.enabled = config.enabled !== false; |
| 79 | this.distinctId = this.loadOrCreateAnonymousId(stateDir); |
| 80 | this.firstSeenDate = this.loadOrCreateFirstSeen(stateDir); |
| 81 | this.sessionId = this.loadOrCreateSessionId(stateDir); |
| 82 | |
| 83 | this.platform = config.platform ?? "openclaw"; |
| 84 | |
| 85 | const creds = loadTelemetryCredentials(pluginDir); |
| 86 | this.armsEndpoint = creds.endpoint; |
| 87 | this.armsPid = creds.pid; |
| 88 | this.armsEnv = creds.env; |
| 89 | |
| 90 | if (!this.enabled || !this.armsEndpoint) { |
| 91 | this.enabled = false; |
| 92 | this.log.debug( |
| 93 | !this.armsEndpoint |
| 94 | ? "Telemetry disabled (no credentials configured)" |
| 95 | : "Telemetry disabled (opt-out)", |
| 96 | ); |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | this.flushTimer = setInterval(() => this.flush(), FLUSH_INTERVAL_MS); |
| 101 | if (this.flushTimer.unref) this.flushTimer.unref(); |
| 102 | this.log.debug("Telemetry initialized (ARMS)"); |
| 103 | } |
| 104 | |
| 105 | private loadOrCreateAnonymousId(stateDir: string): string { |
| 106 | const newDir = path.join(stateDir, "memos-local"); |
nothing calls this directly
no test coverage detected