fix: DjangoInstrumentor poisons settings when OTEL_EXPORTER_OTLP_ENDPOINT is set#192
Merged
fix: DjangoInstrumentor poisons settings when OTEL_EXPORTER_OTLP_ENDPOINT is set#192
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #192 +/- ##
==========================================
+ Coverage 96.88% 96.95% +0.06%
==========================================
Files 101 101
Lines 3983 4008 +25
==========================================
+ Hits 3859 3886 +27
+ Misses 124 122 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
DjangoInstrumentor accesses settings.MIDDLEWARE during instrument(), which requires the project directory on sys.path and DJANGO_SETTINGS_MODULE set. Previously these were set after the OTel block, causing the instrumentor to call settings.configure() with empty defaults and poisoning Django for the rest of the process. Also migrates test_main to pytest-mock (MockerFixture) and monkeypatch.setenv. Fixes #191
4cb2c78 to
a0e4e1c
Compare
Zaimwa9
reviewed
Apr 6, 2026
Zaimwa9
approved these changes
Apr 6, 2026
Member
Author
|
Tested on Depot CI (where |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #191.
In this PR, we reorder
ensure_cli_env()so thatsys.path.append(os.getcwd())andos.environ.setdefault("DJANGO_SETTINGS_MODULE", ...)run before the OTel setup block. Previously,DjangoInstrumentor().instrument()accessedsettings.MIDDLEWAREbefore the project directory was onsys.path, causing Django to fail the settings import. The instrumentor silently caught the error and calledsettings.configure()with empty defaults, poisoning Django for the rest of the process — making commands likeflagsmith docgendisappear.Also, we migrate
test_main.pyfromunittest.mock.patch/patch.dicttopytest-mock/monkeypatch.setenv, and add tests for thedocgenandtask-processorargv branches.