Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions web/src/pages/[...tool].toml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ export const GET: APIRoute = async ({ request, params, locals }) => {
// Track version request for DAU/MAU using waitUntil to ensure it completes
const clientIP = getClientIP(request);
const miseVersion = getMiseVersionFromHeaders(request.headers);
const isCI = request.headers.get("x-mise-ci") === "true";
runtime.ctx.waitUntil(
hashIP(clientIP, runtime.env.API_SECRET).then(async (ipHash) => {
try {
const analytics = setupAnalytics(db);
await analytics.trackVersionRequest(ipHash);
// Always emit telemetry (includes is_ci flag for analysis)
await emitTelemetry(runtime.env, {
schema_version: 1,
type: "version_request",
Expand All @@ -77,7 +77,13 @@ export const GET: APIRoute = async ({ request, params, locals }) => {
ip_hash: ipHash,
mise_version: miseVersion,
source: "toml",
is_ci: isCI,
});
// Skip database storage for CI requests (excludes from MAU calculations)
if (!isCI) {
const analytics = setupAnalytics(db);
await analytics.trackVersionRequest(ipHash);
}
} catch (e) {
console.error("Failed to track version request:", e);
}
Expand Down
43 changes: 32 additions & 11 deletions web/src/pages/api/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Comment on lines 40 to 42

Copilot AI Jan 28, 2026

Copy link

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 emitTelemetry fails, it could cause the waitUntil promise 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).

Copilot uses AI. Check for mistakes.
Expand All @@ -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,

Copilot AI Jan 28, 2026

Copy link

Choose a reason for hiding this comment

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

The deduplicated: false field in the CI response may be misleading since no deduplication check occurs for CI requests. Consider either removing this field from the CI response or documenting why it's always false for CI requests, as it could confuse API consumers who expect this field to reflect actual deduplication logic.

Suggested change
deduplicated: false,

Copilot uses AI. Check for mistakes.
ci: true,
}),
{
status: 200,
headers: { "Content-Type": "application/json" },
},
);
}

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,
);

return new Response(
JSON.stringify({
success: true,
Expand Down
10 changes: 8 additions & 2 deletions web/src/pages/tools/[tool].toml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ export const GET: APIRoute = async ({ request, params, locals }) => {
// Track version request for DAU/MAU using waitUntil to ensure it completes
const clientIP = getClientIP(request);
const miseVersion = getMiseVersionFromHeaders(request.headers);
const isCI = request.headers.get("x-mise-ci") === "true";
runtime.ctx.waitUntil(
hashIP(clientIP, runtime.env.API_SECRET).then(async (ipHash) => {
try {
const analytics = setupAnalytics(db);
await analytics.trackVersionRequest(ipHash);
// Always emit telemetry (includes is_ci flag for analysis)
await emitTelemetry(runtime.env, {
schema_version: 1,
type: "version_request",
Expand All @@ -75,7 +75,13 @@ export const GET: APIRoute = async ({ request, params, locals }) => {
ip_hash: ipHash,
mise_version: miseVersion,
source: "toml",
is_ci: isCI,
});
// Skip database storage for CI requests (excludes from MAU calculations)
if (!isCI) {
const analytics = setupAnalytics(db);
await analytics.trackVersionRequest(ipHash);
}
} catch (e) {
console.error("Failed to track version request:", e);
}
Expand Down