-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat(observability): extend audit log, PostHog, and storage metering coverage #5269
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
base: staging
Are you sure you want to change the base?
Changes from all commits
9c4c342
56835de
4bd30ae
b19912f
9da4270
4aaf1b1
8064b9a
5a2191d
b9ac77e
9d9186e
ba23b00
59ee511
f0a18ef
c06e507
f617608
f759a0d
139174b
50052ba
470edf7
0433e52
fe36c68
e824f38
0c4a843
1ca8d3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| import { AuditAction, AuditResourceType, recordAudit } from '@sim/audit' | ||
| import { createLogger } from '@sim/logger' | ||
| import { type NextRequest, NextResponse } from 'next/server' | ||
| import { fileDownloadContract } from '@/lib/api/contracts/storage-transfer' | ||
| import { getValidationErrorMessage, parseRequest } from '@/lib/api/server' | ||
| import { checkSessionOrInternalAuth } from '@/lib/auth/hybrid' | ||
| import { withRouteHandler } from '@/lib/core/utils/with-route-handler' | ||
| import { captureServerEvent } from '@/lib/posthog/server' | ||
| import type { StorageContext } from '@/lib/uploads/config' | ||
| import { hasCloudStorage } from '@/lib/uploads/core/storage-service' | ||
| import { verifyFileAccess } from '@/app/api/files/authorization' | ||
|
|
@@ -84,10 +86,26 @@ export const POST = withRouteHandler(async (request: NextRequest) => { | |
|
|
||
| logger.info(`Generated download URL for ${storageContext ?? 'inferred'} file: ${key}`) | ||
|
|
||
| const downloadName = name || key.split('/').pop() || 'download' | ||
| recordAudit({ | ||
| workspaceId: null, | ||
| actorId: userId, | ||
| action: AuditAction.FILE_DOWNLOADED, | ||
| resourceType: AuditResourceType.FILE, | ||
| resourceName: downloadName, | ||
| description: `Downloaded file "${downloadName}"`, | ||
| metadata: { key, fileName: downloadName, context: storageContext }, | ||
| request, | ||
| }) | ||
| captureServerEvent(userId, 'file_downloaded', { | ||
| is_bulk: false, | ||
|
waleedlatif1 marked this conversation as resolved.
|
||
| file_count: 1, | ||
| }) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Download audit before transferLow Severity These handlers emit Additional Locations (1)Reviewed by Cursor Bugbot for commit 1ca8d3d. Configure here. |
||
|
|
||
| return NextResponse.json({ | ||
| downloadUrl, | ||
| expiresIn: null, | ||
| fileName: name || key.split('/').pop() || 'download', | ||
| fileName: downloadName, | ||
| }) | ||
| } catch (error) { | ||
| logger.error('Error in file download endpoint:', error) | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.