Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AI Integration: Adds SubStatusCode Information in attributes #3533

Merged
merged 4 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ private string ToStringHelper(
internal static void RecordOtelAttributes(CosmosException exception, DiagnosticScope scope)
{
scope.AddAttribute(OpenTelemetryAttributeKeys.StatusCode, exception.StatusCode);
scope.AddAttribute(OpenTelemetryAttributeKeys.SubStatusCode, exception.SubStatusCode);
scope.AddAttribute(OpenTelemetryAttributeKeys.RequestCharge, exception.RequestCharge);
scope.AddAttribute(OpenTelemetryAttributeKeys.Region,
ClientTelemetryHelper.GetContactedRegions(exception.Diagnostics?.GetContactedRegions()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ internal sealed class OpenTelemetryAttributeKeys
public const string RequestContentLength = "db.cosmosdb.request_content_length_bytes";
public const string ResponseContentLength = "db.cosmosdb.response_content_length_bytes";
public const string StatusCode = "db.cosmosdb.status_code";
public const string SubStatusCode = "db.cosmosdb.sub_status_code";
public const string RequestCharge = "db.cosmosdb.request_charge";
public const string Region = "db.cosmosdb.regions_contacted";
public const string RetryCount = "db.cosmosdb.retry_count";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,10 @@ internal OpenTelemetryAttributes(RequestMessage requestMessage, string container
/// OperationType
/// </summary>
internal string OperationType { get; set; }

/// <summary>
/// SubStatusCode
/// </summary>
internal int SubStatusCode { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public void Record(OpenTelemetryAttributes response)
this.scope.AddAttribute(OpenTelemetryAttributeKeys.RequestContentLength, response.RequestContentLength);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ResponseContentLength, response.ResponseContentLength);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.StatusCode, response.StatusCode);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.SubStatusCode, response.SubStatusCode);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.RequestCharge, response.RequestCharge);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ItemCount, response.ItemCount);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.OperationType, response.OperationType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ internal OpenTelemetryResponse(TransactionalBatchResponse responseMessage, strin
itemCount: responseMessage.Headers?.ItemCount,
databaseName: databaseName,
containerName: containerName,
requestMessage: null)
requestMessage: null,
subStatusCode: (int)responseMessage.Headers?.SubStatusCode)
{
}

Expand All @@ -32,7 +33,8 @@ internal OpenTelemetryResponse(ResponseMessage responseMessage, string container
itemCount: responseMessage.Headers?.ItemCount,
databaseName: databaseName,
containerName: containerName,
requestMessage: responseMessage.RequestMessage)
requestMessage: responseMessage.RequestMessage,
subStatusCode: (int)responseMessage.Headers?.SubStatusCode)
{
}

Expand All @@ -44,14 +46,16 @@ private OpenTelemetryResponse(
string itemCount,
string databaseName,
string containerName,
RequestMessage requestMessage)
RequestMessage requestMessage,
int subStatusCode)
: base(requestMessage, containerName, databaseName)
{
this.StatusCode = statusCode;
this.RequestCharge = requestCharge;
this.ResponseContentLength = responseContentLength ?? OpenTelemetryAttributes.NotAvailable;
this.Diagnostics = diagnostics;
this.ItemCount = itemCount ?? OpenTelemetryAttributes.NotAvailable;
this.ItemCount = itemCount ?? OpenTelemetryAttributes.NotAvailable;
this.SubStatusCode = subStatusCode;
}

private static string GetPayloadSize(ResponseMessage response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ internal OpenTelemetryResponse(FeedResponse<T> responseMessage, string container
itemCount: responseMessage.Headers?.ItemCount,
databaseName: databaseName,
containerName: containerName,
requestMessage: responseMessage.RequestMessage)
requestMessage: responseMessage.RequestMessage,
subStatusCode: (int)responseMessage.Headers?.SubStatusCode)
{
}

Expand All @@ -31,7 +32,8 @@ internal OpenTelemetryResponse(Response<T> responseMessage, string containerName
itemCount: responseMessage.Headers?.ItemCount,
databaseName: databaseName,
containerName: containerName,
requestMessage: responseMessage.RequestMessage)
requestMessage: responseMessage.RequestMessage,
subStatusCode: (int)responseMessage.Headers?.SubStatusCode)
{
}

Expand All @@ -43,14 +45,16 @@ private OpenTelemetryResponse(
string itemCount,
string databaseName,
string containerName,
RequestMessage requestMessage)
RequestMessage requestMessage,
int subStatusCode)
: base(requestMessage, containerName, databaseName)
{
this.StatusCode = statusCode;
this.RequestCharge = requestCharge;
this.ResponseContentLength = responseContentLength ?? OpenTelemetryAttributes.NotAvailable;
this.Diagnostics = diagnostics;
this.ItemCount = itemCount ?? OpenTelemetryAttributes.NotAvailable;
this.SubStatusCode = subStatusCode;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
}
]
}]]></Json>
<OTelActivities><ACTIVITY><OPERATION>Cosmos.ExecuteAsync</OPERATION><ATTRIBUTE-KEY>kind</ATTRIBUTE-KEY><ATTRIBUTE-KEY>az.namespace</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.system</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.hashed_machine_id</ATTRIBUTE-KEY><ATTRIBUTE-KEY>net.peer.name</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.client_id</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.user_agent</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.connection_mode</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.operation</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.name</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.container</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.request_content_length_bytes</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.response_content_length_bytes</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.status_code</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.request_charge</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.item_count</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.operation_type</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.regions_contacted</ATTRIBUTE-KEY></ACTIVITY>
<OTelActivities><ACTIVITY><OPERATION>Cosmos.ExecuteAsync</OPERATION><ATTRIBUTE-KEY>kind</ATTRIBUTE-KEY><ATTRIBUTE-KEY>az.namespace</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.system</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.hashed_machine_id</ATTRIBUTE-KEY><ATTRIBUTE-KEY>net.peer.name</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.client_id</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.user_agent</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.connection_mode</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.operation</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.name</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.container</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.request_content_length_bytes</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.response_content_length_bytes</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.status_code</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.sub_status_code</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.request_charge</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.item_count</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.operation_type</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.regions_contacted</ATTRIBUTE-KEY></ACTIVITY>
sourabh1007 marked this conversation as resolved.
Show resolved Hide resolved
<EVENT>Ideally, this should contain request diagnostics but request diagnostics is subject to change with each request as it contains few unique id. So just putting this tag with this static text to make sure event is getting generated for each test.</EVENT>
</OTelActivities>
</Output>
Expand Down
Loading