Esempio n. 1
0
        public async Task TestSubsegmentOutLiveParent()
        {
            var mockEmitter = new Mock <ISegmentEmitter>();

            using (var client = AWSXRayRecorderFactory.CreateAWSXRayRecorder(mockEmitter.Object))
            {
                client.BeginSegment("parent", TraceId);
                var parent = AWSXRayRecorder.Instance.TraceContext.GetEntity();

                Subsegment child = null;
                Task       task  = Task.Run(async() =>
                {
                    client.BeginSubsegment("child");
                    child = (Subsegment)AWSXRayRecorder.Instance.TraceContext.GetEntity();

                    await Task.Delay(1000);    // Wait for parent to end first

                    client.EndSubsegment();
                });

                await Task.Delay(50);    // Wait to ensure subsegment has started

                client.EndSegment();

                // Subsegment is not ended
                mockEmitter.Verify(x => x.Send(It.IsAny <Segment>()), Times.Never);

                Task.WaitAll(task);
                Assert.IsNotNull(child);

                // subsegment ends
                mockEmitter.Verify(x => x.Send(It.IsAny <Segment>()), Times.Once);
            }
        }
Esempio n. 2
0
        public void Emits()
        {
            using (var client = AWSXRayRecorderFactory.CreateAWSXRayRecorder(mockEmitter.Object))
            {
                client.BeginSegment("test");
                client.EndSegment();

                mockEmitter.Verify(x => x.Send(It.IsAny <Segment>()), Times.Once);
            }
        }
Esempio n. 3
0
        public void TestSetDaemonAddress()
        {
            string address     = "1.2.3.4:56";
            var    mockEmitter = new Mock <ISegmentEmitter>();

            using (var recorder = AWSXRayRecorderFactory.CreateAWSXRayRecorder(mockEmitter.Object))
            {
                recorder.SetDaemonAddress(address);
            }

            mockEmitter.Verify(x => x.SetDaemonAddress(address), Times.Once);
        }
        public void TestDisableXRayTracingAndNoSegmentSent()
        {
#if NET45
            ConfigurationManager.AppSettings[DisableXRayTracingKey] = "true";
            AppSettings.Reset();
#else
            _xRayOptions.IsXRayTracingDisabled = true;
#endif

            Mock <ISegmentEmitter> mockSegmentEmitter = new Mock <ISegmentEmitter>();
#if NET45
            AppSettings.Reset();
#endif
            using (var recorder = AWSXRayRecorderFactory.CreateAWSXRayRecorder(mockSegmentEmitter.Object))
            {
#if NET45
#else
                recorder.XRayOptions = _xRayOptions;
#endif
                recorder.BeginSegment("test", TraceId);
                var segment = TraceContext.GetEntity();    // The segment will be created even if tracing is disabled.

                recorder.BeginSubsegment("test");
                Assert.ReferenceEquals(segment, TraceContext.GetEntity());
                Assert.IsFalse(segment.IsSubsegmentsAdded);

                recorder.EndSubsegment();

                recorder.MarkFault();
                recorder.MarkError();
                recorder.MarkThrottle();
                recorder.AddAnnotation("key", "value");
                recorder.AddHttpInformation("key", "value");
                recorder.AddPrecursorId("id");
                recorder.AddSqlInformation("key", "value");
                recorder.SetNamespace("namespace");
                recorder.TraceMethod("method", () => PlusOneReturn(1));

                recorder.EndSegment();
                mockSegmentEmitter.Verify(x => x.Send(It.IsAny <Segment>()), Times.Never);
            }
        }
Esempio n. 5
0
        public void TestStartSegmentWithNotSampledDecision()
        {
            var mockEmitter = new Mock <ISegmentEmitter>();

            using (var recorder = AWSXRayRecorderFactory.CreateAWSXRayRecorder(mockEmitter.Object))
            {
                recorder.BeginSegment("test", TraceId, samplingResponse: new SamplingResponse(SampleDecision.NotSampled));
                var segment = AWSXRayRecorder.Instance.TraceContext.GetEntity();

                // BeginSubsegment shouldn't overwrite the segment in trace context
                recorder.BeginSubsegment("sub");
                Assert.ReferenceEquals(segment, AWSXRayRecorder.Instance.TraceContext.GetEntity());

                // EndSubsegment shouldn't release the segment
                recorder.EndSubsegment();
                Assert.AreEqual(1, segment.Reference);

                recorder.EndSegment();

                mockEmitter.Verify(x => x.Send(It.IsAny <Segment>()), Times.Never);
            }
        }