-
Notifications
You must be signed in to change notification settings - Fork 8
feat: filter CI requests from MAU calculations #73
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
Changes from all commits
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 | ||
|---|---|---|---|---|
|
|
@@ -31,19 +31,12 @@ export const POST: APIRoute = async ({ request, locals }) => { | |||
| const clientIP = getClientIP(request); | ||||
| const ipHash = await hashIP(clientIP, runtime.env.API_SECRET); | ||||
|
|
||||
| const db = drizzle(runtime.env.ANALYTICS_DB); | ||||
| const analytics = setupAnalytics(db); | ||||
|
|
||||
| const result = await analytics.trackDownload( | ||||
| body.tool, | ||||
| body.version, | ||||
| ipHash, | ||||
| body.os || null, | ||||
| body.arch || null, | ||||
| body.full || null, | ||||
| ); | ||||
| // Check if request is from CI environment | ||||
| const isCI = request.headers.get("x-mise-ci") === "true"; | ||||
|
|
||||
| const miseVersion = getMiseVersionFromHeaders(request.headers); | ||||
|
|
||||
| // Always emit telemetry (includes is_ci flag for analysis) | ||||
| runtime.ctx.waitUntil( | ||||
| emitTelemetry(runtime.env, { | ||||
| schema_version: 1, | ||||
|
|
@@ -57,9 +50,37 @@ export const POST: APIRoute = async ({ request, locals }) => { | |||
| ip_hash: ipHash, | ||||
| mise_version: miseVersion, | ||||
| source: "api/track", | ||||
| is_ci: isCI, | ||||
| }), | ||||
| ); | ||||
|
|
||||
| // Skip database storage for CI requests (excludes from MAU calculations) | ||||
| if (isCI) { | ||||
| return new Response( | ||||
| JSON.stringify({ | ||||
| success: true, | ||||
| deduplicated: false, | ||||
|
||||
| deduplicated: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The telemetry emission has been moved outside of the conditional CI check, but it's no longer wrapped in error handling. If
emitTelemetryfails, it could cause thewaitUntilpromise to reject. Consider wrapping the telemetry call in a try-catch block similar to how it's handled in the other two files (lines 85-87 in tools/[tool].toml.ts and lines 87-89 in [...tool].toml.ts).