Datadog SQL Server Logs

Quote

“A log is a record of what happened. A good log is a record of what happened that you can actually understand six months later at 3 AM.”

Bryan Cantrill, CTO of Oxide Computer

Configure the SQL Server Log Source

SSH into the SQL VM and create the log collection config:

gcloud compute ssh data-pipeline-sql --zone=europe-west1-b --tunnel-through-iap
 
sudo mkdir -p /etc/datadog-agent/conf.d/sqlserver.d
sudo tee /etc/datadog-agent/conf.d/sqlserver.d/logs.yaml <<EOF
logs:
  - type: file
    path: /var/opt/mssql/log/errorlog
    service: data-pipeline-sql
    source: sqlserver
EOF
 
sudo chown -R dd-agent:dd-agent /etc/datadog-agent/conf.d/sqlserver.d/
sudo usermod -aG mssql dd-agent
sudo systemctl restart datadog-agent

The usermod -aG mssql dd-agent step is required — the SQL Server errorlog is owned by the mssql group, and the agent needs group membership to read it.


Verify SQL Server Log Collection

sudo datadog-agent status | grep -A 10 "Integrations" | grep -A 5 "sqlserver"

You should see Status: OK and Inputs: /var/opt/mssql/log/errorlog.


What Gets Logged from SQL Server Errorlog

SQL Server only writes to its error log on significant events — startups, failed logins, errors, backups, checkpoints. A simple SELECT query does not generate an error log entry.

To test that logs are flowing:

SA_PWD=$(curl -s -H "Metadata-Flavor: Google" \
  "http://metadata.google.internal/computeMetadata/v1/instance/attributes/sa-password")
 
# Force a checkpoint (writes to errorlog)
/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "$SA_PWD" -C -Q "CHECKPOINT"
 
# Or trigger a failed login (guaranteed log entry)
/opt/mssql-tools18/bin/sqlcmd -S localhost -U fakeuser -P "wrong" -C -Q "SELECT 1" 2>/dev/null

Logs should appear in Datadog > Logs > Explorer within 1–2 minutes, filterable by host:data-pipeline-sql or service:data-pipeline-sql.


Troubleshooting If Bytes Read Stays at 0

The agent tails from the end of the file by default. If the file had no new entries since the agent started, Bytes Read stays at 0. Force it to read existing content:

sudo tee /etc/datadog-agent/conf.d/sqlserver.d/logs.yaml <<EOF
logs:
  - type: file
    path: /var/opt/mssql/log/errorlog
    service: data-pipeline-sql
    source: sqlserver
    start_position: beginning
EOF
 
sudo systemctl restart datadog-agent

After reading the existing log, remove start_position: beginning if you don’t want to re-read the entire log on every restart.


SQL Server Log Search Queries in Datadog

In Datadog > Logs > Explorer:

host:data-pipeline-sql source:sqlserver                  # All SQL Server logs
host:data-pipeline-sql service:data-pipeline-sql status:error    # Errors only
host:data-pipeline-sql "Login failed"                    # Failed login events

Separation of Logs from Metrics Config

SQL Server metrics (connections, buffer pool, waits) are collected by the sqlserver integration check via ODBC. Logs (errorlog) are collected by the separate logs.yaml file tailing mechanism. These are independent:

  • Metrics: /etc/datadog-agent/conf.d/sqlserver.d/conf.yaml
  • Logs: /etc/datadog-agent/conf.d/sqlserver.d/logs.yaml

Both must be configured separately. See datadog-agent-sql-vm for the metrics integration config and datadog-custom-queries for custom SQL queries.