Skip to content

Unify database batch tests into parameterized scenario tests#19019

Draft
trask wants to merge 31 commits into
open-telemetry:mainfrom
trask:unify-batch-tests
Draft

Unify database batch tests into parameterized scenario tests#19019
trask wants to merge 31 commits into
open-telemetry:mainfrom
trask:unify-batch-tests

Conversation

@trask

@trask trask commented Jun 16, 2026

Copy link
Copy Markdown
Member

Description

Consolidates the per-case batch tests across the database instrumentations that emit db.operation.batch.size into a single @ParameterizedTest driven by a small BatchScenario holder, locking down the shape of batch telemetry (BATCH-prefixed span names/summaries, db.operation.batch.size, joined db.query.text).

Each unified test covers the relevant cases:

  • empty — only where the driver allows it and it produces telemetry
  • single — a size-1 batch (verifies it is not treated as a batch: no db.operation.batch.size)
  • two, same operationBATCH <op> span/summary, db.operation.batch.size = 2
  • two, different operationsBATCH span/summary, joined query text

Modules updated:

Module Cases Notes
JDBC (Statement) empty / single / two-same / two-different stable-only, h2
DynamoDB aws-sdk 1.11 GetItem & WriteItem × empty / single / two dual-mode
DynamoDB aws-sdk 2.2 empty / two-get / two-write dual-mode
Cassandra 3.0 / 4.0 / 4.4 two-same / two-different dual-mode
R2DBC 1.0 single / two-same stable-only
Vert.x SQL client 4.0 / 5.0 single / two-same dual-mode
Redisson two-same / two-different dual-mode

Notes

  • Batch telemetry is database-agnostic (it comes from the shared SQL extractors), so JDBC locks the shape against a single in-memory database rather than the full driver cross-product.
  • A size-1 batch is executed as a normal single statement/command (e.g. Cassandra INSERT ks.users, Redisson SET), not a batch — so the single case is dropped where that path diverges and kept where the size-1 span still looks batch-shaped.
  • Alternate-API batch tests that exercise genuinely different behavior (JDBC executeLargeBatch/prepared batch, Redisson large/atomic batch) are left as separate tests.

Opening as a draft to run CI across the Docker-based integration suites.

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 consolidates per-case batch telemetry tests across multiple database instrumentations into @ParameterizedTest methods driven by BatchScenario holder classes. The goal is to standardize how batch telemetry shape is tested (BATCH-prefixed span names/summaries, db.operation.batch.size, joined db.query.text), making future changes to batch behavior easier to validate in one place per module.

Changes:

  • Replaced individual @Test methods for batch variants (empty, single, two-same-op, two-different-ops) with @ParameterizedTest/@MethodSource driven by a BatchScenario data class in each module (JDBC, DynamoDB v1.11 & v2.2, Cassandra 3.0 & 4.0, R2DBC, Vert.x SQL 4.0 & 5.0, Redisson).
  • JDBC batch tests were narrowed from multi-driver (h2+sqlite) to h2-only and stable-semconv-only, since batch telemetry comes from shared SQL extractors and is database-agnostic.
  • AWS SDK 2.2 batch test was rewritten from using the shared assertDynamoDbRequest helper to inline attribute construction, adding a new "empty batch" scenario and conditional metric assertions.

Reviewed changes

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

Show a summary per file
File Description
instrumentation/jdbc/testing/.../AbstractJdbcInstrumentationTest.java Adds testStatementBatch parameterized test with BatchScenario builder; removes testBatch, testMultiBatch, testSingleItemBatch, and testBatchImpl
instrumentation/aws-sdk/aws-sdk-2.2/testing/.../AbstractAws2ClientCoreTest.java Unifies testBatchGetItem* and testBatchWriteItem* into batchOperation with inline assertions, adds empty-batch scenario
instrumentation/aws-sdk/aws-sdk-1.11/testing/.../AbstractDynamoDbClientTest.java Unifies 4 batch tests into batchOperation with 6 scenarios (empty/single/two × get/write)
instrumentation/cassandra/cassandra-common-4.0/testing/.../AbstractCassandraTest.java Unifies batchStatementWithSameQuery and batchStatementWithDifferentQueries into batchStatement
instrumentation/cassandra/cassandra-3.0/.../CassandraClientTest.java Same refactoring as Cassandra 4.0 but for v3 driver API
instrumentation/r2dbc-1.0/testing/.../AbstractR2dbcStatementTest.java Converts testBatchQueries to parameterized batchQueries with single/twoSameOp scenarios
instrumentation/vertx/.../v4_0/VertxSqlClientTest.java Converts testBatch to parameterized with single/twoSameOp scenarios
instrumentation/vertx/.../v5_0/VertxSqlClientTest.java Same as Vert.x 4.0
instrumentation/redisson/.../AbstractRedissonClientTest.java Unifies batchCommand and mixedBatchCommand into parameterized batchCommand

trask added 24 commits June 16, 2026 11:27
…trumentations

db.operation.batch.size is now captured for every batch execution including
empty batches (size 0). It is only omitted when the batch size is 1, which
is reported as a non-batch operation.

This change applies uniformly to JDBC, R2DBC, Cassandra (3.0/4.0/4.4),
Vert.x SQL client (4.0/5.0), and AWS DynamoDB SDK (1.11/2.2).

Key changes:
- Core gate in SqlClientAttributesExtractor/DbClientAttributesExtractor
  changed from batchSize > 1 to batchSize != 1
- JDBC javaagent tracks empty batches to report size 0 (option B)
- R2DBC uses ExecutionType.BATCH to distinguish from Statement executions
- Vert.x batch size computed for size != 1
- DynamoDB extractors emit 0 for empty BatchGetItem/BatchWriteItem
- All test matrices updated to assert batchSize(0) on empty scenarios
For stable semconv, inspect BatchWriteItem requests to determine
the actual operation type:
- Single PutRequest -> PutItem
- Single DeleteRequest -> DeleteItem
- Multiple PutRequests -> BATCH PutItem
- Multiple DeleteRequests -> BATCH DeleteItem
- Mixed Put/Delete -> BATCH

This aligns DynamoDB with SQL/Cassandra batch naming conventions
where specific operation names are used when all items in a batch
perform the same operation type.

Also adds test coverage for all BatchWriteItem scenarios.
R2DBC batch getter tests built a mock query execution with a batch size but
without marking it as an R2DBC batch, so stable semconv batch attributes were
not available. AWS SDK 1.11 looked up DynamoDB WriteRequest accessors with an
exact Object return type, so PutRequest/DeleteRequest methods were not found
and batch write operations were misclassified.

Mark the R2DBC mock as a batch and resolve AWS v1.11 write accessors without
requiring a specific return type.

Validation:
./gradlew :instrumentation:r2dbc-1.0:library:testStableSemconv --tests "io.opentelemetry.instrumentation.r2dbc.v1_0.R2dbcSqlAttributesGetterTest" --rerun --no-daemon
./gradlew :instrumentation:aws-sdk:aws-sdk-1.11:library:testStableSemconv --tests "*batchOperation*" --rerun --no-daemon
./gradlew :instrumentation:aws-sdk:aws-sdk-1.11:javaagent:testStableSemconv --tests "*batchOperation*" --rerun --no-daemon
./gradlew :instrumentation:r2dbc-1.0:library:spotlessApply :instrumentation:aws-sdk:aws-sdk-1.11:library:spotlessApply --no-daemon
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.

2 participants