Skip to content

Commit

Permalink
first drfat
Browse files Browse the repository at this point in the history
uogeated dimensio name

refactor code
  • Loading branch information
sourabh1007 committed Nov 18, 2024
1 parent 36079d4 commit cf24aeb
Show file tree
Hide file tree
Showing 12 changed files with 435 additions and 27 deletions.
1 change: 1 addition & 0 deletions Microsoft.Azure.Cosmos/src/DocumentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ internal virtual void Initialize(Uri serviceEndpoint,
if (this.cosmosClientTelemetryOptions.IsClientMetricsEnabled)
{
CosmosOperationMeter.Initialize();
CosmosNetworkMeter.Initialize();

CosmosOperationMeter.AddInstanceCount(this.ServiceEndpoint);
}
Expand Down
18 changes: 15 additions & 3 deletions Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,17 +533,23 @@ private async Task<TResult> RunWithDiagnosticsHelperAsync<TResult>(
&& (!this.ClientOptions.CosmosClientTelemetryOptions.DisableDistributedTracing || this.ClientOptions.CosmosClientTelemetryOptions.IsClientMetricsEnabled))
{
// Extracts and records telemetry data from the result of the operation.
OpenTelemetryAttributes response = openTelemetry?.Item2(result);
OpenTelemetryAttributes otelAttributes = openTelemetry?.Item2(result);

// Records the telemetry attributes for Distributed Tracing (if enabled)
recorder.Record(response);
recorder.Record(otelAttributes);

// Records metrics such as request units, latency, and item count for the operation.
CosmosOperationMeter.RecordTelemetry(getOperationName: getOperationName,
accountName: this.client.Endpoint,
containerName: containerName,
databaseName: databaseName,
attributes: response);
attributes: otelAttributes);

CosmosNetworkMeter.RecordTelemetry(getOperationName: getOperationName,
accountName: this.client.Endpoint,
containerName: containerName,
databaseName: databaseName,
attributes: otelAttributes);
}
return result;
}
Expand Down Expand Up @@ -584,6 +590,12 @@ private async Task<TResult> RunWithDiagnosticsHelperAsync<TResult>(
containerName: containerName,
databaseName: databaseName,
ex: cosmosException);

CosmosNetworkMeter.RecordTelemetry(getOperationName: getOperationName,
accountName: this.client.Endpoint,
containerName: containerName,
databaseName: databaseName,
ex: cosmosException);
}

throw;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.Azure.Cosmos
public sealed class CosmosDbClientMetrics
{
/// <summary>
/// OperationMetrics
/// Operation Metrics
/// </summary>
public static class OperationMetrics
{
Expand Down Expand Up @@ -101,6 +101,120 @@ public static class Description
}
}

/// <summary>
/// Network Metrics
/// </summary>
public static class NetworkMetrics
{
/// <summary>
/// the name of the operation meter
/// </summary>
public const string MeterName = "Azure.Cosmos.Client.Request";

/// <summary>
/// Version of the operation meter
/// </summary>
public const string Version = "1.0.0";

/// <summary>
/// Metric Names
/// </summary>
public static class Name
{
/// <summary>
/// Network Call Latency
/// </summary>
public const string Latency = "db.client.cosmosdb.request.duration";

/// <summary>
/// Request Payload Size
/// </summary>
public const string RequestBodySize = "db.client.cosmosdb.request.body.size";

/// <summary>
/// Request Payload Size
/// </summary>
public const string ResponseBodySize = "db.client.cosmosdb.response.body.size";

/// <summary>
/// Channel Aquisition Latency
/// </summary>
public const string ChannelAquisitionLatency = "db.client.cosmosdb.request.channel_aquisition.duration";

/// <summary>
/// Backend Server Latency
/// </summary>
public const string BackendLatency = "db.server.cosmosdb.request.duration";

/// <summary>
/// Transit Time Latency
/// </summary>
public const string TransitTimeLatency = "db.client.cosmosdb.request.transit.duration";

/// <summary>
/// Received Time Latency
/// </summary>
public const string ReceivedTimeLatency = "db.client.cosmosdb.request.received.duration";
}

/// <summary>
/// Unit for metrics
/// </summary>
public static class Unit
{
/// <summary>
/// Unit representing bytes
/// </summary>
public const string Bytes = "bytes";

/// <summary>
/// Unit representing time in seconds
/// </summary>
public const string Sec = "s";
}

/// <summary>
/// Provides descriptions for metrics.
/// </summary>
public static class Description
{
/// <summary>
/// Network Call Latency
/// </summary>
public const string Latency = "Duration of client requests.";

/// <summary>
/// Request Payload Size
/// </summary>
public const string RequestBodySize = "Size of client request body.";

/// <summary>
/// Request Payload Size
/// </summary>
public const string ResponseBodySize = "Size of client response body.";

/// <summary>
/// Channel Aquisition Latency
/// </summary>
public const string ChannelAquisitionLatency = "The duration of the successfully established outbound TCP connections. i.e. Channel Aquisition Time (for direct mode).";

/// <summary>
/// Backend Server Latency
/// </summary>
public const string BackendLatency = "Backend Latency (for direct mode).";

/// <summary>
/// Transit Time Latency
/// </summary>
public const string TransitTimeLatency = "Time spent on the wire (for direct mode).";

/// <summary>
/// Received Time Latency
/// </summary>
public const string ReceivedTimeLatency = "Time spent on 'Received' stage (for direct mode).";
}
}

/// <summary>
/// Buckets
/// </summary>
Expand Down
Loading

0 comments on commit cf24aeb

Please sign in to comment.