Skip to content

Commit

Permalink
[INTERNAL] Open Telemetry: Adds documentation with details (#4944)
Browse files Browse the repository at this point in the history
## Description

1. Remove Client Telemetry Documentation
2. Added Open Telemetry Traces/Metrics Documentation
3. Added Traces for recording telemetry

---------

Co-authored-by: Kiran Kumar Kolli <kirankk@microsoft.com>
  • Loading branch information
sourabh1007 and kirankumarkolli authored Jan 8, 2025
1 parent 76f0e7b commit 9b2fae6
Show file tree
Hide file tree
Showing 3 changed files with 235 additions and 114 deletions.
40 changes: 24 additions & 16 deletions Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Microsoft.Azure.Cosmos
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Core.Trace;
using Microsoft.Azure.Cosmos.Handlers;
using Microsoft.Azure.Cosmos.Resource.CosmosExceptions;
using Microsoft.Azure.Cosmos.Routing;
Expand Down Expand Up @@ -616,22 +617,29 @@ private static void RecordMetrics(Func<string> getOperationName,
OpenTelemetryAttributes attributes = null,
Exception cosmosException = null)
{
// Records telemetry data
CosmosDbOperationMeter.RecordTelemetry(getOperationName: getOperationName,
accountName: accountName,
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);
try
{
// Records telemetry data
CosmosDbOperationMeter.RecordTelemetry(getOperationName: getOperationName,
accountName: accountName,
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);
}
catch (Exception ex)
{
DefaultTrace.TraceError(ex.ToString());
}
}

private async Task<ResponseMessage> ProcessResourceOperationAsBulkStreamAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,34 +102,27 @@ internal static void RecordTelemetry(
return;
}

try
Func<KeyValuePair<string, object>[]> dimensionsFunc = () =>
DimensionPopulator.PopulateOperationMeterDimensions(
getOperationName(),
containerName,
databaseName,
accountName,
attributes,
ex,
operationMetricsOptions);

if (CosmosDbMeterUtil.TryOperationMetricsValues(attributes, ex, out OperationMetricData value))
{
Func<KeyValuePair<string, object>[]> dimensionsFunc = () =>
DimensionPopulator.PopulateOperationMeterDimensions(
getOperationName(),
containerName,
databaseName,
accountName,
attributes,
ex,
operationMetricsOptions);

if (CosmosDbMeterUtil.TryOperationMetricsValues(attributes, ex, out OperationMetricData value))
{
CosmosDbMeterUtil.RecordHistogramMetric<int>(value.ItemCount, dimensionsFunc, ActualItemHistogram, Convert.ToInt32);
CosmosDbMeterUtil.RecordHistogramMetric<double>(value.RequestCharge, dimensionsFunc, RequestUnitsHistogram);
}

if (CosmosDbMeterUtil.TryGetDiagnostics(attributes, ex, out CosmosTraceDiagnostics diagnostics))
{
CosmosDbMeterUtil.RecordHistogramMetric<double>(value: diagnostics.GetClientElapsedTime(),
dimensionsFunc, RequestLatencyHistogram,
t => ((TimeSpan)t).TotalSeconds);
}
CosmosDbMeterUtil.RecordHistogramMetric<int>(value.ItemCount, dimensionsFunc, ActualItemHistogram, Convert.ToInt32);
CosmosDbMeterUtil.RecordHistogramMetric<double>(value.RequestCharge, dimensionsFunc, RequestUnitsHistogram);
}
catch (Exception exception)

if (CosmosDbMeterUtil.TryGetDiagnostics(attributes, ex, out CosmosTraceDiagnostics diagnostics))
{
DefaultTrace.TraceWarning($"Failed to record telemetry data. {exception.StackTrace}");
CosmosDbMeterUtil.RecordHistogramMetric<double>(value: diagnostics.GetClientElapsedTime(),
dimensionsFunc, RequestLatencyHistogram,
t => ((TimeSpan)t).TotalSeconds);
}
}

Expand Down
Loading

0 comments on commit 9b2fae6

Please sign in to comment.