Skip to main content
Collect MySQL error and slow query logs with an OpenTelemetry collector and send them to ClickHouse Observability. Use the demo dataset to try the integration without installing MySQL.

Prerequisites

  • A ClickHouse Observability service
  • Docker to run the collector examples, or an existing OpenTelemetry Collector Contrib deployment
  • For your own logs, MySQL 5.7 or newer with access to its configuration and log files
  • For the demo, curl to download the sample files

Connection details

Open ClickHouse Observability and go to Team Settings → Data → Managed Telemetry. Copy your OTLP HTTP endpoint and API key. You can use Copy connection details to copy the configuration, or Reveal key to view the masked key.For the OTLP exporter examples below, set these variables in the terminal where you will run the collector:
Replace the placeholders with the exact endpoint, including its port, and API key from your service. Use the base HTTP endpoint without a /v1/logs suffix; the exporter appends the signal path.
The endpoint must be reachable from the collector container. For a destination collector running on this computer, use http://host.docker.internal:4318. The Docker commands below include the host mapping.

Integration with existing MySQL

1

Configure MySQL logging

MySQL supports multiple log types. For comprehensive monitoring with OpenTelemetry, we recommend enabling the error log and slow query log.The my.cnf or my.ini configuration file is typically located at:
  • Linux (apt/yum): /etc/mysql/my.cnf or /etc/my.cnf
  • macOS (Homebrew): /usr/local/etc/my.cnf or /opt/homebrew/etc/my.cnf
  • Docker: Configuration is usually set via environment variables or mounted config file
Add or modify these settings in the [mysqld] section:
The slow query log captures queries that take longer than long_query_time seconds. Adjust this threshold based on your application’s performance requirements. Setting it too low will generate excessive logs.
Ensure /var/log/mysql exists and is writable by MySQL. After making these changes, restart MySQL:
Verify logs are being written:
2

Configure the collector

Save this as mysql-logs-monitoring.yaml. The receivers expect MySQL’s text error and slow query log formats; JSON error logs require a different parser.
The two receivers parse their respective formats, preserve timestamps and log bodies, and assign service.name as mysql-service. Error log attributes include level, error_code, and message. Slow queries include query_time, lock_time, rows_sent, rows_examined, and query.
3

Run the collector

Run from the directory containing the configuration. Replace the host log directory if needed, and ensure the collector can read its files:If the logs are readable only by their owner and group, add --group-add LOG_GROUP_ID to the command below, replacing LOG_GROUP_ID with the numeric group ID shown by ls -ln /var/log/mysql. The group must have read permission on the files and access to the directory.
Leave this terminal open. The receivers use start_at: end, so generate new logs after starting the collector. For example, execute this query in MySQL:
4

Verify logs

Open Search, select Logs, filter for ServiceName:mysql-service, and select Last 15 minutes. Expand an entry to inspect the parsed attributes. Filter LogAttributes.source:mysql-error or LogAttributes.source:mysql-slow to select a log type.

Demo dataset

The sample contains 30 error log entries and 10 multiline slow queries.
1

Download the sample logs

2

Configure the demo collector

Save this as mysql-logs-demo.yaml:
The demo-only timestamp processor shifts the sample into roughly the past 24 hours, ending two minutes before ingestion. Original timestamp attributes and log bodies stay unchanged. Omit this processor for your own logs.
3

Run the demo collector

From the directory containing the configuration and both downloaded log files, run:
Leave the terminal open while verifying ingestion. Stop the collector with Ctrl+C when finished. Running the demo again re-ingests the sample with refreshed timestamps.
4

Verify the demo logs

Open Search, select Logs, filter for ServiceName:mysql-demo, and select Last 2 days. You should see 40 records: 30 with LogAttributes.source:mysql-demo-error and 10 with LogAttributes.source:mysql-demo-slow.

Dashboards and visualization

1

2

Import the dashboard

  1. Open Dashboards and click Import in the upper-right corner.
  2. Upload mysql-logs-dashboard.json.
  3. Map the charts to your Logs source and click Finish Import.
3

View the dashboard

Select Last 2 days for the sample. Optionally filter for ServiceName:mysql-demo to isolate it from other services.For your own logs, change the Errors and Slow queries chart filters from mysql-demo-error and mysql-demo-slow to mysql-error and mysql-slow respectively, then select a time range covering your records.

Troubleshooting

Collector fails to start

Check the collector output for configuration errors. Verify the configuration mount and connection variables in the terminal where Docker runs.

No logs appear

Check for authentication or export errors. Verify that MySQL writes files at the mounted paths and that the collector can read them. With start_at: end, only new entries are collected. For the demo, select Last 2 days and include the timestamp processor.

Slow queries do not appear

Check your MySQL settings:
Confirm slow_query_log is enabled and log_output includes FILE. Run a query exceeding your configured threshold, then check mysql-slow.log.

Logs do not parse correctly

Compare your log format with the receiver patterns. These examples expect ISO 8601 timestamps and MySQL’s text log format. Custom formats, JSON error logs, and additional slow-query fields may require parser changes.

Next steps