mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-31 06:03:21 +08:00
Adding try catch to fix ImproperlyConfigured exception while allowing (#1369)
This commit is contained in:
@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- `opentelemetry-instrumentation-django` Fixed bug where auto-instrumentation fails when django is installed and settings are not configured.
|
||||||
|
([#1369](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1369))
|
||||||
- `opentelemetry-instrumentation-system-metrics` add supports to collect system thread count. ([#1339](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1339))
|
- `opentelemetry-instrumentation-system-metrics` add supports to collect system thread count. ([#1339](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1339))
|
||||||
|
|
||||||
## [1.13.0-0.34b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.13.0-0.34b0) - 2022-09-26
|
## [1.13.0-0.34b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.13.0-0.34b0) - 2022-09-26
|
||||||
|
@ -195,6 +195,7 @@ from typing import Collection
|
|||||||
|
|
||||||
from django import VERSION as django_version
|
from django import VERSION as django_version
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
|
|
||||||
from opentelemetry.instrumentation.django.environment_variables import (
|
from opentelemetry.instrumentation.django.environment_variables import (
|
||||||
OTEL_PYTHON_DJANGO_INSTRUMENT,
|
OTEL_PYTHON_DJANGO_INSTRUMENT,
|
||||||
@ -275,7 +276,23 @@ class DjangoInstrumentor(BaseInstrumentor):
|
|||||||
# https://docs.djangoproject.com/en/3.0/ref/middleware/#middleware-ordering
|
# https://docs.djangoproject.com/en/3.0/ref/middleware/#middleware-ordering
|
||||||
|
|
||||||
_middleware_setting = _get_django_middleware_setting()
|
_middleware_setting = _get_django_middleware_setting()
|
||||||
settings_middleware = getattr(settings, _middleware_setting, [])
|
settings_middleware = []
|
||||||
|
try:
|
||||||
|
settings_middleware = getattr(settings, _middleware_setting, [])
|
||||||
|
except ImproperlyConfigured as exception:
|
||||||
|
_logger.debug(
|
||||||
|
"DJANGO_SETTINGS_MODULE environment variable not configured. Defaulting to empty settings: %s",
|
||||||
|
exception,
|
||||||
|
)
|
||||||
|
settings.configure()
|
||||||
|
settings_middleware = getattr(settings, _middleware_setting, [])
|
||||||
|
except ModuleNotFoundError as exception:
|
||||||
|
_logger.debug(
|
||||||
|
"DJANGO_SETTINGS_MODULE points to a non-existent module. Defaulting to empty settings: %s",
|
||||||
|
exception,
|
||||||
|
)
|
||||||
|
settings.configure()
|
||||||
|
settings_middleware = getattr(settings, _middleware_setting, [])
|
||||||
|
|
||||||
# Django allows to specify middlewares as a tuple, so we convert this tuple to a
|
# Django allows to specify middlewares as a tuple, so we convert this tuple to a
|
||||||
# list, otherwise we wouldn't be able to call append/remove
|
# list, otherwise we wouldn't be able to call append/remove
|
||||||
|
Reference in New Issue
Block a user