This example demonstrates how to publish application metrics to Datadog during a Multiple load test, specifically the API response time of a POST request to the /chat endpoint. In vuInit, the Datadog client is initialized with the appropriate credentials and axios is used as the HTTP client.


  1. An active Datadog account
  2. The following environment variables from your Datadog account:
    • DD_API_KEY: Found in your Datadog account under Organization Settings > Access > API Keys
    • DD_SITE: Your Datadog domain, e.g.,


Environment Variables
# Datadog Credentials

# API Base URL
Test Spec
// Datadog API client
import dd from 'dogapi';

// axios for making HTTP requests
import axios from 'axios';

class DatadogTestSpec {
  npmDeps = {
    axios: '1.6.0',
    dogapi: '2.8.4',

  async vuInit(ctx) {
    // Initialize the Datadog client
      api_host: process.env.DD_SITE,
      api_key: process.env.DD_API_KEY,

    // Create an axios API client with the API_BASE_URL environment variable
    const apiClient = axios.create({ baseURL: process.env.API_BASE_URL });

    // Return the API client so we can use it in the VU loop
    return { apiClient };

  async vuLoop(ctx) {
    // Retrieve the apiClient from VU Init
    const { apiClient } = ctx.vuInitData;

    const startTime =;

    // Send a POST request to the chat endpoint
    await'chat', {
      message: 'Hello World!',

    // Measure the API response time
    const metricValue = - startTime;
    const metricLabel = 'POST /chat';

    // Capture the metric in Multiple
    ctx.metric(metricLabel, metricValue, 'ms (API)');

    // Publish the metric to Datadog
    dd.metric.send(metricLabel, metricValue);