Distributed Tracing: Adds Request charge and Payload size Threshold options (#4433)

* Added Request charge and Payload size options to generate request diagnostics

* Added default values

* add exception handling for payload size

* Added test

* update contract file

* added docs

* add null check

* added more docs

* updated contract

* changed event name

* remove unused import
This commit is contained in:
Sourabh Jain 2024-05-02 09:50:26 +05:30 коммит произвёл GitHub
Родитель f304e970c5
Коммит dee9abaedf
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
14 изменённых файлов: 358 добавлений и 209 удалений

Просмотреть файл

@ -10,17 +10,30 @@ namespace Microsoft.Azure.Cosmos
public class CosmosClientTelemetryOptions
{
/// <summary>
/// Disable sending telemetry to service, <see cref="Microsoft.Azure.Cosmos.CosmosThresholdOptions"/> is not applicable to this as of now.
/// Disable sending telemetry data to Microsoft, <see cref="Microsoft.Azure.Cosmos.CosmosThresholdOptions"/> is not applicable for this.
/// </summary>
/// <remarks>This option will disable sending telemetry to service.even it is opt-in from portal.</remarks>
/// <remarks>This feature has to be enabled at 2 places:
/// <list type="bullet">
/// <item>Opt-in from portal to subscribe for this feature.</item>
/// <item>Setting this property to false, to enable it for a particular client instance.</item>
/// </list>
/// </remarks>
/// <value>true</value>
public bool DisableSendingMetricsToService { get; set; } = true;
/// <summary>
/// This method enable/disable generation of operation level <see cref="System.Diagnostics.Activity"/> if listener is subscribed to the Source Name "Azure.Cosmos.Operation".
/// This method enable/disable generation of operation level <see cref="System.Diagnostics.Activity"/> if listener is subscribed to the Source Name <i>"Azure.Cosmos.Operation"</i>(to capture operation level traces)
/// and <i>"Azure-Cosmos-Operation-Request-Diagnostics"</i>(to capture events with request diagnostics JSON)
/// </summary>
/// <value>false</value>
/// <remarks> Please Refer https://opentelemetry.io/docs/instrumentation/net/exporters/ to know more about open telemetry exporters</remarks>
/// <remarks>
/// You can set different thresholds values by setting <see cref="Microsoft.Azure.Cosmos.CosmosThresholdOptions"/>.
/// It would generate events with Request Diagnostics JSON, if any of the configured threshold is crossed, otherwise it would always generate events with Request Diagnostics JSON for failed requests.
/// There is some overhead of emitting the more detailed diagnostics - so recommendation is to choose these thresholds that reduce the noise level
/// and only emit detailed diagnostics when there is really business impact seen.<br></br>
/// Refer <a href="https://opentelemetry.io/docs/instrumentation/net/exporters/"></a> to know more about open telemetry exporters available. <br></br>
/// Refer <a href="https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/sdk-observability?tabs=dotnet"></a> to know more about this feature.
/// </remarks>
public bool DisableDistributedTracing { get; set; } =
#if PREVIEW
false;
@ -30,9 +43,8 @@ namespace Microsoft.Azure.Cosmos
/// <summary>
/// Threshold values for Distributed Tracing.
/// These values decides whether to generate operation level <see cref="System.Diagnostics.Tracing.EventSource"/> with request diagnostics or not.
/// These values decides whether to generate an <see cref="System.Diagnostics.Tracing.EventSource"/> with request diagnostics or not.
/// </summary>
public CosmosThresholdOptions CosmosThresholdOptions { get; set; } = new CosmosThresholdOptions();
}
}

Просмотреть файл

@ -7,20 +7,48 @@ namespace Microsoft.Azure.Cosmos
using System;
/// <summary>
/// Threshold values for Distributed Tracing
/// This class describes the thresholds when more details diagnostics events are emitted, if subscribed, for an operation due to high latency,
/// high RU consumption or high payload sizes.
/// </summary>
public class CosmosThresholdOptions
{
/// <summary>
/// Latency Threshold for non point operations i.e. Query
/// Can be used to define custom latency thresholds. When the latency threshold is exceeded more detailed
/// diagnostics will be emitted (including the request diagnostics). There is some overhead of emitting the
/// more detailed diagnostics - so recommendation is to choose latency thresholds that reduce the noise level
/// and only emit detailed diagnostics when there is really business impact seen.
/// The default value for the point operation latency threshold is 3 seconds.
/// all operations except (ReadItem, CreateItem, UpsertItem, ReplaceItem, PatchItem or DeleteItem)
/// </summary>
/// <value>3 seconds</value>
public TimeSpan NonPointOperationLatencyThreshold { get; set; } = TimeSpan.FromSeconds(3);
/// <summary>
/// Latency Threshold for point operations i.e operation other than Query
/// Can be used to define custom latency thresholds. When the latency threshold is exceeded more detailed
/// diagnostics will be emitted (including the request diagnostics). There is some overhead of emitting the
/// more detailed diagnostics - so recommendation is to choose latency thresholds that reduce the noise level
/// and only emit detailed diagnostics when there is really business impact seen.
/// The default value for the point operation latency threshold is 1 second.
/// Point Operations are: (ReadItem, CreateItem, UpsertItem, ReplaceItem, PatchItem or DeleteItem)
/// </summary>
/// <value>1 second</value>
public TimeSpan PointOperationLatencyThreshold { get; set; } = TimeSpan.FromSeconds(1);
/// <summary>
/// Can be used to define a custom RU (request charge) threshold. When the threshold is exceeded more detailed
/// diagnostics will be emitted (including the request diagnostics). There is some overhead of emitting the
/// more detailed diagnostics - so recommendation is to choose a request charge threshold that reduces the noise
/// level and only emits detailed diagnostics when the request charge is significantly higher than expected.
/// </summary>
public double? RequestChargeThreshold { get; set; } = null;
/// <summary>
/// Can be used to define a payload size threshold. When the threshold is exceeded for either request or
/// response payloads more detailed diagnostics will be emitted (including the request diagnostics).
/// There is some overhead of emitting the more detailed diagnostics - so recommendation is to choose a
/// payload size threshold that reduces the noise level and only emits detailed diagnostics when the payload size
/// is significantly higher than expected.
/// </summary>
public int? PayloadSizeThresholdInBytes { get; set; } = null;
}
}

Просмотреть файл

@ -15,7 +15,7 @@ namespace Microsoft.Azure.Cosmos.Telemetry
internal sealed class CosmosDbEventSource : AzureEventSource
{
internal const string EventSourceName = "Azure-Cosmos-Operation-Request-Diagnostics";
private static CosmosDbEventSource Singleton { get; } = new CosmosDbEventSource();
private CosmosDbEventSource()
@ -35,17 +35,26 @@ namespace Microsoft.Azure.Cosmos.Telemetry
Documents.OperationType operationType,
OpenTelemetryAttributes response)
{
if (!DiagnosticsFilterHelper.IsSuccessfulResponse(
response.StatusCode, response.SubStatusCode) && CosmosDbEventSource.IsEnabled(EventLevel.Warning))
if (CosmosDbEventSource.IsEnabled(EventLevel.Warning))
{
CosmosDbEventSource.Singleton.FailedRequest(response.Diagnostics.ToString());
}
else if (DiagnosticsFilterHelper.IsLatencyThresholdCrossed(
config: config,
operationType: operationType,
response: response) && CosmosDbEventSource.IsEnabled(EventLevel.Warning))
{
CosmosDbEventSource.Singleton.LatencyOverThreshold(response.Diagnostics.ToString());
if (!DiagnosticsFilterHelper.IsSuccessfulResponse(
response.StatusCode, response.SubStatusCode))
{
CosmosDbEventSource.Singleton.FailedRequest(response.Diagnostics.ToString());
}
else if (DiagnosticsFilterHelper.IsLatencyThresholdCrossed(
config: config,
operationType: operationType,
response: response) ||
(config.RequestChargeThreshold is not null &&
config.RequestChargeThreshold <= response.RequestCharge) ||
(config.PayloadSizeThresholdInBytes is not null &&
DiagnosticsFilterHelper.IsPayloadSizeThresholdCrossed(
config: config,
response: response)))
{
CosmosDbEventSource.Singleton.ThresholdViolation(response.Diagnostics.ToString());
}
}
}
@ -65,7 +74,7 @@ namespace Microsoft.Azure.Cosmos.Telemetry
}
[Event(2, Level = EventLevel.Warning)]
private void LatencyOverThreshold(string message)
private void ThresholdViolation(string message)
{
this.WriteEvent(2, message);
}

Просмотреть файл

@ -21,28 +21,59 @@ namespace Microsoft.Azure.Cosmos.Telemetry.Diagnostics
OperationType operationType,
OpenTelemetryAttributes response)
{
return response.Diagnostics.GetClientElapsedTime() > DiagnosticsFilterHelper.DefaultThreshold(operationType, config);
return response.Diagnostics.GetClientElapsedTime() > DiagnosticsFilterHelper.DefaultLatencyThreshold(operationType, config);
}
/// <summary>
/// Allow only Payload size(request/response) is more the configured threshold
/// </summary>
/// <returns>true or false</returns>
public static bool IsPayloadSizeThresholdCrossed(
CosmosThresholdOptions config,
OpenTelemetryAttributes response)
{
int requestContentLength = 0;
int responseContentLength = 0;
try
{
requestContentLength = Convert.ToInt32(response.RequestContentLength);
}
catch (Exception)
{
// Ignore, if this conversion fails for any reason.
}
try
{
responseContentLength = Convert.ToInt32(response.ResponseContentLength);
}
catch (Exception)
{
// Ignore, if this conversion fails for any reason.
}
return config.PayloadSizeThresholdInBytes <= Math.Max(requestContentLength, responseContentLength);
}
/// <summary>
/// Check if response HTTP status code is returning successful
/// </summary>
/// <returns>true or false</returns>
public static bool IsSuccessfulResponse(HttpStatusCode statusCode, int substatusCode)
public static bool IsSuccessfulResponse(HttpStatusCode statusCode, int subStatusCode)
{
return statusCode.IsSuccess()
|| (statusCode == System.Net.HttpStatusCode.NotFound && substatusCode == 0)
|| (statusCode == System.Net.HttpStatusCode.NotModified && substatusCode == 0)
|| (statusCode == System.Net.HttpStatusCode.Conflict && substatusCode == 0)
|| (statusCode == System.Net.HttpStatusCode.PreconditionFailed && substatusCode == 0);
|| (statusCode == System.Net.HttpStatusCode.NotFound && subStatusCode == 0)
|| (statusCode == System.Net.HttpStatusCode.NotModified && subStatusCode == 0)
|| (statusCode == System.Net.HttpStatusCode.Conflict && subStatusCode == 0)
|| (statusCode == System.Net.HttpStatusCode.PreconditionFailed && subStatusCode == 0);
}
/// <summary>
/// Get default threshold value based on operation type
/// Get default Latency threshold value based on operation type
/// </summary>
/// <param name="operationType"></param>
/// <param name="config"></param>
internal static TimeSpan DefaultThreshold(OperationType operationType, CosmosThresholdOptions config)
internal static TimeSpan DefaultLatencyThreshold(OperationType operationType, CosmosThresholdOptions config)
{
config ??= DiagnosticsFilterHelper.defaultThresholdOptions;
return DiagnosticsFilterHelper.IsPointOperation(operationType) ?

Просмотреть файл

@ -343,16 +343,16 @@
<ATTRIBUTE key="db.cosmosdb.request_charge">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -680,16 +680,16 @@
<ATTRIBUTE key="db.cosmosdb.request_charge">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -1017,16 +1017,16 @@
<ATTRIBUTE key="db.cosmosdb.request_charge">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -1354,16 +1354,16 @@
<ATTRIBUTE key="db.cosmosdb.request_charge">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -1691,16 +1691,16 @@
<ATTRIBUTE key="db.cosmosdb.request_charge">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -2028,16 +2028,16 @@
<ATTRIBUTE key="db.cosmosdb.request_charge">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -2365,16 +2365,16 @@
<ATTRIBUTE key="db.cosmosdb.request_charge">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -2702,16 +2702,16 @@
<ATTRIBUTE key="db.cosmosdb.request_charge">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -3039,16 +3039,16 @@
<ATTRIBUTE key="db.cosmosdb.request_charge">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -3376,16 +3376,16 @@
<ATTRIBUTE key="db.cosmosdb.request_charge">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>

Просмотреть файл

@ -1118,11 +1118,11 @@
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -1864,11 +1864,11 @@
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -2591,11 +2591,11 @@
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -3338,11 +3338,11 @@
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -3662,7 +3662,7 @@
<ATTRIBUTE key="db.cosmosdb.request_charge">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
</Results>

Просмотреть файл

@ -151,8 +151,8 @@
<ATTRIBUTE key="db.cosmosdb.request_charge">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -292,8 +292,8 @@
<ATTRIBUTE key="db.cosmosdb.request_charge">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
</Results>

Просмотреть файл

@ -694,10 +694,10 @@
<ATTRIBUTE key="db.cosmosdb.correlated_activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -1415,10 +1415,10 @@
<ATTRIBUTE key="db.cosmosdb.correlated_activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -2117,10 +2117,10 @@
<ATTRIBUTE key="db.cosmosdb.correlated_activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -2839,10 +2839,10 @@
<ATTRIBUTE key="db.cosmosdb.correlated_activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -3635,10 +3635,10 @@
<ATTRIBUTE key="db.cosmosdb.correlated_activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -4346,10 +4346,10 @@
<ATTRIBUTE key="db.cosmosdb.correlated_activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -5077,10 +5077,10 @@
<ATTRIBUTE key="db.cosmosdb.correlated_activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
</Results>

Просмотреть файл

@ -656,10 +656,10 @@
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -1339,10 +1339,10 @@
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -2003,10 +2003,10 @@
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -2687,10 +2687,10 @@
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
</Results>

Просмотреть файл

@ -569,7 +569,7 @@
<ATTRIBUTE key="db.cosmosdb.request_charge">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -1154,7 +1154,7 @@
<ATTRIBUTE key="db.cosmosdb.request_charge">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
</Results>

Просмотреть файл

@ -118,7 +118,7 @@
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -234,7 +234,7 @@
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -358,7 +358,7 @@
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -477,7 +477,7 @@
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
</Results>

Просмотреть файл

@ -138,7 +138,7 @@
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -259,7 +259,7 @@
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -393,7 +393,7 @@
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
<Result>
@ -516,7 +516,7 @@
<ATTRIBUTE key="db.cosmosdb.activity_id">Some Value</ATTRIBUTE>
<ATTRIBUTE key="db.cosmosdb.regions_contacted">South Central US</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="ThresholdViolation" />
</OTelActivities></Output>
</Result>
</Results>

Просмотреть файл

@ -3686,6 +3686,30 @@
"Microsoft.Azure.Cosmos.CosmosThresholdOptions;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": {
"Subclasses": {},
"Members": {
"System.Nullable`1[System.Double] get_RequestChargeThreshold()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": {
"Type": "Method",
"Attributes": [
"CompilerGeneratedAttribute"
],
"MethodInfo": "System.Nullable`1[System.Double] get_RequestChargeThreshold();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.Nullable`1[System.Double] RequestChargeThreshold": {
"Type": "Property",
"Attributes": [],
"MethodInfo": "System.Nullable`1[System.Double] RequestChargeThreshold;CanRead:True;CanWrite:True;System.Nullable`1[System.Double] get_RequestChargeThreshold();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_RequestChargeThreshold(System.Nullable`1[System.Double]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.Nullable`1[System.Int32] get_PayloadSizeThresholdInBytes()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": {
"Type": "Method",
"Attributes": [
"CompilerGeneratedAttribute"
],
"MethodInfo": "System.Nullable`1[System.Int32] get_PayloadSizeThresholdInBytes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.Nullable`1[System.Int32] PayloadSizeThresholdInBytes": {
"Type": "Property",
"Attributes": [],
"MethodInfo": "System.Nullable`1[System.Int32] PayloadSizeThresholdInBytes;CanRead:True;CanWrite:True;System.Nullable`1[System.Int32] get_PayloadSizeThresholdInBytes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_PayloadSizeThresholdInBytes(System.Nullable`1[System.Int32]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.TimeSpan get_NonPointOperationLatencyThreshold()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": {
"Type": "Method",
"Attributes": [
@ -3722,12 +3746,26 @@
],
"MethodInfo": "Void set_NonPointOperationLatencyThreshold(System.TimeSpan);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Void set_PayloadSizeThresholdInBytes(System.Nullable`1[System.Int32])[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": {
"Type": "Method",
"Attributes": [
"CompilerGeneratedAttribute"
],
"MethodInfo": "Void set_PayloadSizeThresholdInBytes(System.Nullable`1[System.Int32]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Void set_PointOperationLatencyThreshold(System.TimeSpan)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": {
"Type": "Method",
"Attributes": [
"CompilerGeneratedAttribute"
],
"MethodInfo": "Void set_PointOperationLatencyThreshold(System.TimeSpan);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Void set_RequestChargeThreshold(System.Nullable`1[System.Double])[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": {
"Type": "Method",
"Attributes": [
"CompilerGeneratedAttribute"
],
"MethodInfo": "Void set_RequestChargeThreshold(System.Nullable`1[System.Double]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
}
},
"NestedTypes": {}

Просмотреть файл

@ -51,6 +51,37 @@ namespace Microsoft.Azure.Cosmos.Tests.Telemetry
$"and Is response Success : {response.StatusCode.IsSuccess()}" );
}
[TestMethod]
[DataRow("50", "60", false, DisplayName = "When Request and Response content length is less than threshold.")]
[DataRow("150", "60", true, DisplayName = "When Request content length is greater than threshold but response content length is less than threshold.")]
[DataRow("50", "160", true, DisplayName = "When Request content length is less than threshold but response content length is greater than threshold.")]
[DataRow("150", "160", true, DisplayName = "When Request and Response content length is greater than threshold.")]
[DataRow("Invalid Request Length", "160", true, DisplayName = "When Request content length is 'Invalid' and response content length is greater than threshold.")]
[DataRow("Invalid Request Length", "60", false, DisplayName = "When Request content length is 'Invalid' and response content length is less than threshold.")]
[DataRow("150", "Invalid Response Length", true, DisplayName = "When Request content length is greater than threshold and response content length is 'Invalid'.")]
[DataRow("50", "Invalid Response Length", false, DisplayName = "When Request content length is less than threshold and response content length is 'invalid'.")]
[DataRow(null, "160", true, DisplayName = "When Request content length is 'null' and response content length is greater than threshold.")]
[DataRow(null, "60", false, DisplayName = "When Request content length is 'null' and response content length is less than threshold.")]
[DataRow("150", null, true, DisplayName = "When Request content length is greater than threshold and response content length is 'null'.")]
[DataRow("50", null, false, DisplayName = "When Request content length is less than threshold and response content length is 'null'.")]
public void CheckReturnFalseOnSuccessAndLowerPayloadSizeThanConfiguredConfig(string requestContentLength, string responseContentLength, bool expectedResult)
{
CosmosThresholdOptions distributedTracingOptions = new CosmosThresholdOptions
{
PayloadSizeThresholdInBytes = 100
};
OpenTelemetryAttributes response = new OpenTelemetryAttributes
{
ResponseContentLength = requestContentLength,
RequestContentLength = responseContentLength,
};
Assert.AreEqual(expectedResult,
DiagnosticsFilterHelper
.IsPayloadSizeThresholdCrossed(distributedTracingOptions, response));
}
[TestMethod]
public void CheckReturnTrueOnFailedStatusCode()
{
@ -79,7 +110,7 @@ namespace Microsoft.Azure.Cosmos.Tests.Telemetry
foreach(OperationType operationType in values)
{
TimeSpan defaultThreshold = DiagnosticsFilterHelper.DefaultThreshold(operationType, config);
TimeSpan defaultThreshold = DiagnosticsFilterHelper.DefaultLatencyThreshold(operationType, config);
if(DiagnosticsFilterHelper.IsPointOperation(operationType))
Assert.AreEqual(defaultThreshold, config.PointOperationLatencyThreshold);