Skip to content

Conversation

sincejune
Copy link
Contributor

Description

This PR introduced query-level data collection for MySQL receiver in the logs pipeline.

We introduced Query Sample collection in this initial PR (Query samples are those queries which are currently running at the moment that scraper is working)

Configuration

We introduced 2 configurations for the feature(see receiver's README for details):

  • events."db.server.query_sample".enabled: Flag to enable the feature.
  • query_sample_collection.max_rows_per_query: The expected report numbers of queries sample in each scrape.
Example output"
resourceLogs:
  - resource: {}
    scopeLogs:
      - logRecords:
          - attributes:
              - key: db.system.name
                value:
                  stringValue: mysql
              - key: mysql.threads.thread_id
                value:
                  intValue: "1034384"
              - key: user.name
                value:
                  stringValue: myuser
              - key: db.namespace
                value:
                  stringValue: adventureworks
              - key: mysql.threads.processlist_command
                value:
                  stringValue: Query
              - key: mysql.threads.processlist_state
                value:
                  stringValue: executing
              - key: db.query.text
                value:
                  stringValue: SELECT soh.SalesOrderID, soh.OrderDate, c.CustomerID, p.Name AS ProductName, sod.OrderQty, sod.LineTotal FROM salesorderheader soh JOIN salesorderdetail sod ON soh.SalesOrderID = sod.SalesOrderID JOIN product p ON sod.ProductID = p.ProductID JOIN customer c ON soh.CustomerID = c.CustomerID ORDER BY soh.OrderDate DESC
              - key: mysql.events_statements_current.digest
                value:
                  stringValue: aaaaaa
              - key: mysql.event_id
                value:
                  intValue: "17470257762"
              - key: mysql.wait_type
                value:
                  stringValue: CPU
              - key: mysql.events_waits_current.timer_wait
                value:
                  doubleValue: 1.2851652e-05
              - key: client.address
                value:
                  stringValue: 192.168.1.80
              - key: client.port
                value:
                  intValue: "1234"
              - key: network.peer.address
                value:
                  stringValue: 192.168.1.80
              - key: network.peer.port
                value:
                  intValue: "1234"
            body: {}
            eventName: db.server.query_sample
            spanId: ""
            timeUnixNano: "1751033212422664000"
            traceId: ""
        scope:
          name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mysqlreceiver
          version: latest

Link to tracking issue

n/a

Testing

Added

Documentation

Added

Copy link
Member

@dmitryax dmitryax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dmitryax
Copy link
Member

dmitryax commented Jul 8, 2025

@antonblock@ishleenk17 PTAL once you have a chance. This is the same approach that is being used in other database receivers to scrape similar events

@dmitryax
Copy link
Member

dmitryax commented Jul 15, 2025

It's been 3 weeks since the PR's open. I'm merging this

@dmitryax dmitryax merged commit 6d12f4d into open-telemetry:main Jul 15, 2025
177 checks passed
@github-actions github-actions bot added this to the next release milestone Jul 15, 2025
Dylan-M pushed a commit to Dylan-M/opentelemetry-collector-contrib that referenced this pull request Aug 5, 2025
…y#40965)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
This PR introduced query-level data collection for `MySQL` receiver in
the logs pipeline.

We introduced `Query Sample` collection in this initial PR (Query
samples are those queries which are currently running at the moment that
scraper is working)

#### Configuration
We introduced 2 configurations for the feature(see receiver's README for
details):
* `events."db.server.query_sample".enabled`: Flag to enable the feature.
* `query_sample_collection.max_rows_per_query`: The expected report
numbers of queries sample in each scrape.

##### Example output"
```
resourceLogs:
  - resource: {}
    scopeLogs:
      - logRecords:
          - attributes:
              - key: db.system.name
                value:
                  stringValue: mysql
              - key: mysql.threads.thread_id
                value:
                  intValue: "1034384"
              - key: user.name
                value:
                  stringValue: myuser
              - key: db.namespace
                value:
                  stringValue: adventureworks
              - key: mysql.threads.processlist_command
                value:
                  stringValue: Query
              - key: mysql.threads.processlist_state
                value:
                  stringValue: executing
              - key: db.query.text
                value:
                  stringValue: SELECT soh.SalesOrderID, soh.OrderDate, c.CustomerID, p.Name AS ProductName, sod.OrderQty, sod.LineTotal FROM salesorderheader soh JOIN salesorderdetail sod ON soh.SalesOrderID = sod.SalesOrderID JOIN product p ON sod.ProductID = p.ProductID JOIN customer c ON soh.CustomerID = c.CustomerID ORDER BY soh.OrderDate DESC
              - key: mysql.events_statements_current.digest
                value:
                  stringValue: aaaaaa
              - key: mysql.event_id
                value:
                  intValue: "17470257762"
              - key: mysql.wait_type
                value:
                  stringValue: CPU
              - key: mysql.events_waits_current.timer_wait
                value:
                  doubleValue: 1.2851652e-05
              - key: client.address
                value:
                  stringValue: 192.168.1.80
              - key: client.port
                value:
                  intValue: "1234"
              - key: network.peer.address
                value:
                  stringValue: 192.168.1.80
              - key: network.peer.port
                value:
                  intValue: "1234"
            body: {}
            eventName: db.server.query_sample
            spanId: ""
            timeUnixNano: "1751033212422664000"
            traceId: ""
        scope:
          name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mysqlreceiver
          version: latest
```
<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
n/a

<!--Describe what testing was performed and which tests were added.-->
#### Testing
Added

<!--Describe the documentation added.-->
#### Documentation
Added

<!--Please delete paragraphs that you did not use before submitting.-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants