Skip to content

Conversation

@jamietanna
Copy link
Contributor

@jamietanna jamietanna commented Dec 1, 2025

Changes

A previous refactor had incorrectly made it so we were not correctly
awaiting 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.

Screenshots

Before (git clone immediately returns):

Screenshot 2025-12-01 at 11 41 19

After (git clone returns correct timing)

Screenshot 2025-12-01 at 11 40 25

Context

Please select one of the below:

  • This closes an existing Issue: #
  • This doesn't close an Issue, but I accept the risk that this PR may be closed if maintainers disagree with its opening or implementation

AI assistance disclosure

Did you use AI tools to create any part of this pull request?

Please select one option and, if yes, briefly describe how AI was used (e.g., code, tests, docs) and which tool(s) you used.

  • No — I did not use AI for this contribution.
  • Yes — minimal assistance (e.g., IDE autocomplete, small code completions, grammar fixes).
  • Yes — substantive assistance (AI generated non‑trivial portions of code, tests, or documentation).
  • Yes — other (please describe):

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please select one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

The public repository:

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.
Copy link
Member

@viceice viceice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't understand why those changese makes a difference, see comment. 🤷‍♂️

return instrument(
spanName,
() => this.git.clone(repo, dir, options),
async () => await this.git.clone(repo, dir, options),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder why this maks a difference. 🤔

if (ret instanceof Promise) {
return ret
.catch((e) => {
span.recordException(e);
span.setStatus({
code: SpanStatusCode.ERROR,
message: massageThrowable(e),
});
throw e;
})
.finally(() => span.end()) as ReturnType<F>;
}

this should handle the response properly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, maybe simple git isn't returning a proper Promise so it doesn't get into the if condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so possibly because it returns:

export type Response<T> = SimpleGit & Promise<T>;

So maybe if we refactored ☝️ to also look at instanceof Response, it'd work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the ordering if the types (when the object is constructed) can catch us out here - I've got a reproducing unit test I'm trying to get passing then will see if that fixes it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When adding:

      console.log({ name, typF: typeof fn, typeR: typeof ret, fn, ret, })

I see i.e.

{
  name: 'syncGit',
  typF: 'function',
  typeR: 'object',
  fn: [Function (anonymous)],
  ret: Promise {
    undefined,
    [Symbol(async_id_symbol)]: 1857648,
    [Symbol(trigger_async_id_symbol)]: 1857588,
    [Symbol(kResourceStore)]: BaseContext {
      _currentContext: [Map],
      getValue: [Function (anonymous)],
      setValue: [Function (anonymous)],
      deleteValue: [Function (anonymous)]
    }
  }
}
{
  name: 'git show',
  typF: 'function',
  typeR: 'object',
  fn: [Function (anonymous)],
  ret: Git2 {}
}

Notice that SimpleGit's calls return a Git2 (from the CommonJS code)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative: #39661

@jamietanna
Copy link
Contributor Author

#39661 was the better fix

@jamietanna
Copy link
Contributor Author

Moved the types changes into #39664

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants