Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/examples/django/README.rst
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?

Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions docs/examples/django/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,26 @@
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():
os.environ.setdefault(
"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()

Expand Down
Loading