Datadog
Monitor and observe your SDK with Datadog.
Datadog supports different languages, frameworks, and platforms to retrieve metrics and traces.
Java SDK
Prerequisites
- Version 17.6 (or later) of the Java SDK
- Active Datadog account with an API key
Include the Datadog middleware in the Java SDK
The Java SDK integrates with Datadog through the commercetools-monitoring-datadog module.
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.
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 name | Description | Unit | Tags |
---|---|---|---|
commercetools.client.total_requests | Number of requests made by the SDK. | Count | http.response.status_code http.request.method server.address server.port |
commercetools.client.error_requests | Number of requests made by the SDK with an HTTP error response (status code between 400 and 599 ). | Count | http.response.status_code http.request.method server.address server.port |
commercetools.client.duration | Duration of the request to commercetools Composable Commerce. | Milliseconds | http.response.status_code http.request.method server.address server.port |
commercetools.json.serialization | Duration of the JSON serialization of the response from Composable Commerce. | Milliseconds | response.body.type |
commercetools.json.deserialization | Duration of the JSON deserialization of the request to Composable Commerce. | Milliseconds | request.body.type |
For an example of integrating Datadog with the Java SDK, refer to the Spring Boot Datadog example application.
PHP SDK
Prerequisites
- Version 10.5 (or later) of the PHP SDK
Datadog Agent
To monitor your application using Datadog Agent, there is no need to change the SDK. Follow the steps to install the Datadog Agent on your host and configure it to monitor your application.
To test an application with the PHP SDK and Datadog, you can use the provided example application.
.NET SDK
Prerequisites
- Version 11.0 (or later) of the .NET SDK
Datadog Agent
To monitor your application using Datadog Agent, there is no need to change the SDK. Follow the steps to install the Datadog Agent on your host and configure it to monitor your application.
To test an application with the .NET SDK and Datadog, you can use the provided example application.
TypeScript SDK
Prerequisites
- Version 2.0.0 (or later) of the TypeScript SDK
- Version 5.5.0 of the Datadog dd-trace package
- Active Datadog account with an API key
- Install the appropriate Datadog integration for your environment if you are using a non-containerized service or direct host integration
- You can run the script install.sh to install the Datadog agent on macOS
Include the Datadog middleware in the TypeScript SDK
The TypeScript SDK integrates Datadog using the @commercetools/ts-sdk-apm module.
Create a tracer.js
or tracer.ts
module in your project and add the following:
import tracer from 'dd-trace';tracer.init();export default tracer;
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.
import { ClientBuilder } from '@commercetools/sdk-client-v2'import { createTelemetryMiddleware } from '@commercetools/ts-sdk-apm'// Configure the telemetry optionsconst telemetryOptions = {tracer: () => require('./tracer'), // path to the tracer.js fileuserAgent: 'typescript-sdk-middleware-datadog',createTelemetryMiddleware}// Create the client with the withTelemetryMiddleware() middlewareconst client = new ClientBuilder().withClientCredentialsFlow(...).withHttpMiddleware(...).withTelemetryMiddleware(telemetryOptions) // telemetry middleware....build()
@commercetools/ts-sdk-am
adds the Datadog instrumentation module for monitoring request execution and response times, alongside counters for requests, errors, and other metrics.
You can include the Datadog tracing library module to add the following custom metrics:
Metric name | Description | Unit | Tags |
---|---|---|---|
commercetools_client_response<Success> | Number of requests made by the SDK with an HTTP success response (status code between 200 and 399 ). | Count | http.environment http.status_code http.method.success<true> |
commercetools_client_response<Error> | Number of requests made by the SDK with an HTTP error response (status code between 400 and 599 ). | Count | http.environment http.status_code http.method.success<false> |
commercetools_client_request_total | Number of requests made to this listening HTTP server. | Count | http.environment |
The nodejs datadog agent can also capture other custom metrics.
For examples of integrating Datadog with the TypeScript SDK using a host
or containerized
agent, refer to the Datadog example application.