Skip to content

Comments

Add workspace_id support for multi-workspace tracking#3

Open
saint0x wants to merge 1 commit intomainfrom
claude/multi-workspace-tracking-ha65l
Open

Add workspace_id support for multi-workspace tracking#3
saint0x wants to merge 1 commit intomainfrom
claude/multi-workspace-tracking-ha65l

Conversation

@saint0x
Copy link
Owner

@saint0x saint0x commented Jan 25, 2026

Summary

This PR adds workspace ID support throughout the system to enable multi-workspace tracking and data isolation. The workspace ID is now extracted from the auth response, propagated through the event processing pipeline, and stored in all ClickHouse tables alongside the project ID.

Key Changes

  • Auth Layer: Added workspace_id field to AuthContext and AuthResponse structs with extraction logic and mock generation
  • Event Processing: Updated ClickHouseEvent::from_sdk() to accept and store workspace ID, modified transform_batch() to pass workspace ID through the transformation pipeline
  • ClickHouse Schema: Added workspace_id column to all event and metric tables (events, sessions, pageviews, clicks, scroll_events, mouse_moves, form_events, errors, performance_metrics, visibility_events, resource_loads, geographic, custom_events)
  • Query Layer: Updated SELECT queries to include workspace_id field in result rows
  • Index Optimization: Updated ORDER BY clauses in all tables to include workspace_id for better query performance with multi-workspace filtering
  • Testing: Added test fixtures and mock implementations to generate deterministic workspace IDs, updated existing tests to verify workspace_id propagation

Implementation Details

  • Workspace ID is generated deterministically in the mock auth client using a hash of the API key (similar to project ID generation)
  • The workspace ID flows through the entire event pipeline: auth → extraction → transformation → ClickHouse insertion
  • All ClickHouse table schemas have been updated to include workspace_id as a primary dimension for partitioning and ordering
  • The implementation maintains backward compatibility with existing project_id-based filtering while adding workspace-level isolation

Add workspace_id field throughout the ingestion pipeline to enable
per-website attribution within workspaces for multi-site analytics.

Changes:
- AuthResponse: Add workspace_id field from daemon auth validation
- AuthContext: Extract and require workspace_id from auth response
- ClickHouseEvent: Add workspace_id to event transformation pipeline
- transform_batch: Pass workspace_id through event processing
- ClickHouse row structs: Add workspace_id to all 12 specialized tables
- ClickHouse schema: Update all table definitions with workspace_id column
- Query functions: Include workspace_id in query results
- Mock auth: Generate deterministic workspace_id for testing
- Tests: Update all tests to include workspace_id assertions

The workspace_id is required (not optional) and flows from:
SDK request → Auth validation → Event transform → ClickHouse insert

Breaking change: workspace_id is now required in auth responses.
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