The Service Map for APM is here!

Python

Crawler Crawler

Overview

The Python integration enables you to monitor any custom metric by instrumenting a few lines of code. For instance, you can have a metric that returns the number of page views or the time of any function call. For additional information about the Python integration, please refer to the guide on submitting metrics. For advanced usage, please refer to the documentation in the repository. You can also review the API docs for details on how to use the API with Python.

Setup

Installation

  1. To install from pip:

    pip install datadog
    
  2. Start instrumenting your code:

from datadog import initialize

options = {
    'api_key':'<DATADOG_API_KEY>',
    'app_key':'<DATADOG_APP_KEY>'
}

initialize(**options)

# Use Datadog REST API client
from datadog import api

title = "Something big happened!"
text = 'And let me tell you all about it here!'
tags = ['version:1', 'application:web']

api.Event.create(title=title, text=text, tags=tags)


# Use Statsd, a Python client for DogStatsd
from datadog import statsd

statsd.increment('whatever')
statsd.gauge('foo', 42)

# Or ThreadStats, an alternative tool to collect and flush metrics,using Datadog REST API
from datadog import ThreadStats
stats = ThreadStats()
stats.start()
stats.increment('home.page.hits')

Configuration

There is nothing that you need to do in the Datadog application to configure Python.

Log collection

Available for Agent >6.0

Use your favorite python logger to log from your application directly into a file on your host. Then follow our log collection guide for python to start forwarding your logs to Datadog.

Validation

Go to the Metrics explorer page and see that it just works!

Troubleshooting

Need help? Contact Datadog Support.