Skip to content

Conversation

@BrianPetkovsek
Copy link
Contributor

@BrianPetkovsek BrianPetkovsek commented Nov 27, 2025

Description

This PR fixes the Django instrumentation documentation example which was missing the TracerProvider and ConsoleSpanExporter setup. Without this configuration, the Django example would capture traces but not export them anywhere, resulting in no visible output despite the documentation claiming JSON span data would appear in STDOUT.

The fix adds proper TracerProvider and SpanProcessor (with ConsoleSpanExporter) configuration to the Django example, bringing it in line with the Flask example which correctly includes this setup.

Type of change

Please delete options that are not relevant.

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

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Linting passed: tox -e ruff - All checks passed
  • SDK tests passed: tox -e py312-test-opentelemetry-sdk
  • Manual verification: Ran the tracing_example.py which uses the same TracerProvider/ConsoleSpanExporter pattern and confirmed it produces expected JSON output
  • Import verification: Confirmed all new imports in manage.py resolve correctly

Test Configuration:

  • Python 3.12
  • tox with tox-uv
  • Ubuntu Linux

Does This PR Require a Contrib Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated (fix_changelog.md created)
  • Unit tests have been added (no new tests needed - documentation fix)
  • Documentation has been updated (README.rst updated with explanation)

Additional Notes

Security Considerations

No security implications. This is a documentation fix that adds proper OpenTelemetry SDK setup code.

Performance Considerations

No performance implications. The change only affects documentation examples.

Related Issues

BrianPetkovsek and others added 10 commits November 27, 2025 08:09
… example

The Django example was missing TracerProvider and ConsoleSpanExporter
configuration. Without this setup, the instrumentation captures traces
but they are not exported anywhere, resulting in no visible output.

Co-authored-by: BrianPetkovsek <16124109+BrianPetkovsek@users.noreply.github.com>
…te README

Added required deliverables:
- fix_changelog.md: Detailed explanation of the problem and fix
- pull_request.md: Generated from PR template with full details
- fix_summary.txt: Commands run and test results
- README.rst: Added reference to Flask example for consistency

Co-authored-by: BrianPetkovsek <16124109+BrianPetkovsek@users.noreply.github.com>
…issue

fix(docs): add TracerProvider setup to Django instrumentation example
@BrianPetkovsek BrianPetkovsek requested a review from a team as a code owner November 27, 2025 13:47
@BrianPetkovsek BrianPetkovsek changed the title Fix Django autoinstrumentation not producing STDOUT output Fix Django autoinstrumentation not producing span in STDOUT output Nov 27, 2025
Comment on lines 55 to 74
The ``manage.py`` example includes this setup:

.. code-block:: python
from opentelemetry import trace
from opentelemetry.instrumentation.django import DjangoInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
BatchSpanProcessor,
ConsoleSpanExporter,
)
# Set up tracing with console exporter to see spans in stdout
trace.set_tracer_provider(TracerProvider())
trace.get_tracer_provider().add_span_processor(
BatchSpanProcessor(ConsoleSpanExporter())
)
# This call is what makes the Django application be instrumented
DjangoInstrumentor().instrument()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR!

To avoid repeating, I'd suggest not including this code block in the Readme and just encourage readers to look at manage.py. Maybe: remove this block, then update L49 to say something like

Once there, open the ``manage.py`` file which uses the OpenTelemetry SDK to set up tracing with console exporter and manual instrumentation of Django:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed code block and added comment to encourage readers to look at manage.py

Comment on lines 76 to 77
Without the ``TracerProvider`` and ``SpanProcessor`` setup, the instrumentation will
capture traces but they won't be exported anywhere (no output will be visible).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest removing this because manage.py already says

# Set up tracing with console exporter to see spans in stdout

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please could you also update https://github.com/open-telemetry/opentelemetry-python/blob/main/docs/examples/django/README.rst?plain=1#L113-L114 to say that the TracerProvider calls should also be commented out when doing auto-instrumentation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make the code handling tracing already setup instead?

@xrmx xrmx moved this to Easy to review / merge / close in @xrmx's Python PR digest Nov 27, 2025
@xrmx xrmx moved this from Easy to review / merge / close to Reviewed PRs that need fixes in @xrmx's Python PR digest Nov 27, 2025
Copilot AI and others added 3 commits December 3, 2025 22:43
…mentation

Co-authored-by: BrianPetkovsek <16124109+BrianPetkovsek@users.noreply.github.com>
…de-example

Update Django README.rst to avoid duplication and clarify auto-instrumentation
Copilot AI review requested due to automatic review settings December 3, 2025 23:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the Django instrumentation documentation example to properly export spans to STDOUT. The example was missing the necessary OpenTelemetry SDK setup (TracerProvider and ConsoleSpanExporter) that would actually export the captured traces, resulting in no visible output despite the documentation claiming JSON span data would appear.

  • Adds proper TracerProvider initialization with BatchSpanProcessor and ConsoleSpanExporter to manage.py
  • Updates README.rst to accurately reflect the setup requirements and auto-instrumentation instructions

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
docs/examples/django/manage.py Adds TracerProvider setup with ConsoleSpanExporter configuration to properly export spans to STDOUT, following the same pattern used in Flask examples
docs/examples/django/README.rst Updates documentation to accurately describe the TracerProvider setup and clarifies auto-instrumentation instructions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tammy-baylis-swi
Copy link
Contributor

Thanks for updates! Please also add an entry to CHANGELOG.md linking this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

3 participants