豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

chore: implement telemetry persistence and daily active logging#769

Merged
ergunsh merged 2 commits intomainfrom
telemetry/persistence-03
Jan 15, 2026
Merged

chore: implement telemetry persistence and daily active logging#769
ergunsh merged 2 commits intomainfrom
telemetry/persistence-03

Conversation

@ergunsh
Copy link
Copy Markdown
Contributor

@ergunsh ergunsh commented Jan 14, 2026

This PR implements the persistence layer for the telemetry system. It introduces FilePersistence for local state management and integrates it with ClearcutLogger to support "Daily Active" metric. I have decided not to send first_time_installation events since we can deduce them from daily active events where the days_since_last_active will be -1 for that case.

Implementation Roadmap:
This is the third in a series of PRs designed to implement the telemetry system:

  1. CLI & Opt-out Mechanism (Merged):
    • Added --usage-statistics flag and transparency logging.
  2. Logger Scaffolding & Integration (Merged):
    • ClearcutLogger: Implemented the main logging entry point.
    • One-way Data Flow: Integrated logToolInvocation and logServerStart hooks into main.ts to capture events.
    • ClearcutSender: Introduced a transport abstraction.
    • Type Definitions: Added TypeScript definitions for the telemetry Protocol Buffer messages.
  3. Persistence Layer (This PR):
    • FilePersistence: Implemented a local file-based state manager to persist the lastActive timestamp.
    • Daily Active Logic: Integrated persistence into ClearcutLogger to automatically detect and log daily_active events (with days_since_last_active calculation) via logDailyActiveIfNeeded.
  4. Watchdog Process Architecture (Next):
    • Move ClearcutSender execution to a dedicated watchdog process to ensure reliable event transmission even during abrupt server shutdowns.
  5. Transport, Batching & Retries (Next):
    • Finalize ClearcutSender with actual HTTP transport logic, including event batching and exponential backoff retries.

- Add `FilePersistence` to manage local telemetry state (last active date).
- Integrate persistence into `ClearcutLogger` to track and log daily active users.
- Implement `logDailyActiveIfNeeded` to handle Daily Active events.
- Explicitly call `logDailyActiveIfNeeded` in `main.ts` during server startup.
- Update `ClearcutLogger` to use the shared `logger` module for error reporting.
- Add comprehensive tests for `FilePersistence` and `ClearcutLogger` logic.
Comment thread src/telemetry/clearcut-logger.ts
Comment thread src/telemetry/persistence.ts
Comment thread src/telemetry/persistence.ts
Comment thread src/telemetry/persistence.ts Outdated
@ergunsh ergunsh enabled auto-merge January 15, 2026 10:56
@ergunsh ergunsh added this pull request to the merge queue Jan 15, 2026
Merged via the queue into main with commit a3de5e4 Jan 15, 2026
20 checks passed
@ergunsh ergunsh deleted the telemetry/persistence-03 branch January 15, 2026 11:01
github-merge-queue bot pushed a commit that referenced this pull request Jan 27, 2026
… by default (#805)

This PR completes the telemetry system by implementing the transport
layer for `ClearcutSender`. It enables actual HTTP communication with
the Clearcut backend, handling event batching, rate limiting, and
reliable delivery, including robust shutdown handling.

**Key Changes:**
* **HTTP Transport**: Implemented `fetch`-based transport sending `POST`
requests to the Clearcut HTTP server.
* **Event Batching**: Events are now buffered and flushed periodically
(default: 15 minutes) or on shutdown.
*   **Reliability & Rate Limiting**:
* **Server-Side Backoff**: Respects `next_request_wait_millis` from
server responses to handle rate limiting dynamically.
* **Transient Error Retries**: Failed requests (5xx, 429) result in
events being requeued for the next flush.
* **Request Timeouts**: Enforced 30s timeout on requests to prevent
hanging processes.
* **Session Rotation**: Automatically rotates session IDs every 24
hours.
*   **Safety & Stability**:
* **Buffer Overflow Protection**: Caps the buffer at 1000 events to
prevent memory leaks, dropping oldest events if necessary.
* **Optimistic Removal**: Prevents race conditions and duplicate events
during shutdown by optimistically removing events from the buffer before
sending.
*   **Testing Improvements**:
* **E2E Robustness**: Updated E2E tests to use a mock web server instead
of relying on the logger to log specific lines.

**Implementation Roadmap:**
These changes finalize the planned telemetry architecture:
1. **CLI & Opt-out Mechanism
([Merged](#757
2. **Logger Scaffolding & Integration
([Merged](#758
3. **Persistence Layer
([Merged](#766
4. **Watchdog Process Architecture
([Merged](#769
5.  **Transport, Batching & Retries (This PR):**
* Finalized `ClearcutSender` with HTTP transport, batching, and
server-directed backoff strategies.

---------

Co-authored-by: Alex Rudenko <alexrudenko@chromium.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants