diff --git a/docs/examples/django/README.rst b/docs/examples/django/README.rst index 4f1771fbe6..03592fb576 100644 --- a/docs/examples/django/README.rst +++ b/docs/examples/django/README.rst @@ -46,8 +46,7 @@ an ``opentelemetry.instrumentation.django.DjangoInstrumentor`` to instrument the Clone the ``opentelemetry-python`` repository and go to ``opentelemetry-python/docs/examples/django``. -Once there, open the ``manage.py`` file. The call to ``DjangoInstrumentor().instrument()`` -in ``main`` is all that is needed to make the app be instrumented. +Once there, open the ``manage.py`` file, which uses the OpenTelemetry SDK to set up tracing with console exporter and manual instrumentation of Django. Run the Django app with ``python manage.py runserver --noreload``. The ``--noreload`` flag is needed to avoid Django from running ``main`` twice. @@ -110,9 +109,10 @@ Django's instrumentation can be disabled by setting the following environment va Auto Instrumentation -------------------- -This same example can be run using auto instrumentation. Comment out the call -to ``DjangoInstrumentor().instrument()`` in ``main``, then Run the django app -with ``opentelemetry-instrument python manage.py runserver --noreload``. +This same example can be run using auto instrumentation. Comment out the +``TracerProvider`` setup and the call to ``DjangoInstrumentor().instrument()`` +in ``main``, then run the Django app with +``opentelemetry-instrument python manage.py runserver --noreload``. Repeat the steps with the client, the result should be the same. Usage with Auto Instrumentation and uWSGI diff --git a/docs/examples/django/manage.py b/docs/examples/django/manage.py index 75d9bc2c68..8c8d469fc3 100755 --- a/docs/examples/django/manage.py +++ b/docs/examples/django/manage.py @@ -18,7 +18,13 @@ import os import sys +from opentelemetry import trace from opentelemetry.instrumentation.django import DjangoInstrumentor +from opentelemetry.sdk.trace import TracerProvider +from opentelemetry.sdk.trace.export import ( + BatchSpanProcessor, + ConsoleSpanExporter, +) def main(): @@ -26,6 +32,12 @@ def main(): "DJANGO_SETTINGS_MODULE", "instrumentation_example.settings" ) + # 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()