public void GenerateSpan() { ZipkinEndpoint localEndpoint = new ZipkinEndpoint() { ServiceName = "tweetiebird" }; var traceId = "d239036e7d5cec116b562147388b35bf"; var spanId = "9cc1e3049173be09"; var parentId = "8b03ab423da481c5"; Dictionary <string, IAttributeValue> attributes = new Dictionary <string, IAttributeValue>(); IList <ITimedEvent <IAnnotation> > annotations = new List <ITimedEvent <IAnnotation> >(); List <ITimedEvent <IMessageEvent> > networkEvents = new List <ITimedEvent <IMessageEvent> >() { TimedEvent <IMessageEvent> .Create(Timestamp.Create(EPOCH_SECONDS + 1505855799, 433901068), new MessageEventBuilder(MessageEventType.RECEIVED, 0, 0, 0).SetCompressedMessageSize(7).Build()), TimedEvent <IMessageEvent> .Create(Timestamp.Create(EPOCH_SECONDS + 1505855799, 459486280), new MessageEventBuilder(MessageEventType.SENT, 0, 0, 0).SetCompressedMessageSize(13).Build()) }; ISpanData data = SpanData.Create( SpanContext.Create( TraceId.FromBytes(Arrays.StringToByteArray(traceId)), SpanId.FromBytes(Arrays.StringToByteArray(spanId)), TraceOptions.FromBytes(new byte[] { 1 })), SpanId.FromBytes(Arrays.StringToByteArray(parentId)), true, /* hasRemoteParent */ "Recv.helloworld.Greeter.SayHello", /* name */ Timestamp.Create(EPOCH_SECONDS + 1505855794, 194009601) /* startTimestamp */, Attributes.Create(attributes, 0 /* droppedAttributesCount */), TimedEvents <IAnnotation> .Create(annotations, 0 /* droppedEventsCount */), TimedEvents <IMessageEvent> .Create(networkEvents, 0 /* droppedEventsCount */), LinkList.Create(new List <ILink>(), 0 /* droppedLinksCount */), null, /* childSpanCount */ Status.OK, Timestamp.Create(EPOCH_SECONDS + 1505855799, 465726528) /* endTimestamp */); var handler = new TraceExporterHandler(new TraceExporterOptions() { UseShortTraceIds = false }); var result = handler.GenerateSpan(data, localEndpoint); var zspan = ZipkinSpan.NewBuilder() .TraceId(traceId) .ParentId(parentId) .Id(spanId) .Kind(ZipkinSpanKind.SERVER) .Name(data.Name) .Timestamp(1505855794000000L + (194009601L / 1000)) .Duration( (1505855799000000L + (465726528L / 1000)) - (1505855794000000L + (194009601L / 1000))) .LocalEndpoint(localEndpoint) .AddAnnotation(1505855799000000L + (433901068L / 1000), "RECEIVED") .AddAnnotation(1505855799000000L + (459486280L / 1000), "SENT") .PutTag("census.status_code", "OK") .Build(); Assert.Equal(zspan, result); }
public void Builder_FromOptions() { Assert.Equal(6 | 1, TraceOptions.Builder(TraceOptions.FromBytes(thirdBytes)) .SetIsSampled(true) .Build() .Options); }
public void getOptions() { Assert.Equal(0, TraceOptions.Default.Options); Assert.Equal(0, TraceOptions.Builder().SetIsSampled(false).Build().Options); Assert.Equal(1, TraceOptions.Builder().SetIsSampled(true).Build().Options); Assert.Equal(0, TraceOptions.Builder().SetIsSampled(true).SetIsSampled(false).Build().Options); Assert.Equal(-1, TraceOptions.FromBytes(firstBytes).Options); Assert.Equal(1, TraceOptions.FromBytes(secondBytes).Options); Assert.Equal(6, TraceOptions.FromBytes(thirdBytes).Options); }
public void GetOptions() { Assert.Equal(0, TraceOptions.DEFAULT.Options); Assert.Equal(0, TraceOptions.Builder().SetIsSampled(false).Build().Options); Assert.Equal(1, TraceOptions.Builder().SetIsSampled(true).Build().Options); Assert.Equal(0, TraceOptions.Builder().SetIsSampled(true).SetIsSampled(false).Build().Options); Assert.Equal(-1, TraceOptions.FromBytes(FirstBytes).Options); Assert.Equal(1, TraceOptions.FromBytes(SecondBytes).Options); Assert.Equal(6, TraceOptions.FromBytes(ThirdBytes).Options); }
public SpanContext FromByteArray(byte[] bytes) { if (bytes == null) { throw new ArgumentNullException(nameof(bytes)); } if (bytes.Length == 0 || bytes[0] != VersionId) { throw new SpanContextParseException("Unsupported version."); } var traceId = TraceId.Invalid; var spanId = SpanId.Invalid; var traceOptions = TraceOptions.Default; var pos = 1; try { if (bytes.Length > pos && bytes[pos] == TraceIdFieldId) { traceId = TraceId.FromBytes(bytes, pos + IdSize); pos += IdSize + TraceId.Size; } if (bytes.Length > pos && bytes[pos] == SpanIdFieldId) { spanId = SpanId.FromBytes(bytes, pos + IdSize); pos += IdSize + SpanId.Size; } if (bytes.Length > pos && bytes[pos] == TraceOptionsFieldId) { traceOptions = TraceOptions.FromBytes(bytes, pos + IdSize); } return(SpanContext.Create(traceId, spanId, traceOptions, Tracestate.Empty)); } catch (Exception e) { throw new SpanContextParseException("Invalid input.", e); } }
public override ISpanContext FromByteArray(byte[] bytes) { if (bytes == null) { throw new ArgumentNullException(nameof(bytes)); } if (bytes.Length == 0 || bytes[0] != VERSION_ID) { throw new SpanContextParseException("Unsupported version."); } ITraceId traceId = TraceId.INVALID; ISpanId spanId = SpanId.INVALID; TraceOptions traceOptions = TraceOptions.DEFAULT; int pos = 1; try { if (bytes.Length > pos && bytes[pos] == TRACE_ID_FIELD_ID) { traceId = TraceId.FromBytes(bytes, pos + ID_SIZE); pos += ID_SIZE + TraceId.SIZE; } if (bytes.Length > pos && bytes[pos] == SPAN_ID_FIELD_ID) { spanId = SpanId.FromBytes(bytes, pos + ID_SIZE); pos += ID_SIZE + SpanId.SIZE; } if (bytes.Length > pos && bytes[pos] == TRACE_OPTION_FIELD_ID) { traceOptions = TraceOptions.FromBytes(bytes, pos + ID_SIZE); } return(SpanContext.Create(traceId, spanId, traceOptions)); } catch (Exception e) { throw new SpanContextParseException("Invalid input.", e); } }
public void ToFromBytes() { Assert.Equal(firstBytes, TraceOptions.FromBytes(firstBytes).Bytes); Assert.Equal(secondBytes, TraceOptions.FromBytes(secondBytes).Bytes); Assert.Equal(thirdBytes, TraceOptions.FromBytes(thirdBytes).Bytes); }
public void ToFromBytes() { Assert.Equal(FirstBytes, TraceOptions.FromBytes(FirstBytes).Bytes); Assert.Equal(SecondBytes, TraceOptions.FromBytes(SecondBytes).Bytes); Assert.Equal(ThirdBytes, TraceOptions.FromBytes(ThirdBytes).Bytes); }