redis/redis-py · error · ImportError
OpenTelemetry is not installed. Install it with: pip…
Error message
OpenTelemetry is not installed. Install it with: pip install opentelemetry-api opentelemetry-sdk opentelemetry-exporter-otlp-proto-http
What it means
Raised as ImportError by OTelProviderManager.get_meter_provider() (redis/observability/providers.py:79) when config.is_enabled() is True but the lazy import `from opentelemetry import metrics` fails. Unlike error 461 (which needs only opentelemetry-api for the collector), this path requires the SDK packages so the manager can obtain a real MeterProvider. The message lists the full set: opentelemetry-api, opentelemetry-sdk, and the OTLP HTTP exporter.
Solutions
- Install the full SDK set exactly as the message instructs: `pip install opentelemetry-api opentelemetry-sdk opentelemetry-exporter-otlp-proto-http` (or `pip install redis[otel]` plus the exporter if you export over OTLP HTTP).
- Confirm both `from opentelemetry import metrics` and `from opentelemetry.sdk.metrics import MeterProvider` import cleanly in the target interpreter.
- If you do not want metrics, pass an OTelConfig with enabled_telemetry cleared so get_meter_provider() returns early before the import.
- Pin opentelemetry-sdk and the exporter to compatible versions in your lockfile to prevent a resolver from dropping them.
Example fix
# before - only the api package present pip install opentelemetry-api otel.init(OTelConfig(enable_metrics=True)) # providers.py:79 ImportError # after pip install opentelemetry-api opentelemetry-sdk opentelemetry-exporter-otlp-proto-http
Defensive patterns
Strategy: validation
Validate before calling
def otel_sdk_available():
try:
from opentelemetry import metrics # noqa: F401
from opentelemetry.sdk.metrics import MeterProvider # noqa: F401
return True
except ImportError:
return False
# only enable metrics if the full SDK is present
config = OTelConfig(enable_metrics=True) if otel_sdk_available() else OTelConfig(enabled_telemetry=[]) Try / catch
try:
otel.init(OTelConfig(enable_metrics=True))
except ImportError as e:
if 'OpenTelemetry' in str(e):
logging.warning('OpenTelemetry SDK not installed; observability disabled')
else:
raise Prevention
- Install opentelemetry-api, opentelemetry-sdk, and opentelemetry-exporter-otlp-proto-http together (or use the otel extra plus the exporter).
- Guard the init call with an import probe so a missing SDK disables metrics instead of raising.
- Run a startup self-check importing the SDK packages in the production interpreter.
- Pin all three OpenTelemetry packages to mutually compatible versions in requirements.
When it happens
Trigger: Calling otel.init(OTelConfig(enable_metrics=True)) (or any default OTelConfig, since DEFAULT_TELEMETRY is METRICS) and then issuing a Redis command that triggers get_meter_provider(). Only opentelemetry-api is installed but not opentelemetry-sdk; or neither is installed and the module happened to construct the manager before hitting the collector check.
Common situations: Developer installed just `opentelemetry-api` (the light API package) thinking it was enough; requirements list `opentelemetry-sdk` but a version conflict removed it; the OTLP exporter package needed to actually export metrics was never added; dev environment works but production slim image omits the SDK wheels.
Related errors
- OpenTelemetry API is not installed. Install it with: pip…
- Metrics are enabled but no global MeterProvider is…
- cryptography is not installed.
- Python wasn't built with SSL support
- The PyJWT library is required for
AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10).
Data as JSON: /api/errors/b1e43785a5d094fa.
Report an issue: GitHub.
Appendix: source
Thrown at redis/observability/providers.py:79
"""
Get the global MeterProvider set by the application.
Returns:
MeterProvider instance or None if metrics are disabled
Raises:
ImportError: If OpenTelemetry is not installed
RuntimeError: If metrics are enabled but no global MeterProvider is set
"""
if not self.config.is_enabled():
return None
# Lazy import - only import OTel when metrics are enabled
try:
from opentelemetry import metrics
from opentelemetry.metrics import NoOpMeterProvider
except ImportError:
raise ImportError(
"OpenTelemetry is not installed. Install it with:\n"
" pip install opentelemetry-api opentelemetry-sdk opentelemetry-exporter-otlp-proto-http"
)
# Get the global MeterProvider
if self._meter_provider is None:
self._meter_provider = metrics.get_meter_provider()
# Check if it's a real provider (not NoOp)
if isinstance(self._meter_provider, NoOpMeterProvider):
raise RuntimeError(
"Metrics are enabled but no global MeterProvider is configured.\n"
"\n"
"Set up OpenTelemetry before initializing redis-py observability:\n"
"\n"
" from opentelemetry import metrics\n"
" from opentelemetry.sdk.metrics import MeterProvider\n"
" from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader\n"View on GitHub (pinned to 6a6b581b48)