feat(analytics): posthog audit — remove noise, add 10 new events#3956
feat(analytics): posthog audit — remove noise, add 10 new events#3956waleedlatif1 wants to merge 5 commits intostagingfrom
Conversation
* feat(block): add cloudwatch integration * Fix bun lock * Add logger, use execution timeout * Switch metric dimensions to map style input * Fix attribute names for dimension map * Fix import styling --------- Co-authored-by: Theodore Li <theo@sim.ai>
Remove task_marked_read (fires automatically on every task view). Add workspace_id to task_message_sent for group analytics. New events: - search_result_selected: block/tool/trigger/workflow/table/file/ knowledge_base/workspace/task/page/docs with query_length - workflow_imported: count + format (json/zip) - workflow_exported: count + format (json/zip) - folder_created / folder_deleted - logs_filter_applied: status/workflow/folder/trigger/time - knowledge_base_document_deleted - scheduled_task_created / scheduled_task_deleted
PR SummaryMedium Risk Overview Introduces an AWS CloudWatch integration. Adds a new Reviewed by Cursor Bugbot for commit 728fa7b. Configure here. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile SummaryThis PR re-introduces the PostHog analytics audit from the accidentally-deleted branch: it removes the noisy Key highlights:
Confidence Score: 5/5Safe to merge — no P0 or P1 issues found; all new analytics events are fired after the success path with proper type safety. The only findings are two P2 cache-key observations for the CloudWatch selectors (incorrect credentials after a key rotation would resolve itself after staleTime anyway, and no data loss occurs) and a minor style inconsistency in ref-sync pattern. None of these block production correctness. apps/sim/hooks/selectors/registry.ts — the two cloudwatch selector query keys should include a prefix of awsSecretAccessKey to avoid serving stale log-group/stream lists after a secret rotation. Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant UI as React UI
participant PH as PostHog
participant API as Next.js API
participant DB as Database
User->>UI: Submit message / export / import / filter
UI->>UI: captureEvent(posthogRef.current, event, props)
UI->>PH: track event (client-side)
User->>API: POST /api/folders (create)
API->>DB: insert workflowFolder
API->>PH: captureServerEvent('folder_created')
API-->>User: 200 OK
User->>API: DELETE /api/folders/:id
API->>DB: delete folder
API->>PH: captureServerEvent('folder_deleted')
API-->>User: 200 OK
User->>API: POST /api/schedules
API->>DB: insert workflowSchedule
API->>PH: captureServerEvent('scheduled_task_created')
API-->>User: 201 Created
User->>API: DELETE /api/schedules/:id
API->>DB: delete workflowSchedule
API->>PH: captureServerEvent('scheduled_task_deleted')
API-->>User: 200 OK
User->>API: DELETE /api/knowledge/:id/documents/:docId
API->>DB: delete document
API->>PH: captureServerEvent('knowledge_base_document_deleted')
API-->>User: 200 OK
User->>API: PATCH /api/mothership/chats/:chatId
API->>DB: update copilotChats
API->>PH: captureServerEvent('task_renamed' or 'task_marked_unread')
API-->>User: 200 OK
|
| ], | ||
| enabled: ({ context }) => | ||
| Boolean(context.awsAccessKeyId && context.awsSecretAccessKey && context.awsRegion), | ||
| fetchList: async ({ context, search }: SelectorQueryArgs) => { | ||
| const body = JSON.stringify({ | ||
| accessKeyId: context.awsAccessKeyId, | ||
| secretAccessKey: context.awsSecretAccessKey, |
There was a problem hiding this comment.
awsSecretAccessKey absent from query key
The cloudwatch.logGroups (and cloudwatch.logStreams) query key includes awsAccessKeyId and awsRegion but not awsSecretAccessKey. If a user rotates only the secret key while keeping the same access key ID and region, React Query will serve the stale cached list of log groups until SELECTOR_STALE ms elapse — after which the refetch will fail with an AWS auth error. Adding a short hash (e.g., first 8 chars) of the secret to the key ensures immediate invalidation without leaking the raw secret into cache storage.
| ], | |
| enabled: ({ context }) => | |
| Boolean(context.awsAccessKeyId && context.awsSecretAccessKey && context.awsRegion), | |
| fetchList: async ({ context, search }: SelectorQueryArgs) => { | |
| const body = JSON.stringify({ | |
| accessKeyId: context.awsAccessKeyId, | |
| secretAccessKey: context.awsSecretAccessKey, | |
| getQueryKey: ({ context }: SelectorQueryArgs) => [ | |
| 'selectors', | |
| 'cloudwatch.logGroups', | |
| context.awsAccessKeyId ?? 'none', | |
| context.awsRegion ?? 'none', | |
| context.awsSecretAccessKey ? context.awsSecretAccessKey.slice(0, 8) : 'none', | |
| ], |
| ], | ||
| enabled: ({ context }) => | ||
| Boolean( | ||
| context.awsAccessKeyId && | ||
| context.awsSecretAccessKey && | ||
| context.awsRegion && | ||
| context.logGroupName | ||
| ), |
There was a problem hiding this comment.
Same stale-cache issue for
cloudwatch.logStreams
The same awsSecretAccessKey-absent query key problem applies here. A short prefix of the secret key should be included for consistent cache invalidation.
| ], | |
| enabled: ({ context }) => | |
| Boolean( | |
| context.awsAccessKeyId && | |
| context.awsSecretAccessKey && | |
| context.awsRegion && | |
| context.logGroupName | |
| ), | |
| getQueryKey: ({ context }: SelectorQueryArgs) => [ | |
| 'selectors', | |
| 'cloudwatch.logStreams', | |
| context.awsAccessKeyId ?? 'none', | |
| context.awsRegion ?? 'none', | |
| context.logGroupName ?? 'none', | |
| context.awsSecretAccessKey ? context.awsSecretAccessKey.slice(0, 8) : 'none', | |
| ], |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 728fa7b. Configure here.
| onOpenChangeRef.current(false) | ||
| }, | ||
| [workspaceId] | ||
| ) |
There was a problem hiding this comment.
Four identical search select handlers differ only by string
Low Severity
The handleTaskSelect, handleTableSelect, handleFileSelect, and handleKbSelect useCallback hooks duplicate logic. Each pushes item.href to the router, captures a search_result_selected event, and closes the modal, differing only by the result_type string. This duplication introduces a maintenance risk.
Reviewed by Cursor Bugbot for commit 728fa7b. Configure here.


Re-opening of #3917 — originally merged into staging but lost when the branch was accidentally deleted and recreated from main.