public async Task PointOperationSummaryTest()
        {
            ToDoActivity testItem = ToDoActivity.CreateRandomToDoActivity();
            ItemResponse <ToDoActivity> response = await this.Container.CreateItemAsync(testItem, new Cosmos.PartitionKey(testItem.pk));

            Assert.IsNotNull(response.Diagnostics);
            ITrace             trace = ((CosmosTraceDiagnostics)response.Diagnostics).Value;
            SummaryDiagnostics summaryDiagnostics = new SummaryDiagnostics(trace);

            Assert.AreEqual(summaryDiagnostics.DirectRequestsSummary.Value[(201, 0)], 1);
Beispiel #2
0
            public static void WriteTrace(
                IJsonWriter writer,
                ITrace trace,
                bool isRootTrace)
            {
                if (writer == null)
                {
                    throw new ArgumentNullException(nameof(writer));
                }

                if (trace == null)
                {
                    throw new ArgumentNullException(nameof(trace));
                }

                writer.WriteObjectStart();

                if (isRootTrace)
                {
                    writer.WriteFieldName("Summary");
                    SummaryDiagnostics summaryDiagnostics = new SummaryDiagnostics(trace);
                    summaryDiagnostics.WriteSummaryDiagnostics(writer);
                }

                writer.WriteFieldName("name");
                writer.WriteStringValue(trace.Name);

                writer.WriteFieldName("id");
                writer.WriteStringValue(trace.Id.ToString());

                writer.WriteFieldName("start time");
                writer.WriteStringValue(trace.StartTime.ToString("hh:mm:ss:fff"));

                writer.WriteFieldName("duration in milliseconds");
                writer.WriteNumber64Value(trace.Duration.TotalMilliseconds);

                if (trace.Data.Any())
                {
                    writer.WriteFieldName("data");
                    writer.WriteObjectStart();

                    foreach (KeyValuePair <string, object> kvp in trace.Data)
                    {
                        string key   = kvp.Key;
                        object value = kvp.Value;

                        writer.WriteFieldName(key);
                        WriteTraceDatum(writer, value);
                    }

                    writer.WriteObjectEnd();
                }

                if (trace.Children.Any())
                {
                    writer.WriteFieldName("children");
                    writer.WriteArrayStart();

                    foreach (ITrace child in trace.Children)
                    {
                        WriteTrace(writer,
                                   child,
                                   isRootTrace: false);
                    }

                    writer.WriteArrayEnd();
                }
                writer.WriteObjectEnd();
            }
            public static void WriteTrace(
                IJsonWriter writer,
                ITrace trace,
                bool isRootTrace)
            {
                if (writer == null)
                {
                    throw new ArgumentNullException(nameof(writer));
                }

                if (trace == null)
                {
                    throw new ArgumentNullException(nameof(trace));
                }

                writer.WriteObjectStart();

                if (isRootTrace)
                {
                    writer.WriteFieldName("Summary");
                    SummaryDiagnostics summaryDiagnostics = new SummaryDiagnostics(trace);
                    summaryDiagnostics.WriteSummaryDiagnostics(writer);
                }

                writer.WriteFieldName("name");
                writer.WriteStringValue(trace.Name);

                writer.WriteFieldName("id");
                writer.WriteStringValue(trace.Id.ToString());

                // Request handler use the base class to create the trace.
                // This makes it pointless to log the caller info because
                // it is always just the base class info.
                if (trace.Component != TraceComponent.RequestHandler)
                {
                    writer.WriteFieldName("caller info");
                    writer.WriteObjectStart();

                    writer.WriteFieldName("member");
                    writer.WriteStringValue(trace.CallerInfo.MemberName);

                    writer.WriteFieldName("file");
                    writer.WriteStringValue(GetFileNameFromPath(trace.CallerInfo.FilePath));

                    writer.WriteFieldName("line");
                    writer.WriteNumber64Value(trace.CallerInfo.LineNumber);

                    writer.WriteObjectEnd();
                }

                writer.WriteFieldName("start time");
                writer.WriteStringValue(trace.StartTime.ToString("hh:mm:ss:fff"));

                writer.WriteFieldName("duration in milliseconds");
                writer.WriteNumber64Value(trace.Duration.TotalMilliseconds);

                if (trace.Data.Any())
                {
                    writer.WriteFieldName("data");
                    writer.WriteObjectStart();

                    foreach (KeyValuePair <string, object> kvp in trace.Data)
                    {
                        string key   = kvp.Key;
                        object value = kvp.Value;

                        writer.WriteFieldName(key);
                        WriteTraceDatum(writer, value);
                    }

                    writer.WriteObjectEnd();
                }

                if (trace.Children.Any())
                {
                    writer.WriteFieldName("children");
                    writer.WriteArrayStart();

                    foreach (ITrace child in trace.Children)
                    {
                        WriteTrace(writer,
                                   child,
                                   isRootTrace: false);
                    }

                    writer.WriteArrayEnd();
                }
                writer.WriteObjectEnd();
            }