public void SpansShouldAllowThreadSafeAccess()
        {
            var recorder = new SimpleMockRecorder();
            var tracer   = GetTracer(recorder);
            var span     = tracer.BuildSpan("testOperation").Start();

            var t1 = Task.Run(() =>
            {
                span.Log("t1 run");
                span.SetTag("sameTag", "t1");
                span.SetTag("t1Tag", "t1");
            });
            var t2 = Task.Run(() =>
            {
                span.Log("t2 run");
                span.SetTag("sameTag", "t2");
                span.SetTag("t2Tag", "t2");
            });

            t1.Wait();
            t2.Wait();

            span.Finish();

            var finishedSpan = recorder.GetSpanBuffer().First();

            // we expect there to be 2 logs and 3 tags
            Assert.True(finishedSpan.LogData.Count == 2);
            Assert.True(finishedSpan.Tags.Count == 3);
        }
        public void TracerShouldRecordAllSpanData()
        {
            var recorder = new SimpleMockRecorder();
            var tracer   = GetTracer(recorder);

            var startTimeStamp = new DateTimeOffset(2018, 2, 19, 12, 0, 0, TimeSpan.Zero);
            var endTimeStamp   = new DateTimeOffset(2018, 2, 19, 12, 0, 5, TimeSpan.Zero);

            var span = tracer.BuildSpan("test")
                       .WithStartTimestamp(startTimeStamp)
                       .Start()
                       .SetTag("key", "testValue")
                       .SetBaggageItem("baggageKey", "bagTestValue");

            span.Finish(endTimeStamp);

            var recordedSpans = recorder.GetSpanBuffer().First();

            Assert.Equal("test", recordedSpans.OperationName);
            Assert.Equal(startTimeStamp, recordedSpans.StartTimestamp);
            Assert.Equal(TimeSpan.FromSeconds(5), recordedSpans.Duration);

            Assert.Equal("bagTestValue", recordedSpans.Context.GetBaggageItem("baggageKey"));
            Assert.Equal("testValue", recordedSpans.Tags["key"]);

            Assert.False(string.IsNullOrWhiteSpace(recordedSpans.Context.TraceId));
            Assert.False(string.IsNullOrWhiteSpace(recordedSpans.Context.SpanId));
        }
        public void ConverterShouldConvertValues()
        {
            var recorder   = new SimpleMockRecorder();
            var translator = GetTranslator();
            var tracer     = GetTracer(recorder);
            var span       = tracer.BuildSpan("testOperation")
                             .WithTag("boolTrueTag", true)
                             .WithTag("boolFalseTag", false)
                             .WithTag("intTag", 0)
                             .WithTag("stringTag", "test")
                             .WithTag("doubleTag", 0.1)
                             .WithTag("nullTag", null)
                             .WithTag("jsonTag", @"{""key"":""value""}")
                             .Start();

            span.Finish();

            var client = GetClient();

            var translatedSpans = translator.Translate(recorder.GetSpanBuffer());
            var translatedSpan  = translatedSpans.Spans[0];

            foreach (var tag in translatedSpan.Tags)
            {
                switch (tag.Key)
                {
                case "boolTrueFlag":
                    Assert.True(tag.BoolValue);
                    break;

                case "boolFalseFlag":
                    Assert.False(tag.BoolValue);
                    break;

                case "intTag":
                    Assert.Equal(0, tag.IntValue);
                    break;

                case "stringTag":
                    Assert.Equal("test", tag.StringValue);
                    break;

                case "doubleTag":
                    Assert.Equal(0.1, tag.DoubleValue);
                    break;

                case "nullTag":
                    Assert.Equal("null", tag.StringValue);
                    break;

                case "jsonTag":
                    Assert.Equal(@"{""key"":""value""}", tag.JsonValue);
                    break;

                default:
                    continue;
                }
            }
        }
Ejemplo n.º 4
0
        public void DroppedSpanCountShouldSerializeCorrectly()
        {
            var mockBuffer = new SimpleMockRecorder();

            mockBuffer.RecordDroppedSpans(1);

            var client           = GetClient();
            var translatedBuffer = client.Translate(mockBuffer.GetSpanBuffer());

            Assert.Equal(1, translatedBuffer.InternalMetrics.Counts[0].IntValue);
        }
Ejemplo n.º 5
0
        public void DroppedSpanCountShouldIncrementOnBadSpan()
        {
            var recorder = new SimpleMockRecorder();
            var badSpan  = new SpanData {
                Duration      = new TimeSpan(-1),
                OperationName = "badSpan"
            };

            recorder.RecordSpan(badSpan);
            var client           = GetClient();
            var translatedBuffer = client.Translate(recorder.GetSpanBuffer());

            Assert.Equal(1, translatedBuffer.InternalMetrics.Counts[0].IntValue);
        }
Ejemplo n.º 6
0
        public void InternalMetricsShouldExist()
        {
            var recorder = new SimpleMockRecorder();
            var tracer   = GetTracer(recorder);
            var span     = tracer.BuildSpan("test").Start();

            span.Finish();

            var client = GetClient();

            var translatedSpans = client.Translate(recorder.GetSpanBuffer());

            Assert.Equal("spans.dropped", translatedSpans.InternalMetrics.Counts[0].Name);
        }
Ejemplo n.º 7
0
        public void ReportShouldBeBinaryWithoutJsonOption()
        {
            var recorder = new SimpleMockRecorder();
            var tracer   = GetTracer(recorder);
            var span     = tracer.BuildSpan("test").Start();

            span.Finish();

            var client          = GetClient();
            var translatedSpans = client.Translate(recorder.GetSpanBuffer());
            var report          = client.BuildRequest(translatedSpans);

            Assert.Equal("application/octet-stream", report.Content.Headers.ContentType.MediaType);
        }
Ejemplo n.º 8
0
        public void ReportShouldBeJsonWithJsonOption()
        {
            var recorder = new SimpleMockRecorder();
            var tracer   = GetTracer(recorder);
            var span     = tracer.BuildSpan("test").Start();

            span.Finish();

            var client          = GetClient(TransportOptions.JsonProto);
            var translatedSpans = client.Translate(recorder.GetSpanBuffer());
            var report          = client.BuildRequest(translatedSpans);

            Assert.Equal("application/json", report.Content.Headers.ContentType.MediaType);
            var contentString = report.Content.ReadAsStringAsync().Result;

            Assert.Contains("test", contentString);
        }
        public void SpansShouldRecordLogs()
        {
            var recorder = new SimpleMockRecorder();
            var tracer   = GetTracer(recorder);
            var span     = tracer.BuildSpan("testOperation").Start();

            span.Log("hello world!");
            span.Finish();

            var finishedSpan = recorder.GetSpanBuffer().First();
            // project the sequence of logdata into an array with one item, the aforementioned log message
            var finishedSpanLogData = finishedSpan.LogData.Select(
                item => item.Fields.First(
                    f => f.Value.Equals("hello world!")
                    ).Value).ToArray()[0];

            Assert.Equal("hello world!", (string)finishedSpanLogData);
        }
Ejemplo n.º 10
0
        public void SpansShouldBuildProperTypedKeyTags()
        {
            var recorder = new SimpleMockRecorder();
            var tracer   = GetTracer(recorder);
            var span     = tracer.BuildSpan("testOperation")
                           .WithTag(new BooleanTag("testBoolTag"), true)
                           .WithTag(new IntTag("testIntTag"), 1)
                           .WithTag(new StringTag("testStringTag"), "test")
                           .WithTag(new IntOrStringTag("testIntOrStringTagAsString"), "string")
                           .WithTag(new IntOrStringTag("testIntOrStringTagAsInt"), 1)
                           .Start();

            span.Finish();
            var finishedSpan = recorder.GetSpanBuffer().First();

            Assert.True((bool)finishedSpan.Tags["testBoolTag"]);
            Assert.Equal(1, finishedSpan.Tags["testIntTag"]);
            Assert.Equal("test", finishedSpan.Tags["testStringTag"]);
            Assert.Equal("string", finishedSpan.Tags["testIntOrStringTagAsString"]);
            Assert.Equal(1, finishedSpan.Tags["testIntOrStringTagAsInt"]);
        }
Ejemplo n.º 11
0
        public void SpansShouldBuildProperStringKeyTags()
        {
            var recorder = new SimpleMockRecorder();
            var tracer   = GetTracer(recorder);
            var span     = tracer.BuildSpan("testOperation")
                           .WithTag("boolTrueTag", true)
                           .WithTag("boolFalseTag", false)
                           .WithTag("intTag", 0)
                           .WithTag("stringTag", "test")
                           .WithTag("doubleTag", 0.1)
                           .Start();

            span.Finish();
            var finishedSpan = recorder.GetSpanBuffer().First();

            Assert.True((bool)finishedSpan.Tags["boolTrueTag"]);
            Assert.False((bool)finishedSpan.Tags["boolFalseTag"]);
            Assert.Equal(0, finishedSpan.Tags["intTag"]);
            Assert.Equal("test", finishedSpan.Tags["stringTag"]);
            Assert.Equal(0.1, finishedSpan.Tags["doubleTag"]);
        }