| @ -1,6 +1,12 @@ | |||||
| #!/usr/bin/env bash | #!/usr/bin/env bash | ||||
| # Setup workshop code | |||||
| mkdir /tracing-workshop | mkdir /tracing-workshop | ||||
| git clone https://github.com/brettlangdon/distributed-tracing-with-apm-workshop /tracing-workshop | git clone https://github.com/brettlangdon/distributed-tracing-with-apm-workshop /tracing-workshop | ||||
| cd /tracing-workshop | cd /tracing-workshop | ||||
| # Try to install yaml_cli helper | |||||
| (cd /tmp/ && git clone https://github.com/Gallore/yaml_cli && cd ./yaml_cli && python setup.py install) || true | |||||
| # Start pulling containers as soon as they load | |||||
| docker-compose pull | docker-compose pull | ||||
| @ -0,0 +1,7 @@ | |||||
| In this phase we are going to introduce a service failure. | |||||
| Open a new terminal window and run: | |||||
| `docker-compose stop pumps` | |||||
| to cause the `pumps` service to stop. | |||||
| @ -0,0 +1,5 @@ | |||||
| Before continuing to the next step please be sure to restart the `pumps` service. | |||||
| `docker-compose start pumps`. | |||||
| You may close the new terminal window you have opened in the previous step. | |||||
| @ -1,29 +1,8 @@ | |||||
| What happens when unexpected exceptions are raised from our application? | |||||
| In this phase we are going to introduce an exception into our application | |||||
| to see how we can track it down. | |||||
| Open `frontend/frontend/api.py` file in the editor. | |||||
| `restart-services`{{execute interrupt}} to continue. | |||||
| Add the following code to the beginning of the `def simulate_sensors` route. | |||||
| Open the `frontend` service page to continue. | |||||
| ``` python | |||||
| maybe_raise_exception() | |||||
| ```{{copy}} | |||||
| The end result function should look like: | |||||
| ``` python | |||||
| @app.route('/simulate_sensors') | |||||
| def simulate_sensors(): | |||||
| maybe_raise_exception() | |||||
| app.logger.info('Simulating refresh of sensor data') | |||||
| resp = requests.get('http://sensors:5002/refresh_sensors') | |||||
| resp.raise_for_status() | |||||
| sensors = resp.json() | |||||
| return jsonify(sensors) | |||||
| ```{{copy}} | |||||
| `restart-services`{{execute interrupt}}. | |||||
| Open the `/simulate_sensors` resource page for our `frontend` service. | |||||
| https://app.datadoghq.com/apm/service/frontend/flask.request | |||||
| https://app.datadoghq.com/apm/service/frontend | |||||
| @ -0,0 +1,7 @@ | |||||
| #!/usr/bin/env bash | |||||
| command -v yaml_cli > /dev/null && \ | |||||
| yaml_cli -i docker-compose.yml \ | |||||
| -o docker-compose.yml \ | |||||
| --list-append \ | |||||
| -s services:frontend:environment 'WORKSHOP_ADD_ERRORS=true' | |||||
| @ -1,30 +1,8 @@ | |||||
| With APM we can easily visualize where latencies are coming from. | |||||
| In this phase we are going to introduce an latency into our application | |||||
| to see how we can track it down. | |||||
| Open `sensors/sensors.py` file in the editor. | |||||
| `restart-services`{{execute interrupt}} to continue. | |||||
| Add the following to the `def simulate_all_sensors` function. | |||||
| Open the `frontend` service page to continue. | |||||
| ```python | |||||
| db.session.execute('SELECT pg_sleep(2);') | |||||
| ```{{copy}} | |||||
| When we are done the function should look like: | |||||
| ``` python | |||||
| @tracer.wrap(name='sensor-simulator') | |||||
| def simulate_all_sensors(): | |||||
| db.session.execute('SELECT pg_sleep(2);') | |||||
| sensors = Sensor.query.all() | |||||
| for sensor in sensors: | |||||
| sensor.value = random.randint(1,100) | |||||
| db.session.add_all(sensors) | |||||
| db.session.commit() | |||||
| app.logger.info('Sensor data updated') | |||||
| return [s.serialize() for s in sensors] | |||||
| ```{{copy}} | |||||
| `restart-services`{{execute interrupt}} | |||||
| Open the service page for our `frontend` service. | |||||
| https://app.datadoghq.com/apm/service/frontend/flask.request | |||||
| https://app.datadoghq.com/apm/service/frontend | |||||
| @ -0,0 +1,7 @@ | |||||
| #!/usr/bin/env bash | |||||
| command -v yaml_cli > /dev/null && \ | |||||
| yaml_cli -i docker-compose.yml \ | |||||
| -o docker-compose.yml \ | |||||
| --list-append \ | |||||
| -s services:sensors:environment 'WORKSHOP_ADD_LATENCY=true' | |||||