From 7d88a5eeb6c7ffdc51df29a84ce0124c3492b926 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 30 Jul 2026 17:29:52 -0500 Subject: [PATCH 1/2] Fix Django example so spans reach stdout in manual and auto instrumentation 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. --- .changelog/5472.fixed | 1 + docs/examples/django/README.rst | 15 ++++++++++----- docs/examples/django/manage.py | 18 +++++++++++++++++- 3 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 .changelog/5472.fixed diff --git a/.changelog/5472.fixed b/.changelog/5472.fixed new file mode 100644 index 00000000000..426a340696a --- /dev/null +++ b/.changelog/5472.fixed @@ -0,0 +1 @@ +`docs`: fix Django example so spans are printed to stdout for both manual and auto-instrumentation setups diff --git a/docs/examples/django/README.rst b/docs/examples/django/README.rst index 4f1771fbe68..4076029bff1 100644 --- a/docs/examples/django/README.rst +++ b/docs/examples/django/README.rst @@ -47,7 +47,8 @@ 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. +in ``main`` is what instruments the app, and the ``TracerProvider`` configured with a +``ConsoleSpanExporter`` right above it is what prints the generated spans to stdout. Run the Django app with ``python manage.py runserver --noreload``. The ``--noreload`` flag is needed to avoid Django from running ``main`` twice. @@ -110,9 +111,13 @@ 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 --traces_exporter console python manage.py runserver --noreload``. +The ``--traces_exporter console`` option makes ``opentelemetry-instrument`` +print spans to stdout, matching the manual setup above; without it the default +OTLP exporter is used and nothing is shown in the console. Repeat the steps with the client, the result should be the same. Usage with Auto Instrumentation and uWSGI @@ -126,7 +131,7 @@ first install uWSGI in the previous virtual environment: Once that is done, run the server with ``uwsgi`` from the directory that contains ``instrumentation_example``: -``opentelemetry-instrument uwsgi --http :8000 --module instrumentation_example.wsgi`` +``opentelemetry-instrument --traces_exporter console uwsgi --http :8000 --module instrumentation_example.wsgi`` This should start one uWSGI worker in your console. Open up a browser and point it to ``localhost:8000``. This request should display a span exported in the diff --git a/docs/examples/django/manage.py b/docs/examples/django/manage.py index 2ddd5e8eb93..861c8a88f20 100755 --- a/docs/examples/django/manage.py +++ b/docs/examples/django/manage.py @@ -10,7 +10,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 ( + ConsoleSpanExporter, + SimpleSpanProcessor, +) def main(): @@ -18,7 +24,17 @@ def main(): "DJANGO_SETTINGS_MODULE", "instrumentation_example.settings" ) - # This call is what makes the Django application be instrumented + # Set up a tracer provider with a console exporter so that the spans + # generated below are printed to stdout. Comment out this block when + # running with auto instrumentation (``opentelemetry-instrument``), which + # configures the tracer provider and exporter for you. + trace.set_tracer_provider(TracerProvider()) + trace.get_tracer_provider().add_span_processor( + SimpleSpanProcessor(ConsoleSpanExporter()) + ) + + # This call is what makes the Django application be instrumented. + # Comment it out when running with auto instrumentation. DjangoInstrumentor().instrument() try: From fc9b4fe8817e247925a1e161538f85e9625c45e2 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 30 Jul 2026 17:32:19 -0500 Subject: [PATCH 2/2] Rename changelog fragment to PR number --- .changelog/{5472.fixed => 5492.fixed} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/{5472.fixed => 5492.fixed} (100%) diff --git a/.changelog/5472.fixed b/.changelog/5492.fixed similarity index 100% rename from .changelog/5472.fixed rename to .changelog/5492.fixed