Skip to content

Commit

Permalink
Fix the auto instrumentation command
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Apr 29, 2020
1 parent 99600e2 commit 4adf1bb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/examples/auto-instrumentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Span(name="serv_request", context=SpanContext(trace_id=0x9c0e0ce8f7b7dbb51d1d6e7
Now, kill the execution of `server_instrumented.py` with `ctrl + c` and run this instead:

```sh
$ opentelemetry-auto-instrumentation opentelemetry-python/opentelemetry-auto-instrumentation/example/server_uninstrumented.py
$ opentelemetry-auto-instrumentation python opentelemetry-python/opentelemetry-auto-instrumentation/example/server_uninstrumented.py
```

In the console where you previously executed `client.py`, run again this again:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
# limitations under the License.

from logging import getLogger
from runpy import run_path
from os import environ, execl
from os.path import abspath, dirname, pathsep
from shutil import which
from sys import argv

from pkg_resources import iter_entry_points

logger = getLogger(__file__)


def run() -> None:

for entry_point in iter_entry_points("opentelemetry_instrumentor"):
try:
entry_point.load()().instrument() # type: ignore
logger.debug("Instrumented %s", entry_point.name)
python_path = environ.get("PYTHONPATH", "")
filedir_path = dirname(abspath(__file__))

if filedir_path not in python_path:
environ["PYTHONPATH"] = pathsep.join([filedir_path, python_path])

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

run_path(argv[1], run_name="__main__") # type: ignore
execl(executable, executable, *argv[2:])
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from logging import getLogger

from pkg_resources import iter_entry_points

logger = getLogger(__file__)


for entry_point in iter_entry_points("opentelemetry_instrumentor"):
try:
entry_point.load()().instrument() # type: ignore
logger.debug("Instrumented %s", entry_point.name)

except Exception: # pylint: disable=broad-except
logger.exception("Instrumenting of %s failed", entry_point.name)

0 comments on commit 4adf1bb

Please sign in to comment.