public async Task <int> AppendAsync(Span span, CancellationToken cancellationToken) { if (_process == null) { _process = new GrpcProcess { ServiceName = span.Tracer.ServiceName, Tags = { JaegerGrpcSpanConverter.BuildTags(span.Tracer.Tags) } }; _processBytesSize = _process.CalculateSize(); _byteBufferSize += _processBytesSize; _maxSpanSize = _maxPacketSize - _processBytesSize; if (_maxSpanSize < 0) { throw new SenderException($"GrpcSender was misconfigured, packet size too small, size = {_maxPacketSize}, max = {_processBytesSize}", null, 1); } } GrpcSpan grpcSpan = JaegerGrpcSpanConverter.ConvertSpan(span); int spanSize = grpcSpan.CalculateSize(); if (spanSize > _maxSpanSize) { throw new SenderException($"GrpcSender received a span that was too large, size = {spanSize}, max = {_maxSpanSize}", null, 1); } _byteBufferSize += spanSize; if (_byteBufferSize <= _maxPacketSize) { _spanBuffer.Add(grpcSpan); if (_byteBufferSize < _maxPacketSize) { 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(grpcSpan); _byteBufferSize = _processBytesSize + spanSize; return(n); }
public void TestConvertSpanOneReferenceChildOf() { Span parent = (Span)_tracer.BuildSpan("foo").Start(); Span child = (Span)_tracer.BuildSpan("foo") .AsChildOf(parent) .Start(); GrpcSpan span = JaegerGrpcSpanConverter.ConvertSpan(child); Assert.Single(span.References); Assert.Equal(BuildReference(parent.Context, References.ChildOf), span.References[0]); }
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(); GrpcSpan span = JaegerGrpcSpanConverter.ConvertSpan(child); Assert.Equal(2, span.References.Count); Assert.Equal(BuildReference(parent.Context, References.FollowsFrom), span.References[0]); Assert.Equal(BuildReference(parent2.Context, References.ChildOf), span.References[1]); }
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"); GrpcSpan grpcSpan = JaegerGrpcSpanConverter.ConvertSpan(span); Assert.Equal("operation-name", grpcSpan.OperationName); Assert.Equal(2, grpcSpan.Logs.Count); GrpcLog grpcLog = grpcSpan.Logs[0]; Assert.Equal(logTimestamp, grpcLog.Timestamp.ToDateTimeOffset()); Assert.Single(grpcLog.Fields); GrpcTag grpcTag = grpcLog.Fields[0]; Assert.Equal("k", grpcTag.Key); Assert.Equal("v", grpcTag.VStr); // NOTE: In Java, the order is different (event, value, key) because the HashMap algorithm is different. grpcLog = grpcSpan.Logs[1]; Assert.Equal(3, grpcLog.Fields.Count); grpcTag = grpcLog.Fields[0]; Assert.Equal("event", grpcTag.Key); Assert.Equal("baggage", grpcTag.VStr); grpcTag = grpcLog.Fields[1]; Assert.Equal("key", grpcTag.Key); Assert.Equal("foo", grpcTag.VStr); grpcTag = grpcLog.Fields[2]; Assert.Equal("value", grpcTag.Key); Assert.Equal("bar", grpcTag.VStr); }