Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
3d1d6ba
Added request level metrics
sourabh1007 Sep 13, 2024
60c411b
add IsClientMetricsEnabled option
sourabh1007 Sep 13, 2024
55b6505
added contract file
sourabh1007 Sep 13, 2024
6fb216c
wip
sourabh1007 Sep 16, 2024
841c7bc
adding test
sourabh1007 Sep 18, 2024
ee32e43
added documentation
sourabh1007 Oct 14, 2024
1ddbcbe
emit metrics
sourabh1007 Oct 16, 2024
7e9a344
fixed dimensions
sourabh1007 Oct 17, 2024
bc6f273
nonworking changes
sourabh1007 Oct 17, 2024
278c5c5
final commit
sourabh1007 Oct 18, 2024
8bae2a9
remove unnecessary dependencies
sourabh1007 Oct 18, 2024
cebace3
contract update
sourabh1007 Oct 18, 2024
6c32e52
fix merges
sourabh1007 Oct 18, 2024
f6974ea
remove console
sourabh1007 Oct 18, 2024
161abe9
add noops if disables
sourabh1007 Oct 18, 2024
2569ed9
added null check
sourabh1007 Oct 18, 2024
a3ee34d
[INTERNAL] CI: Fixes emulator set-up to leverage central SDK teams sc…
kirankumarkolli Oct 18, 2024
de96acc
VectorIndexDefinition: Adds Support for Partitioned DiskANN (#4792)
kundadebdatta Oct 18, 2024
2af0b05
Azurecore: Fixes upgrading azure core dependency to latest (#4819)
kirankumarkolli Oct 18, 2024
8d80c1c
DeleteAllItemsByPartitionKeyStreamAsync: Adds DeleteAllItemsByPartiti…
kirankumarkolli Oct 18, 2024
316b3d8
Merge branch 'master' into users/sourabhjain/otelmetriccpu
sourabh1007 Oct 22, 2024
c6a33b0
rename file
sourabh1007 Oct 22, 2024
4fd1193
refactor code
sourabh1007 Oct 23, 2024
033fda4
refactor code
sourabh1007 Oct 23, 2024
e92477a
perf tests
sourabh1007 Oct 23, 2024
cf5bb03
updated contracts
sourabh1007 Oct 24, 2024
6338908
code refactor
sourabh1007 Oct 24, 2024
321520c
refactored code
sourabh1007 Oct 25, 2024
51d485c
Merge branch 'master' into users/sourabhjain/otelmetriccpu
sourabh1007 Oct 25, 2024
7d03b8f
Merge branch 'master' into users/sourabhjain/otelmetriccpu
sourabh1007 Oct 26, 2024
1614b75
Merge branch 'master' into users/sourabhjain/otelmetriccpu
sourabh1007 Nov 1, 2024
9081e1a
added region contacted as dimension
sourabh1007 Nov 1, 2024
66efcf9
Merge branch 'master' into users/sourabhjain/otelmetriccpu
sourabh1007 Nov 6, 2024
ba63724
Merge branch 'master' into users/sourabhjain/otelmetriccpu
sourabh1007 Nov 12, 2024
a451d49
Merge branch 'master' into users/sourabhjain/otelmetriccpu
sourabh1007 Nov 14, 2024
736c292
perf fix
sourabh1007 Nov 14, 2024
6d6957b
inc perf test
sourabh1007 Nov 14, 2024
36d0ee1
perf results
sourabh1007 Nov 14, 2024
2509f3a
Merge branch 'master' into users/sourabhjain/otelmetriccpu
sourabh1007 Nov 14, 2024
36079d4
refactor according to versioning
sourabh1007 Nov 18, 2024
b7ae941
Merge branch 'master' into users/sourabhjain/otelmetriccpu
sourabh1007 Nov 19, 2024
d01a3c4
Merge branch 'master' into users/sourabhjain/otelmetriccpu
sourabh1007 Nov 20, 2024
e0efe5b
fix test
sourabh1007 Nov 20, 2024
369160b
refactor code
sourabh1007 Nov 20, 2024
1f64899
added try catch
sourabh1007 Nov 20, 2024
79b7307
added console
sourabh1007 Nov 20, 2024
f184813
updated contract
sourabh1007 Nov 20, 2024
ef2f2a5
code refatoring
sourabh1007 Nov 20, 2024
731951a
fix tetss
sourabh1007 Nov 20, 2024
a9eeba6
refactor code
sourabh1007 Nov 20, 2024
963824c
first drfat
sourabh1007 Nov 8, 2024
35c3141
updated
sourabh1007 Nov 18, 2024
eb289e5
fix test
sourabh1007 Nov 20, 2024
1280e13
updated sln
sourabh1007 Nov 21, 2024
675c49f
refactor code
sourabh1007 Nov 21, 2024
b4e2045
test fix
sourabh1007 Nov 21, 2024
3f30e87
Merge branch 'master' into users/sourabhjain/otelnetworkmetrics
sourabh1007 Nov 24, 2024
e4a7459
cleanup
sourabh1007 Nov 24, 2024
164d615
compile fix
sourabh1007 Nov 25, 2024
b03d026
Merge branch 'master' into users/sourabhjain/otelnetworkmetrics
sourabh1007 Nov 25, 2024
e618478
fix direct contract changes
sourabh1007 Nov 25, 2024
f576bc4
exception handling
sourabh1007 Nov 25, 2024
b4a0113
fix tets
sourabh1007 Nov 26, 2024
ff10923
Merge branch 'master' into users/sourabhjain/otelnetworkmetrics
sourabh1007 Nov 26, 2024
8ed1645
refcator code
sourabh1007 Nov 26, 2024
852ebf9
updated contract
sourabh1007 Nov 26, 2024
b71a164
fix bug
sourabh1007 Nov 26, 2024
d10cab2
Merge branch 'master' into users/sourabhjain/otelnetworkmetrics
sourabh1007 Nov 27, 2024
2c9dfcf
Merge branch 'master' into users/sourabhjain/otelnetworkmetrics
sourabh1007 Nov 27, 2024
f3679bc
fix test
sourabh1007 Nov 27, 2024
5e00973
add logs
sourabh1007 Nov 27, 2024
3b7fcb7
fix bug
sourabh1007 Nov 28, 2024
100273b
Merge branch 'master' into users/sourabhjain/otelnetworkmetrics
sourabh1007 Nov 28, 2024
22be226
update pipeline
sourabh1007 Nov 28, 2024
cf4951b
excption handling
sourabh1007 Nov 29, 2024
dc3f71a
fix tests
sourabh1007 Dec 2, 2024
f05a443
fix test
sourabh1007 Dec 2, 2024
66a30fc
Merge branch 'master' into users/sourabhjain/otelnetworkmetrics
sourabh1007 Dec 3, 2024
e5c8e0d
review commenst
sourabh1007 Dec 9, 2024
56d53c7
Add metrics options
sourabh1007 Dec 9, 2024
b902b64
use custom dimensions
sourabh1007 Dec 9, 2024
65609f4
Merge branch 'master' into users/sourabhjain/otelnetworkmetrics
sourabh1007 Dec 13, 2024
f91c17b
fix conflicts
sourabh1007 Dec 13, 2024
83c0a5d
update contract
sourabh1007 Dec 13, 2024
563bfc2
Merge branch 'users/sourabhjain/otelnetworkmetrics' into users/sourab…
sourabh1007 Dec 16, 2024
9b6cf75
Merge branch 'master' into users/sourabhjain/tagcustomized
sourabh1007 Dec 17, 2024
cd26826
conflict resolved
sourabh1007 Dec 17, 2024
08d35bb
refactor code
sourabh1007 Dec 17, 2024
975666d
clean up
sourabh1007 Dec 17, 2024
d9209a5
updated doc
sourabh1007 Dec 17, 2024
0f4af52
contract changes
sourabh1007 Dec 17, 2024
5f9a0de
refactor code
sourabh1007 Dec 17, 2024
39ee183
fix test
sourabh1007 Dec 17, 2024
a4bc4ce
addded docs
sourabh1007 Dec 19, 2024
460399c
test fix for query
sourabh1007 Dec 24, 2024
c0d40c0
contract fix
sourabh1007 Dec 24, 2024
990a664
query iterator fox
sourabh1007 Dec 24, 2024
ba033b9
unused imports
sourabh1007 Dec 24, 2024
462c1fc
code refcator
sourabh1007 Dec 24, 2024
dceaae8
contract update
sourabh1007 Dec 24, 2024
2d80895
udated doc
sourabh1007 Dec 26, 2024
9cc46a0
Merge branch 'master' into users/sourabhjain/tagcustomized
sourabh1007 Dec 29, 2024
4c098e3
Merge branch 'master' into users/sourabhjain/tagcustomized
sourabh1007 Dec 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Microsoft.Azure.Cosmos/src/CosmosClientTelemetryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,15 @@ public class CosmosClientTelemetryOptions
/// <remarks>Metrics data can be published to a monitoring system like Prometheus or Azure Monitor, depending on the configured metrics provider.</remarks>
/// </summary>
public bool IsClientMetricsEnabled { get; set; }

/// <summary>
/// Gets or sets the configuration for operation-level metrics.
/// </summary>
public OperationMetricsOptions OperationMetricsOptions { get; set; }

/// <summary>
/// Gets or sets the configuration for network-level metrics.
/// </summary>
public NetworkMetricsOptions NetworkMetricsOptions { get; set; }
}
}
4 changes: 2 additions & 2 deletions Microsoft.Azure.Cosmos/src/DocumentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,8 @@ internal virtual void Initialize(Uri serviceEndpoint,

if (this.cosmosClientTelemetryOptions.IsClientMetricsEnabled)
{
CosmosDbOperationMeter.Initialize();
CosmosDbNetworkMeter.Initialize();
CosmosDbOperationMeter.Initialize(this.cosmosClientTelemetryOptions);
CosmosDbNetworkMeter.Initialize(this.cosmosClientTelemetryOptions);

CosmosDbOperationMeter.AddInstanceCount(this.ServiceEndpoint);
}
Expand Down
55 changes: 55 additions & 0 deletions Microsoft.Azure.Cosmos/src/NetworkMetricsOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos
{
using System.Collections.Generic;

/// <summary>
/// Represents the configuration options for collecting metrics related to Cosmos DB network operations.
/// </summary>
public class NetworkMetricsOptions
{
/// <summary>
/// <para>
/// Gets or sets a value indicating whether the routing ID (e.g., PK Range ID for Gateway Mode or Partition/Replica information for Direct Mode, if available)
/// should be included in the network metrics.
/// </para>
/// By default, Routing Id information is not included as a dimension in the network metrics.
/// </summary>
/// <remarks>
/// <para>
/// Enabling this option provides greater diagnostic granularity, allowing you to identify issues
/// with specific Partition Key Range IDs, replicas, or partitions.
/// However, including the routing ID as a dimension increases the cardinality of metrics. This can result
/// in significantly higher storage costs and generate a large number of metrics with low sample counts,
/// making analysis more challenging.
/// </para>
/// <para>
/// Carefully evaluate whether the additional granularity is necessary
/// for your use case, as it may lead to increased resource consumption and complexity.
/// </para>
/// </remarks>
public bool? IncludeRoutingId { get; set; }

/// <summary>
/// Gets or sets a collection of custom dimensions to include in the network metrics. Each dimension is defined as a key-value pair.
/// </summary>
/// <example>
/// <code language="c#">
/// <![CDATA[
/// var telemetryOptions = new NetworkMetricsOptions
/// {
/// CustomDimensions = new Dictionary<string, string>
/// {
/// { "Region", "EastUS" },
/// }
/// };
/// ]]>
/// </code>
/// </example>
public IDictionary<string, string> CustomDimensions { get; set; }
}

}
53 changes: 53 additions & 0 deletions Microsoft.Azure.Cosmos/src/OperationMetricsOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos
{
using System.Collections.Generic;

/// <summary>
/// Represents the configuration options for collecting metrics related to Cosmos DB operations.
/// </summary>
public class OperationMetricsOptions
{
/// <summary>
/// <para>
/// Gets or sets a value indicating whether the region information should be included in the operation metrics.
/// </para>
/// By default, Region information is not included as a dimension in the operation metrics.
/// </summary>
/// <remarks>
/// <para>
/// Enabling this option provides greater diagnostic granularity, allowing you to identify issues
/// with specific Partition Key Range IDs, replicas, or partitions.
/// However, including the routing ID as a dimension increases the cardinality of metrics. This can result
/// in significantly higher storage costs and generate a large number of metrics with low sample counts,
/// making analysis more challenging.
/// </para>
/// <para>
/// Carefully evaluate whether the additional granularity is necessary
/// for your use case, as it may lead to increased resource consumption and complexity.
/// </para>
/// </remarks>
public bool? IncludeRegion { get; set; }

/// <summary>
/// Gets or sets a collection of custom dimensions to include in the operation metrics. Each dimension is defined as a key-value pair.
/// </summary>
/// <example>
/// <code language="c#">
/// <![CDATA[
/// var telemetryOptions = new OperationMetricsOptions
/// {
/// CustomDimensions = new Dictionary<string, string>
/// {
/// { "Region", "EastUS" }
/// }
/// };
/// ]]>
/// </code>
/// </example>
public IDictionary<string, string> CustomDimensions { get; set; }
}
}
11 changes: 8 additions & 3 deletions Microsoft.Azure.Cosmos/src/Query/v3Query/QueryIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ private QueryIterator(
this.hasMoreResults = true;
this.correlatedActivityId = correlatedActivityId;

this.querySpec = sqlQuerySpec;
this.container = container;
this.operationName = OpenTelemetryConstants.Operations.QueryItems;
this.operationType = Documents.OperationType.Query;

this.SetupInfoForTelemetry(
databaseName: container?.Database?.Id,
operationName: OpenTelemetryConstants.Operations.QueryItems,
operationType: Documents.OperationType.Query,
querySpec: sqlQuerySpec,
operationMetricsOptions: requestOptions?.OperationMetricsOptions,
networkMetricOptions: requestOptions?.NetworkMetricsOptions);
}

public static QueryIterator Create(
Expand Down
10 changes: 9 additions & 1 deletion Microsoft.Azure.Cosmos/src/ReadFeed/ReadFeedIteratorCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@ public ReadFeedIteratorCore(
CancellationToken cancellationToken)
{
this.container = container;
this.operationName = OpenTelemetryConstants.Operations.ReadFeedRanges;

this.queryRequestOptions = queryRequestOptions;

this.SetupInfoForTelemetry(
databaseName: container?.Database?.Id,
operationName: OpenTelemetryConstants.Operations.ReadFeedRanges,
operationType: OperationType.ReadFeed,
querySpec: null,
operationMetricsOptions: queryRequestOptions?.OperationMetricsOptions,
networkMetricOptions: queryRequestOptions?.NetworkMetricsOptions);

readFeedPaginationOptions ??= ReadFeedExecutionOptions.Default;

if (!string.IsNullOrEmpty(continuationToken))
Expand Down
12 changes: 11 additions & 1 deletion Microsoft.Azure.Cosmos/src/RequestOptions/RequestOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ internal static void SetSessionToken(RequestMessage request, string sessionToken
{
request.Headers.Add(HttpConstants.HttpHeaders.SessionToken, sessionToken);
}
}
}

/// <summary>
/// Gets or sets the configuration for operation-level metrics.
/// </summary>
public OperationMetricsOptions OperationMetricsOptions { get; set; } = null;

/// <summary>
/// Gets or sets the configuration for network-level metrics.
/// </summary>
public NetworkMetricsOptions NetworkMetricsOptions { get; set; } = null;
}
}
5 changes: 5 additions & 0 deletions Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ private async Task<TResult> RunWithDiagnosticsHelperAsync<TResult>(
this.client.Endpoint,
containerName,
databaseName,
requestOptions,
attributes: otelAttributes);
}

Expand All @@ -555,6 +556,7 @@ private async Task<TResult> RunWithDiagnosticsHelperAsync<TResult>(
gatewayEndpoint,
containerName,
databaseName,
requestOptions,
cosmosException: cosmosException);
}

Expand Down Expand Up @@ -609,6 +611,7 @@ private static void RecordMetrics(Func<string> getOperationName,
Uri accountName,
string containerName,
string databaseName,
RequestOptions requestOptions,
OpenTelemetryAttributes attributes = null,
Exception cosmosException = null)
{
Expand All @@ -618,13 +621,15 @@ private static void RecordMetrics(Func<string> getOperationName,
containerName: containerName,
databaseName: databaseName,
attributes: attributes,
operationMetricsOptions: requestOptions?.OperationMetricsOptions,
ex: cosmosException);

CosmosDbNetworkMeter.RecordTelemetry(getOperationName: getOperationName,
accountName: accountName,
containerName: containerName,
databaseName: databaseName,
attributes: attributes,
networkMetricsOptions: requestOptions?.NetworkMetricsOptions,
ex: cosmosException);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Microsoft.Azure.Cosmos
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Query.Core;
using Microsoft.Azure.Documents;

/// <summary>
/// Cosmos Result set iterator that keeps track of the continuation token when retrieving results form a query.
Expand Down Expand Up @@ -151,5 +152,56 @@ public void Dispose()
/// collect SQL query Specs for tracing
/// </summary>
internal SqlQuerySpec querySpec;

/// <summary>
/// Collect operation metrics options for open telemetry metrics
/// </summary>
internal OperationMetricsOptions operationMetricsOptions;

/// <summary>
/// Collect network metrics options for open telemetry metrics
/// </summary>
internal NetworkMetricsOptions networkMetricsOptions;

/// <summary>
/// Setup the information required for telemetry
/// </summary>
/// <param name="feedIteratorInternal"></param>
internal void SetupInfoForTelemetry(FeedIterator feedIteratorInternal)
{
this.SetupInfoForTelemetry(
feedIteratorInternal.databaseName,
feedIteratorInternal.operationName,
feedIteratorInternal.operationType,
feedIteratorInternal.querySpec,
feedIteratorInternal.operationMetricsOptions,
feedIteratorInternal.networkMetricsOptions);
}

/// <summary>
/// Setup the information required for telemetry
/// </summary>
/// <param name="databaseName"></param>
/// <param name="operationName"></param>
/// <param name="operationType"></param>
/// <param name="querySpec"></param>
/// <param name="operationMetricsOptions"></param>
/// <param name="networkMetricOptions"></param>
internal void SetupInfoForTelemetry(string databaseName,
string operationName,
OperationType? operationType,
SqlQuerySpec querySpec,
OperationMetricsOptions operationMetricsOptions,
NetworkMetricsOptions networkMetricOptions)
{
this.databaseName = databaseName;

this.operationName = operationName;
this.operationType = operationType;

this.querySpec = querySpec;
this.operationMetricsOptions = operationMetricsOptions;
this.networkMetricsOptions = networkMetricOptions;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ public FeedIteratorCore(
this.requestOptions = options;
this.hasMoreResultsInternal = true;

this.databaseName = databaseId;
this.container = container;

this.operationName = OpenTelemetryConstants.Operations.QueryItems;
this.operationType = OperationType.Query;
this.SetupInfoForTelemetry(databaseName: databaseId,
operationName: OpenTelemetryConstants.Operations.QueryItems,
operationType: OperationType.Query,
querySpec: this.querySpec,
operationMetricsOptions: options?.OperationMetricsOptions,
networkMetricOptions: options?.NetworkMetricsOptions);
}

public override bool HasMoreResults => this.hasMoreResultsInternal;
Expand Down Expand Up @@ -213,13 +216,20 @@ internal FeedIteratorCore(
this.responseCreator = responseCreator;
this.feedIterator = feedIterator;

this.databaseName = feedIterator.databaseName;
this.container = feedIterator.container;
this.SetupInfoForTelemetry(feedIterator);
}

private void SetupInfoForTelemetry(FeedIterator feedIteratorInternal)
{
this.container = feedIteratorInternal.container;
this.databaseName = feedIteratorInternal.databaseName;

this.operationName = feedIterator.operationName;
this.operationType = feedIterator.operationType;
this.operationName = feedIteratorInternal.operationName;
this.operationType = feedIteratorInternal.operationType;

this.querySpec = feedIterator.querySpec;
this.querySpec = feedIteratorInternal.querySpec;
this.operationMetricsOptions = feedIteratorInternal.operationMetricsOptions;
this.networkMetricsOptions = feedIteratorInternal.networkMetricsOptions;
}

public override bool HasMoreResults => this.feedIterator.HasMoreResults;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ internal FeedIteratorInlineCore(
this.feedIteratorInternal = feedIteratorInternal;
this.clientContext = clientContext;

this.querySpec = feedIteratorInternal.querySpec;
this.container = feedIteratorInternal.container;
this.databaseName = feedIteratorInternal.databaseName;

this.operationName = feedIteratorInternal.operationName;
this.operationType = feedIteratorInternal.operationType;
this.SetupInfoForTelemetry(feedIteratorInternal);
}

internal FeedIteratorInlineCore(
Expand All @@ -44,10 +41,8 @@ internal FeedIteratorInlineCore(
this.clientContext = clientContext;

this.container = feedIteratorInternal.container;
this.databaseName = feedIteratorInternal.databaseName;

this.operationName = feedIteratorInternal.operationName;
this.operationType = feedIteratorInternal.operationType;
this.SetupInfoForTelemetry(feedIteratorInternal);
}

public override bool HasMoreResults => this.feedIteratorInternal.HasMoreResults;
Expand All @@ -59,7 +54,11 @@ public override Task<ResponseMessage> ReadNextAsync(CancellationToken cancellati
containerName: this.container?.Id,
databaseName: this.container?.Database?.Id ?? this.databaseName,
operationType: Documents.OperationType.ReadFeed,
requestOptions: null,
requestOptions: new RequestOptions()
{
OperationMetricsOptions = this.operationMetricsOptions,
NetworkMetricsOptions = this.networkMetricsOptions,
},
task: (trace) => this.feedIteratorInternal.ReadNextAsync(trace, cancellationToken),
openTelemetry: new (this.operationName, (response) =>
{
Expand Down
Loading