Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
review comments
  • Loading branch information
sourabh1007 committed Jan 5, 2023
commit dbba65f4f3dba3d0a8f27388a9fc842d41c6dd6c
4 changes: 2 additions & 2 deletions Microsoft.Azure.Cosmos/src/Headers/Headers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public virtual string ContinuationToken
/// </summary>
internal virtual string CorrelatedActivityId
{
get => this.CosmosMessageHeaders.INameValueCollection.Get(HttpConstants.HttpHeaders.CorrelatedActivityId);
set => this.CosmosMessageHeaders.INameValueCollection.Set(HttpConstants.HttpHeaders.CorrelatedActivityId, value);
get => this.CosmosMessageHeaders.INameValueCollection?.Get(HttpConstants.HttpHeaders.CorrelatedActivityId);
set => this.CosmosMessageHeaders.INameValueCollection?.Set(HttpConstants.HttpHeaders.CorrelatedActivityId, value);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static bool IsEnabled(EventLevel level)
[NonEvent]
public static void RecordDiagnosticsForRequests(
DistributedTracingOptions config,
string operationType,
Documents.OperationType operationType,
OpenTelemetryAttributes response)
{
if (DiagnosticsFilterHelper.IsTracingNeeded(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal static class DiagnosticsFilterHelper
/// <returns>true or false</returns>
public static bool IsTracingNeeded(
DistributedTracingOptions config,
string operationType,
Documents.OperationType operationType,
OpenTelemetryAttributes response)
{
TimeSpan latencyThreshold;
Expand All @@ -28,7 +28,7 @@ public static bool IsTracingNeeded(
}
else
{
latencyThreshold = operationType == OperationType.Query.ToString() ? DistributedTracingOptions.DefaultQueryTimeoutThreshold : DistributedTracingOptions.DefaultCrudLatencyThreshold;
latencyThreshold = operationType == OperationType.Query ? DistributedTracingOptions.DefaultQueryTimeoutThreshold : DistributedTracingOptions.DefaultCrudLatencyThreshold;
}

return response.Diagnostics.GetClientElapsedTime() > latencyThreshold || !response.StatusCode.IsSuccess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ internal OpenTelemetryAttributes(RequestMessage requestMessage)
/// <summary>
/// OperationType
/// </summary>
internal string OperationType { get; set; }
internal Documents.OperationType OperationType { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ namespace Microsoft.Azure.Cosmos.Telemetry
internal struct OpenTelemetryCoreRecorder : IDisposable
{
private const string CosmosDb = "cosmosdb";

private readonly DiagnosticScope scope;
private readonly DistributedTracingOptions config;

private readonly string operationType;
private readonly Documents.OperationType operationType;
private OpenTelemetryAttributes response = null;

internal static IDictionary<Type, Action<Exception, DiagnosticScope>> OTelCompatibleExceptions = new Dictionary<Type, Action<Exception, DiagnosticScope>>()
Expand All @@ -41,7 +41,7 @@ public OpenTelemetryCoreRecorder(
{
this.scope = scope;
this.config = config;
this.operationType = operationType.ToString();
this.operationType = operationType;

if (scope.IsEnabled)
{
Expand Down Expand Up @@ -155,7 +155,8 @@ public void Dispose()
{
if (this.scope.IsEnabled)
{
string operationType = this.response?.OperationType ?? this.operationType;
Documents.OperationType operationType
= (this.response == null || this.response?.OperationType == Documents.OperationType.Invalid) ? this.operationType : this.response.OperationType;

this.scope.AddAttribute(OpenTelemetryAttributeKeys.OperationType, operationType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal OpenTelemetryResponse(TransactionalBatchResponse responseMessage)
itemCount: responseMessage.Headers?.ItemCount,
requestMessage: null,
subStatusCode: (int)responseMessage.Headers?.SubStatusCode,
activityId: string.Join(",", responseMessage.GetActivityIds()),
activityId: responseMessage.Headers?.ActivityId,
correlationId: responseMessage.Headers?.CorrelatedActivityId)
{
}
Expand All @@ -35,7 +35,7 @@ internal OpenTelemetryResponse(ResponseMessage responseMessage)
subStatusCode: (int)responseMessage.Headers?.SubStatusCode,
activityId: responseMessage.Headers?.ActivityId,
correlationId: responseMessage.Headers?.CorrelatedActivityId,
operationType: responseMessage is QueryResponse ? Documents.OperationType.Query.ToString() : null
operationType: responseMessage is QueryResponse ? Documents.OperationType.Query : Documents.OperationType.Invalid
)
{
}
Expand All @@ -50,7 +50,7 @@ private OpenTelemetryResponse(
int subStatusCode,
string activityId,
string correlationId,
string operationType = null)
Documents.OperationType operationType = Documents.OperationType.Invalid)
: base(requestMessage)
{
this.StatusCode = statusCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal OpenTelemetryResponse(FeedResponse<T> responseMessage)
subStatusCode: (int)responseMessage.Headers?.SubStatusCode,
activityId: responseMessage.Headers?.ActivityId,
correlatedActivityId: responseMessage.Headers?.CorrelatedActivityId,
operationType: responseMessage is QueryResponse<T> ? Documents.OperationType.Query.ToString() : null)
operationType: responseMessage is QueryResponse<T> ? Documents.OperationType.Query : Documents.OperationType.Invalid)
{
}

Expand All @@ -35,7 +35,7 @@ internal OpenTelemetryResponse(Response<T> responseMessage)
subStatusCode: (int)responseMessage.Headers?.SubStatusCode,
activityId: responseMessage.Headers?.ActivityId,
correlatedActivityId: responseMessage.Headers?.CorrelatedActivityId,
operationType: responseMessage is QueryResponse ? Documents.OperationType.Query.ToString() : null)
operationType: responseMessage is QueryResponse ? Documents.OperationType.Query : Documents.OperationType.Invalid)
{
}

Expand All @@ -49,7 +49,7 @@ private OpenTelemetryResponse(
int subStatusCode,
string activityId,
string correlatedActivityId,
string operationType)
Documents.OperationType operationType)
: base(requestMessage)
{
this.StatusCode = statusCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void CheckReturnFalseOnSuccessAndLowerLatencyThanConfiguredConfig()

Assert.IsFalse(
DiagnosticsFilterHelper
.IsTracingNeeded(distributedTracingOptions, OperationType.Read.ToString(), response),
.IsTracingNeeded(distributedTracingOptions, OperationType.Read, response),
$" Response time is {response.Diagnostics.GetClientElapsedTime().Milliseconds}ms " +
$"and Configured threshold value is {distributedTracingOptions.DiagnosticsLatencyThreshold.Value.Milliseconds}ms " +
$"and Is response Success : {response.StatusCode.IsSuccess()}" );
Expand All @@ -74,7 +74,7 @@ public void CheckReturnTrueOnFailedStatusCode()

Assert.IsTrue(
DiagnosticsFilterHelper
.IsTracingNeeded(distributedTracingOptions, OperationType.Read.ToString(), response),
.IsTracingNeeded(distributedTracingOptions, OperationType.Read, response),
$" Response time is {response.Diagnostics.GetClientElapsedTime().Milliseconds}ms " +
$"and Configured threshold value is {distributedTracingOptions.DiagnosticsLatencyThreshold.Value.Milliseconds}ms " +
$"and Is response Success : {response.StatusCode.IsSuccess()}");
Expand Down