Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
18 changes: 10 additions & 8 deletions create-db/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ class EventCaptureError extends Error {

class PosthogEventCapture {
async capture(eventName, properties = {}) {
const POSTHOG_CAPTURE_URL = process.env.POSTHOG_API_HOST
? process.env.POSTHOG_API_HOST + "/capture"
: "https://proxyhog.prisma-data.net/capture";
const POSTHOG_KEY = process.env.POSTHOG_API_KEY || "phc_cmc85avbWyuJ2JyKdGPdv7dxXli8xLdWDBPbvIXWJfs";
const POSTHOG_CAPTURE_URL = process.env.POSTHOG_API_HOST + "/capture";
const POSTHOG_KEY = process.env.POSTHOG_API_KEY;

const payload = {
api_key: POSTHOG_KEY,
Expand All @@ -35,11 +33,15 @@ class PosthogEventCapture {
if (!response.ok) {
throw new EventCaptureError(eventName, response.statusText);
}

// Log success message
console.log(`${eventName}: Success`);
} catch (error) {
// Silently fail analytics to not disrupt user experience
if (process.env.NODE_ENV === "development") {
console.error("Analytics error:", error.message);
}
// Log all analytics errors for debugging
console.error(`${eventName}: Failed - ${error.message}`);

// Re-throw the error so calling code can handle it if needed
throw error;
}
}
}
Expand Down
36 changes: 30 additions & 6 deletions create-db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ async function promptForRegion(defaultRegion) {
region: region,
"selection-method": "interactive",
});
} catch (error) {}
} catch (error) {
console.error("Failed to send region_selected analytics :", error.message);
}

return region;
}
Expand Down Expand Up @@ -310,7 +312,12 @@ async function createDatabase(name, region, returnJson = false) {
"error-type": "rate_limit",
"status-code": 429,
});
} catch (error) {}
} catch (error) {
console.error(
"Failed to send database_creation_failed analytics:",
error.message
);
}

process.exit(1);
}
Expand Down Expand Up @@ -339,7 +346,12 @@ async function createDatabase(name, region, returnJson = false) {
"error-type": "invalid_json",
"status-code": resp.status,
});
} catch {}
} catch (error) {
console.error(
"Failed to send database_creation_failed analytics:",
error.message
);
}
process.exit(1);
}

Expand Down Expand Up @@ -403,7 +415,12 @@ async function createDatabase(name, region, returnJson = false) {
"error-type": "api_error",
"error-message": result.error.message,
});
} catch (error) {}
} catch (error) {
console.error(
"Failed to send database_creation_failed analytics:",
error.message
);
}
process.exit(1);
}

Expand Down Expand Up @@ -474,7 +491,9 @@ async function main() {
platform: process.platform,
arch: process.arch,
});
} catch (error) {}
} catch (error) {
console.error("Failed to send cli_command_ran analytics:", error.message);
}

const { flags } = await parseArgs();

Expand Down Expand Up @@ -504,7 +523,12 @@ async function main() {
region: region,
"selection-method": "flag",
});
} catch (error) {}
} catch (error) {
console.error(
"Failed to send region_selected analytics:",
error.message
);
}
}

if (flags.interactive) {
Expand Down