public void TestBuildTag(object tagValue, ThriftTagType tagType, object expected)
        {
            ThriftTag tag = JaegerThriftSpanConverter.BuildTag("key", tagValue);

            Assert.Equal(tagType, tag.VType);
            Assert.Equal("key", tag.Key);
            switch (tagType)
            {
            case ThriftTagType.BOOL:
                Assert.Equal(expected, tag.VBool);
                break;

            case ThriftTagType.LONG:
                Assert.Equal(expected, tag.VLong);
                break;

            case ThriftTagType.DOUBLE:
                Assert.Equal(expected, tag.VDouble);
                break;

            case ThriftTagType.BINARY:
                break;

            case ThriftTagType.STRING:
            default:
                Assert.Equal(expected, tag.VStr);
                break;
            }
        }
Exemple #2
0
        public Task <int> AppendAsync(Span span, CancellationToken cancellationToken)
        {
            _blocker.Wait();

            ThriftSpan thriftSpan = JaegerThriftSpanConverter.ConvertSpan(span);

            _appended.Add(thriftSpan);
            _received.Add(thriftSpan);
            return(Task.FromResult(0));
        }
        public void TestConvertSpanOneReferenceChildOf()
        {
            Span parent = (Span)_tracer.BuildSpan("foo").Start();

            Span child = (Span)_tracer.BuildSpan("foo")
                         .AsChildOf(parent)
                         .Start();

            ThriftSpan span = JaegerThriftSpanConverter.ConvertSpan(child);

            Assert.Equal((long)child.Context.ParentId, span.ParentSpanId);
            Assert.Empty(span.References);
        }
        public void TestBuildTags()
        {
            var tags = new Dictionary <string, object> {
                { "key", "value" }
            };

            List <ThriftTag> thriftTags = JaegerThriftSpanConverter.BuildTags(tags);

            Assert.NotNull(thriftTags);
            Assert.Single(thriftTags);
            Assert.Equal("key", thriftTags[0].Key);
            Assert.Equal("value", thriftTags[0].VStr);
            Assert.Equal(ThriftTagType.STRING, thriftTags[0].VType);
        }
        public void TestConvertSpanMixedReferences()
        {
            Span parent  = (Span)_tracer.BuildSpan("foo").Start();
            Span parent2 = (Span)_tracer.BuildSpan("foo").Start();

            Span child = (Span)_tracer.BuildSpan("foo")
                         .AddReference(References.FollowsFrom, parent.Context)
                         .AsChildOf(parent2)
                         .Start();

            ThriftSpan span = JaegerThriftSpanConverter.ConvertSpan(child);

            Assert.Equal(0, span.ParentSpanId);
            Assert.Equal(2, span.References.Count);
            Assert.Equal(BuildReference(parent.Context, References.FollowsFrom), span.References[0], _thriftReferenceComparer);
            Assert.Equal(BuildReference(parent2.Context, References.ChildOf), span.References[1], _thriftReferenceComparer);
        }
Exemple #6
0
        public async Task <int> AppendAsync(SpanData span, CancellationToken cancellationToken)
        {
            if (this.process == null)
            {
                this.process          = new Process(this.processName);
                this.processBytesSize = this.CalculateProcessSize(this.process);
                this.byteBufferSize  += this.processBytesSize;
            }

            var thriftSpan = JaegerThriftSpanConverter.ConvertSpan(span);
            var spanSize   = this.CalculateSpanSize(thriftSpan);

            if (spanSize > this.MaxSpanBytes)
            {
                throw new SenderException($"ThriftSender received a span that was too large, size = {spanSize}, max = {this.MaxSpanBytes}", null, 1);
            }

            this.byteBufferSize += spanSize;
            if (this.byteBufferSize <= this.MaxSpanBytes)
            {
                this.spanBuffer.Add(thriftSpan);
                if (this.byteBufferSize < this.MaxSpanBytes)
                {
                    return(0);
                }

                return(await this.FlushAsync(cancellationToken).ConfigureAwait(false));
            }

            int n;

            try
            {
                n = await this.FlushAsync(cancellationToken).ConfigureAwait(false);
            }
            catch (SenderException ex)
            {
                // +1 for the span not submitted in the buffer above
                throw new SenderException(ex.Message, ex, ex.DroppedSpanCount + 1);
            }

            this.spanBuffer.Add(thriftSpan);
            this.byteBufferSize = this.processBytesSize + spanSize;
            return(n);
        }
Exemple #7
0
        public async Task <int> AppendAsync(Span span, CancellationToken cancellationToken)
        {
            if (_process == null)
            {
                _process          = new ThriftProcess(span.Tracer.ServiceName);
                _process.Tags     = JaegerThriftSpanConverter.BuildTags(span.Tracer.Tags);
                _processBytesSize = CalculateProcessSize(_process);
                _byteBufferSize  += _processBytesSize;
            }

            ThriftSpan thriftSpan = JaegerThriftSpanConverter.ConvertSpan(span);
            int        spanSize   = CalculateSpanSize(thriftSpan);

            if (spanSize > MaxSpanBytes)
            {
                throw new SenderException($"ThriftSender received a span that was too large, size = {spanSize}, max = {MaxSpanBytes}", null, 1);
            }

            _byteBufferSize += spanSize;
            if (_byteBufferSize <= MaxSpanBytes)
            {
                _spanBuffer.Add(thriftSpan);
                if (_byteBufferSize < MaxSpanBytes)
                {
                    return(0);
                }
                return(await FlushAsync(cancellationToken).ConfigureAwait(false));
            }

            int n;

            try
            {
                n = await FlushAsync(cancellationToken).ConfigureAwait(false);
            }
            catch (SenderException ex)
            {
                // +1 for the span not submitted in the buffer above
                throw new SenderException(ex.Message, ex, ex.DroppedSpanCount + 1);
            }

            _spanBuffer.Add(thriftSpan);
            _byteBufferSize = _processBytesSize + spanSize;
            return(n);
        }
        public void TestConvertSpan()
        {
            var logTimestamp = new DateTimeOffset(2018, 4, 13, 10, 30, 0, TimeSpan.Zero);
            var fields       = new Dictionary <string, object> {
                { "k", "v" }
            };

            Span span = (Span)_tracer.BuildSpan("operation-name").Start();

            span.Log(logTimestamp, fields);
            span.SetBaggageItem("foo", "bar");

            ThriftSpan thriftSpan = JaegerThriftSpanConverter.ConvertSpan(span);

            Assert.Equal("operation-name", thriftSpan.OperationName);
            Assert.Equal(2, thriftSpan.Logs.Count);
            ThriftLog thriftLog = thriftSpan.Logs[0];

            Assert.Equal(logTimestamp.ToUnixTimeMilliseconds() * 1000, thriftLog.Timestamp);
            Assert.Single(thriftLog.Fields);
            ThriftTag thriftTag = thriftLog.Fields[0];

            Assert.Equal("k", thriftTag.Key);
            Assert.Equal("v", thriftTag.VStr);

            // NOTE: In Java, the order is different (event, value, key) because the HashMap algorithm is different.
            thriftLog = thriftSpan.Logs[1];
            Assert.Equal(3, thriftLog.Fields.Count);
            thriftTag = thriftLog.Fields[0];
            Assert.Equal("event", thriftTag.Key);
            Assert.Equal("baggage", thriftTag.VStr);
            thriftTag = thriftLog.Fields[1];
            Assert.Equal("key", thriftTag.Key);
            Assert.Equal("foo", thriftTag.VStr);
            thriftTag = thriftLog.Fields[2];
            Assert.Equal("value", thriftTag.Key);
            Assert.Equal("bar", thriftTag.VStr);
        }
 private static ThriftReference BuildReference(SpanContext context, string referenceType)
 {
     return(JaegerThriftSpanConverter.BuildReferences(new List <Reference> {
         new Reference(context, referenceType)
     }.AsReadOnly())[0]);
 }