Getting Started with Tracing
Security Monitoring is now available Security Monitoring is now available

Getting Started with Tracing

Overview

Datadog Application Performance Monitoring (APM or tracing) is used to collect traces from your backend application code. This beginners’ guide shows you how get your first trace into Datadog.

Note: Datadog APM is available for many languages and frameworks. See the documentation on Instrumenting Your Application

Datadog account

If you haven’t already, create a Datadog account.

Datadog Agent

Before installing the Datadog Agent, set up a Vagrant Ubuntu 16.04 virtual machine using the following commands. For more information about Vagrant, see their Getting Started page.

vagrant init ubuntu/xenial64
vagrant up
vagrant ssh

To install the Datadog Agent on a host, use the one line install command updated with your Datadog API key:

DD_API_KEY=<DATADOG_API_KEY> bash -c "$(curl -L https://s3.amazonaws.com/dd-agent/scripts/install_script.sh)"

Validation

Verify the Agent is running with the status command:

sudo datadog-agent status

After a few minutes, verify the Agent is connected to your account by checking the Infrastructure List in Datadog.

Datadog APM

Enable APM

For the latest versions of Agent v6 and v7, APM is enabled by default. You can see this in the Agent datadog.yaml configuration file:

# apm_config:
#   Whether or not the APM Agent should run
#   enabled: true

And in trace-agent.log:

# /var/log/datadog/trace-agent.log:
2019-03-25 20:33:18 INFO (run.go:136) - trace-agent running on host ubuntu-xenial
2019-03-25 20:33:18 INFO (api.go:144) - listening for traces at http://localhost:8126
2019-03-25 20:33:28 INFO (api.go:341) - no data received
2019-03-25 20:34:18 INFO (service.go:63) - total number of tracked services: 0

Environment name

For the best experience, it is recommended to use the the environment variable DD_ENV to configure env through your service’s tracer.

Additionally, if your tracer has logs injection enabled then the env will be consistent across traces and logs. Read more about how this works in Unified Service Tagging.

Alternatively, name your environment by updating datadog.yaml to set env under apm_config. To learn more about setting env for APM, see the setting primary tags to scope guide.

APM application

Installation

Before setting up the application, install pip then flask and ddtrace on your Ubuntu VM:

sudo apt-get install python-pip
pip install flask
pip install ddtrace

Create

On the Ubuntu VM, create the application hello.py with the following content:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def index():
    return 'hello world'

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5050)

Run

Run hello.py with ddtrace which automatically instruments your application in Datadog:

export DD_SERVICE=hello
ddtrace-run python hello.py

You should see a similar output to:

* Serving Flask app "hello" (lazy loading)
  ...
* Running on http://0.0.0.0:5050/ (Press CTRL+C to quit)

Test

Test your application and send your traces to Datadog using curl. Your application should be running (as shown above). In a separate command prompt run:

vagrant ssh
curl http://0.0.0.0:5050/

This outputs:

hello world

After a few minutes, your trace displays in Datadog under the hello service. Check the services page or trace list.

Further Reading