From 2911e4737ee5bdf6d5bb9d8c31209ab4217a9bbe Mon Sep 17 00:00:00 2001 From: Tamir David Date: Sun, 6 Oct 2024 09:44:47 +0300 Subject: [PATCH 1/2] fix: importing django module incorrect --- initializer/lib_handling.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/initializer/lib_handling.py b/initializer/lib_handling.py index fe956fa..2fa9793 100644 --- a/initializer/lib_handling.py +++ b/initializer/lib_handling.py @@ -53,7 +53,10 @@ def reload_distro_modules() -> None: # These changes address this issue: https://github.com/open-telemetry/opentelemetry-python-contrib/issues/2495. # TODO: Remove once the bug is fixed. def handle_django_instrumentation(): - if os.getenv('DJANGO_SETTINGS_MODULE', None) is None: + # Get the DJANGO_SETTINGS_MODULE environment variable value. + django_settings_module = os.getenv('DJANGO_SETTINGS_MODULE', None) + + if django_settings_module is None: os.environ.setdefault(OTEL_PYTHON_DJANGO_INSTRUMENT, 'False') else: @@ -64,7 +67,7 @@ def handle_django_instrumentation(): # As an additional safeguard, we're ensuring that DJANGO_SETTINGS_MODULE is importable. # This is done to prevent instrumentation from being enabled if the Django settings module cannot be imported. try: - importlib.import_module('DJANGO_SETTINGS_MODULE') + importlib.import_module(django_settings_module) except: os.environ.setdefault(OTEL_PYTHON_DJANGO_INSTRUMENT, 'False') \ No newline at end of file From c42a16a867e17e6add69ee214734f3c64aa35875 Mon Sep 17 00:00:00 2001 From: Tamir David Date: Sun, 6 Oct 2024 10:00:18 +0300 Subject: [PATCH 2/2] fix: avoid using django dependencies --- initializer/lib_handling.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/initializer/lib_handling.py b/initializer/lib_handling.py index 2fa9793..8d5b004 100644 --- a/initializer/lib_handling.py +++ b/initializer/lib_handling.py @@ -1,9 +1,6 @@ import sys import importlib import os -from opentelemetry.instrumentation.django.environment_variables import ( - OTEL_PYTHON_DJANGO_INSTRUMENT, -) def reorder_python_path(): paths_to_move = [path for path in sys.path if path.startswith('/var/odigos/')] @@ -57,7 +54,7 @@ def handle_django_instrumentation(): django_settings_module = os.getenv('DJANGO_SETTINGS_MODULE', None) if django_settings_module is None: - os.environ.setdefault(OTEL_PYTHON_DJANGO_INSTRUMENT, 'False') + os.environ.setdefault("OTEL_PYTHON_DJANGO_INSTRUMENT", 'False') else: cwd_path = os.getcwd() @@ -69,5 +66,5 @@ def handle_django_instrumentation(): try: importlib.import_module(django_settings_module) except: - os.environ.setdefault(OTEL_PYTHON_DJANGO_INSTRUMENT, 'False') + os.environ.setdefault("OTEL_PYTHON_DJANGO_INSTRUMENT", 'False') \ No newline at end of file