-
Notifications
You must be signed in to change notification settings - Fork 774
Fix Django autoinstrumentation not producing span in STDOUT output #4822
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
base: main
Are you sure you want to change the base?
Conversation
… 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
docs/examples/django/README.rst
Outdated
| 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() |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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
docs/examples/django/README.rst
Outdated
| Without the ``TracerProvider`` and ``SpanProcessor`` setup, the instrumentation will | ||
| capture traces but they won't be exported anywhere (no output will be visible). |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
…mentation Co-authored-by: BrianPetkovsek <16124109+BrianPetkovsek@users.noreply.github.com>
…de-example Update Django README.rst to avoid duplication and clarify auto-instrumentation
There was a problem hiding this 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.
|
Thanks for updates! Please also add an entry to |
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.
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
tox -e ruff- All checks passedtox -e py312-test-opentelemetry-sdkTest Configuration:
Does This PR Require a Contrib Repo Change?
Checklist:
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