-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fdb5e4
commit c47f59b
Showing
10 changed files
with
220 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
Microsoft.Azure.Cosmos/src/Telemetry/Collector/OpenTelemetryMetricsCollector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//------------------------------------------------------------ | ||
|
||
namespace Microsoft.Azure.Cosmos.Telemetry | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Azure.Cosmos.Telemetry.Collector; | ||
|
||
/// <summary> | ||
/// The OpenTelemetryMetricsCollector class is responsible for collecting and recording Cosmos DB operational metrics, such as item counts, request latency, request units, and regions contacted. | ||
/// This data is captured using the OpenTelemetry metrics API, which allows tracking and analysis of Cosmos DB operations at a granular level. | ||
/// </summary> | ||
internal class OpenTelemetryMetricsCollector : ITelemetryCollector | ||
{ | ||
private readonly string clientId; | ||
private readonly string accountName; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the OpenTelemetryMetricsCollector class. | ||
/// </summary> | ||
/// <param name="clientId">A unique identifier for the Cosmos DB client instance</param> | ||
/// <param name="accountName">The Cosmos DB account name.</param> | ||
public OpenTelemetryMetricsCollector(string clientId, string accountName) | ||
{ | ||
this.clientId = clientId; | ||
this.accountName = accountName; | ||
} | ||
|
||
public void CollectCacheInfo(string cacheName, Func<TelemetryInformation> getTelemetryInformation) | ||
{ | ||
// No OP | ||
} | ||
|
||
/// <summary> | ||
/// Collects telemetry data related to operations and network information, including request performance, item counts, and regions contacted. | ||
/// </summary> | ||
/// <param name="getTelemetryInformation"> A function that provides telemetry details such as operation type, status code, consistency level, and request charge.</param> | ||
/// <remarks>This method gathers telemetry information, including details such as the database, container, operation type, status code, consistency level, and partition key range ID. It uses these dimensions to push metrics to OpenTelemetry, enabling tracking of performance metrics such as request latency, request charge, and item counts.</remarks> | ||
public void CollectOperationAndNetworkInfo(Func<TelemetryInformation> getTelemetryInformation) | ||
{ | ||
TelemetryInformation telemetryInformation = getTelemetryInformation(); | ||
|
||
KeyValuePair<string, object>[] dimensions = new[] | ||
{ | ||
new KeyValuePair<string, object>("Container", $"{this.accountName}/{telemetryInformation.DatabaseId}/{telemetryInformation.ContainerId}"), | ||
new KeyValuePair<string, object>("Operation", telemetryInformation.OperationType), | ||
new KeyValuePair<string, object>("OperationStatusCode", telemetryInformation.StatusCode), | ||
new KeyValuePair<string, object>("ClientCorrelationId", this.clientId), | ||
new KeyValuePair<string, object>("ConsistencyLevel", telemetryInformation.ConsistencyLevel), | ||
new KeyValuePair<string, object>("PartitionKeyRangeId", telemetryInformation.PartitionKeyRangeId), | ||
}; | ||
|
||
PushOperationLevelMetrics(telemetryInformation, dimensions); | ||
} | ||
|
||
/// <summary> | ||
/// Pushes various operation-level metrics to OpenTelemetry. | ||
/// </summary> | ||
/// <param name="telemetryInformation">Contains telemetry data related to the operation, such as item counts, request charge, and latency.</param> | ||
/// <param name="dimensions">Key-value pairs representing various metadata about the operation (e.g., container, operation type, consistency level).</param> | ||
private static void PushOperationLevelMetrics(TelemetryInformation telemetryInformation, KeyValuePair<string, object>[] dimensions) | ||
{ | ||
OpenTelemetryMetrics.MaxItemCounter.Add(Convert.ToInt32(telemetryInformation.MaxItemCount), dimensions); | ||
OpenTelemetryMetrics.ActualItemCounter.Add(Convert.ToInt32(telemetryInformation.ActualItemCount), dimensions); | ||
OpenTelemetryMetrics.RegionsContactedCounter.Add(telemetryInformation.RegionsContactedList.Count, dimensions); | ||
OpenTelemetryMetrics.RequestUnitsHistogram.Record(telemetryInformation.RequestCharge, dimensions); | ||
OpenTelemetryMetrics.RequestLatencyHistogram.Record(telemetryInformation.RequestLatency.Value.Milliseconds, dimensions); | ||
OpenTelemetryMetrics.NumberOfOperationCallCounter.Add(1, dimensions); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryMetrics.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// ------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// ------------------------------------------------------------ | ||
|
||
namespace Microsoft.Azure.Cosmos | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.Metrics; | ||
using System.Text; | ||
|
||
/// <summary> | ||
/// The OpenTelemetryMetrics class contains internal static members to create and record Cosmos DB SDK metrics using OpenTelemetry. These metrics allow you to monitor the performance and resource consumption of Cosmos DB operations. | ||
/// </summary> | ||
internal static class OpenTelemetryMetrics | ||
{ | ||
private static readonly Meter Meter = new Meter("Azure.Cosmos.SDK.Metrics"); | ||
|
||
internal static readonly Counter<int> NumberOfOperationCallCounter = | ||
Meter.CreateCounter<int>("cosmos.client.op.calls", "#", "Number of operation calls"); | ||
|
||
internal static readonly Histogram<double> RequestLatencyHistogram = | ||
Meter.CreateHistogram<double>("cosmos.client.op.latency", "#", "Total end-to-end duration of the operation"); | ||
|
||
internal static readonly Histogram<double> RequestUnitsHistogram = | ||
Meter.CreateHistogram<double>("cosmos.client.op.RUs", "#", "Total request units per operation (sum of RUs for all requested needed when processing an operation)"); | ||
|
||
internal static readonly Counter<int> MaxItemCounter = | ||
Meter.CreateCounter<int>("cosmos.client.op.maxItemCount", "#", "For feed operations (query, readAll, readMany, change feed) and batch operations this meter capture the requested maxItemCount per page/request"); | ||
|
||
internal static readonly Counter<int> ActualItemCounter = | ||
Meter.CreateCounter<int>("cosmos.client.op.actualItemCount", "#", "For feed operations (query, readAll, readMany, change feed) batch operations this meter capture the actual item count in responses from the service"); | ||
|
||
internal static readonly Counter<int> RegionsContactedCounter = | ||
Meter.CreateCounter<int>("cosmos.client.op.regionsContacted", "#", "Number of regions contacted when executing an operation"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.