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

OperationCanceledException: Adds Exception Trace as Child #3319

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 @@ -50,7 +50,10 @@ internal CosmosOperationCanceledException(
throw new ArgumentNullException(nameof(trace));
}

trace.AddDatum("Operation Cancelled Exception", originalException);
using (ITrace child = trace.StartChild("CosmosOperationCanceledException"))
imanvt marked this conversation as resolved.
Show resolved Hide resolved
{
child.AddDatum("Operation Cancelled Exception", originalException);
}
this.Diagnostics = new CosmosTraceDiagnostics(trace);
this.tokenCancellationRequested = originalException.CancellationToken.IsCancellationRequested;
this.toStringMessage = this.CreateToStringMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Diagnostics;
using Microsoft.Azure.Cosmos.Tracing;
Expand Down Expand Up @@ -133,5 +134,27 @@ public async Task CachedSerializationTest()
string deserializedJson = Encoding.UTF8.GetString(clientConfigurationTraceDatum.SerializedJson.Span);
Assert.IsTrue(deserializedJson.Contains("ConnectionMode"));
}

[TestMethod]
public async Task VerifyDiagnosticsOrderTest()
{
ToDoActivity testItem = ToDoActivity.CreateRandomToDoActivity();
ItemResponse<ToDoActivity> response = await this.Container.CreateItemAsync(testItem, new Cosmos.PartitionKey(testItem.pk));
ITrace trace = ((CosmosTraceDiagnostics)response.Diagnostics).Value;
TestCommon.CreateCosmosClient();
CancellationToken token = new CancellationToken(canceled: true);
try
{
response = await this.Container.ReadItemAsync<ToDoActivity>(testItem.id, new Cosmos.PartitionKey(testItem.pk), cancellationToken: token);
Assert.Fail("Test should throw/catch a CosmosOperationCanceledException");
}
catch (CosmosOperationCanceledException oce)
{
IReadOnlyList<ITrace> children = ((CosmosTraceDiagnostics)oce.Diagnostics).Value.Children;
ITrace exceptionChild = children[^1];
Assert.AreEqual("CosmosOperationCanceledException", exceptionChild.Name);
Assert.IsNotNull(exceptionChild.Data["Operation Cancelled Exception"]);
}
}
}
}