Real Time MonitoringIntermediate

Sending Test Metrics to Datadog

Export test execution metrics to Datadog for comprehensive monitoring

ObserveOne Team
3 min read

Sending test metrics to Datadog can dramatically improve your team's observability and performance tracking. This comprehensive guide will walk you through exporting test execution metrics to Datadog, enabling you to gain deeper insights into your testing infrastructure and performance.

Prerequisites#

  • Node.js (v16+ recommended)
  • Datadog account
  • Active Datadog API key
  • TypeScript project
  • Existing test suite (Playwright/Jest recommended)
  • Basic understanding of monitoring concepts

💡 Pro Tip: Create a dedicated Datadog API key for your testing metrics to simplify access management.

Setting Up Datadog Metric Reporting#

Installing Required Packages#

Before you can send metrics, you'll need to install the necessary libraries:

npm install @datadog/datadog-api-client
npm install --save-dev @types/jest

Configuring Datadog Client#

Initialize your Datadog client with secure configuration:

import { v2 } from "@datadog/datadog-api-client";
const configuration = v2.Configuration.getDefaultApiClient();
configuration.setApiKey(process.env.DATADOG_API_KEY);
const metricsApi = new v2.MetricsApi(configuration);

Sending Test Execution Metrics#

Basic Metric Submission#

Create a utility function to submit test performance metrics:

async function submitTestMetric(testName: string, duration: number) {
try {
const metricPayload: v2.MetricSubmission = {
series: [
{
metric: "test.execution.duration",
type: v2.MetricIntakeType.Gauge,
points: [
{
timestamp: new Date(),
value: duration,
},
],
tags: [`test:${testName}`, `environment:${process.env.NODE_ENV}`],
},
],
};
await metricsApi.submitMetrics({ body: metricPayload });
} catch (error) {
console.error("Failed to submit test metric", error);
}
}

⚠️ Always handle potential API submission errors to prevent test suite interruption.

Advanced Metric Tracking#

Integrate metric submission into your test framework:

describe("User Authentication Tests", () => {
it("should login successfully", async () => {
const startTime = performance.now();
try {
// Actual test logic
await performLogin();
} finally {
const duration = performance.now() - startTime;
await submitTestMetric("login_test", duration);
}
});
});

Comprehensive Metric Tracking#

Key Metrics to Track#

  1. Test Execution Duration
  2. Success/Failure Rates
  3. Resource Utilization
  4. Environment-Specific Performance

Troubleshooting#

Problem
Metrics not appearing in Datadog dashboard
Solution
Verify API key, check network connectivity, ensure correct metric namespace
Problem
High latency in metric submission
Solution
Implement async metric submission, use background workers, add timeout configurations
Problem
Unauthorized API access
Solution
Regenerate Datadog API key, verify IP whitelisting, check permission scopes

Best Practices#

  • Use environment-specific tags
  • Implement robust error handling
  • Set appropriate metric retention periods
  • Normalize metric names consistently
  • Use lightweight metric submission strategies
  • Implement circuit breakers for API calls
  • Secure API keys using environment variables

Next Steps#

  • Explore Datadog's advanced monitoring features
  • Implement custom dashboards for test metrics
  • Set up alerting based on test performance
  • Integrate with CI/CD pipelines
  • Explore distributed tracing capabilities

Related comparisons

Weighing the tools you just read about? Here's how they stack up side by side.

See alternatives to your stack

Looking to swap one of these out? Here's where to start.

Ready for AI-Powered Testing?

ObserveOne monitors your selectors 24/7 and automatically heals them when websites change. Never deal with broken tests again.

Start Free Trial