Skip to main content
All recipes

Datadog

CodeOTLPMetrics

Send metrics through a Datadog Agent configured to receive OTLP. Use the SDK's beforeSend hook with your existing OpenTelemetry metrics provider to record request duration.

Configure the OTLP exporter for Datadog

Enable the HTTP receiver and metrics in your Datadog Agent OTLP configuration. This example assumes the Agent is reachable at localhost:4318. Configure the Datadog API key on the Agent and start your application metrics provider before adding the hook.

Bash
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318

Mirror CheckUpstream events into Datadog metrics

Use this with the initialized metrics provider from your application. See the OpenTelemetry recipe for sampling, retry and shutdown considerations.

instrumentation.ts
import { metrics } from "@opentelemetry/api";
import { initCheckUpstream } from "@checkupstream/sdk/integrations/next";

const meter = metrics.getMeter("checkupstream");
const latency = meter.createHistogram("upstream.latency_ms", { unit: "ms" });

export function register() {
  const sdkKey = process.env.CHECKUPSTREAM_SDK_KEY;
  if (!sdkKey) throw new Error("Set CHECKUPSTREAM_SDK_KEY before starting the app");

  initCheckUpstream({
    sdkKey,
    beforeSend: (events) => {
      for (const e of events) {
        latency.record(e.latency_ms, {
          service: e.service,
          status: String(e.status),
        });
      }
      return events;
    },
  });
}

Continue your setup

Check runtime availability and credentials before deploying an integration.