Skip to content

Fix Django example so spans reach stdout in manual and auto instrumentation - #5492

Draft
ocelotl wants to merge 2 commits into
open-telemetry:mainfrom
ocelotl:fix_PR_4822
Draft

Fix Django example so spans reach stdout in manual and auto instrumentation#5492
ocelotl wants to merge 2 commits into
open-telemetry:mainfrom
ocelotl:fix_PR_4822

Conversation

@ocelotl

@ocelotl ocelotl commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

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:

  • Manual (python manage.py runserver --noreload): manage.py never set up a TracerProvider/exporter, so spans were created but dropped.
  • Auto (opentelemetry-instrument python manage.py runserver --noreload): opentelemetry-instrument defaults to the OTLP exporter, so it tried to ship spans to localhost:4317 and printed nothing to the console.

This PR fixes the example for both scenarios:

  • Manual: set up a TracerProvider with a SimpleSpanProcessor(ConsoleSpanExporter()) in manage.py so spans print to stdout immediately.
  • Auto: document opentelemetry-instrument --traces_exporter console ... (for both runserver and the uWSGI variant), and instruct commenting out the in-code TracerProvider setup and DjangoInstrumentor().instrument() call.

SimpleSpanProcessor is used rather than BatchSpanProcessor so 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.py setup but (a) used BatchSpanProcessor (delayed output) and (b) left the auto-instrumentation path on the default OTLP exporter, so opentelemetry-instrument still produced no console output. This PR addresses the maintainer feedback on that PR by making the auto path work via --traces_exporter console in addition to fixing the manual path.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • This change requires a documentation update

How Has This Been Tested?

  • tox -e ruff (ruff check + format) passes on docs/examples/django/manage.py
  • rstcheck docs/examples/django/README.rst passes
  • --traces_exporter console resolves to the console entry point registered by opentelemetry-sdk (opentelemetry.sdk.trace.export:ConsoleSpanExporter)

Does This PR Require a Contrib Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added (n/a — documentation example fix)
  • Documentation has been updated

…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.
@ocelotl
ocelotl requested a review from a team as a code owner July 30, 2026 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant