Common sql comment extractor oracle#48404
Conversation
Add support for extracting and filtering SQL query comments to enable correlation
between database monitoring and APM traces. This feature allows users to configure
allowlists of comment keys that should be extracted from SQL queries and included
as telemetry attributes.
Changes:
- Add internal/common/sqlcomments package for extracting key-value pairs from
leading SQL block comments
- Add AllowedCommentKeys configuration to both TopQueryCollection and QuerySample
in oracledbreceiver config
- Extract and filter comments in both top query collection and query sampling
- Add query.comments attribute to db.server.query_sample and db.server.top_query
events in metadata
- Add unit tests for comment extraction functionality
The implementation is secure by default - only comments with keys explicitly listed
in allowed_comment_keys configuration will be extracted. Empty allowlist returns
empty string.
This enables correlation with APM tools that inject metadata into SQL comments
|
Welcome, contributor! Thank you for your contribution to opentelemetry-collector-contrib. Important reminders:
|
| query.comments: | ||
| description: Filtered SQL query comments extracted from leading block comments. Contains comma-separated key=value pairs for keys specified in allowed_comment_keys configuration. Used for correlation with APM traces. |
There was a problem hiding this comment.
Would much rather see this as a templated attribute with a base name of db.query.comment.<Key> and the value simply being the value which corresponds to that key.
There was a problem hiding this comment.
Hi @thompson-tomo , have thought of this approach but all the attributes must be defined in metadata.yml and key name is dynamic and can't be pre-defined in metadata.yml
WDYT?
There was a problem hiding this comment.
I believe you need to concat the attribute & the key in your reciever.
There was a problem hiding this comment.
Yes, i understand the approach and it would definitely make these values more queryable in observability backends.
but what i'am trying to say is
For example, if a user has this SQL query:
/* key1=val1,key2=val2,key3=val3 */
SELECT * FROM exampleTable
And configures:
allowed_comment_keys:
- key1
- key3
We would extract and send key1=val1,key3=val3 in the query.comments attribute. Since we can't know in advance which keys users will configure, we can't pre-define them as individual attributes in metadata.yaml.
The Collector's metadata generation system (mdatagen) requires all attribute names to be predefined in metadata.yaml, which doesn't support truly dynamic attribute names.
What are your thoughts? If you feel strongly about the templated attributes approach, I'm happy to explore some approaches which might add complexity to work around the mdatagen generated code.
There was a problem hiding this comment.
I understand but I don't think you need to define them in mdatagen but rather just define the base key as an opt-in.
One of the big issues by concating key-value pairs as the order is now important and usability is poor.
Note templated attributes are heavily used in the k8s attributes https://opentelemetry.io/docs/specs/semconv/registry/attributes/k8s/ hence it should be a supported option.
| } | ||
|
|
||
| // Join filtered pairs with comma (no space) | ||
| return strings.Join(filteredPairs, ",") |
There was a problem hiding this comment.
| return strings.Join(filteredPairs, ",") | |
| return filteredPairs |
There was a problem hiding this comment.
Ah, i want to understand about the suggested change more please?
The sql comments is designed to float in comma seperated key value pairs in query.comments attr
There was a problem hiding this comment.
It goes hand in hand with the other comment.
Description
This change enhances the Oracle DB receiver by adding SQL comment extraction support for APM correlation. The
receiver can now extract key-value pairs from leading SQL block comments (e.g., /* traceparent=... */) and include
them as telemetry attributes, enabling correlation between database queries and distributed traces.
What Changed
New Configuration Option: allowed_comment_keys
New Attribute: query.comments
New Package: internal/common/sqlcomments
Use Cases
Distributed Tracing Correlation
Application Context Propagation
Multi-tenant Performance Analysis
Deployment and Feature Tracking
A/B Testing and Experimentation
Configuration Example
Security Considerations
Link to tracking issue
Fixes #48338
Testing
Unit Tests
Integration Tests
Manual Validation
Test Coverage
internal/common/sqlcomments/extractor.go 100% coverage
receiver/oracledbreceiver/scraper.go Integration tested
Documentation