@@ -46,8 +46,35 @@ an ``opentelemetry.instrumentation.django.DjangoInstrumentor`` to instrument the
4646
4747Clone the ``opentelemetry-python `` repository and go to ``opentelemetry-python/docs/examples/django ``.
4848
49- Once there, open the ``manage.py `` file. The call to ``DjangoInstrumentor().instrument() ``
50- in ``main `` is all that is needed to make the app be instrumented.
49+ Once there, open the ``manage.py `` file. To see spans output to console, you need to:
50+
51+ 1. Set up a ``TracerProvider ``
52+ 2. Add a ``SpanProcessor `` with an exporter (e.g., ``ConsoleSpanExporter `` for stdout)
53+ 3. Call ``DjangoInstrumentor().instrument() `` to instrument the Django app
54+
55+ The ``manage.py `` example includes this setup:
56+
57+ .. code-block :: python
58+
59+ from opentelemetry import trace
60+ from opentelemetry.instrumentation.django import DjangoInstrumentor
61+ from opentelemetry.sdk.trace import TracerProvider
62+ from opentelemetry.sdk.trace.export import (
63+ BatchSpanProcessor,
64+ ConsoleSpanExporter,
65+ )
66+
67+ # Set up tracing with console exporter to see spans in stdout
68+ trace.set_tracer_provider(TracerProvider())
69+ trace.get_tracer_provider().add_span_processor(
70+ BatchSpanProcessor(ConsoleSpanExporter())
71+ )
72+
73+ # This call is what makes the Django application be instrumented
74+ DjangoInstrumentor().instrument()
75+
76+ Without the ``TracerProvider `` and ``SpanProcessor `` setup, the instrumentation will
77+ capture traces but they won't be exported anywhere (no output will be visible).
5178
5279Run the Django app with ``python manage.py runserver --noreload ``.
5380The ``--noreload `` flag is needed to avoid Django from running ``main `` twice.
0 commit comments