Conversation
mantrakp04
commented
Mar 25, 2026
- Enhance documentation tools integration
- Enhance error handling and API response for documentation tools
- Refactor askStackAuth key to ask_stack_auth in API documentation
- Enhance analytics and spans functionality in backend
- Added new SQL migrations for Clickhouse to support spans and events, including new columns and views. - Implemented validation for analytics events and spans, ensuring proper structure and data integrity. - Introduced new API endpoints for uploading analytics spans and events, improving data collection capabilities. - Updated existing analytics event handling to accommodate new fields and ensure compatibility with the updated database schema. - Added tests for analytics event insertion and validation to ensure reliability and correctness. These changes improve the analytics framework, enabling better tracking and analysis of user interactions.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR ships the custom events / tracing feature for Stack Auth's analytics SDK. It adds client-side and server-side Issues found:
Confidence Score: 4/5Safe to merge; no data-loss or security regressions found. All prior critical concerns are addressed. The implementation is thorough, well-tested, and resolves all issues flagged in the previous review. The one logic issue (random trace_id on system events) affects analytics data quality but is not a runtime error or security vulnerability. Remaining findings are minor style/redundancy issues. apps/backend/src/lib/events.tsx (trace_id generation for system events), apps/backend/scripts/clickhouse-migrations.ts (redundant SPANS_VIEW_SQL call) Important Files Changed
Sequence DiagramsequenceDiagram
participant Browser as Browser SDK
participant Server as Server SDK
participant EventsAPI as /analytics/events/batch
participant SpansAPI as /analytics/spans/batch
participant CH as ClickHouse
Note over Browser: trackEvent() / captureException()
Browser->>Browser: EventTracker._enqueueEvent()
Browser->>Browser: ClientSpanBatcher.push()
Browser-->>EventsAPI: POST (client auth, keepalive)
Browser-->>SpansAPI: POST (client auth, keepalive)
Note over Server: trackEvent() / startSpan()
Server->>Server: ServerBatcher.push(event, session)
Server->>Server: ServerBatcher.push(span, session)
Server-->>EventsAPI: POST (server auth, grouped by session)
Server-->>SpansAPI: POST (server auth, grouped by session)
EventsAPI->>EventsAPI: Validate auth type + event_type
EventsAPI->>EventsAPI: Resolve session_replay_id from DB
EventsAPI->>CH: insertAnalyticsEvents()
SpansAPI->>SpansAPI: Validate auth type + span_type
SpansAPI->>CH: insertSpans()
Note over CH: ReplacingMergeTree deduplicates spans by span_id
Reviews (5): Last reviewed commit: "Enhance client analytics event validatio..." | Re-trigger Greptile |
packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts
Outdated
Show resolved
Hide resolved
apps/backend/src/app/api/latest/analytics/spans/batch/route.tsx
Outdated
Show resolved
Hide resolved
packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts
Show resolved
Hide resolved
- Added validation to prevent client analytics spans from overriding user_id or team_id. - Refactored _superProperties in client and server app implementations to use Map for better performance and memory management. - Updated methods to handle super properties using Object.fromEntries for compatibility with the new Map structure. These changes improve data integrity and optimize property management in the analytics framework.
|
@greptile-ai review |
packages/template/src/lib/stack-app/apps/implementations/tracing.ts
Outdated
Show resolved
Hide resolved
- Removed unused browserSessionId from analytics event batch upload and query functions to streamline data handling. - Updated SQL queries in tests to include new event types and ensure proper validation messages. - Enhanced test cases to reflect changes in permissions for accessing spans, improving overall test coverage. These changes optimize the analytics event processing and strengthen the integrity of test validations.
- Removed unused browserSessionId from client-side and server-side event tracking to streamline the analytics process. - Updated the `trackEvent` method to ensure immediate flushing of events, enhancing reliability in event delivery. - Improved documentation for `trackEvent` usage, clarifying the behavior of fire-and-forget calls and the importance of flushing analytics. These changes optimize event handling and enhance the clarity of the analytics framework documentation.
|
@greptile-ai review additionally give extra attention to hard to read slop, non DRY code, n etc |
packages/template/src/lib/stack-app/apps/implementations/server-app-impl.ts
Show resolved
Hide resolved
packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts
Show resolved
Hide resolved
- Added a new utility function `stripLoneSurrogates` to handle lone surrogate characters in strings, ensuring compatibility with ClickHouse's JSON parser. - Refactored `sanitizeAnalyticsEventData` and `insertSpans` functions to utilize the new `stripLoneSurrogates` function for data sanitization before processing. - Improved code organization by moving the lone surrogate handling logic from `events.tsx` to a dedicated validation module. These changes enhance data integrity and prevent potential parsing errors in analytics event handling.
- Updated the type of `_waitUntil` to use `Promise<unknown>` for improved type safety. - Refactored the `_trackAutoCapturedEvent` method to simplify the handling of request options. - Enhanced the `_normalizeRequestArg` method to ensure proper type handling for headers and options. - Improved global state management in `server-event-batcher` by using a more explicit type definition. - Adjusted header reading functions in `tracing.ts` to enhance type safety and clarity. These changes improve code maintainability and ensure better type safety across the server app implementation.
- Introduced a `Set` for known event types in the `PageClient` component to enhance performance and readability. - Updated the filtering logic for custom event types to utilize the new `Set`, ensuring more efficient checks. - Adjusted type definitions in `server-app-impl` and `server-event-batcher` to use `Promise<unknown>` for better type safety. These changes streamline event type management and enhance type safety across the application.
|
@greptile-ai review and check for best practices and clean code with a high focus on readability |
- Removed browser_session_id from SQL queries and test assertions to streamline analytics data handling. - Updated related functions to ensure consistency in event type queries and improve clarity in test cases. These changes enhance the focus on relevant event data and improve the overall structure of analytics queries.
…ences - Removed all instances of browser_session_id from analytics queries and documentation to streamline event tracking and improve clarity. - Updated related SQL queries and documentation to reflect the changes in session replay linkage, focusing on sessionReplayId and sessionReplaySegmentId. - Improved type safety in server app specifications by adjusting the waitUntil promise type. These changes optimize the analytics framework and enhance the overall clarity of event handling.
- Introduced a new validation function, `isValidClientAnalyticsEventType`, to ensure client analytics events do not use server-only event types. - Updated the analytics validation logic to differentiate between client and server event types, improving clarity and security in event handling. - Adjusted documentation to reflect the new validation rules for client-sent analytics events. These changes strengthen the integrity of analytics event processing and enhance the overall structure of event type management.
|
@greptile-ai review |
- Introduced a new endpoint for ingesting OpenTelemetry traces in OTLP/HTTP JSON format, allowing backend services to send trace data as analytics spans. - Implemented validation and sanitization for incoming trace data, ensuring only valid spans are processed. - Enhanced error handling for invalid payloads and added support for server or admin authentication. - Updated analytics validation to accept additional formats for OpenTelemetry IDs, improving flexibility in trace identification. These changes expand the analytics capabilities and improve the integration with OpenTelemetry for better observability.