Skip to content

Commit d0500c2

Browse files
Add error handling to opentelemetry-bootstrap -a (#2517)
* Revert "Refactor bootstrap generation (#2101)" This reverts commit 1ee7261. * Add error handling to opentelemetry-bootstrap -a Fixes #2516 --------- Co-authored-by: Tammy Baylis <[email protected]>
1 parent 6a40ffd commit d0500c2

File tree

3 files changed

+47
-45
lines changed

3 files changed

+47
-45
lines changed

opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@
1414

1515
import argparse
1616
import logging
17-
import subprocess
1817
import sys
18+
from subprocess import (
19+
PIPE,
20+
CalledProcessError,
21+
Popen,
22+
SubprocessError,
23+
check_call,
24+
)
1925

2026
import pkg_resources
2127

@@ -34,7 +40,7 @@ def wrapper(package=None):
3440
if package:
3541
return func(package)
3642
return func()
37-
except subprocess.SubprocessError as exp:
43+
except SubprocessError as exp:
3844
cmd = getattr(exp, "cmd", None)
3945
if cmd:
4046
msg = f'Error calling system command "{" ".join(cmd)}"'
@@ -48,18 +54,21 @@ def wrapper(package=None):
4854
@_syscall
4955
def _sys_pip_install(package):
5056
# explicit upgrade strategy to override potential pip config
51-
subprocess.check_call(
52-
[
53-
sys.executable,
54-
"-m",
55-
"pip",
56-
"install",
57-
"-U",
58-
"--upgrade-strategy",
59-
"only-if-needed",
60-
package,
61-
]
62-
)
57+
try:
58+
check_call(
59+
[
60+
sys.executable,
61+
"-m",
62+
"pip",
63+
"install",
64+
"-U",
65+
"--upgrade-strategy",
66+
"only-if-needed",
67+
package,
68+
]
69+
)
70+
except CalledProcessError as error:
71+
print(error)
6372

6473

6574
def _pip_check():
@@ -70,8 +79,8 @@ def _pip_check():
7079
'opentelemetry-instrumentation-flask 1.0.1 has requirement opentelemetry-sdk<2.0,>=1.0, but you have opentelemetry-sdk 0.5.'
7180
To not be too restrictive, we'll only check for relevant packages.
7281
"""
73-
with subprocess.Popen(
74-
[sys.executable, "-m", "pip", "check"], stdout=subprocess.PIPE
82+
with Popen(
83+
[sys.executable, "-m", "pip", "check"], stdout=PIPE
7584
) as check_pipe:
7685
pip_check = check_pipe.communicate()[0].decode()
7786
pip_check_lower = pip_check.lower()

opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"library": "aiohttp ~= 3.0",
2525
"instrumentation": "opentelemetry-instrumentation-aiohttp-client==0.46b0.dev",
2626
},
27+
{
28+
"library": "aiohttp ~= 3.0",
29+
"instrumentation": "opentelemetry-instrumentation-aiohttp-server==0.46b0.dev",
30+
},
2731
{
2832
"library": "aiopg >= 0.13.0, < 2.0.0",
2933
"instrumentation": "opentelemetry-instrumentation-aiopg==0.46b0.dev",
@@ -187,6 +191,7 @@
187191
"opentelemetry-instrumentation-dbapi==0.46b0.dev",
188192
"opentelemetry-instrumentation-logging==0.46b0.dev",
189193
"opentelemetry-instrumentation-sqlite3==0.46b0.dev",
194+
"opentelemetry-instrumentation-threading==0.46b0.dev",
190195
"opentelemetry-instrumentation-urllib==0.46b0.dev",
191196
"opentelemetry-instrumentation-wsgi==0.46b0.dev",
192197
]

scripts/otel_packaging.py

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,55 +12,43 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from tomli import load
16-
from os import path, listdir
17-
from subprocess import check_output, CalledProcessError
18-
from requests import get
15+
import os
16+
import subprocess
17+
from subprocess import CalledProcessError
1918

20-
scripts_path = path.dirname(path.abspath(__file__))
21-
root_path = path.dirname(scripts_path)
22-
instrumentations_path = path.join(root_path, "instrumentation")
19+
import tomli
20+
21+
scripts_path = os.path.dirname(os.path.abspath(__file__))
22+
root_path = os.path.dirname(scripts_path)
23+
instrumentations_path = os.path.join(root_path, "instrumentation")
2324

2425

2526
def get_instrumentation_packages():
26-
for pkg in sorted(listdir(instrumentations_path)):
27-
pkg_path = path.join(instrumentations_path, pkg)
28-
if not path.isdir(pkg_path):
27+
for pkg in sorted(os.listdir(instrumentations_path)):
28+
pkg_path = os.path.join(instrumentations_path, pkg)
29+
if not os.path.isdir(pkg_path):
2930
continue
3031

31-
error = f"Could not get version for package {pkg}"
32-
3332
try:
34-
hatch_version = check_output(
33+
version = subprocess.check_output(
3534
"hatch version",
3635
shell=True,
3736
cwd=pkg_path,
38-
universal_newlines=True
37+
universal_newlines=True,
3938
)
40-
4139
except CalledProcessError as exc:
4240
print(f"Could not get hatch version from path {pkg_path}")
4341
print(exc.output)
42+
raise exc
4443

45-
try:
46-
response = get(f"https://pypi.org/pypi/{pkg}/json", timeout=10)
47-
48-
except Exception:
49-
print(error)
50-
continue
51-
52-
if response.status_code != 200:
53-
print(error)
54-
continue
55-
56-
pyproject_toml_path = path.join(pkg_path, "pyproject.toml")
44+
pyproject_toml_path = os.path.join(pkg_path, "pyproject.toml")
5745

5846
with open(pyproject_toml_path, "rb") as file:
59-
pyproject_toml = load(file)
47+
pyproject_toml = tomli.load(file)
6048

6149
instrumentation = {
6250
"name": pyproject_toml["project"]["name"],
63-
"version": hatch_version.strip(),
51+
"version": version.strip(),
6452
"instruments": pyproject_toml["project"]["optional-dependencies"][
6553
"instruments"
6654
],

0 commit comments

Comments
 (0)