Skip to content

Conversation

Copy link

Copilot AI commented Jan 22, 2026

Implements getDbResponseStatusCode() for Couchbase SDK 2.x instrumentation as part of database semantic conventions support.

Changes

  • Added getDbResponseStatusCode() to CouchbaseAttributesGetter
  • Returns null since Couchbase SDK 2.x uses typed exceptions (DocumentDoesNotExistException, CASMismatchException, etc.) rather than numeric error codes
@Override
@Nullable
public String getDbResponseStatusCode(@Nullable Void response, @Nullable Throwable error) {
  return null; // Couchbase SDK 2.x does not expose status codes
}

This follows the same pattern as OpenSearch Java 3.0 instrumentation where status codes aren't available at the DB client level.

Original prompt

Add getDbResponseStatusCode to Couchbase Instrumentation

Phase 1: Analysis

1.1 Understand Status Code Source

  • Check the RESPONSE generic type parameter in DbClientAttributesGetter/SqlClientAttributesGetter
  • Determine if status codes come from: response objects, exceptions, both, or not available
  • Review database semantic conventions for your database
  • Research the instrumented library: Check out the library's source code to understand what status/error information is available in response objects or exceptions
  • Note: If RESPONSE is Void or doesn't have access to the status code, it can be changed to another type (even a custom wrapper if really needed to wrap multiple underlying objects from the library)

1.2 Identify Status Code Format

  • String codes, numeric codes, enums, or error prefixes
  • When available: all operations, failures only, or specific responses

Phase 2: Implement getDbResponseStatusCode()

Locate [DatabaseName]AttributesGetter.java and add implementation:

From Response Object:

@Override
public String getDbResponseStatusCode(REQUEST request, @Nullable RESPONSE response, @Nullable Throwable error) {
  if (response == null) return null;
  // Extract from response API (direct method, enum.name(), String.valueOf(), or reflection)
  return response.getStatusCode();  // adjust based on API
}

From Exception:

@Override
public String getDbResponseStatusCode(REQUEST request, @Nullable RESPONSE response, @Nullable Throwable error) {
  if (error == null) return null;
  // Check exception type and extract code/message
  if (error instanceof SpecificException) {
    return extractStatusFromException(error);
  }
  return null;
}

From Both:

@Override
public String getDbResponseStatusCode(REQUEST request, @Nullable RESPONSE response, @Nullable Throwable error) {
  if (response != null) {
    String status = extractFromResponse(response);
    if (status != null) return status;
  }
  if (error != null) {
    return extractFromException(error);
  }
  return null;
}

Not Available:

@Override
public String getDbResponseStatusCode(REQUEST request, @Nullable RESPONSE response, @Nullable Throwable error) {
  return null;  // Client does not expose status codes
}

Add necessary imports for exception types.

Phase 3: Update Tests

3.1 Add Import

import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_RESPONSE_STATUS_CODE;

3.2 Update All Test Assertions

Add conditional assertion to each test (note: DB_RESPONSE_STATUS_CODE should be last among attributes):

.hasAttributesSatisfyingExactly(
    equalTo(maybeStable(DB_SYSTEM), "database_name"),
    equalTo(maybeStable(DB_OPERATION), "operation_name"),
    // ... other attributes
    equalTo(DB_RESPONSE_STATUS_CODE, SemconvStability.emitStableDatabaseSemconv() ? "ACTUAL_STATUS" : null)
)

Replace "ACTUAL_STATUS" with appropriate value or null if not available for that operation.

Alternatively, if status codes are available for other spans in the instrumentation but not for this particular operation, leave the DB_RESPONSE_STATUS_CODE assertion out completely with a comment:

.hasAttributesSatisfyingExactly(
    equalTo(maybeStable(DB_SYSTEM), "database_name"),
    equalTo(maybeStable(DB_OPERATION), "operation_name"),
    // ... other attributes
    // db.response.status_code is not available for this operation
)

3.3 Determine Status Codes

Run tests to see actual emitted values, then verify against database documentation.

Phase 4: Verification

Run all four test combinations:

./gradlew :instrumentation:[db]:[version]:javaagent:test --console=plain
./gradlew :instrumentation:[db]:[version]:javaagent:test -PtestLatestDeps=true --console=plain
./gradlew :instrumentation:[db]:[version]:javaagent:testStableSemconv --console=plain
./gradlew :instrumentation:[db]:[version]:javaagent:testStableSemconv -PtestLatestDeps=true --console=plain

All should show BUILD SUCCESSFUL with all tests passing.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: trask <218610+trask@users.noreply.github.com>
Copilot AI changed the title [WIP] Add getDbResponseStatusCode to Couchbase instrumentation Add getDbResponseStatusCode to Couchbase instrumentation Jan 22, 2026
Copilot AI requested a review from trask January 22, 2026 04:56
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