Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: importing django module incorrect #35

Merged
merged 2 commits into from
Oct 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions initializer/lib_handling.py
Original file line number Diff line number Diff line change
@@ -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/')]
Expand Down Expand Up @@ -53,8 +50,11 @@ 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:
os.environ.setdefault(OTEL_PYTHON_DJANGO_INSTRUMENT, 'False')
# 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:
cwd_path = os.getcwd()
Expand All @@ -64,7 +64,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')
os.environ.setdefault("OTEL_PYTHON_DJANGO_INSTRUMENT", 'False')

Loading