Skip to content

Update what is being audit logged #11833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

Conversation

FelixMalfait
Copy link
Member

@FelixMalfait FelixMalfait commented May 2, 2025

No need to audit log workflow runs as it's already a form of audit log.
Add more audit log for other objects
Rename MessagingTelemetry to MessagingMonitoring
Merge Analytics and Audit in one (Audit)

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR updates audit logging practices and renames telemetry services for better clarity across the Twenty application.

  • Removes @WorkspaceIsNotAuditLogged decorator from multiple entities (api-key, blocklist, connected-account, etc.) to enable audit logging for important operations
  • Renames MessagingTelemetryService to MessagingMonitoringService for better semantic clarity
  • Changes ClickHouse table name from 'migrations' to '_migration' and 'events' to 'event' for consistent naming
  • Adds @WorkspaceIsNotAuditLogged to WorkflowRunWorkspaceEntity since runs already serve as audit logs
  • Modifies event table schema to include userId in ORDER BY clause for better indexing

24 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile


await this.auditLogRepository.insert(
workspaceEventBatch.name,
eventProperties,
workspaceMemberId,
workspaceEventBatch.name.split('.')[0],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: splitting on '.' is fragile - consider using a more robust method to extract object name

Comment on lines 66 to 72
if (workspaceEventBatch.name.endsWith('.updated')) {
analytics.track(OBJECT_RECORD_UPDATED_EVENT, eventData.properties);
analytics.track(OBJECT_RECORD_UPDATED_EVENT, eventProperties);
} else if (workspaceEventBatch.name.endsWith('.created')) {
analytics.track(OBJECT_RECORD_CREATED_EVENT, eventData.properties);
analytics.track(OBJECT_RECORD_CREATED_EVENT, eventProperties);
} else if (workspaceEventBatch.name.endsWith('.deleted')) {
analytics.track(OBJECT_RECORD_DELETED_EVENT, eventData.properties);
analytics.track(OBJECT_RECORD_DELETED_EVENT, eventProperties);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: consider using a switch statement or event type enum for better maintainability

Copy link
Contributor

github-actions bot commented May 2, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:59364

This environment will automatically shut down when the PR is closed or after 5 hours.

@FelixMalfait FelixMalfait requested a review from Copilot May 3, 2025 08:47
@FelixMalfait
Copy link
Member Author

@greptileai review again

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR consolidates audit logging by merging analytics into the audit module, updating ClickHouse-related integrations, and renaming/refining related components.

  • Removed the analytics module and its corresponding tests in favor of the audit module.
  • Updated the ClickHouse seeds, migrations, and service to reflect new audit log table names and configurations.
  • Adjusted front-end components by removing deprecated feature flag checks for analytics.

Reviewed Changes

Copilot reviewed 95 out of 98 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/twenty-server/src/engine/core-modules/analytics/services/clickhouse.service.spec.ts Removed analytics clickhouse service tests.
packages/twenty-server/src/engine/core-modules/analytics/analytics.module.ts Removed analytics module as part of consolidation.
packages/twenty-server/src/engine/api/graphql/workspace-query-runner/workspace-query-runner.module.ts Swapped AnalyticsModule for AuditModule and adjusted import order.
packages/twenty-server/src/engine/api/graphql/workspace-query-runner/listeners/telemetry.listener.ts Replaced analyticsService with auditService for telemetry logging.
packages/twenty-server/src/database/clickHouse/seeds/run-seeds.ts Updated target table name from 'events' to 'auditEvent'.
packages/twenty-server/src/database/clickHouse/migrations/run-migrations.ts Changed migration table name from 'migrations' to '_migration'.
packages/twenty-front/src/pages/settings/security/SettingsSecurity.tsx Removed conditional UI block based on deprecated feature flags.
Other files Adjusted import paths and renamed identifiers to support new audit logging approach.
Files not reviewed (3)
  • packages/twenty-server/project.json: Language not supported
  • packages/twenty-server/src/database/clickHouse/migrations/001-create-audit-event-table.sql: Language not supported
  • packages/twenty-server/src/database/clickHouse/migrations/003-create-external-event-table.sql: Language not supported
Comments suppressed due to low confidence (3)

packages/twenty-server/src/engine/api/graphql/workspace-query-runner/listeners/telemetry.listener.ts:23

  • [nitpick] The method name 'createAnalyticsContext' in the auditService may cause confusion given the module merge; consider renaming it to better reflect its audit logging purpose.
this.auditService.createAnalyticsContext({

packages/twenty-front/src/pages/settings/security/SettingsSecurity.tsx:65

  • [nitpick] The removal of the conditional rendering based on the 'IsApprovedAccessDomainsEnabled' feature flag should be reviewed to ensure it aligns with the overall business logic and feature flag strategy.
{IsApprovedAccessDomainsEnabled && (

packages/twenty-server/src/database/clickHouse/seeds/run-seeds.ts:21

  • Verify that the change from 'events' to 'auditEvent' is consistent across the codebase and documentation, ensuring that all references and integrations align with the new audit logging design.
table: 'auditEvent',

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

(updates since last review)

This PR continues the audit logging system overhaul by consolidating analytics and audit functionality into a unified audit module, with significant architectural changes.

  • Replaces AnalyticsService with AuditService across the application, moving from traditional database-backed audit logs to ClickHouse for better performance
  • Removes AuditLogWorkspaceEntity and BehavioralEventWorkspaceEntity from standard objects, centralizing event tracking in the new audit system
  • Adds new ClickHouse tables (auditEvent, pageview, externalEvent) with optimized schemas for different types of events
  • Removes feature flags IsAnalyticsV2Enabled, IsEventObjectEnabled, and IsApprovedAccessDomainsEnabled as these features are now permanent
  • Concerning: MessagingMonitoringService has commented-out tracking logic with a TODO about Prometheus replacement, potentially missing audit logs

80 file(s) reviewed, 17 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +209 to +211
jest
.spyOn(service, 'connectToClient')
.mockResolvedValueOnce(mockClickHouseClient);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Mocking connectToClient while testing connectToClient creates a circular dependency and may mask real issues. Consider testing the actual implementation instead.

Comment on lines +132 to +134
mockClickHouseClient.query.mockResolvedValueOnce({
json: jest.fn().mockResolvedValueOnce([{ id: 1, name: 'test' }]),
} as any);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Type assertion to 'any' could hide type mismatches. Consider creating a proper mock type that matches ClickHouseClient's QueryResult interface.

Comment on lines +19 to +20
ObjectRecordDeletedTrackEvent,
} from 'src/engine/core-modules/audit/utils/events/track/object-record/object-record-delete';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: File name in import path contains 'delete' but the event name uses 'deleted'. Consider renaming file to match event name for consistency

Comment on lines 32 to 34
useValue: {
createAnalyticsContext: AnalyticsContextMock,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Mock should be renamed from createAnalyticsContext to createAuditContext to match service name changes

@@ -75,7 +75,7 @@ export class UserResolver {
private readonly onboardingService: OnboardingService,
private readonly userVarService: UserVarsService,
private readonly fileService: FileService,
private readonly analyticsService: AnalyticsService,
private readonly auditService: AuditService,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: The auditService is injected but not used anywhere in this resolver. Consider removing if unused.

FelixMalfait and others added 6 commits May 3, 2025 12:07
…create-external-event-table.sql

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
…create-external-event-table.sql

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants