From 6a914f68df8c4bc5b3d799bc3cce2bda60e936df Mon Sep 17 00:00:00 2001 From: Jamie Tanna Date: Mon, 1 Dec 2025 11:27:58 +0000 Subject: [PATCH] fix(instrumentation): correctly `async` / `await` Git operations A previous refactor had incorrectly made it so we were not correctly `await`ing any calls to the SimpleGit method calls. This has mostly led to the Git operations continuing to work, but the instrumentation hasn't been correctly rendering. This also corrects incorrect return types that were previously not returned correctly. --- lib/util/git/instrument.ts | 151 ++++++++++++++++++++++++------------- 1 file changed, 99 insertions(+), 52 deletions(-) diff --git a/lib/util/git/instrument.ts b/lib/util/git/instrument.ts index 9778f059d43..c1abfaed6a4 100644 --- a/lib/util/git/instrument.ts +++ b/lib/util/git/instrument.ts @@ -5,6 +5,7 @@ import type { DiffResult, LogOptions, LogResult, + MergeResult, Options, RemoteWithRefs, RemoteWithoutRefs, @@ -97,10 +98,10 @@ export class InstrumentedSimpleGit { return this.git.version(); } - raw(args: string[]): Response { + raw(args: string[]): Promise { const { spanName, options } = prepareInstrumentation(args[0]); - return instrument(spanName, () => this.git.raw(args), options); + return instrument(spanName, async () => await this.git.raw(args), options); } async checkout(whatOrOptions: string | TaskOptions): Promise { @@ -119,71 +120,99 @@ export class InstrumentedSimpleGit { ); } - async checkoutBranch(branch: string, startPoint: string): Promise { + checkoutBranch(branch: string, startPoint: string): Promise { const { spanName, options } = prepareInstrumentation('checkout'); - await instrument( + return instrument( spanName, - () => this.git.checkoutBranch(branch, startPoint), + async () => await this.git.checkoutBranch(branch, startPoint), options, ); } - async branch(args: string[]): Promise { + branch(args: string[]): Promise { const { spanName, options } = prepareInstrumentation('branch'); - return await instrument(spanName, () => this.git.branch(args), options); + return instrument( + spanName, + async () => await this.git.branch(args), + options, + ); } - async branchLocal(): Promise { + branchLocal(): Promise { const { spanName, options } = prepareInstrumentation('branch'); - return await instrument(spanName, () => this.git.branchLocal(), options); + return instrument( + spanName, + async () => await this.git.branchLocal(), + options, + ); } - async add(files: string | string[]): Promise { + add(files: string | string[]): Promise { const { spanName, options } = prepareInstrumentation('add'); - return await instrument(spanName, () => this.git.add(files), options); + return instrument(spanName, async () => await this.git.add(files), options); } - async addConfig(key: string, value: string): Promise { + addConfig(key: string, value: string): Promise { const { spanName, options } = prepareInstrumentation('config'); - await instrument(spanName, () => this.git.addConfig(key, value), options); + return instrument( + spanName, + async () => await this.git.addConfig(key, value), + options, + ); } - async rm(files: string | string[]): Promise { + rm(files: string | string[]): Promise { const { spanName, options } = prepareInstrumentation('rm'); - await instrument(spanName, () => this.git.rm(files), options); + return instrument(spanName, async () => await this.git.rm(files), options); } - async reset(modeOrOptions: any): Promise { + reset(modeOrOptions: any): Promise { const { spanName, options } = prepareInstrumentation('reset'); - await instrument(spanName, () => this.git.reset(modeOrOptions), options); + return instrument( + spanName, + async () => await this.git.reset(modeOrOptions), + options, + ); } - async merge(args: string[]): Promise { + merge(args: string[]): Promise { const { spanName, options } = prepareInstrumentation('merge'); - await instrument(spanName, () => this.git.merge(args), options); + return instrument( + spanName, + async () => await this.git.merge(args), + options, + ); } - async push(...args: any[]): Promise { + push(...args: any[]): Promise { const { spanName, options } = prepareInstrumentation('push'); - return await instrument(spanName, () => this.git.push(...args), options); + return instrument( + spanName, + async () => await this.git.push(...args), + options, + ); } - async pull(args: string[]): Promise { + pull(args: string[]): Promise { const { spanName, options } = prepareInstrumentation('pull'); - return await instrument(spanName, () => this.git.pull(args), options); + return instrument(spanName, async () => await this.git.pull(args), options); } - async fetch(args: string[]): Promise { + fetch(args: string[]): Promise { const { spanName, options } = prepareInstrumentation('fetch'); - return await instrument(spanName, () => this.git.fetch(args), options); + return instrument( + spanName, + async () => await this.git.fetch(args), + options, + ); } - async clone(repo: string, dir: string, options: string[]): Promise { + clone(repo: string, dir: string, options: string[]): Promise { const { spanName, options: spanOptions } = prepareInstrumentation('clone'); - await instrument( + return instrument( spanName, - () => this.git.clone(repo, dir, options), + async () => await this.git.clone(repo, dir, options), spanOptions, ); } @@ -196,21 +225,29 @@ export class InstrumentedSimpleGit { return instrument( spanName, - () => this.git.commit(message, files, options), + async () => await this.git.commit(message, files, options), spanOptions, ); } - status(args?: string[]): Response { + status(args?: string[]): Promise { const { spanName, options } = prepareInstrumentation('status'); - return instrument(spanName, () => this.git.status(args), options); + return instrument( + spanName, + async () => await this.git.status(args), + options, + ); } - async log( + log( options?: TaskOptions | LogOptions, ): Promise> { const { spanName, options: spanOptions } = prepareInstrumentation('log'); - return await instrument(spanName, () => this.git.log(options), spanOptions); + return instrument( + spanName, + async () => await this.git.log(options), + spanOptions, + ); } async revparse(optionOrOptions: string | TaskOptions): Promise { const { spanName, options } = prepareInstrumentation('log'); @@ -227,65 +264,75 @@ export class InstrumentedSimpleGit { options, ); } - async show(args: string[]): Promise { + show(args: string[]): Promise { const { spanName, options } = prepareInstrumentation('show'); - return await instrument(spanName, () => this.git.show(args), options); + return instrument(spanName, async () => await this.git.show(args), options); } - async diff(args: string[]): Promise { + diff(args: string[]): Promise { const { spanName, options } = prepareInstrumentation('diff'); - return await instrument(spanName, () => this.git.diff(args), options); + return instrument(spanName, async () => await this.git.diff(args), options); } - async diffSummary(options: TaskOptions): Promise { + diffSummary(options: TaskOptions): Promise { const { spanName, options: spanOptions } = prepareInstrumentation('diff'); - return await instrument( + return instrument( spanName, - () => this.git.diffSummary(options), + async () => await this.git.diffSummary(options), spanOptions, ); } - async getRemotes( + getRemotes( verbose?: boolean, ): Promise { const { spanName, options } = prepareInstrumentation('remote'); - return await instrument( + return instrument( spanName, async () => { if (verbose === true) { - return await instrument('other', () => this.git.getRemotes(true)); + return await instrument( + 'other', + async () => await this.git.getRemotes(true), + ); } else { - return await instrument('other', () => this.git.getRemotes()); + return await instrument( + 'other', + async () => await this.git.getRemotes(), + ); } }, options, ); } - async addRemote(name: string, repo: string): Promise { + addRemote(name: string, repo: string): Promise { const { spanName, options } = prepareInstrumentation('remote'); - await instrument(spanName, () => this.git.addRemote(name, repo), options); + return instrument( + spanName, + async () => await this.git.addRemote(name, repo), + options, + ); } env(env: Record): this { this.git = this.git.env(env); return this; } - async catFile(args: string[]): Promise { + catFile(args: string[]): Promise { const { spanName, options } = prepareInstrumentation('remote'); - return await instrument(spanName, () => this.git.catFile(args), options); + return instrument(spanName, () => this.git.catFile(args), options); } - async listRemote(args: string[]): Promise { + listRemote(args: string[]): Promise { const { spanName, options } = prepareInstrumentation('ls-remote'); - return await instrument(spanName, () => this.git.listRemote(args), options); + return instrument(spanName, () => this.git.listRemote(args), options); } - async submoduleUpdate(args: string[]): Promise { + submoduleUpdate(args: string[]): Promise { const { spanName, options } = prepareInstrumentation('submodule'); - await instrument(spanName, () => this.git.submoduleUpdate(args), options); + return instrument(spanName, () => this.git.submoduleUpdate(args), options); } }