DataDog / dd-trace-py

Datadog Python APM Client
https://ddtrace.readthedocs.io/
Other
519 stars 407 forks source link

Git executable not found error #9981

Closed ollz272 closed 1 month ago

ollz272 commented 1 month ago

Summary of problem

When trying to upgrade from 2.9.3 and beyond, we get an error that a git exectuable can't be found on bitbucket pipelines:

[Datadog CI Visibility] ERROR    ddtrace.ext.git:git.py:129 Git executable not found, cannot extract git metadata.
[Datadog CI Visibility] ERROR    ddtrace.ext.git:git.py:320 Git executable not found, cannot extract git metadata.
/usr/local/lib/python3.12/multiprocessing/popen_fork.py:66: DeprecationWarning: This process (pid=903) is multi-threaded, use of fork() may lead to deadlocks in the child.
  self.pid = os.fork()
[Datadog CI Visibility] INFO     ddtrace.internal.ci_visibility.recorder:recorder.py:231 Service: sherlock (env: None)
[Datadog CI Visibility] INFO     ddtrace.internal.ci_visibility.recorder:recorder.py:232 Requests mode: agent EVP proxy
[Datadog CI Visibility] INFO     ddtrace.internal.ci_visibility.recorder:recorder.py:233 Git metadata upload enabled: True
[Datadog CI Visibility] INFO     ddtrace.internal.ci_visibility.recorder:recorder.py:234 API-provided settings: coverage collection: False
[Datadog CI Visibility] INFO     ddtrace.internal.ci_visibility.recorder:recorder.py:235 API-provided settings: Intelligent Test Runner: False, test skipping: False
[Datadog CI Visibility] INFO     ddtrace.internal.ci_visibility.recorder:recorder.py:240 Detected configurations: {'os.architecture': 'x86_64', 'os.platform': 'Linux', 'os.version': '5.15.0-1064-aws', '[runtime.name](http://runtime.name/)': 'CPython', 'runtime.version': '3.12.4'}
[Datadog CI Visibility] WARNING  ddtrace.internal.ci_visibility.recorder:recorder.py:247 CODEOWNERS file is not available
[Datadog CI Visibility] INFO     ddtrace.internal.ci_visibility.recorder:recorder.py:605 Final settings: coverage collection: False, test skipping: False
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/opt/atlassian/pipelines/agent/build/.venv/lib/python3.12/site-packages/_pytest/main.py", line 281, in wrap_session
INTERNALERROR>     config.hook.pytest_sessionstart(session=session)
INTERNALERROR>   File "/opt/atlassian/pipelines/agent/build/.venv/lib/python3.12/site-packages/pluggy/_hooks.py", line 513, in __call__
INTERNALERROR>     return self._hookexec([self.name](http://self.name/), self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/opt/atlassian/pipelines/agent/build/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 120, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/opt/atlassian/pipelines/agent/build/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 139, in _multicall
INTERNALERROR>     raise exception.with_traceback(exception.__traceback__)
INTERNALERROR>   File "/opt/atlassian/pipelines/agent/build/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 122, in _multicall
INTERNALERROR>     teardown.throw(exception)  # type: ignore[union-attr]
INTERNALERROR>     ^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/opt/atlassian/pipelines/agent/build/.venv/lib/python3.12/site-packages/_pytest/logging.py", line 784, in pytest_sessionstart
INTERNALERROR>     return (yield)
INTERNALERROR>             ^^^^^
INTERNALERROR>   File "/opt/atlassian/pipelines/agent/build/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 103, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>           ^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/opt/atlassian/pipelines/agent/build/.venv/lib/python3.12/site-packages/ddtrace/contrib/pytest/_plugin_v1.py", line 455, in pytest_sessionstart
INTERNALERROR>     workspace_path = extract_workspace_path()
INTERNALERROR>                      ^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/opt/atlassian/pipelines/agent/build/.venv/lib/python3.12/site-packages/ddtrace/ext/git.py", line 284, in extract_workspace_path
INTERNALERROR>     workspace_path = _git_subprocess_cmd("rev-parse --show-toplevel", cwd=cwd)
INTERNALERROR>                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/opt/atlassian/pipelines/agent/build/.venv/lib/python3.12/site-packages/ddtrace/ext/git.py", line 118, in _git_subprocess_cmd
INTERNALERROR>     stdout, stderr, _, returncode = _git_subprocess_cmd_with_details(*cmd, cwd=cwd, std_in=None)
INTERNALERROR>                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/opt/atlassian/pipelines/agent/build/.venv/lib/python3.12/site-packages/ddtrace/ext/git.py", line 99, in _git_subprocess_cmd_with_details
INTERNALERROR>     process = subprocess.Popen(
INTERNALERROR>               ^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/local/lib/python3.12/subprocess.py", line 1026, in __init__
INTERNALERROR>     self._execute_child(args, executable, preexec_fn, close_fds,
INTERNALERROR>   File "/usr/local/lib/python3.12/subprocess.py", line 1955, in _execute_child
INTERNALERROR>     raise child_exception_type(errno_num, err_msg, err_filename)
INTERNALERROR> FileNotFoundError: [Errno 2] No such file or directory: 'git'
Process Process-1:
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/usr/local/lib/python3.12/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/atlassian/pipelines/agent/build/.venv/lib/python3.12/site-packages/ddtrace/internal/ci_visibility/git_client.py", line 163, in _run_protocol
    latest_commits = cls._get_latest_commits(cwd=cwd)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/atlassian/pipelines/agent/build/.venv/lib/python3.12/site-packages/ddtrace/internal/ci_visibility/git_client.py", line 235, in _get_latest_commits
    latest_commits, stderr, duration, returncode = _extract_latest_commits_with_details(cwd=cwd)
                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/atlassian/pipelines/agent/build/.venv/lib/python3.12/site-packages/ddtrace/ext/git.py", line 219, in _extract_latest_commits_with_details
    return _git_subprocess_cmd_with_details("log", "--format=%H", "-n", "1000", '--since="1 month ago"', cwd=cwd)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/atlassian/pipelines/agent/build/.venv/lib/python3.12/site-packages/ddtrace/ext/git.py", line 99, in _git_subprocess_cmd_with_details
    process = subprocess.Popen(
              ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/local/lib/python3.12/subprocess.py", line 1955, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'git'

Which version of dd-trace-py are you using?

2.9.3, 2.10.1

Which version of pip are you using?

Unsure

How can we reproduce your problem?

Try running tests in bitbucket with ddrace 2.9.3 installed.

What is the result that you get?

We get a crash because git can't be found.

What is the result that you expected?

The tests to run as normal

emmettbutler commented 1 month ago

Thanks for raising this issue, @ollz272. We'll see how we can help.

cc @romainkomorndatadog

romainkomorndatadog commented 1 month ago

Ah, this comes from #9586 . I'll get a fix going ASAP.

@ollz272 , I assume you've been using our ddtrace plugin on bitbucket for some time, have you always used it without git available? The CIVisibility service that gets enabled by the plugin ends up making quite a few calls to the git executable.

romainkomorndatadog commented 1 month ago

I've just released ddtrace versions which all contain a fix for this issue:

I've tested all three in a docker container without a git binary installed and all finished without crashes. In the screenshot below, the branch is empty due to git being missing:

image