Handle explicit empty database batches - #19143
Conversation
|
This PR has review comments. Review suggestions, whether from maintainers or automated reviewers, aren't always correct or required. Please evaluate each comment on its merits, then make sure each thread has a clear outcome. For example, link to the commit if you applied a suggestion, explain why it wasn't applied, or ask a follow-up question. Automation flags a PR for human review once every review thread has a reply or is marked as resolved. Status across open PRs is visible on the pull request dashboard. |
There was a problem hiding this comment.
Pull request overview
This PR updates the shared database semantic-convention helpers in instrumentation-api-incubator so that an explicit empty database batch (a batch executed with zero statements, reported as db.operation.batch.size = 0) is treated as a batch rather than as a plain non-batch statement. The batch predicate changes from batchSize > 1 to batchSize != 1, aligning it with the existing convention already used by the DynamoDB extractors. As a result, empty batches now drive stable batch span naming ("BATCH") and emit db.operation.batch.size, while single-statement batches (size 1) continue to be reported as non-batch. It also enriches multi-query batch summaries with db.operation.name/db.collection.name (for getters using singleOperationAndCollection, currently only Cassandra), and adds extractor/span-name tests for the empty-batch paths.
Changes:
- Treat
batchSize == 0(and any value!= 1) as a batch acrossSqlClientAttributesExtractor,DbClientAttributesExtractor, andDbClientSpanNameExtractor; empty batches now yield the"BATCH"span name and emit the batch-size attribute. - Extend
MultiQueryto derive a batch-leveloperationName("BATCH"/"BATCH <op>") andcollectionName, exposed to the extractor whensingleOperationAndCollectionis enabled. - Update JDBC, Cassandra (3.0 / common-4.0), and rediscala tests, and add new incubator extractor/span-name unit tests covering empty and single-operation multi-query batches.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
SqlClientAttributesExtractor.java |
Adds emitBatchSize/isBatch (!= 1) and emits db.operation.name/db.collection.name for multi-query batches. |
DbClientAttributesExtractor.java |
Mirrors the != 1 batch predicate so empty batches emit db.operation.batch.size. |
DbClientSpanNameExtractor.java |
Returns "BATCH" for empty query-text batches and updates isBatch to != 1. |
MultiQuery.java |
Adds operationName/collectionName fields and builder uniqueness tracking. |
SqlClientAttributesExtractorTest.java |
New tests for empty single-query batch and single-operation multi-query batch attributes. |
DbClientSpanNameExtractorTest.java |
New tests for empty-batch span naming (stable + migration paths). |
AbstractCassandraTest.java |
Updates empty/batch scenarios and adds oldOperationName()/oldCollectionName() helpers. |
CassandraClientTest.java (3.0) |
Parallel Cassandra 3.0 test updates for the new batch behavior. |
AbstractJdbcInstrumentationTest.java |
Empty batch now expects span name "BATCH" with batchSize(0). |
RediscalaClientTest.scala |
Empty transaction scenario now asserts batchSize = 0. |
Treat explicit empty database batches as batches in the shared database semconv helpers. This makes
db.operation.batch.size = 0drive stable batch span naming and query summaries while continuing to omit the batch-size attribute for single-statement batches, and adds extractor tests covering the empty-batch paths.