Skip to content

Commit

Permalink
Open Telemetry: Fixes attribute name following otel convention (#4765)
Browse files Browse the repository at this point in the history
## Description

### What is the change?
`db.cosmosdb.operation_type `--> removed (moved to classic sdk support)
`db.cosmosdb.machine_id` --> removed (moved to classic sdk support)
`db.cosmosdb.client_id` --> ~~`db.cosmosdb.client.id`~~ it will remain
same ~~(aligns with OTel messaging conventions)~~
`db.cosmosdb.request_content_length` -->
~~`db.cosmosdb.request.content_length`~~ it will remain same ~~(aligns
with OTel HTTP conventions)~~
`db.cosmosdb.response_content_length` -->
~~`db.cosmosdb.request.content_length`~~ it will remain same ~~(aligns
with OTel HTTP conventions)~~
`db.cosmosdb.status_code` --> `db.response.status_code` (moved
`db.cosmosdb.status_code` to classic sdk support)
`db.cosmosdb.consistency_level` -> added
`db.cosmosdb.request_content_length_bytes` -> added for classic sdk
support

### Why?

Lot of discussions are going on with Azure Core and Open Telemetry
Community teams. As part of that discussion, we are making these changes
as our goal is to be Open Telemetry and Azure compliant,

## Type of change

Please delete options that are not relevant.

- [] Bug fix (non-breaking change which fixes an issue)

## Closing issues

To automatically close an issue: closes #4553

---------

Co-authored-by: Kiran Kumar Kolli <kirankk@microsoft.com>
  • Loading branch information
sourabh1007 and kirankumarkolli authored Oct 15, 2024
1 parent 138601f commit 72eed8a
Show file tree
Hide file tree
Showing 17 changed files with 1,197 additions and 1,167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ internal sealed class AppInsightClassicAttributeKeys
/// </summary>
public const string SubStatusCode = "db.cosmosdb.sub_status_code";

/// <summary>
/// Represents the content length of the request.
/// </summary>
public const string RequestContentLength = "db.cosmosdb.request_content_length_bytes";

/// <summary>
/// Represents the content length of the response.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ internal sealed class OpenTelemetryAttributeKeys
/// </summary>
public const string ClientId = "db.cosmosdb.client_id";

/// <summary>
/// Represents the machine ID for Cosmos DB.
/// </summary>
public const string MachineId = "db.cosmosdb.machine_id";

/// <summary>
/// Represents the user agent, compliant with OpenTelemetry conventions.
/// </summary>
Expand All @@ -80,11 +75,6 @@ internal sealed class OpenTelemetryAttributeKeys
/// </summary>
public const string ConnectionMode = "db.cosmosdb.connection_mode";

/// <summary>
/// Represents the type of operation for Cosmos DB.
/// </summary>
public const string OperationType = "db.cosmosdb.operation_type";

// Request/Response specifics

/// <summary>
Expand All @@ -105,7 +95,7 @@ internal sealed class OpenTelemetryAttributeKeys
/// <summary>
/// Represents the status code of the response.
/// </summary>
public const string StatusCode = "db.cosmosdb.status_code";
public const string StatusCode = "db.response.status_code";

/// <summary>
/// Represents the sub-status code of the response.
Expand Down Expand Up @@ -147,6 +137,11 @@ internal sealed class OpenTelemetryAttributeKeys
/// </summary>
public const string BatchSize = "db.operation.batch_size";

/// <summary>
/// Consistency Level
/// </summary>
public const string ConsistencyLevel = "db.cosmosdb.consistency_level";

// Exceptions

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Microsoft.Azure.Cosmos.Telemetry
{
using System;
using System.Net;
using Microsoft.Azure.Cosmos.Query.Core;

Expand All @@ -20,6 +19,8 @@ internal OpenTelemetryAttributes()
internal OpenTelemetryAttributes(RequestMessage requestMessage)
{
this.RequestContentLength = requestMessage?.Headers?.ContentLength;
this.ConsistencyLevel = requestMessage?.Headers?.ConsistencyLevel;

if (requestMessage != null)
{
this.OperationType = requestMessage.OperationType;
Expand Down Expand Up @@ -95,5 +96,10 @@ internal OpenTelemetryAttributes(RequestMessage requestMessage)
/// Query Spec with Query Text and Parameters
/// </summary>
internal SqlQuerySpec QuerySpec { get; set; }

/// <summary>
/// Consistency Level
/// </summary>
internal string ConsistencyLevel { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace Microsoft.Azure.Cosmos.Telemetry
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Antlr4.Runtime.Misc;
using global::Azure.Core;
using Microsoft.Azure.Cosmos.Telemetry.Diagnostics;
using Microsoft.Azure.Documents;
Expand Down Expand Up @@ -159,7 +158,6 @@ public void Record(
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ContainerName, containerName);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ServerAddress, clientContext.Client?.Endpoint?.Host);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.UserAgent, clientContext.UserAgent);

}
else
{
Expand All @@ -169,16 +167,12 @@ public void Record(
this.scope.AddAttribute(AppInsightClassicAttributeKeys.ContainerName, containerName);
this.scope.AddAttribute(AppInsightClassicAttributeKeys.ServerAddress, clientContext.Client?.Endpoint?.Host);
this.scope.AddAttribute(AppInsightClassicAttributeKeys.UserAgent, clientContext.UserAgent);
this.scope.AddAttribute(AppInsightClassicAttributeKeys.MachineId, VmMetadataApiHandler.GetMachineId());
}

// Other information
this.scope.AddAttribute(OpenTelemetryAttributeKeys.DbSystemName, OpenTelemetryCoreRecorder.CosmosDb);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.MachineId, VmMetadataApiHandler.GetMachineId());

// Client Information
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ClientId, clientContext?.Client?.Id);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ConnectionMode, this.connectionModeCache);

}
}

Expand Down Expand Up @@ -248,25 +242,29 @@ public void Dispose()
{
OperationType operationType
= (this.response == null || this.response?.OperationType == OperationType.Invalid) ? this.operationType : this.response.OperationType;

string operationName = Enum.GetName(typeof(OperationType), operationType);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.OperationType, operationName);
if (otelStabilityMode != OpenTelemetryStablityModes.DatabaseDupe)
{
string operationName = Enum.GetName(typeof(OperationType), operationType);
this.scope.AddAttribute(AppInsightClassicAttributeKeys.OperationType, operationName);
}

if (this.response != null)
{
if (this.response.BatchSize is not null)
{
this.scope.AddIntegerAttribute(OpenTelemetryAttributeKeys.BatchSize, (int)this.response.BatchSize);
}
this.scope.AddAttribute(OpenTelemetryAttributeKeys.RequestContentLength, this.response.RequestContentLength);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ResponseContentLength, this.response.ResponseContentLength);

if (otelStabilityMode == OpenTelemetryStablityModes.DatabaseDupe)
{
this.scope.AddIntegerAttribute(OpenTelemetryAttributeKeys.StatusCode, (int)this.response.StatusCode);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.RequestContentLength, this.response.RequestContentLength);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ResponseContentLength, this.response.ResponseContentLength);
}
else
{
this.scope.AddAttribute(AppInsightClassicAttributeKeys.RequestContentLength, this.response.RequestContentLength);
this.scope.AddAttribute(AppInsightClassicAttributeKeys.ResponseContentLength, this.response.ResponseContentLength);
this.scope.AddIntegerAttribute(AppInsightClassicAttributeKeys.StatusCode, (int)this.response.StatusCode);
}

Expand All @@ -275,6 +273,7 @@ OperationType operationType
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ItemCount, this.response.ItemCount);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ActivityId, this.response.ActivityId);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.CorrelatedActivityId, this.response.CorrelatedActivityId);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ConsistencyLevel, this.response.ConsistencyLevel);

if (this.response.QuerySpec is not null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,16 @@
<ACTIVITY source="Azure.Cosmos.Operation" operationName="Operation.execute_batch" displayName="execute_batch containerName">
<ATTRIBUTE key="az.namespace">Microsoft.DocumentDB</ATTRIBUTE>
<ATTRIBUTE key="az.schema_url">https://opentelemetry.io/schemas/1.23.0</ATTRIBUTE>
<ATTRIBUTE key="db.operation">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.name">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.container">Some Value</ATTRIBUTE>
<ATTRIBUTE key="net.peer.name">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.operation">execute_batch</ATTRIBUTE>
<ATTRIBUTE key="db.name">databaseName</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.container">containerName</ATTRIBUTE>
<ATTRIBUTE key="net.peer.name">127.0.0.1</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.user_agent">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.system">cosmosdb</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.machine_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.system">cosmosdb</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.client_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.connection_mode">Direct</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.operation_type">Batch</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.operation_type">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.operation.batch_size">90</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.status_code">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.sub_status_code">Some Value</ATTRIBUTE>
Expand Down Expand Up @@ -295,16 +295,16 @@
<ACTIVITY source="Azure.Cosmos.Operation" operationName="Operation.execute_batch" displayName="execute_batch containerName">
<ATTRIBUTE key="az.namespace">Microsoft.DocumentDB</ATTRIBUTE>
<ATTRIBUTE key="az.schema_url">https://opentelemetry.io/schemas/1.23.0</ATTRIBUTE>
<ATTRIBUTE key="db.operation">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.name">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.container">Some Value</ATTRIBUTE>
<ATTRIBUTE key="net.peer.name">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.operation">execute_batch</ATTRIBUTE>
<ATTRIBUTE key="db.name">databaseName</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.container">containerName</ATTRIBUTE>
<ATTRIBUTE key="net.peer.name">127.0.0.1</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.user_agent">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.system">cosmosdb</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.machine_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.system">cosmosdb</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.client_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.connection_mode">Direct</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.operation_type">Batch</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.operation_type">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.operation.batch_size">50</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.status_code">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.sub_status_code">Some Value</ATTRIBUTE>
Expand Down
Loading

0 comments on commit 72eed8a

Please sign in to comment.