public void RichPayloadEventSourceOperationStartStopTest()
        {
            if (IsRunningOnEnvironmentSupportingRichPayloadEventSource())
            {
                var client = CreateTelemetryClient();

                using (var listener = new TestFramework.TestEventListener())
                {
                    listener.EnableEvents(RichPayloadEventSource.Log.EventSourceInternal, EventLevel.Informational, RichPayloadEventSource.Keywords.Operations);

                    // Simulate a Start/Stop request operation
                    var requestTelemetry = new RequestTelemetry {
                        Name = "Request"
                    };
                    using (client.StartOperation(requestTelemetry))
                    {
                    }

                    // Expect exactly two events (start and stop)
                    var actualEvents = listener.Messages.Where(m => m.Keywords.HasFlag(RichPayloadEventSource.Keywords.Operations)).Take(2).ToArray();

                    VerifyOperationEvent(requestTelemetry, RequestTelemetry.TelemetryName, EventOpcode.Start, actualEvents[0]);
                    VerifyOperationEvent(requestTelemetry, RequestTelemetry.TelemetryName, EventOpcode.Stop, actualEvents[1]);
                }
            }
            else
            {
                // 4.5 doesn't have RichPayload events
                Assert.IsNull(RichPayloadEventSource.Log.EventSourceInternal);
            }
        }
예제 #2
0
        public void RichPayloadEventSourceNestedOperationStartStopTest()
        {
            if (IsRunningOnEnvironmentSupportingRichPayloadEventSource())
            {
                var client = CreateTelemetryClient();

                using (var listener = new TestFramework.TestEventListener())
                {
                    listener.EnableEvents(RichPayloadEventSource.Log.EventSourceInternal, EventLevel.Informational, RichPayloadEventSource.Keywords.Operations);

                    // Simulate a Start/Stop request operation
                    var requestTelemetry = new RequestTelemetry {
                        Name = "Request"
                    };
                    var nestedOperation = new DependencyTelemetry {
                        Name = "Dependency"
                    };
                    using (client.StartOperation(requestTelemetry))
                    {
                        using (client.StartOperation(nestedOperation))
                        {
                        }
                    }

                    // Expect exactly four events (start, start, stop, stop)
                    var actualEvents = listener.Messages.Where(m => m.Keywords.HasFlag(RichPayloadEventSource.Keywords.Operations)).Take(4).ToArray();

                    VerifyOperationEvent(requestTelemetry, ServiceProfilerNameContracts[requestTelemetry.GetType()], EventOpcode.Start, actualEvents[0]);
                    VerifyOperationEvent(nestedOperation, ServiceProfilerNameContracts[typeof(OperationTelemetry)], EventOpcode.Start, actualEvents[1]);
                    VerifyOperationEvent(nestedOperation, ServiceProfilerNameContracts[typeof(OperationTelemetry)], EventOpcode.Stop, actualEvents[2]);
                    VerifyOperationEvent(requestTelemetry, ServiceProfilerNameContracts[requestTelemetry.GetType()], EventOpcode.Stop, actualEvents[3]);
                }
            }
            else
            {
                // 4.5 doesn't have RichPayload events
                Assert.IsNull(RichPayloadEventSource.Log.EventSourceInternal);
            }
        }