Skip to content

Commit 4adf1bb

Browse files
committed
Fix the auto instrumentation command
Fixes open-telemetry#566
1 parent 99600e2 commit 4adf1bb

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

docs/examples/auto-instrumentation/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Span(name="serv_request", context=SpanContext(trace_id=0x9c0e0ce8f7b7dbb51d1d6e7
9292
Now, kill the execution of `server_instrumented.py` with `ctrl + c` and run this instead:
9393

9494
```sh
95-
$ opentelemetry-auto-instrumentation opentelemetry-python/opentelemetry-auto-instrumentation/example/server_uninstrumented.py
95+
$ opentelemetry-auto-instrumentation python opentelemetry-python/opentelemetry-auto-instrumentation/example/server_uninstrumented.py
9696
```
9797

9898
In the console where you previously executed `client.py`, run again this again:

opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/auto_instrumentation.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@
1515
# limitations under the License.
1616

1717
from logging import getLogger
18-
from runpy import run_path
18+
from os import environ, execl
19+
from os.path import abspath, dirname, pathsep
20+
from shutil import which
1921
from sys import argv
2022

21-
from pkg_resources import iter_entry_points
22-
2323
logger = getLogger(__file__)
2424

2525

2626
def run() -> None:
2727

28-
for entry_point in iter_entry_points("opentelemetry_instrumentor"):
29-
try:
30-
entry_point.load()().instrument() # type: ignore
31-
logger.debug("Instrumented %s", entry_point.name)
28+
python_path = environ.get("PYTHONPATH", "")
29+
filedir_path = dirname(abspath(__file__))
30+
31+
if filedir_path not in python_path:
32+
environ["PYTHONPATH"] = pathsep.join([filedir_path, python_path])
3233

33-
except Exception: # pylint: disable=broad-except
34-
logger.exception("Instrumenting of %s failed", entry_point.name)
34+
executable = which(argv[1])
3535

36-
run_path(argv[1], run_name="__main__") # type: ignore
36+
execl(executable, executable, *argv[2:])
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from logging import getLogger
16+
17+
from pkg_resources import iter_entry_points
18+
19+
logger = getLogger(__file__)
20+
21+
22+
for entry_point in iter_entry_points("opentelemetry_instrumentor"):
23+
try:
24+
entry_point.load()().instrument() # type: ignore
25+
logger.debug("Instrumented %s", entry_point.name)
26+
27+
except Exception: # pylint: disable=broad-except
28+
logger.exception("Instrumenting of %s failed", entry_point.name)

0 commit comments

Comments
 (0)