Send OTel metrics to Datadog
Use this setup when sending PG Proxy’s OpenTelemetry metrics to Datadog through a Collector. It converts event counts to per-second rates, matching the format used by DogStatsD. For example, 100 events over 10 seconds becomes a rate of 10/s.
If you use -telemetry datadog, the proxy already sends metrics through DogStatsD; this Collector setup is unnecessary.
Prerequisites
Section titled “Prerequisites”- A working
proxy.yamlfrom Local development, and the binary built in yourpg-proxycheckout withgo build -o bin/pg-proxy ./cmd/pg-proxy. - OpenTelemetry Collector Contrib 0.163.2, the version validated with this configuration.
- A Datadog API key and your Datadog site.
The examples use Bash or Zsh and run the proxy and Collector on the same machine. The Collector receives metrics only on 127.0.0.1:4318.
1. Configure the Collector
Section titled “1. Configure the Collector”Save this as collector.yaml. The repository keeps the same file as docs/otel-collector-datadog.yaml.
receivers: otlp: protocols: http: endpoint: 127.0.0.1:4318
processors: transform/pg_proxy_datadog_rates: error_mode: propagate metric_statements: - context: datapoint statements: - >- set(datapoint.attributes["datadog.metric.as_type"], "rate") where instrumentation_scope.name == "pg-proxy" and IsMatch(metric.name, "^datadog[.]pg_proxy[.]") and metric.type == METRIC_DATA_TYPE_SUM and metric.is_monotonic == true and metric.aggregation_temporality == AGGREGATION_TEMPORALITY_DELTA batch: {}
exporters: datadog: api: key: ${env:DD_API_KEY} site: ${env:DD_SITE}
service: pipelines: metrics: receivers: - otlp processors: - transform/pg_proxy_datadog_rates - batch exporters: - datadogThe transform applies only to monotonic delta counters in the pg-proxy instrumentation scope with the datadog.pg_proxy. prefix. It leaves gauges, histograms, and other scopes unchanged. If you embed the library with a different MetricNamespace, change the pattern to match, for example ^acme[.]pg_proxy[.] for acme.. If you export to several backends, use this transform only in the Datadog pipeline.
2. Start the Collector
Section titled “2. Start the Collector”In the Collector’s terminal, set your API key and site. Replace the API-key placeholder; datadoghq.com is the US1 site.
export DD_API_KEY='<your-datadog-api-key>'export DD_SITE=datadoghq.com
otelcol-contrib \ --config collector.yaml \ --feature-gates=exporter.datadogexporter.InferIntervalForDeltaMetricsThe feature gate is required in this version. It lets the exporter divide each count by its reporting interval. Without it, a count can be labeled as a rate without being converted to events per second.
3. Start the proxy
Section titled “3. Start the proxy”In another terminal, select delta export and send only metrics to the Collector:
export OTEL_METRICS_EXPORTER=otlpexport OTEL_TRACES_EXPORTER=noneexport OTEL_LOGS_EXPORTER=noneexport OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318export OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=deltaexport OTEL_METRIC_EXPORT_INTERVAL=1000
./bin/pg-proxy -config proxy.yamlOmit -telemetry so these per-signal settings take effect. The one-second export interval is for local feedback; the SDK default is 60 seconds. Add trace and log pipelines to the Collector before enabling those exporters.
4. Check the result
Section titled “4. Check the result”Run queries through the proxy and look for datadog.pg_proxy.messages.queries in Datadog. The counter should be reported as a rate. SQL text and bind parameters are not part of this metric.
For example, 100 queries over 10 seconds show as a rate of 10.
If you send the same metric names through both OTLP and DogStatsD, check the combined values in your dashboards and monitors before rollout, including after process restarts.
