Datadog

Elevate, May 20-22-2025, Miami Beach, Florida

Monitor and observe your SDK with Datadog.

Java SDK

Prerequisites

Include the Datadog middleware in the Java SDK

After adding commercetools-monitoring-datadog as a dependency in your application, add the Datadog middleware and serializer to your SDK using the .withTelemetryMiddleware() and withSerializer() methods.
Create a Java SDK client with Datadog telemetry middlewarejava
ApiHttpClient apiHttpClient = ApiRootBuilder
  .of()
  .defaultClient(ServiceRegion.GCP_EUROPE_WEST1.getApiUrl())
  .withTelemetryMiddleware(
    new DatadogMiddleware(ApiClient.getDefaultApiClient())
  )
  .withSerializer(
    new DatadogResponseSerializer(
      ResponseSerializer.of(),
      ApiClient.getDefaultApiClient()
    )
  )
  .buildClient();
The commercetools-monitoring-datadog module includes a telemetry middleware and a serializer that adds the following metrics:
Metric nameDescriptionUnitTags
commercetools.client.total_requestsNumber of requests made by the SDK.Counthttp.response.status_code
http.request.method
server.address
server.port
commercetools.client.error_requestsNumber of requests made by the SDK with an HTTP error response (status code between 400 and 599).Counthttp.response.status_code
http.request.method
server.address
server.port
commercetools.client.durationDuration of the request to commercetools Composable Commerce.Millisecondshttp.response.status_code
http.request.method
server.address
server.port
commercetools.json.serializationDuration of the JSON serialization of the response from Composable Commerce.Millisecondsresponse.body.type
commercetools.json.deserializationDuration of the JSON deserialization of the request to Composable Commerce.Millisecondsrequest.body.type

TypeScript SDK

Prerequisites

Include the Datadog middleware in the TypeScript SDK

tracer.tstypescript
import tracer from 'dd-trace';
tracer.init();
export default tracer;
tracer.jsjavascript
require('dd-trace').init();
After adding @commercetools/ts-sdk-apm as a dependency, add the Datadog instrumentation to your app using the withTelemetryMiddleware() middleware method.
Create a TypeScript SDK client with Datadog telemetry middlewaretypescript
import { ClientBuilder } from '@commercetools/ts-client';
import { createTelemetryMiddleware } from '@commercetools/ts-sdk-apm';

// Configure the telemetry options
const telemetryOptions = {
  createTelemetryMiddleware,
  userAgent: 'typescript-sdk-middleware-datadog',
  tracer: async () => await import('dd-trace').init(),
  customMetrics: {
    datadog: true,
  },
};

// Create the client with the withTelemetryMiddleware() middleware
const client = new ClientBuilder()
  .withClientCredentialsFlow(...)
  .withHttpMiddleware(...)
  .withTelemetryMiddleware(telemetryOptions) // telemetry middleware
  ...
  .build();
@commercetools/ts-sdk-apm adds the Datadog instrumentation module to monitor request execution and response times along with counters for requests, errors, and other metrics.
You can add custom metrics in your application by including the Datadog tracing library module and then adding in your code some settings to define your custom metrics as shown in the following examples:

This example includes the metric to count all the error client responses:

Create custom metric to view the error client responsetypescript
agent.init().dogstatsd.increment(`ct_error_response_count`, 1, {
  env: 'dev',
  status_code: statusCode,
  http_method: response.req.method,
  success: false,
});

This example includes the metric to count all the client requests:

Create custom metric to view all client requeststypescript
agent.dogstatsd.gauge(`ct_request_count`, count(), {
  env: 'dev',
});
For more examples about integrating Datadog with the TypeScript SDK by using a host or containerized agent, see the Datadog example application. In the same folder, there are some examples about how to set up custom metrics like the ones mentioned here:
Metric nameDescriptionUnitTags
ct_success_response_countNumber of requests made by the SDK with an HTTP success response (status code between 200 and 399).Counthttp.environment
http.status_code
http.method.success<true>
ct_error_response_countNumber of requests made by the SDK with an HTTP error response (status code between 400 and 599).Counthttp.environment
http.status_code
http.method.success<false>
ct_request_countNumber of requests made to the commercetools API, representing the volume of interactions from your application.Counthttp.environment

PHP SDK

Prerequisites

  • Version 10.5 (or later) of the PHP SDK

Datadog Agent

.NET SDK

Prerequisites

  • Version 11.0 (or later) of the .NET SDK

Datadog Agent