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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Added PostHog events for repo index job success/failure and code host type to connection sync events. [#878](https://github.com/sourcebot-dev/sourcebot/pull/878)

### Changed
- Changed the me-control to render the user's avatar in the top-bar. [#874](https://github.com/sourcebot-dev/sourcebot/pull/874)
- Moved the "current version" indicator into the "what's new" dropdown. [#874](https://github.com/sourcebot-dev/sourcebot/pull/874)
Expand Down
10 changes: 8 additions & 2 deletions packages/backend/src/connectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export class ConnectionManager {
const logger = createJobLogger(job.id!);
const { connectionId, connectionName, orgId } = job.data;

await this.db.connectionSyncJob.update({
const { connection } = await this.db.connectionSyncJob.update({
where: {
id: job.id!,
},
Expand All @@ -307,6 +307,9 @@ export class ConnectionManager {
syncedAt: new Date(),
}
}
},
select: {
connection: true,
}
});

Expand All @@ -332,9 +335,11 @@ export class ConnectionManager {
this.promClient.activeConnectionSyncJobs.dec({ connection: connectionName });
this.promClient.connectionSyncJobSuccessTotal.inc({ connection: connectionName });

const config = connection.config as unknown as ConnectionConfig;
captureEvent('backend_connection_sync_job_completed', {
connectionId: connectionId,
repoCount: result.repoCount,
type: config.type,
});
} catch (error) {
Sentry.captureException(error);
Expand Down Expand Up @@ -375,9 +380,10 @@ export class ConnectionManager {

jobLogger.error(`Failed job ${job.id} for connection ${connection.name} (id: ${connection.id}). Failing job.`);

const config = connection.config as unknown as ConnectionConfig;
captureEvent('backend_connection_sync_job_failed', {
connectionId: job.data.connectionId,
error: error.message,
type: config.type,
});
} catch (err) {
Sentry.captureException(err);
Expand Down
23 changes: 12 additions & 11 deletions packages/backend/src/posthogEvents.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
/* eslint-disable @typescript-eslint/no-empty-object-type */

export type PosthogEventMap = {
repo_created: {
vcs: string;
codeHost?: string;
},
repo_deleted: {
vcs: string;
codeHost?: string;
},
//////////////////////////////////////////////////////////////////
backend_connection_sync_job_failed: {
connectionId: number,
error: string,
type: string,
},
backend_connection_sync_job_completed: {
connectionId: number,
repoCount: number,
type: string,
},
backend_revisions_truncated: {
repoId: number,
revisionCount: number,
},
//////////////////////////////////////////////////////////////////
backend_repo_index_job_failed: {
repoId: number,
jobType: 'INDEX' | 'CLEANUP',
type: string,
},
backend_repo_index_job_completed: {
repoId: number,
jobType: 'INDEX' | 'CLEANUP',
type: string,
},
}

export type PosthogEvent = keyof PosthogEventMap;
11 changes: 11 additions & 0 deletions packages/backend/src/repoIndexManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,12 @@ export class RepoIndexManager {
// Track metrics for successful job
this.promClient.activeRepoIndexJobs.dec({ repo: job.data.repoName, type: jobTypeLabel });
this.promClient.repoIndexJobSuccessTotal.inc({ repo: job.data.repoName, type: jobTypeLabel });

captureEvent('backend_repo_index_job_completed', {
repoId: job.data.repoId,
jobType: job.data.type,
type: jobData.repo.external_codeHostType,
});
} catch (error) {
Sentry.captureException(error);
logger.error(`Exception thrown while executing lifecycle function \`onJobCompleted\`.`, error);
Expand Down Expand Up @@ -618,6 +624,11 @@ export class RepoIndexManager {

jobLogger.error(`Failed job ${job.data.jobId} for repo ${repo.name} (id: ${repo.id}).`);

captureEvent('backend_repo_index_job_failed', {
repoId: job.data.repoId,
jobType: job.data.type,
type: repo.external_codeHostType,
});
} catch (err) {
Sentry.captureException(err);
logger.error(`Exception thrown while executing lifecycle function \`onJobMaybeFailed\`.`, err);
Expand Down