SDKs overview
Datadog provides client libraries, commonly referred to as Software Development Kits (SDKs), to facilitate interaction with its API. These SDKs abstract the underlying HTTP requests and response parsing, allowing developers to focus on integrating Datadog's observability features into their applications and infrastructure. The SDKs cover various programming languages, offering idiomatic interfaces for tasks such as submitting custom metrics, configuring monitors, managing dashboards, and querying historical data. Using an SDK can reduce development time and potential errors compared to making raw HTTP requests to the Datadog API endpoints directly.
The SDKs are designed to align with the Datadog API's structure, which includes endpoints for different product areas like Infrastructure Monitoring, APM, Log Management, and Synthetic Monitoring. This allows for a consistent programmatic experience across the platform's features. Developers can use these libraries to automate operational tasks, integrate monitoring into CI/CD pipelines, or build custom tools that interact with their Datadog environment. The official SDKs are maintained by Datadog and are generally kept up-to-date with API changes and new features, ensuring compatibility and access to the latest capabilities.
Official SDKs by language
Datadog maintains official SDKs for several popular programming languages, ensuring robust and supported access to its API. These libraries are developed to provide a native experience within each language ecosystem, handling API authentication, request formatting, and response parsing. The official SDKs are typically the recommended approach for integrating with the Datadog API due to their direct support and maintenance by Datadog engineers. Each SDK is designed to reflect the specific conventions and best practices of its respective language, offering a familiar interface for developers.
The following table outlines the official SDKs, their typical package names, installation commands, and general maturity status:
| Language | Package/Module Name | Typical Install Command | Maturity |
|---|---|---|---|
| Python | datadog |
pip install datadog |
Stable, actively maintained |
| Go | github.com/DataDog/datadog-api-client-go |
go get github.com/DataDog/datadog-api-client-go |
Stable, actively maintained |
| Java | com.datadoghq:datadog-api-client (Maven) |
Add to pom.xml dependencies |
Stable, actively maintained |
| Ruby | datadog-api-client |
gem install datadog-api-client |
Stable, actively maintained |
| C# | Datadog.Api.Client (NuGet) |
dotnet add package Datadog.Api.Client |
Stable, actively maintained |
| Node.js | @datadog/datadog-api-client |
npm install @datadog/datadog-api-client |
Stable, actively maintained |
Each of these SDKs is available through the standard package managers for their respective ecosystems, simplifying dependency management and updates. Developers can find detailed usage examples and API documentation for each language on the Datadog API documentation portal.
Installation
Installing Datadog's official SDKs typically follows the standard practices for each programming language's package management system. Prior to installation, ensure you have the appropriate language runtime and package manager set up on your development environment. For example, Python projects generally use pip, while Node.js projects use npm or yarn. Java projects commonly integrate dependencies via Maven or Gradle by adding entries to their project configuration files like pom.xml or build.gradle.
Once the SDK is installed, you will need to configure it with your Datadog API key and Application key. These credentials are essential for authenticating your requests against the Datadog API. Your API key identifies your organization, while the Application key identifies the specific user or application making the API requests. It is a best practice to manage these keys securely, often by using environment variables or a secure configuration management system rather than hardcoding them directly into your source code. You can obtain and manage your keys from your Datadog account settings, as detailed in the Datadog API Key Management guide.
Quickstart example
Below is a quickstart example demonstrating how to send a custom metric to Datadog using the Python SDK. This example illustrates the basic steps of initializing the client and making an API call. For other languages, the structure will be similar, involving importing the relevant client library, setting API and Application keys, and then invoking the appropriate methods to interact with Datadog services.
Python Example: Sending a Custom Metric
import os
from datadog_api_client.v1 import ApiClient, Configuration
from datadog_api_client.v1.api.metrics_api import MetricsApi
from datadog_api_client.v1.model.metrics_payload import MetricsPayload
from datadog_api_client.v1.model.series import Series
# Configure API key and Application key
configuration = Configuration()
configuration.api_key["apiKeyAuth"] = os.getenv("DD_API_KEY")
configuration.api_key["appKeyAuth"] = os.getenv("DD_APP_KEY")
# Set the host if not using default Datadog US site
# configuration.host = "https://api.datadoghq.eu"
with ApiClient(configuration) as api_client:
api_instance = MetricsApi(api_client)
body = MetricsPayload(
series=[
Series(
metric="my.custom.metric",
points=[[float(os.times().elapsed), 10.5]], # Timestamp and value
type="gauge",
tags=["environment:dev", "service:web-app"],
),
],
)
try:
api_response = api_instance.submit_metrics(body=body)
print("Metrics submitted successfully:")
print(api_response)
except Exception as e:
print(f"Error submitting metrics: {e}")
This example assumes that DD_API_KEY and DD_APP_KEY environment variables are set. The metric my.custom.metric is sent as a gauge with a value of 10.5 and associated tags. For more detailed examples and advanced usage, refer to the Datadog Metrics API documentation.
Node.js Example: Creating a Monitor
For Node.js developers, creating a monitor programmatically is a common task. This snippet demonstrates how to define and create a simple metric alert monitor.
const { client, v1 } = require("@datadog/datadog-api-client");
const configuration = client.createConfiguration({
authMethods: {
apiKeyAuth: process.env.DD_API_KEY,
appKeyAuth: process.env.DD_APP_KEY,
},
});
const apiInstance = new v1.MonitorsApi(configuration);
const params = {
body: {
name: "My Custom CPU Monitor",
type: "metric alert",
query: "avg(last_5m):system.cpu.idle{*} < 10",
message: "CPU usage is too high! @slack-myteam",
tags: ["env:production", "team:backend"],
options: {
thresholds: { warning: 20, critical: 10 },
notify_no_data: false,
no_data_timeframe: 20,
renotify_interval: 0,
},
},
};
apiInstance
.createMonitor(params)
.then((data) => {
console.log("Monitor created successfully:");
console.log(JSON.stringify(data, null, 2));
})
.catch((error) => console.error(error));
This Node.js example sets up a monitor to alert when the average CPU idle time falls below 10% over the last five minutes. It also includes tags and notification options. The Datadog Monitors API reference provides comprehensive details on all available monitor types and configuration options.
Community libraries
Beyond the official SDKs, the Datadog ecosystem benefits from various community-contributed libraries and integrations. These libraries often address specific use cases, provide bindings for languages not officially supported, or offer alternative interfaces to the Datadog API. While community libraries may not carry the same level of direct support as official SDKs, they can be valuable resources for developers seeking specialized functionality or working in niche environments.
For example, some community projects might focus on integrating Datadog with specific frameworks (e.g., a Django or Rails plugin for metric submission), or provide tools for automated dashboard creation from code. It's important to evaluate the maintainability, documentation, and active development status of any community library before incorporating it into a production environment. Resources like GitHub and public forums can be used to assess the health and community support for such projects. The broader developer community often shares these tools on platforms like GitHub, and discussions can be found on Datadog's community forums or general developer communities like Stack Overflow, which often feature examples of Datadog API usage patterns.
When considering community libraries, developers should review the project's license, contribution guidelines, and recent activity to ensure it aligns with their project requirements and risk tolerance. While official SDKs are the primary recommendation, community efforts can extend Datadog's reach and flexibility for specific integration challenges, demonstrating the platform's extensibility. Always verify the source and security practices of third-party libraries before integrating them into your systems.