Skip to Content

What should Datadog monitors about slow database queries include for an AI SRE?

Tares works best when a Datadog monitor for slow database queries sends a flat JSON payload with a service name, severity, summary and start time. Datadog reaches Tares through the webhook connector and a vendor setup. Tares has no connector of its own for Datadog today. You write the payload in Datadog, and you map each field to a label or template in a Tares webhook source.

How it works

Datadog reaches Tares through the webhook connector and a vendor setup in Datadog. The Datadog Webhooks integration posts to the ingest URL of a Tares webhook source. Tares stores the payload lossless and maps the fields you declare into the envelope.

Because you write the payload in Datadog’s Payload field, the shape is yours. You can build it from Datadog variables such as $ALERT_ID, $EVENT_MSG and $LINK. For a slow query monitor, send four things as flat, top-level fields:

  • A service name. Declare it as a label and mark it primary. Sources that carry the same service label are keyed the same way, as in the AI SRE guide.
  • A severity. Send it as its own field so you can declare a label for it.
  • A summary. The monitor message text is a good fit. text_template renders a line from top-level payload fields.
  • A start time. Send an ISO-8601 timestamp and point event_time_field at it.

Keep the payload flat. event_type_field and text_template read top-level fields only, so a nested object cannot feed them. Any field names in this article are examples. Use the names you put in your own payload.

Set it up

  1. In Tares, create a webhook source under Sources → Add source → webhook, or ask a connected agent to create it. Declare a label for each payload field you want to correlate on, and mark one primary. This is the shape of a webhook source:
- name: ci-events connector: webhook config: event_type_field: action text_template: '{action} by {sender}' labels: - { name: pipeline, field: pipeline, primary: true }

Here pipeline, action and sender are example fields. For your monitor, make the service the primary label:

labels: - { name: service, field: service, primary: true }

Add a label for each other field you send, such as severity. Set event_time_field to the payload field that holds the start time.

  1. Save the source and copy its ingest endpoint from the source page.
  2. In Datadog, open the Webhooks integration and add a webhook whose URL is the Tares ingest URL. Write the payload as JSON from Datadog variables.
  3. If Tares has auth on, add custom headers as JSON in the Datadog webhook with an Authorization Bearer header that holds an ingest-scoped API key. On an instance without auth, you need no header.
  4. Put the webhook handle in the monitor message so the monitor calls it. The handle is @webhook- followed by the name you gave the webhook.
  5. Check the mapping. Post a sample payload to the ingest URL, then read Recent events and Fields on the source page. Fields shows which payload fields arrive and how often.
curl -X POST http://localhost:8787/ingest/<ingest_key> \ -H 'Content-Type: application/json' \ -d '{"action": "deploy", "sender": "ci", "pipeline": "web"}'

This sample uses the example fields from the webhook page. Replace them with the fields from your own Datadog payload. Then trigger the monitor once from Datadog and look at Recent events again.

What you get

  • Each slow query alert arrives as an event with a service label, so you can correlate it with the other sources you key by service.
  • The full payload is stored lossless, so a field you did not map is still there.
  • A summary line rendered from your own fields through text_template.
  • A start time taken from the field you name in event_time_field.
  • The monitor link and alert ID stay in the stored payload when you send them from the Datadog variables.

A flat payload with a clear service name also makes the Fields view on the source page easy to read when you pick a reliable key.

When something else fits

  • If the alerts come from Prometheus rules, the Prometheus alerts connector or the Alertmanager connector takes them without a vendor setup. Both are described in the AI SRE guide.
  • If you need a nested payload, flatten it in Datadog first. A field that is not top level cannot be the event type field.

Still stuck? Get help

Last updated on