Skip to content

Commit bb5600a

Browse files
authored
[o11y] Fix some attributes to match Otel Semantic Conventions (#45753)
* [o11y] Fix some attributes to match Otel Semantic Conventions * db.cosmosdb.sub_status_code is now an int * Added `azure.cosmosdb.response.sub_status_code` to reflect this too since it's the non-deprecated label * db.cosmosdb.request_charge is now a double * Added `azure.cosmosdb.operation.request_charge` to reflect this too Sources * https://github.com/open-telemetry/semantic-conventions/blob/723789b86a803492d03191b458138fff6e7a6b9f/docs/registry/attributes/db.md#db-cosmosdb-request-charge * https://opentelemetry.io/docs/specs/semconv/registry/attributes/azure/#azure-cosmosdb-operation-request-charge Signed-off-by: lloydmeta <lloydmeta@gmail.com> * Add some tests to validate types and values. * Add changelog Signed-off-by: lloydmeta <lloydmeta@gmail.com> * * Restore wrong types for existing attributes * * Remove from bugs fixed --------- Signed-off-by: lloydmeta <lloydmeta@gmail.com>
1 parent dca0ce5 commit bb5600a

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/CosmosTracerTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,14 @@ private void verifyOTelTracerAttributes(
14791479

14801480
assertThat(attributes.get("db.cosmosdb.request_content_length")).isNotNull();
14811481

1482+
assertThat(attributes.get("azure.cosmosdb.operation.request_charge")).isNotNull();
1483+
assertThat(attributes.get("azure.cosmosdb.operation.request_charge")).isInstanceOf(Double.class);
1484+
assertThat(attributes.get("azure.cosmosdb.operation.request_charge")).isEqualTo(Double.valueOf(ctx.getTotalRequestCharge()));
1485+
1486+
assertThat(attributes.get("azure.cosmosdb.response.sub_status_code")).isNotNull();
1487+
assertThat(attributes.get("azure.cosmosdb.response.sub_status_code")).isInstanceOf(Integer.class);
1488+
assertThat(attributes.get("azure.cosmosdb.response.sub_status_code")).isEqualTo(Integer.valueOf(ctx.getSubStatusCode()));
1489+
14821490
assertThat(attributes.get("db.cosmosdb.operation_type")).isEqualTo(ctx.getOperationType());
14831491
if (customOperationId != null) {
14841492
assertThat(attributes.get("db.cosmosdb.operation_id")).isEqualTo(customOperationId);

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### 4.72.0-beta.1 (Unreleased)
44

55
#### Features Added
6+
* Added `azure.cosmosdb.operation.request_charge` and `azure.cosmosdb.response.sub_status_code` trace attributes. - [PR 45753](https://github.com/Azure/azure-sdk-for-java/pull/45753)
67

78
#### Breaking Changes
89

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/DiagnosticsProvider.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,10 +1538,18 @@ public void endSpan(CosmosDiagnosticsContext cosmosCtx, Context context, boolean
15381538
"db.cosmosdb.sub_status_code",
15391539
Integer.toString(cosmosCtx.getSubStatusCode()),
15401540
context);
1541+
tracer.setAttribute(
1542+
"azure.cosmosdb.response.sub_status_code",
1543+
cosmosCtx.getSubStatusCode(),
1544+
context);
15411545
tracer.setAttribute(
15421546
"db.cosmosdb.request_charge",
15431547
Float.toString(cosmosCtx.getTotalRequestCharge()),
15441548
context);
1549+
tracer.setAttribute(
1550+
"azure.cosmosdb.operation.request_charge",
1551+
(double) cosmosCtx.getTotalRequestCharge(),
1552+
context);
15451553
tracer.setAttribute("db.cosmosdb.request_content_length",cosmosCtx.getMaxRequestPayloadSizeInBytes(), context);
15461554
tracer.setAttribute("db.cosmosdb.max_response_content_length_bytes",cosmosCtx.getMaxResponsePayloadSizeInBytes(), context);
15471555
tracer.setAttribute("db.cosmosdb.retry_count",cosmosCtx.getRetryCount() , context);

0 commit comments

Comments
 (0)