mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-05 22:26:41 +00:00
Add opt-out backend telemetry and fix dev compose frontend envars
This commit is contained in:
@@ -12,8 +12,8 @@ const MONGO_URL = process.env.MONGO_URL!;
|
|||||||
const NODE_ENV = process.env.NODE_ENV! || 'production';
|
const NODE_ENV = process.env.NODE_ENV! || 'production';
|
||||||
const OAUTH_CLIENT_SECRET_HEROKU = process.env.OAUTH_CLIENT_SECRET_HEROKU!;
|
const OAUTH_CLIENT_SECRET_HEROKU = process.env.OAUTH_CLIENT_SECRET_HEROKU!;
|
||||||
const OAUTH_TOKEN_URL_HEROKU = process.env.OAUTH_TOKEN_URL_HEROKU!;
|
const OAUTH_TOKEN_URL_HEROKU = process.env.OAUTH_TOKEN_URL_HEROKU!;
|
||||||
const POSTHOG_HOST = process.env.POSTHOG_HOST!;
|
const POSTHOG_HOST = process.env.POSTHOG_HOST! || 'https://app.posthog.com';
|
||||||
const POSTHOG_PROJECT_API_KEY = process.env.POSTHOG_PROJECT_API_KEY!;
|
const POSTHOG_PROJECT_API_KEY = process.env.POSTHOG_PROJECT_API_KEY! || 'phc_nSin8j5q2zdhpFDI1ETmFNUIuTG4DwKVyIigrY10XiE';
|
||||||
const PRIVATE_KEY = process.env.PRIVATE_KEY!;
|
const PRIVATE_KEY = process.env.PRIVATE_KEY!;
|
||||||
const PUBLIC_KEY = process.env.PUBLIC_KEY!;
|
const PUBLIC_KEY = process.env.PUBLIC_KEY!;
|
||||||
const SENTRY_DSN = process.env.SENTRY_DSN!;
|
const SENTRY_DSN = process.env.SENTRY_DSN!;
|
||||||
@@ -28,6 +28,7 @@ const STRIPE_PRODUCT_STARTER = process.env.STRIPE_PRODUCT_STARTER!;
|
|||||||
const STRIPE_PUBLISHABLE_KEY = process.env.STRIPE_PUBLISHABLE_KEY!;
|
const STRIPE_PUBLISHABLE_KEY = process.env.STRIPE_PUBLISHABLE_KEY!;
|
||||||
const STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY!;
|
const STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY!;
|
||||||
const STRIPE_WEBHOOK_SECRET = process.env.STRIPE_WEBHOOK_SECRET!;
|
const STRIPE_WEBHOOK_SECRET = process.env.STRIPE_WEBHOOK_SECRET!;
|
||||||
|
const TELEMETRY_ENABLED = (process.env.TELEMETRY_ENABLED! !== 'false') && true;
|
||||||
|
|
||||||
export {
|
export {
|
||||||
PORT,
|
PORT,
|
||||||
@@ -59,5 +60,6 @@ export {
|
|||||||
STRIPE_PRODUCT_STARTER,
|
STRIPE_PRODUCT_STARTER,
|
||||||
STRIPE_PUBLISHABLE_KEY,
|
STRIPE_PUBLISHABLE_KEY,
|
||||||
STRIPE_SECRET_KEY,
|
STRIPE_SECRET_KEY,
|
||||||
STRIPE_WEBHOOK_SECRET
|
STRIPE_WEBHOOK_SECRET,
|
||||||
|
TELEMETRY_ENABLED
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,16 +7,9 @@ import {
|
|||||||
reformatPullSecrets
|
reformatPullSecrets
|
||||||
} from '../helpers/secret';
|
} from '../helpers/secret';
|
||||||
import { pushKeys } from '../helpers/key';
|
import { pushKeys } from '../helpers/key';
|
||||||
import { PostHog } from 'posthog-node';
|
|
||||||
import { ENV_SET } from '../variables';
|
import { ENV_SET } from '../variables';
|
||||||
import { NODE_ENV, POSTHOG_PROJECT_API_KEY, POSTHOG_HOST } from '../config';
|
|
||||||
|
|
||||||
let client: any;
|
import { postHogClient } from '../services';
|
||||||
if (NODE_ENV === 'production' && POSTHOG_PROJECT_API_KEY && POSTHOG_HOST) {
|
|
||||||
client = new PostHog(POSTHOG_PROJECT_API_KEY, {
|
|
||||||
host: POSTHOG_HOST
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
interface PushSecret {
|
interface PushSecret {
|
||||||
ciphertextKey: string;
|
ciphertextKey: string;
|
||||||
@@ -68,11 +61,10 @@ export const pushSecrets = async (req: Request, res: Response) => {
|
|||||||
keys
|
keys
|
||||||
});
|
});
|
||||||
|
|
||||||
if (client) {
|
if (postHogClient) {
|
||||||
// capture secrets pushed event in production
|
postHogClient.capture({
|
||||||
client.capture({
|
|
||||||
distinctId: req.user.email,
|
|
||||||
event: 'secrets pushed',
|
event: 'secrets pushed',
|
||||||
|
distinctId: req.user.email,
|
||||||
properties: {
|
properties: {
|
||||||
numberOfSecrets: secrets.length,
|
numberOfSecrets: secrets.length,
|
||||||
environment,
|
environment,
|
||||||
@@ -81,6 +73,7 @@ export const pushSecrets = async (req: Request, res: Response) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Sentry.setUser({ email: req.user.email });
|
Sentry.setUser({ email: req.user.email });
|
||||||
Sentry.captureException(err);
|
Sentry.captureException(err);
|
||||||
@@ -131,9 +124,9 @@ export const pullSecrets = async (req: Request, res: Response) => {
|
|||||||
secrets = reformatPullSecrets({ secrets });
|
secrets = reformatPullSecrets({ secrets });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client) {
|
if (postHogClient) {
|
||||||
// capture secrets pushed event in production
|
// capture secrets pushed event in production
|
||||||
client.capture({
|
postHogClient.capture({
|
||||||
distinctId: req.user.email,
|
distinctId: req.user.email,
|
||||||
event: 'secrets pulled',
|
event: 'secrets pulled',
|
||||||
properties: {
|
properties: {
|
||||||
@@ -198,9 +191,9 @@ export const pullSecretsServiceToken = async (req: Request, res: Response) => {
|
|||||||
workspace: req.serviceToken.workspace
|
workspace: req.serviceToken.workspace
|
||||||
};
|
};
|
||||||
|
|
||||||
if (client) {
|
if (postHogClient) {
|
||||||
// capture secrets pushed event in production
|
// capture secrets pushed event in production
|
||||||
client.capture({
|
postHogClient.capture({
|
||||||
distinctId: req.serviceToken.user.email,
|
distinctId: req.serviceToken.user.email,
|
||||||
event: 'secrets pulled',
|
event: 'secrets pulled',
|
||||||
properties: {
|
properties: {
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ import mongoose from 'mongoose';
|
|||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
import * as Sentry from '@sentry/node';
|
import * as Sentry from '@sentry/node';
|
||||||
import { PORT, SENTRY_DSN, NODE_ENV, MONGO_URL, SITE_URL } from './config';
|
// import { PostHogClient } from './services';
|
||||||
|
import { PORT, SENTRY_DSN, NODE_ENV, MONGO_URL, SITE_URL, POSTHOG_PROJECT_API_KEY, POSTHOG_HOST, TELEMETRY_ENABLED } from './config';
|
||||||
import { apiLimiter } from './helpers/rateLimiter';
|
import { apiLimiter } from './helpers/rateLimiter';
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
@@ -18,6 +19,12 @@ Sentry.init({
|
|||||||
environment: NODE_ENV
|
environment: NODE_ENV
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// PostHogClient.init({
|
||||||
|
// projectApiKey: POSTHOG_PROJECT_API_KEY,
|
||||||
|
// host: POSTHOG_HOST,
|
||||||
|
// telemetryEnabled: TELEMETRY_ENABLED
|
||||||
|
// });
|
||||||
|
|
||||||
import {
|
import {
|
||||||
signup as signupRouter,
|
signup as signupRouter,
|
||||||
auth as authRouter,
|
auth as authRouter,
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import { PostHog } from 'posthog-node';
|
||||||
|
import { NODE_ENV, POSTHOG_HOST, POSTHOG_PROJECT_API_KEY, TELEMETRY_ENABLED } from '../config';
|
||||||
|
|
||||||
|
let postHogClient: any;
|
||||||
|
if (
|
||||||
|
NODE_ENV === 'production'
|
||||||
|
&& TELEMETRY_ENABLED
|
||||||
|
) {
|
||||||
|
// case: enable opt-out telemetry in production
|
||||||
|
postHogClient = new PostHog(POSTHOG_PROJECT_API_KEY, {
|
||||||
|
host: POSTHOG_HOST
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default postHogClient;
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import postHogClient from './PostHogClient';
|
||||||
|
|
||||||
|
export {
|
||||||
|
postHogClient
|
||||||
|
}
|
||||||
@@ -51,8 +51,11 @@ services:
|
|||||||
- ./frontend/components:/app/components
|
- ./frontend/components:/app/components
|
||||||
env_file: .env
|
env_file: .env
|
||||||
environment:
|
environment:
|
||||||
- NEXT_PUBLIC_ENV=production
|
- NEXT_PUBLIC_ENV=development
|
||||||
- NEXT_PUBLIC_WEBSITE_URL=${SITE_URL}
|
- NEXT_PUBLIC_WEBSITE_URL=${SITE_URL}
|
||||||
|
- NEXT_PUBLIC_POSTHOG_HOST=${POSTHOG_HOST}
|
||||||
|
- NEXT_PUBLIC_POSTHOG_API_KEY=${POSTHOG_PROJECT_API_KEY}
|
||||||
|
- NEXT_PUBLIC_TELEMETRY_ENABLED=${TELEMETRY_ENABLED}
|
||||||
networks:
|
networks:
|
||||||
- infisical-dev
|
- infisical-dev
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user