-
Notifications
You must be signed in to change notification settings - Fork 776
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?
Changes from 10 commits
1b3ca3f
1142c66
0b7c1d8
673d786
71fdb7b
664b59f
ddbacfa
4897c9c
a4b5812
9dd5894
8eeb1ed
16c42d4
a9aa015
ed0b2fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,8 +46,35 @@ 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. To see spans output to console, you need to: | ||
xrmx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 1. Set up a ``TracerProvider`` | ||
| 2. Add a ``SpanProcessor`` with an exporter (e.g., ``ConsoleSpanExporter`` for stdout) | ||
| 3. Call ``DjangoInstrumentor().instrument()`` to instrument the Django app | ||
|
|
||
| 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() | ||
|
||
|
|
||
| Without the ``TracerProvider`` and ``SpanProcessor`` setup, the instrumentation will | ||
| capture traces but they won't be exported anywhere (no output will be visible). | ||
|
||
|
|
||
| Run the Django app with ``python manage.py runserver --noreload``. | ||
| The ``--noreload`` flag is needed to avoid Django from running ``main`` twice. | ||
|
|
||
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?