Skip to content

Commit ac6bd21

Browse files
add posthog group plumbing
1 parent d811d9b commit ac6bd21

5 files changed

Lines changed: 33 additions & 5 deletions

File tree

packages/backend/src/posthog.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export function captureEvent<E extends PosthogEvent>(event: E, properties: Posth
2626
sourcebot_version: SOURCEBOT_VERSION,
2727
install_id: env.SOURCEBOT_INSTALL_ID,
2828
},
29+
groups: { company: env.SOURCEBOT_INSTALL_ID },
2930
});
3031
}
3132

packages/web/src/app/posthogProvider.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export function PostHogProvider({
7777
sourcebot_version: sourcebotVersion,
7878
install_id: sourcebotInstallId,
7979
});
80+
posthog.group('company', sourcebotInstallId);
8081
}
8182
});
8283
} else {

packages/web/src/ee/features/lighthouse/servicePing.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { existsSync } from "fs";
12
import { SINGLE_TENANT_ORG_ID } from "@/lib/constants";
23
import { isServiceError } from "@/lib/utils";
34
import { __unsafePrisma } from "@/prisma";
@@ -10,17 +11,25 @@ const logger = createLogger('service-ping');
1011

1112
const SERVICE_PING_INTERVAL_MS = 24 * 60 * 60 * 1000; // 1 day
1213

14+
1315
export const syncWithLighthouse = async (orgId: number) => {
1416
// Look up the activation code from the License record
1517
const license = await __unsafePrisma.license.findUnique({
1618
where: { orgId },
1719
});
1820

19-
const userCount = await __unsafePrisma.userToOrg.count({
20-
where: {
21-
orgId,
22-
},
23-
});
21+
const [userCount, repoCount] = await Promise.all([
22+
__unsafePrisma.userToOrg.count({
23+
where: {
24+
orgId,
25+
},
26+
}),
27+
__unsafePrisma.repo.count({
28+
where: {
29+
orgId,
30+
},
31+
}),
32+
]);
2433

2534
const activationCode = license?.activationCode
2635
? decryptActivationCode(license.activationCode)
@@ -30,6 +39,9 @@ export const syncWithLighthouse = async (orgId: number) => {
3039
installId: env.SOURCEBOT_INSTALL_ID,
3140
version: SOURCEBOT_VERSION,
3241
userCount,
42+
repoCount,
43+
deploymentType: inferDeploymentType(),
44+
isTelemetryEnabled: env.SOURCEBOT_TELEMETRY_DISABLED === 'false',
3345
...(activationCode && { activationCode }),
3446
};
3547

@@ -111,3 +123,13 @@ export const startServicePingCronJob = () => {
111123
SERVICE_PING_INTERVAL_MS
112124
);
113125
};
126+
127+
const inferDeploymentType = (): string => {
128+
if (process.env.KUBERNETES_SERVICE_HOST) {
129+
return 'kubernetes';
130+
}
131+
if (existsSync('/.dockerenv')) {
132+
return 'docker';
133+
}
134+
return 'other';
135+
};

packages/web/src/ee/features/lighthouse/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ export const servicePingRequestSchema = z.object({
44
installId: z.string(),
55
version: z.string(),
66
userCount: z.number(),
7+
repoCount: z.number(),
8+
deploymentType: z.string(),
9+
isTelemetryEnabled: z.boolean(),
710
activationCode: z.string().optional(),
811
});
912
export type ServicePingRequest = z.infer<typeof servicePingRequestSchema>;

packages/web/src/lib/posthog.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export async function captureEvent<E extends PosthogEvent>(event: E, properties:
100100
$host: host,
101101
},
102102
distinctId,
103+
groups: { company: env.SOURCEBOT_INSTALL_ID },
103104
});
104105
} catch (error) {
105106
logger.error('Failed to capture PostHog event:', error);

0 commit comments

Comments
 (0)