Fix Django example so spans reach stdout in manual and auto instrumentation - #5492
Draft
ocelotl wants to merge 2 commits into
Draft
Fix Django example so spans reach stdout in manual and auto instrumentation#5492ocelotl wants to merge 2 commits into
ocelotl wants to merge 2 commits into
Conversation
…tation The Django example claimed JSON spans would appear in stdout, but no exporter was ever configured. In the manual path (python manage.py runserver) no TracerProvider was set up, and in the auto path (opentelemetry-instrument) the default OTLP exporter was used, so neither produced console output. Manual path: set up a TracerProvider with a SimpleSpanProcessor and ConsoleSpanExporter in manage.py so spans print immediately. Auto path: document opentelemetry-instrument --traces_exporter console (for both runserver and uWSGI) and instruct commenting out the in-code TracerProvider setup and DjangoInstrumentor().instrument() call.
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.
Note
This PR is a draft and is not intended to be merged on its own.
It is an attempt to translate the review comments from @xrmx and @ocelotl on #4822 into
actual code changes, so that the discussion can be seen as concrete diffs rather than prose.
The intent is for @BrianPetkovsek to incorporate these changes into #4822 (his PR), which
remains the PR that should ultimately land. Please treat this as a suggestion/reference for
#4822 rather than a competing change.
Description
The Django instrumentation example claims that JSON span data appears in STDOUT, but no exporter was ever configured, so neither documented run mode actually produced output:
python manage.py runserver --noreload):manage.pynever set up aTracerProvider/exporter, so spans were created but dropped.opentelemetry-instrument python manage.py runserver --noreload):opentelemetry-instrumentdefaults to the OTLP exporter, so it tried to ship spans tolocalhost:4317and printed nothing to the console.This PR fixes the example for both scenarios:
TracerProviderwith aSimpleSpanProcessor(ConsoleSpanExporter())inmanage.pyso spans print to stdout immediately.opentelemetry-instrument --traces_exporter console ...(for bothrunserverand the uWSGI variant), and instruct commenting out the in-codeTracerProvidersetup andDjangoInstrumentor().instrument()call.SimpleSpanProcessoris used rather thanBatchSpanProcessorso a span is printed the moment a request completes, matching the example's "you should see output similar to this" narration (a batch processor only flushes on a timer / at shutdown).Relation to #4822
This supersedes #4822, which added the manual
manage.pysetup but (a) usedBatchSpanProcessor(delayed output) and (b) left the auto-instrumentation path on the default OTLP exporter, soopentelemetry-instrumentstill produced no console output. This PR addresses the maintainer feedback on that PR by making the auto path work via--traces_exporter consolein addition to fixing the manual path.Type of change
How Has This Been Tested?
tox -e ruff(ruff check + format) passes ondocs/examples/django/manage.pyrstcheck docs/examples/django/README.rstpasses--traces_exporter consoleresolves to theconsoleentry point registered byopentelemetry-sdk(opentelemetry.sdk.trace.export:ConsoleSpanExporter)Does This PR Require a Contrib Repo Change?
Checklist: