Skip to content

Commit

Permalink
Allow distro and configurator specification
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydvoss committed May 23, 2023
1 parent cae6ce4 commit eac6bc0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Add optional distro and configurator specification for auto-instrumentation
([#1823](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1823))

## Version 1.18.0/0.39b0 (2023-05-10)

- `opentelemetry-instrumentation-system-metrics` Add `process.` prefix to `runtime.memory`, `runtime.cpu.time`, and `runtime.gc_count`. Change `runtime.memory` from count to UpDownCounter. ([#1735](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1735))
Expand Down
7 changes: 6 additions & 1 deletion opentelemetry-instrumentation/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ This package provides a couple of commands that help automatically instruments a

.. note::
You need to install a distro package to get auto instrumentation working. The ``opentelemetry-distro``
package contains the default distro and automatically configures some of the common options for users.
package contains the default distro and configurator and automatically configures some of the common options for users.
For more info about ``opentelemetry-distro`` check `here <https://opentelemetry-python.readthedocs.io/en/latest/examples/distro/README.html>`__
::

pip install opentelemetry-distro[otlp]

When creating a custom distro and/or configurator, be sure to add entry points for each under opentelemetry_distro and opentelemetry_configurator respectfully.
If you have entry points for multiple distros or configurators present in your environment, you should specify the entry point name of the distro and configurator you want to be used via the OTEL_PYTHON_DISTRO and OTEL_PYTHON_CONFIGURATOR environment variables.


opentelemetry-bootstrap
-----------------------
Expand Down Expand Up @@ -58,6 +61,8 @@ The command supports the following configuration options as CLI arguments and en

* ``--traces_exporter`` or ``OTEL_TRACES_EXPORTER``
* ``--metrics_exporter`` or ``OTEL_METRICS_EXPORTER``
* ``--distro`` or ``OTEL_PYTHON_DISTRO``
* ``--configurator`` or ``OTEL_PYTHON_CONFIGURATOR``

Used to specify which trace exporter to use. Can be set to one or more of the well-known exporter
names (see below).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from opentelemetry.instrumentation.distro import BaseDistro, DefaultDistro
from opentelemetry.instrumentation.environment_variables import (
OTEL_PYTHON_DISABLED_INSTRUMENTATIONS,
OTEL_PYTHON_DISTRO,
OTEL_PYTHON_CONFIGURATOR,
)
from opentelemetry.instrumentation.utils import _python_path_without_directory
from opentelemetry.instrumentation.version import __version__
Expand All @@ -32,19 +34,28 @@


def _load_distros() -> BaseDistro:
distro_name = environ.get(OTEL_PYTHON_DISTRO, None)
for entry_point in iter_entry_points("opentelemetry_distro"):
try:
distro = entry_point.load()()
if not isinstance(distro, BaseDistro):
if distro_name is None or distro_name == entry_point.name:
distro = entry_point.load()()
if not isinstance(distro, BaseDistro):
logger.debug(
"%s is not an OpenTelemetry Distro. Skipping",
entry_point.name,
)
continue
logger.debug(
"%s is not an OpenTelemetry Distro. Skipping",
"Distribution %s will be configured", entry_point.name
)
return distro
else:
logger.warning(
"%s distro not loaded because %s is set by %s",
entry_point.name,
distro_name,
OTEL_PYTHON_DISTRO,
)
continue
logger.debug(
"Distribution %s will be configured", entry_point.name
)
return distro
except Exception as exc: # pylint: disable=broad-except
logger.exception(
"Distribution %s configuration failed", entry_point.name
Expand Down Expand Up @@ -92,6 +103,7 @@ def _load_instrumentors(distro):


def _load_configurators():
configurator_name = environ.get(OTEL_PYTHON_CONFIGURATOR, None)
configured = None
for entry_point in iter_entry_points("opentelemetry_configurator"):
if configured is not None:
Expand All @@ -102,8 +114,19 @@ def _load_configurators():
)
continue
try:
entry_point.load()().configure(auto_instrumentation_version=__version__) # type: ignore
configured = entry_point.name
if (
configurator_name is None
or configurator_name == entry_point.name
):
entry_point.load()().configure(auto_instrumentation_version=__version__) # type: ignore
configured = entry_point.name
else:
logger.warning(
"Configuration of %s not loaded because %s is set by %s",
entry_point.name,
configurator_name,
OTEL_PYTHON_CONFIGURATOR,
)
except Exception as exc: # pylint: disable=broad-except
logger.exception("Configuration of %s failed", entry_point.name)
raise exc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@
"""
.. envvar:: OTEL_PYTHON_DISABLED_INSTRUMENTATIONS
"""

OTEL_PYTHON_DISTRO = "OTEL_PYTHON_DISTRO"
"""
.. envvar:: OTEL_PYTHON_DISTRO
"""

OTEL_PYTHON_CONFIGURATOR = "OTEL_PYTHON_CONFIGURATOR"
"""
.. envvar:: OTEL_PYTHON_CONFIGURATOR
"""

0 comments on commit eac6bc0

Please sign in to comment.