public void ValidateDiagnosticsAppendContext() { CosmosDiagnosticsContext cosmosDiagnostics = new CosmosDiagnosticsContext(); // Test all the different operations on diagnostics context cosmosDiagnostics.Summary.AddSdkRetry(TimeSpan.FromSeconds(42)); using (cosmosDiagnostics.CreateScope("ValidateScope")) { Thread.Sleep(TimeSpan.FromSeconds(2)); } cosmosDiagnostics.Summary.SetSdkUserAgent("MyCustomUserAgentString"); CosmosDiagnosticsContext cosmosDiagnostics2 = new CosmosDiagnosticsContext(); using (cosmosDiagnostics.CreateScope("CosmosDiagnostics2Scope")) { Thread.Sleep(TimeSpan.FromMilliseconds(100)); } cosmosDiagnostics2.Append(cosmosDiagnostics); string diagnostics = cosmosDiagnostics2.ToString(); Assert.IsTrue(diagnostics.Contains("MyCustomUserAgentString")); Assert.IsTrue(diagnostics.Contains("ValidateScope")); Assert.IsTrue(diagnostics.Contains("CosmosDiagnostics2Scope")); }
internal async Task <Response <T> > AggregateResultAsync(CancellationToken cancellationToken = default) { List <T> result = new List <T>(); CosmosDiagnosticsContext diagnosticsContext = null; Headers headers = new Headers(); FeedIterator <T> localFeedIterator = this.CreateFeedIterator(false); while (localFeedIterator.HasMoreResults) { FeedResponse <T> response = await localFeedIterator.ReadNextAsync(); headers.RequestCharge += response.RequestCharge; // If the first page has a diagnostic context use that. Else create a new one and add the diagnostic to it. if (response.Diagnostics is CosmosDiagnosticsContext responseDiagnosticContext) { if (diagnosticsContext == null) { diagnosticsContext = responseDiagnosticContext; } else { diagnosticsContext.Append(responseDiagnosticContext); } } else { throw new ArgumentException($"Invalid diagnostic object {response.Diagnostics.GetType().FullName}"); } result.AddRange(response); } return(new ItemResponse <T>( System.Net.HttpStatusCode.OK, headers, result.FirstOrDefault(), diagnosticsContext)); }