Skip to content

Handle explicit empty database batches - #19143

Merged
trask merged 10 commits into
open-telemetry:mainfrom
trask:handle-explicit-empty-db-batches
Jul 8, 2026
Merged

Handle explicit empty database batches#19143
trask merged 10 commits into
open-telemetry:mainfrom
trask:handle-explicit-empty-db-batches

Conversation

@trask

@trask trask commented Jul 7, 2026

Copy link
Copy Markdown
Member

Treat explicit empty database batches as batches in the shared database semconv helpers. This makes db.operation.batch.size = 0 drive 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.

@opentelemetry-pr-dashboard

Copy link
Copy Markdown

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 across SqlClientAttributesExtractor, DbClientAttributesExtractor, and DbClientSpanNameExtractor; empty batches now yield the "BATCH" span name and emit the batch-size attribute.
  • Extend MultiQuery to derive a batch-level operationName ("BATCH" / "BATCH <op>") and collectionName, exposed to the extractor when singleOperationAndCollection is 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@trask
trask marked this pull request as ready for review July 8, 2026 18:45
@trask
trask requested a review from a team as a code owner July 8, 2026 18:45
@trask
trask merged commit 569d70a into open-telemetry:main Jul 8, 2026
95 checks passed
@trask
trask deleted the handle-explicit-empty-db-batches branch July 8, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants