Skip to content

Add db.collection.name to DynamoDB spans under stable database semconv#18853

Draft
chlos wants to merge 3 commits into
open-telemetry:mainfrom
chlos:egor/dynamodb-db-collection-name
Draft

Add db.collection.name to DynamoDB spans under stable database semconv#18853
chlos wants to merge 3 commits into
open-telemetry:mainfrom
chlos:egor/dynamodb-db-collection-name

Conversation

@chlos
Copy link
Copy Markdown
Contributor

@chlos chlos commented May 26, 2026

Summary

When OTEL_SEMCONV_STABILITY_OPT_IN=database is set the aws-sdk-2.2 and aws-sdk-1.11 DynamoDB extractors already emit db.system.name and db.operation.name, but db.collection.name — the stable replacement for per-operation table identification — was never wired up, leaving it absent from all DynamoDB spans even after opting in.

What changed

DynamoDbAttributesExtractor (aws-sdk-2.2 and aws-sdk-1.11):

  • Under emitStableDatabaseSemconv(), extract and emit db.collection.name with the DynamoDB table name.
  • For single-table operations (GetItem, PutItem, Query, Scan, DeleteItem, etc.) the value is read from the TableName request field.
  • For batch operations (BatchGetItem, BatchWriteItem) the RequestItems map is inspected: a single-entry map yields the one table name; a multi-entry map emits "MULTIPLE_TABLES" in line with the OTel DB spec guidance on multi-collection operations.
  • The legacy aws.dynamodb.table_names attribute is unaffected and continues to be emitted regardless of the stability setting.

Tests:

  • AbstractAws2ClientCoreTest and AbstractDynamoDbClientTest both assert db.collection.name when running under emitStableDatabaseSemconv().

Motivation

The stable database semantic conventions define db.collection.name as the primary way to identify which table a DynamoDB operation targets. Without it, users who opt in via OTEL_SEMCONV_STABILITY_OPT_IN=database cannot filter or group DynamoDB spans by table name using stable attribute names, and dashboards built against the stable conventions show no table-level data.

Testing

Existing parameterized tests in AbstractAws2ClientCoreTest cover all single-table operations (CreateTable, DeleteItem, DeleteTable, GetItem, PutItem, Query, UpdateItem, Scan) with tableName="sometable". The stable-semconv branch of each assertion now includes db.collection.name = "sometable". The AbstractDynamoDbClientTest for aws-sdk-1.11 is updated analogously.

When OTEL_SEMCONV_STABILITY_OPT_IN=database is set the aws-sdk-2.2 and
aws-sdk-1.11 DynamoDb extractors already emit db.system.name and
db.operation.name, but db.collection.name (the stable replacement for
aws.dynamodb.table_names as the human-readable table identifier) was
never wired up.

For single-table operations (GetItem, PutItem, Query, Scan, etc.) the
table name is read from the TableName request field. For batch
operations (BatchGetItem, BatchWriteItem) the RequestItems map is
inspected: a single-entry map yields the one table name; a multi-entry
map emits "MULTIPLE_TABLES" per the OTel DB spec guidance on
multi-collection operations.

The aws.dynamodb.table_names attribute is unaffected and continues to
be emitted regardless of semconv stability setting.
Copilot AI review requested due to automatic review settings May 26, 2026 16:54
@chlos chlos requested a review from a team as a code owner May 26, 2026 16:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR updates DynamoDB AWS SDK instrumentation to emit the stable database semantic convention attribute db.collection.name when stable DB semconv emission is enabled.

Changes:

  • Emit db.collection.name for DynamoDB spans in AWS SDK v1.11 and v2.2 instrumentations.
  • Update corresponding tests to assert db.collection.name under stable semconv emission.
  • Add table name extraction logic for AWS SDK v2.2 requests (including batch operations).

Reviewed changes

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

File Description
instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientCoreTest.java Adds stable-semconv assertion for db.collection.name in DynamoDB request tests.
instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/internal/DynamoDbAttributesExtractor.java Emits db.collection.name for v2.2 and introduces request-based table name extraction.
instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractDynamoDbClientTest.java Makes attribute list mutable and conditionally asserts db.collection.name.
instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/DynamoDbAttributesExtractor.java Emits db.collection.name for v1.11 when stable semconv is enabled and table name is available.

Comment on lines +76 to +83
// When there is exactly one table, return it; otherwise return the sentinel for multiple tables.
Optional<Map> requestItems = request.getValueForField("RequestItems", Map.class);
if (requestItems.isPresent() && !requestItems.get().isEmpty()) {
Map<?, ?> items = requestItems.get();
if (items.size() == 1) {
return items.keySet().iterator().next().toString();
}
return "MULTIPLE_TABLES";
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in the follow-up commit (e62118b). The MULTIPLE_TABLES sentinel has been removed — extractTableName now returns null for multi-table batch operations so db.collection.name is omitted entirely, and is only set when the batch targets exactly one table.

Comment on lines +63 to +64
@SuppressWarnings("rawtypes")
private static String extractTableName(ExecutionAttributes executionAttributes) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in e62118b. Replaced Optional<Map> (raw) and the method-level @SuppressWarnings("rawtypes") with Optional<?> + instanceof Map guard and a narrower @SuppressWarnings("unchecked") scoped to just the single cast line, as suggested.

}
// Batch operations (BatchGetItem, BatchWriteItem) use a map keyed by table names.
// When there is exactly one table, return it; otherwise return the sentinel for multiple tables.
Optional<Map> requestItems = request.getValueForField("RequestItems", Map.class);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same fix as above (e62118b) — duplicate comment on the same change.

Comment on lines +54 to +59
if (emitStableDatabaseSemconv()) {
String tableName = extractTableName(executionAttributes);
if (tableName != null) {
attributes.put(DB_COLLECTION_NAME, tableName);
}
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added in e62118b. testBatchGetItemWithMultipleTablesOmitsDbCollectionName in AbstractAws2ClientCoreTest covers the multi-table case, verifying that a two-table BatchGetItem produces aws.dynamodb.table_names but no db.collection.name. The single-table batch cases (BatchGetItem and BatchWriteItem) were already covered by the parameterised test in provideArguments, which now includes the db.collection.name = "sometable" assertion when emitStableDatabaseSemconv() is active.

- Drop MULTIPLE_TABLES sentinel: omit db.collection.name entirely when
  a batch operation targets more than one table, as the attribute is
  defined as a single collection identifier
- Replace @SuppressWarnings("rawtypes") on the method with a narrower
  @SuppressWarnings("unchecked") on the single Map cast, and retrieve
  via Optional<?> + instanceof guard instead of raw Optional<Map>
- Add testBatchGetItemWithMultipleTablesOmitsDbCollectionName to
  explicitly verify that a two-table BatchGetItem produces
  aws.dynamodb.table_names but no db.collection.name
@chlos chlos marked this pull request as draft May 27, 2026 09:18
- Add explanatory comment to @SuppressWarnings("unchecked") in
  DynamoDbAttributesExtractor (aws-sdk-2.2 library) to satisfy the
  SuppressWarningsWithoutExplanation errorprone check.
- Reformat AbstractDynamoDbClientTest (aws-sdk-1.11 testing) to match
  Google Java Format style expected by spotless.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@linux-foundation-easycla
Copy link
Copy Markdown

CLA Missing ID

One or more co-authors of this pull request were not found. You must specify co-authors in commit message trailer via:

Co-authored-by: name <email>

Supported Co-authored-by: formats include:

  1. Anything <id+login@users.noreply.github.com> - it will locate your GitHub user by id part.
  2. Anything <login@users.noreply.github.com> - it will locate your GitHub user by login part.
  3. Anything <public-email> - it will locate your GitHub user by public-email part. Note that this email must be made public on Github.
  4. Anything <other-email> - it will locate your GitHub user by other-email part but only if that email was used before for any other CLA as a main commit author.
  5. login <any-valid-email> - it will locate your GitHub user by login part, note that login part must be at least 3 characters long.

Alternatively, if the co-author should not be included, remove the Co-authored-by: line from the commit message.

Please update your commit message(s) by doing git commit --amend and then git push [--force] and then request re-running CLA check via commenting on this pull request:

/easycla

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