The aim of this example is to show how to automatically produce distributed traces using the SignalFx Tracing Library for Python. For this example, using the Django REST Framework, we have created a client/server interaction in the form of a basic blog service and consumer.
To run this example locally, and send traces to your available Smart Agent or Gateway, you may first clone this repository.
Next, navigate into the django
directory and run the following commands:
$ pip install -r requirements.txt
# install supported tracer and library instrumentation
$ sfx-py-trace-bootstrap
$ cd blog
$ python manage.py makemigrations posts
$ python manage.py migrate
$ python manage.py createsuperuser --username <USERNAME> --email <EMAIL>
$ sfx-py-trace manage.py runserver localhost:<PORT>
To confirm everything is set up as expected, you may navigate to http://localhost:<PORT>
and sign in with the username
and password
you created above.
- Creating an article (user log in necessary)
- Viewing articles created
- Viewing list of contributing authors and their articles
- Updating/Editing an article (user log in necessary)
- Deleting an article (user log in necessary)
To clearly identify your traces, you may choose to name your server services by setting the
SIGNALFX_SERVICE_NAME
environment variable to your preferred name.
For example:
$ export SIGNALFX_SERVICE_NAME='<YOUR_APP_NAME>'
(Note: This should be done in the same terminal in which your server is running).
The client's service name may be set in create_tracer()
as follows:
create_tracer(service_name='<APP_NAME>')
If not set, the default service name is: SignalFx-Tracing
In the directory containing manage.py
(in this example:django/blog
), start the server by using:
$ sfx-py-trace manage.py runserver <PORT>
In a different terminal, and in the directory containing client.py
(in this case, django/
), run the client using:
$ python client.py --username <USERNAME> --password <PASSWORD> --port <PORT>
And that's it!
-
In this example, we used the SignalFx trace decorator
@trace
to automatically create spans for tracing custom logic. Please see the tracer decoration documentation for more information. -
The
signalfx-tracing
module and this application configuration assume that your Smart Agent or Gateway is accepting traces at http://localhost:9080/v1/trace. If this is not the case, you can set theSIGNALFX_ENDPOINT_URL
environment variable to the desired url to suit your environment before launching the server and client.