public override Output ExecuteTest(Input input) { string text = TraceWriter.TraceToText(input.Trace); string json = TraceWriter.TraceToJson(input.Trace); return(new Output(text, JToken.Parse(json).ToString(Newtonsoft.Json.Formatting.Indented))); }
public async Task Tracing() { List <CosmosObject> documents = new List <CosmosObject>(); for (int i = 0; i < 250; i++) { documents.Add(CosmosObject.Parse($"{{\"pk\" : {i} }}")); } IDocumentContainer documentContainer = await CreateDocumentContainerAsync(documents); IQueryPipelineStage pipelineStage = CreatePipeline(documentContainer, "SELECT * FROM c", pageSize: 10); Trace rootTrace; int numTraces = 1; using (rootTrace = Trace.GetRootTrace("Cross Partition Query")) { while (await pipelineStage.MoveNextAsync(rootTrace)) { TryCatch <QueryPage> tryGetQueryPage = pipelineStage.Current; tryGetQueryPage.ThrowIfFailed(); numTraces++; } } string traceString = TraceWriter.TraceToText(rootTrace); Console.WriteLine(traceString); Assert.AreEqual(numTraces, rootTrace.Children.Count); }
public async Task ReadFeedIteratorCore_Trace() { int batchSize = 1000; await this.CreateRandomItems(this.LargerContainer, batchSize, randomPartitionKey : true); ContainerInternal itemsCore = this.LargerContainer; FeedIteratorInternal feedIterator = (FeedIteratorInternal)itemsCore.GetItemQueryStreamIterator( queryDefinition: null, requestOptions: new QueryRequestOptions() { MaxItemCount = int.MaxValue }); ITrace rootTrace; int childCount = 0; using (rootTrace = Trace.GetRootTrace("Cross Partition Read Feed")) { while (feedIterator.HasMoreResults) { using (ResponseMessage responseMessage = await feedIterator.ReadNextAsync(rootTrace, this.cancellationToken)) { responseMessage.EnsureSuccessStatusCode(); childCount++; } } } string trace = TraceWriter.TraceToText(rootTrace); Console.WriteLine(trace); Assert.AreEqual(childCount, rootTrace.Children.Count); }
public async Task ReadFeedAsync() { int numItems = 100; IDocumentContainer documentContainer = await this.CreateDocumentContainerAsync(numItems); CrossPartitionReadFeedAsyncEnumerator enumerator = CrossPartitionReadFeedAsyncEnumerator.Create( documentContainer, new QueryRequestOptions(), new CrossFeedRangeState <ReadFeedState>(ReadFeedCrossFeedRangeState.CreateFromBeginning().FeedRangeStates), pageSize: 10, cancellationToken: default); int numChildren = 1; // One extra since we need to read one past the last user page to get the null continuation. Trace rootTrace; using (rootTrace = Trace.GetRootTrace("Cross Partition Read Feed")) { while (await enumerator.MoveNextAsync(rootTrace)) { numChildren++; } } string traceString = TraceWriter.TraceToText(rootTrace); Console.WriteLine(traceString); Assert.AreEqual(numChildren, rootTrace.Children.Count); }
public void RootTrace() { Trace rootTrace; using (rootTrace = Trace.GetRootTrace( name: "RootTrace")) { } string traceString = TraceWriter.TraceToText(rootTrace); }
public void RootTraceWithInfo() { Trace rootTrace; using (rootTrace = Trace.GetRootTrace(name: "RootTrace")) { rootTrace.AddDatum("QueryMetrics", new QueryMetricsTraceDatum(MockQueryMetrics)); } string traceString = TraceWriter.TraceToText(rootTrace); }
public void RootTraceWithOneChild() { Trace rootTrace; using (rootTrace = Trace.GetRootTrace(name: "RootTrace")) { using (ITrace childTrace1 = rootTrace.StartChild("Child1")) { } } string traceString = TraceWriter.TraceToText(rootTrace); }
public void RootTraceWithOneChildWithInfo() { Trace rootTrace; using (rootTrace = Trace.GetRootTrace(name: "RootTrace")) { using (ITrace childTrace1 = rootTrace.StartChild("Child1")) { childTrace1.AddDatum("QueryMetrics", new QueryMetricsTraceDatum(MockQueryMetrics)); } } string traceString = TraceWriter.TraceToText(rootTrace); }
public async Task ChangeFeedAsync() { int numItems = 100; IDocumentContainer documentContainer = await this.CreateDocumentContainerAsync(numItems); CrossPartitionChangeFeedAsyncEnumerator enumerator = CrossPartitionChangeFeedAsyncEnumerator.Create( documentContainer, ChangeFeedMode.Incremental, new ChangeFeedRequestOptions() { PageSizeHint = int.MaxValue }, new CrossFeedRangeState <ChangeFeedState>( ChangeFeedCrossFeedRangeState.CreateFromBeginning().FeedRangeStates), cancellationToken: default); int numChildren = 0; Trace rootTrace; using (rootTrace = Trace.GetRootTrace("Cross Partition Change Feed")) { while (await enumerator.MoveNextAsync(rootTrace)) { numChildren++; if (enumerator.Current.Result.Page is ChangeFeedNotModifiedPage) { break; } } } string traceString = TraceWriter.TraceToText(rootTrace); Console.WriteLine(traceString); Assert.AreEqual(numChildren, rootTrace.Children.Count); }
public async Task QueryAsync() { int numItems = 100; IDocumentContainer documentContainer = await this.CreateDocumentContainerAsync(numItems); IQueryPipelineStage pipelineStage = CreatePipeline(documentContainer, "SELECT * FROM c", pageSize: 10); Trace rootTrace; int numChildren = 1; // One extra since we need to read one past the last user page to get the null continuation. using (rootTrace = Trace.GetRootTrace("Cross Partition Query")) { while (await pipelineStage.MoveNextAsync(rootTrace)) { numChildren++; } } string traceString = TraceWriter.TraceToText(rootTrace); Console.WriteLine(traceString); Assert.AreEqual(numChildren, rootTrace.Children.Count); }
public override string ToString() { return($"User Agent: {this.UserAgent} {Environment.NewLine}{TraceWriter.TraceToText(this.Value)}"); }
public async Task TestTraceChildren() { Trace rootTrace; using (rootTrace = Trace.GetRootTrace(name: "RootTrace")) { using (ITrace childTrace1 = rootTrace.StartChild( name: "Child1", component: TraceComponent.Unknown, level: TraceLevel.Info)) { using (ITrace child1Child1 = childTrace1.StartChild( name: "Child1Child1", component: TraceComponent.Unknown, level: TraceLevel.Info)) { Thread.Sleep(100); } using (ITrace child1Child2 = childTrace1.StartChild( name: "Child1Child2", component: TraceComponent.Unknown, level: TraceLevel.Info)) { await Task.Delay(100); } } using (ITrace childTrace2 = rootTrace.StartChild( name: "Child2", component: TraceComponent.Unknown, level: TraceLevel.Info)) { using (ITrace child2Child1 = childTrace2.StartChild( name: "Child2Child1", component: TraceComponent.Unknown, level: TraceLevel.Info)) { await Task.Delay(100); } using (ITrace child2Child2 = childTrace2.StartChild( name: "Child2Child2", component: TraceComponent.Unknown, level: TraceLevel.Info)) { Thread.Sleep(100); } using (ITrace child2Child3 = childTrace2.StartChild( name: "Child2Child3", component: TraceComponent.Unknown, level: TraceLevel.Info)) { await Task.Delay(100); } } } string traceString = TraceWriter.TraceToText(rootTrace); }
public async Task MockQueryOutput() { CosmosClientSideRequestStatistics clientSideRequestStatistics = new CosmosClientSideRequestStatistics(); string id = clientSideRequestStatistics.RecordAddressResolutionStart(new Uri("https://testuri")); clientSideRequestStatistics.RecordAddressResolutionEnd(id); Documents.DocumentServiceRequest documentServiceRequest = new Documents.DocumentServiceRequest( operationType: Documents.OperationType.Read, resourceIdOrFullName: null, resourceType: Documents.ResourceType.Database, body: null, headers: null, isNameBased: false, authorizationTokenType: Documents.AuthorizationTokenType.PrimaryMasterKey); clientSideRequestStatistics.RecordRequest(documentServiceRequest); clientSideRequestStatistics.RecordResponse( documentServiceRequest, new Documents.StoreResult( storeResponse: new Documents.StoreResponse(), exception: null, partitionKeyRangeId: "PkRange", lsn: 42, quorumAckedLsn: 4242, requestCharge: 9000.42, currentReplicaSetSize: 3, currentWriteQuorum: 4, isValid: true, storePhysicalAddress: null, globalCommittedLSN: 2, numberOfReadRegions: 1, itemLSN: 5, sessionToken: null, usingLocalLSN: true, activityId: Guid.NewGuid().ToString())); Trace queryTrace; using (queryTrace = Trace.GetRootTrace( name: "Cross Partition Query", component: TraceComponent.Query, level: TraceLevel.Info)) { using (ITrace getQueryPlanTrace = queryTrace.StartChild("GetQueryPlan")) { using (ITrace gatewayTrace = getQueryPlanTrace.StartChild( "Gateway Call", component: TraceComponent.Transport, level: TraceLevel.Info)) { Thread.Sleep(1); gatewayTrace.AddDatum("ClientSideRequestStats", new CosmosDiagnosticsTraceDatum(clientSideRequestStatistics)); } } using (ITrace getPkRanges = queryTrace.StartChild("GetPkRanges")) { using (ITrace addressResolution = getPkRanges.StartChild( "AddressResolution", component: TraceComponent.Transport, level: TraceLevel.Info)) { await Task.Delay(1); addressResolution.AddDatum("AddressResolutionStatistics", new CosmosDiagnosticsTraceDatum( new AddressResolutionStatistics( DateTime.MinValue, DateTime.MinValue, "https://testuri"))); } } using (ITrace queryPkRange1 = queryTrace.StartChild("Query PkRange 1")) { using (ITrace continuation1 = queryPkRange1.StartChild("Continuation 1")) { using (ITrace gatewayTrace = continuation1.StartChild( "Execute Query Direct", component: TraceComponent.Transport, level: TraceLevel.Info)) { await Task.Delay(1); gatewayTrace.AddDatum("ClientSideRequestStats", new CosmosDiagnosticsTraceDatum(clientSideRequestStatistics)); } continuation1.AddDatum("QueryMetrics", new QueryMetricsTraceDatum(MockQueryMetrics)); continuation1.AddDatum("RequestCharge", 42); } } using (ITrace queryPkRange2 = queryTrace.StartChild("Query PkRange 2")) { using (ITrace continuation1 = queryPkRange2.StartChild("Continuation 1")) { using (ITrace gatewayTrace = continuation1.StartChild( "Execute Query Direct", component: TraceComponent.Transport, level: TraceLevel.Info)) { await Task.Delay(1); gatewayTrace.AddDatum("ClientSideRequestStats", new CosmosDiagnosticsTraceDatum(clientSideRequestStatistics)); } continuation1.AddDatum("QueryMetrics", new QueryMetricsTraceDatum(MockQueryMetrics)); continuation1.AddDatum("RequestCharge", 42); } using (ITrace continuation2 = queryPkRange2.StartChild("Continuation 2")) { using (ITrace gatewayTrace = continuation2.StartChild( "Execute Query Direct", component: TraceComponent.Transport, level: TraceLevel.Info)) { await Task.Delay(1); gatewayTrace.AddDatum("ClientSideRequestStats", new CosmosDiagnosticsTraceDatum(clientSideRequestStatistics)); } continuation2.AddDatum("QueryMetrics", new QueryMetricsTraceDatum(MockQueryMetrics)); continuation2.AddDatum("RequestCharge", 42); } } } string textTraceString = TraceWriter.TraceToText(queryTrace, asciiType: TraceWriter.AsciiType.DoubleLine); string jsonTraceString = TraceWriter.TraceToJson(queryTrace); }