### Go-Metro Installation and Capabilities Setup Source: https://docs.datadoghq.com/integrations/go-metro A consolidated example showing the installation of required libraries and setting capabilities for the go-metro binary, useful for unprivileged execution. ```bash # Install required libraries $ sudo apt-get install libcap # debian $ sudo apt-get install libcap2-bin # debian alternative $ sudo yum install libcap # redhat $ sudo yum install compat-libcap1 # redhat alternative # Set capabilities $ sudo setcap cap_net_raw+ep /opt/datadog-agent/bin/go-metro ``` -------------------------------- ### Install and Run Example Service Source: https://docs.datadoghq.com/getting_started/profiler Clone the example repository, set your Datadog API key, and start the service using Docker Compose. ```shell git clone https://github.com/DataDog/dd-continuous-profiler-example.git cd dd-continuous-profiler-example echo "DD_API_KEY=YOUR_API_KEY" > docker.env docker-compose up -d ``` -------------------------------- ### Install and Run AI Setup CLI (Interactive) Source: https://docs.datadoghq.com/agentic_onboarding/setup Use this command to start an interactive setup process for the Datadog AI Setup CLI. It guides you through account creation or linking and product selection. ```bash npx @datadog/ai-setup-cli --site datadoghq.com ``` -------------------------------- ### Get hourly usage for custom metrics (Rust) Source: https://docs.datadoghq.com/api/latest/usage-metering/get-hourly-usage-for-custom-metrics Use this Rust code to retrieve hourly usage for custom metrics. Ensure you have the datadog-api-client library installed. The example specifies a start and end hour for the query. ```rust // Get hourly usage for custom metrics returns "OK" response use chrono::{DateTime, Utc}; use datadog_api_client::datadog; use datadog_api_client::datadogV1::api_usage_metering::GetUsageTimeseriesOptionalParams; use datadog_api_client::datadogV1::api_usage_metering::UsageMeteringAPI; #[tokio::main] async fn main() { let configuration = datadog::Configuration::new(); let api = UsageMeteringAPI::with_config(configuration); let resp = api .get_usage_timeseries( DateTime::parse_from_rfc3339("2021-11-06T11:11:11+00:00") .expect("Failed to parse datetime") .with_timezone(&Utc), GetUsageTimeseriesOptionalParams::default().end_hr( DateTime::parse_from_rfc3339("2021-11-08T11:11:11+00:00") .expect("Failed to parse datetime") .with_timezone(&Utc), ), ) .await; if let Ok(value) = resp { println!("{:#?}", value); } else { println!("{:#?}", resp.unwrap_err()); } } ``` -------------------------------- ### Install Library and Dependencies Source: https://docs.datadoghq.com/api/latest/test-optimization/update-test-optimization-service-settings Before running the example, install the necessary library and its dependencies. This sets up your environment for test optimization. ```bash npm install @datadog/datadog-api-client ``` -------------------------------- ### Get hourly usage for Fargate in Rust Source: https://docs.datadoghq.com/api/latest/usage-metering/get-hourly-usage-for-fargate Use this Rust code to fetch hourly Fargate usage data. Ensure the Datadog API client library is installed. The example specifies start and end hours for the query. ```rust use chrono::{DateTime, Utc}; use datadog_api_client::datadog; use datadog_api_client::datadogV1::api_usage_metering::GetUsageFargateOptionalParams; use datadog_api_client::datadogV1::api_usage_metering::UsageMeteringAPI; #[tokio::main] async fn main() { let configuration = datadog::Configuration::new(); let api = UsageMeteringAPI::with_config(configuration); let resp = api .get_usage_fargate( DateTime::parse_from_rfc3339("2021-11-06T11:11:11+00:00") .expect("Failed to parse datetime") .with_timezone(&Utc), GetUsageFargateOptionalParams::default().end_hr( DateTime::parse_from_rfc3339("2021-11-08T11:11:11+00:00") .expect("Failed to parse datetime") .with_timezone(&Utc), ), ) .await; if let Ok(value) = resp { println!("{:#?}", value); } else { println!("{:#?}", resp.unwrap_err()); } } ``` -------------------------------- ### Start Example Application with MySQL Source: https://docs.datadoghq.com/getting_started/database_monitoring Start the example application with a MySQL database. This command also starts the Datadog Agent and a Go orders app that generates database traffic. ```bash make mysql ``` -------------------------------- ### Install Datadog Library and Run Example Source: https://docs.datadoghq.com/api/latest/logs/search-logs Instructions for installing the Datadog library and its dependencies, saving an example to a file, and running compilation and execution commands. ```bash DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comuk1.datadoghq.comddog-gov.com" DD_API_KEY="" DD_APP_KEY="" tsc "example.ts" ``` -------------------------------- ### Get hourly usage for ingested spans in Java Source: https://docs.datadoghq.com/api/latest/usage-metering/get-hourly-usage-for-ingested-spans Retrieves hourly usage for ingested spans using the Datadog Java client. This example requires the Datadog API client library to be installed. It fetches data starting five days ago and ending three days ago. ```java import com.datadog.api.client.ApiClient; import com.datadog.api.client.ApiException; import com.datadog.api.client.v1.api.UsageMeteringApi; import com.datadog.api.client.v1.api.UsageMeteringApi.GetIngestedSpansOptionalParameters; import com.datadog.api.client.v1.model.UsageIngestedSpansResponse; import java.time.OffsetDateTime; public class Example { public static void main(String[] args) { ApiClient defaultClient = ApiClient.getDefaultApiClient(); UsageMeteringApi apiInstance = new UsageMeteringApi(defaultClient); try { UsageIngestedSpansResponse result = apiInstance.getIngestedSpans( OffsetDateTime.now().plusDays(-5), new GetIngestedSpansOptionalParameters().endHr(OffsetDateTime.now().plusDays(-3))); System.out.println(result); } catch (ApiException e) { System.err.println("Exception when calling UsageMeteringApi#getIngestedSpans"); System.err.println("Status code: " + e.getCode()); System.err.println("Reason: " + e.getResponseBody()); System.err.println("Response headers: " + e.getResponseHeaders()); e.printStackTrace(); } } } ``` -------------------------------- ### Start Example Application with PostgreSQL Source: https://docs.datadoghq.com/getting_started/database_monitoring Start the example application with a PostgreSQL database. This command also starts the Datadog Agent and a Go orders app that generates database traffic. ```bash make postgres ``` -------------------------------- ### Copy Example Config and Install Agent Source: https://docs.datadoghq.com/agent/guide/install-agent-6 Copy the example configuration file and install the Agent if not upgrading. Replace `MY_API_KEY` with your actual Datadog API key. ```bash sudo sh -c "sudo sh -c \"sed 's/api_key:.*/api_key: .*/api_key: MY_API_KEY/' /etc/datadog-agent/datadog.yaml.example > /etc/datadog-agent/datadog.yaml\"" ``` -------------------------------- ### Get an existing Action Connection - Python Source: https://docs.datadoghq.com/api/latest/action-connection/get-an-existing-action-connection Python example to get an Action Connection. Install the Datadog API client library and configure your API keys. ```python """ Get an existing Action Connection returns "Successfully get Action Connection" response """ from datadog_api_client import ApiClient, Configuration from datadog_api_client.v2.api.action_connection_api import ActionConnectionApi configuration = Configuration() with ApiClient(configuration) as api_client: api_instance = ActionConnectionApi(api_client) response = api_instance.get_action_connection( connection_id="cb460d51-3c88-4e87-adac-d47131d0423d", ) print(response) ``` -------------------------------- ### Get SPA Recommendations (Rust) Source: https://docs.datadoghq.com/api/latest/spa/get-spa-recommendations This Rust example demonstrates how to get SPA recommendations using the Datadog API client. Make sure to install the library and its dependencies. ```rust /** * Get SPA Recommendations returns "OK" response */ use datadog_api_client::datadog; use datadog_api_client::datadogV2::api_spa::GetSPARecommendationsOptionalParams; use datadog_api_client::datadogV2::api_spa::SpaAPI; #[tokio::main] async fn main() { let mut configuration = datadog::Configuration::new(); configuration.set_unstable_operation_enabled("v2.GetSPARecommendations", true); let api = SpaAPI::with_config(configuration); let resp = api .get_spa_recommendations( "service".to_string(), GetSPARecommendationsOptionalParams::default(), ) .await; if let Ok(value) = resp { println!("{:#?}", value); } else { println!("{:#?}", resp.unwrap_err()); } } ``` -------------------------------- ### Run Go Example Source: https://docs.datadoghq.com/api/latest/ci-visibility-pipelines/send-pipeline-event Instructions for running the Go examples, including setting environment variables for API keys and site, and executing the Go program. ```bash DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comuk1.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="" go run "main.go" ``` -------------------------------- ### Start the Sample Application Containers Source: https://docs.datadoghq.com/tracing/guide/tutorial-enable-python-container-agent-host Start the database and notes application containers using docker-compose. ```bash docker-compose -f docker/host-and-containers/exercise/docker-compose.yaml up db notes_app ```