Skip to main content

Slowsql Connector

Status Maintainers: @JaredTan95, @Frapschen, @atoulme Source: opentelemetry-collector-contrib

Overview

Overview

Generate logs from recorded slow database statement associated with spans. Each log will have at least the following dimensions:
  • Service name
  • Span kind
  • Span name
  • Status code
  • Trace ID
  • Span ID
  • Database System
  • Database Statement
  • Database Statement Duration
Each log will additionally have the following attributes:
  • Span attributes. If you want to filter out some attributes (like only copying HTTP attributes starting with http.) use the transform processor.

Configurations

If you are not already familiar with connectors, you may find it helpful to first visit the Connectors README. The following settings can be optionally configured:
  • dimensions: the list of dimensions to add to logs with the default dimensions defined above. Each additional dimension is defined with a name which is looked up in the span’s collection of attributes or resource attributes (AKA process tags) such as ip, host.name or region.
  • db_system: the list value of span attribute db.system, Filter specific db systems, define those database’s statements need to be collected. ref: https://opentelemetry.io/docs/specs/semconv/attributes-registry/db/
    • Default: [h2, mongodb, mssql, mysql, oracle, postgresql, mariadb]
  • threshold: define a threshold and collect when the db.statement, namely span duration, larger than this value.
    • Default: 500ms

Examples

The following is a simple example usage of the slow sql connector.
receivers:
  nop:

exporters:
  nop:

connectors:
  slowsql:
    threshold: 600ms
    dimensions:
      - name: k8s.namespace.name
      - name: k8s.pod.name

service:
  pipelines:
    traces:
      receivers: [nop]
      exporters: [slowsql]
    logs:
      receivers: [slowsql]
      exporters: [nop]      
The following is a more complex example usage of the slowsql connector using Elasticsearch as exporters.
receivers:
  otlp:
    protocols:
      grpc:
      http:

exporters:
  elasticsearch/slow_sql:
    tls:
      insecure: true
    mapping:
      mode: raw
    endpoints:
      - http://localhost:9200
    user: elastic
    password: elastic

connectors:
  slowsql:
    threshold: 600ms
    dimensions:
      - name: k8s.namespace.name
      - name: k8s.pod.name

service:
  pipelines:
    traces:
      receivers: [otl[]]
      exporters: [slowsql]
    logs:
      receivers: [slowsql]
      exporters: [elasticsearch/slow_sql]
The full list of settings exposed for this connector is documented in slowsqlconnector/config.go.

More Examples

For more example configuration covering various other use cases, please visit the testdata directory.

Configuration

Example Configuration

# default configuration
slowsql/default:

# configuration with all possible parameters
slowsql/full:
  threshold: 600ms
  db_system:
    - h2
    - mysql
  dimensions:
    - name: k8s.namespace.name
    - name: k8s.pod.name

Last generated: 2026-04-13