Skip to content

Commit 5da3048

Browse files
committed
Add warning when no opentelemetry_configurator entry points found
1 parent b4a9084 commit 5da3048

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Added
1515

16+
- `opentelemetry-instrumentation`: Add warning when no `opentelemetry_configurator`
17+
entry points are found, suggesting to install `opentelemetry-distro`.
18+
([#4543](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4543))
1619
- Bump `pylint` to `4.0.5`
1720
([#4244](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4244))
1821
- `opentelemetry-instrumentation-sqlite3`: Add uninstrument, error status, suppress, and no-op tests

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ def _key_for(entry_point: EntryPoint):
6161

6262
def _load_distro() -> BaseDistro:
6363
distro_name = environ.get(OTEL_PYTHON_DISTRO, None)
64+
all_distros = list(entry_points(group="opentelemetry_distro"))
65+
if not all_distros:
66+
_logger.warning(
67+
"No distro found. Make sure 'opentelemetry-distro' is installed "
68+
"if you are using automatic instrumentation. "
69+
"See https://opentelemetry.io/docs/zero-code/python/ for details."
70+
)
71+
6472
for entry_point in entry_points(group="opentelemetry_distro"):
6573
try:
6674
# If no distro is specified, use first to come up.
@@ -160,6 +168,15 @@ def _load_instrumentors(distro):
160168
def _load_configurators():
161169
configurator_name = environ.get(OTEL_PYTHON_CONFIGURATOR, None)
162170
configured = None
171+
all_configurators = list(entry_points(group="opentelemetry_configurator"))
172+
if not all_configurators:
173+
_logger.warning(
174+
"No configurator found. Make sure 'opentelemetry-distro' is "
175+
"installed if you are using automatic instrumentation. "
176+
"See https://opentelemetry.io/docs/zero-code/python/ for details."
177+
)
178+
return
179+
163180
for entry_point in entry_points(group="opentelemetry_configurator"):
164181
if configured is not None:
165182
_logger.warning(

opentelemetry-instrumentation/tests/auto_instrumentation/test_load.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ def test_load_configurators(self, iter_mock): # pylint: disable=no-self-use
6767
)
6868
def test_load_configurators_no_ep(self, iter_mock): # pylint: disable=no-self-use
6969
iter_mock.return_value = ()
70+
with self.assertLogs(
71+
"opentelemetry.instrumentation.auto_instrumentation._load",
72+
level="WARNING",
73+
) as cm:
74+
_load._load_configurators()
75+
self.assertTrue(
76+
any("opentelemetry-distro" in msg for msg in cm.output)
77+
)
7078
# Confirm method does not crash if not entry points exist.
7179
_load._load_configurators()
7280

0 commit comments

Comments
 (0)