Monitoring MySQL Performance using OpenTelemetry

This tutorial explains how you can use OpenTelemetry and Uptrace to monitor MySQL performance. Besides using Otel Collector to monitor your MySQL servers, you can also use OpenTelemetry to instrument your applications with traces, metrics, and logs.

What is OpenTelemetry?

OpenTelemetryopen in new window is an open-source observability framework for distributed tracingopen in new window (including logs and errors) and metricsopen in new window.

Otel allows developers to collect and export telemetry data in a vendor agnostic way. With OpenTelemetry, you can instrumentopen in new window your application once and then add or change vendors without changing the instrumentation, for example, here is a list popular DataDog alternativesopen in new window that support OpenTelemetry.

OpenTelemetry is available for most programming languages and provides interoperability across different languages and environments.

What is OpenTelemetry Collector?

OpenTelemetry Collectoropen in new window is an agent that pulls telemetry data from systems you want to monitor and sends it to tracing toolsopen in new window using the OpenTelemetry protocol (OTLP).

You can use OpenTelemetry Collector to monitor system metricsopen in new window, PostgreSQLopen in new window, MySQLopen in new window, Redisopen in new window, and more.


Uptrace is a source-available APMopen in new window powered by OpenTelemetry and ClickHouse. It allows you to identify and fix bugs in production faster knowing what conditions lead to which errors.

You can get startedopen in new window with Uptrace by downloading a DEB/RPM package or a pre-compiled Go binary.

MySQL receiver

To start monitoring MySQL with Otel Collector, you need to configure MySQL receiver in /etc/otel-contrib-collector/config.yaml using Uptrace DSNopen in new window:

    endpoint: localhost:3306
    username: otel
    password: $MYSQL_PASSWORD
    database: otel
    collection_interval: 10s
      digest_text_limit: 120
      time_limit: 24h
      limit: 250

    headers: { 'uptrace-dsn': '<FIXME>' }

    detectors: [system]
    timeout: 10s

      receivers: [otlp]
      processors: [batch]
      exporters: [otlp]
      receivers: [otlp, mysql]
      processors: [batch, resourcedetection]
      exporters: [otlp]

Don't forget to restart the service:

sudo systemctl restart otelcol-contrib

You can also check OpenTelemetry Collector logs for any errors:

sudo journalctl -u otelcol-contrib -f

Available metrics

Uptrace automatically creates the following dashboard when MySQL metrics are available:

MySQL metrics


You can also send OpenTelemetry metrics to Prometheus using OpenTelemetry Prometheus exporter.

What's next?

Next, you can learn more about configuring OpenTelemetry Collector and check available receivers.

To start using OpenTelemetry and Uptrace, see Getting started with Uptraceopen in new window.

Last Updated: