示例#1
0
        public void ParseSampled()
        {
            IDictionary <String, String> headersSampled = new Dictionary <String, String>();

            headersSampled.Add(B3Format.X_B3_TRACE_ID, TRACE_ID_BASE16);
            headersSampled.Add(B3Format.X_B3_SPAN_ID, SPAN_ID_BASE16);
            headersSampled.Add(B3Format.X_B3_SAMPLED, "1");
            Assert.Equal(SpanContext.Create(TRACE_ID, SPAN_ID, TRACE_OPTIONS), b3Format.Extract(headersSampled, getter));
        }
 public SamplersTest()
 {
     traceId               = TraceId.GenerateRandomId(random);
     parentSpanId          = SpanId.GenerateRandomId(random);
     spanId                = SpanId.GenerateRandomId(random);
     sampledSpanContext    = SpanContext.Create(traceId, parentSpanId, TraceOptions.Builder().SetIsSampled(true).Build(), Tracestate.Empty);
     notSampledSpanContext = SpanContext.Create(traceId, parentSpanId, TraceOptions.Default, Tracestate.Empty);
     sampledSpan           = new TestSpan(sampledSpanContext, SpanOptions.RecordEvents);
 }
示例#3
0
        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());
            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);
        }
示例#4
0
        public void ParseEightBytesTraceId()
        {
            IDictionary <String, String> headersEightBytes = new Dictionary <String, String>();

            headersEightBytes.Add(B3Format.XB3TraceId, TRACE_ID_BASE16_EIGHT_BYTES);
            headersEightBytes.Add(B3Format.XB3SpanId, SPAN_ID_BASE16);
            headersEightBytes.Add(B3Format.XB3Sampled, "1");
            Assert.Equal(SpanContext.Create(TRACE_ID_EIGHT_BYTES, SPAN_ID, TRACE_OPTIONS, Tracestate.Empty), b3Format.Extract(headersEightBytes, getter));
        }
示例#5
0
        public void ParseZeroSampled()
        {
            IDictionary <String, String> headersNotSampled = new Dictionary <String, String>();

            headersNotSampled.Add(B3Format.XB3TraceId, TRACE_ID_BASE16);
            headersNotSampled.Add(B3Format.XB3SpanId, SPAN_ID_BASE16);
            headersNotSampled.Add(B3Format.XB3Sampled, "0");
            Assert.Equal(SpanContext.Create(TRACE_ID, SPAN_ID, TraceOptions.Default, Tracestate.Empty), b3Format.Extract(headersNotSampled, getter));
        }
        public LinkTest()
        {
            spanContext = SpanContext.Create(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None, Tracestate.Empty);;

            attributesMap.Add("MyAttributeKey0", "MyStringAttribute");
            attributesMap.Add("MyAttributeKey1", 10L);
            attributesMap.Add("MyAttributeKey2", true);
            attributesMap.Add("MyAttributeKey3", 0.005);
        }
示例#7
0
        public void ParseFlag()
        {
            IDictionary <String, String> headersFlagSampled = new Dictionary <String, String>();

            headersFlagSampled.Add(B3Format.XB3TraceId, TRACE_ID_BASE16);
            headersFlagSampled.Add(B3Format.XB3SpanId, SPAN_ID_BASE16);
            headersFlagSampled.Add(B3Format.XB3Flags, "1");
            Assert.Equal(SpanContext.Create(TRACE_ID, SPAN_ID, TRACE_OPTIONS, Tracestate.Empty), b3Format.Extract(headersFlagSampled, getter));
        }
示例#8
0
 public SamplersTest()
 {
     traceId               = TraceId.GenerateRandomId(random);
     parentSpanId          = SpanId.GenerateRandomId(random);
     spanId                = SpanId.GenerateRandomId(random);
     sampledSpanContext    = SpanContext.Create(traceId, parentSpanId, TraceOptions.Builder().SetIsSampled(true).Build());
     notSampledSpanContext = SpanContext.Create(traceId, parentSpanId, TraceOptions.DEFAULT);
     sampledSpan           = new NoopSpan(sampledSpanContext, SpanOptions.RECORD_EVENTS);
 }
 public SamplersTest()
 {
     traceId               = ActivityTraceId.CreateRandom();
     parentSpanId          = ActivitySpanId.CreateRandom();
     spanId                = ActivitySpanId.CreateRandom();
     sampledSpanContext    = SpanContext.Create(traceId, parentSpanId, ActivityTraceFlags.Recorded, Tracestate.Empty);
     notSampledSpanContext = SpanContext.Create(traceId, parentSpanId, ActivityTraceFlags.None, Tracestate.Empty);
     sampledLink           = Link.FromSpanContext(sampledSpanContext);
 }
示例#10
0
        public void ParseZeroSampled()
        {
            IDictionary <String, String> headersNotSampled = new Dictionary <String, String>();

            headersNotSampled.Add(B3Format.X_B3_TRACE_ID, TRACE_ID_BASE16);
            headersNotSampled.Add(B3Format.X_B3_SPAN_ID, SPAN_ID_BASE16);
            headersNotSampled.Add(B3Format.X_B3_SAMPLED, "0");
            Assert.Equal(SpanContext.Create(TRACE_ID, SPAN_ID, TraceOptions.DEFAULT), b3Format.Extract(headersNotSampled, getter));
        }
示例#11
0
        public void ParseEightBytesTraceId()
        {
            IDictionary <String, String> headersEightBytes = new Dictionary <String, String>();

            headersEightBytes.Add(B3Format.X_B3_TRACE_ID, TRACE_ID_BASE16_EIGHT_BYTES);
            headersEightBytes.Add(B3Format.X_B3_SPAN_ID, SPAN_ID_BASE16);
            headersEightBytes.Add(B3Format.X_B3_SAMPLED, "1");
            Assert.Equal(SpanContext.Create(TRACE_ID_EIGHT_BYTES, SPAN_ID, TRACE_OPTIONS), b3Format.Extract(headersEightBytes, getter));
        }
        /// <inheritdoc/>
        public SpanContext Extract <T>(T carrier, Func <T, string, IEnumerable <string> > getter)
        {
            if (carrier == null)
            {
                throw new ArgumentNullException(nameof(carrier));
            }

            if (getter == null)
            {
                throw new ArgumentNullException(nameof(getter));
            }

            try
            {
                ActivityTraceId traceId;
                var             traceIdStr = getter(carrier, XB3TraceId)?.FirstOrDefault();
                if (traceIdStr != null)
                {
                    if (traceIdStr.Length == 16)
                    {
                        // This is an 8-byte traceID.
                        traceIdStr = UpperTraceId + traceIdStr;
                    }

                    traceId = ActivityTraceId.CreateFromString(traceIdStr.AsSpan());
                }
                else
                {
                    throw new SpanContextParseException("Missing X_B3_TRACE_ID.");
                }

                ActivitySpanId spanId;
                var            spanIdStr = getter(carrier, XB3SpanId)?.FirstOrDefault();
                if (spanIdStr != null)
                {
                    spanId = ActivitySpanId.CreateFromString(spanIdStr.AsSpan());
                }
                else
                {
                    throw new SpanContextParseException("Missing X_B3_SPAN_ID.");
                }

                var traceOptions = ActivityTraceFlags.None;
                if (SampledValue.Equals(getter(carrier, XB3Sampled)?.FirstOrDefault()) ||
                    FlagsValue.Equals(getter(carrier, XB3Flags)?.FirstOrDefault()))
                {
                    traceOptions |= ActivityTraceFlags.Recorded;
                }

                return(SpanContext.Create(traceId, spanId, traceOptions, Tracestate.Empty));
            }
            catch (Exception e)
            {
                throw new SpanContextParseException("Invalid input.", e);
            }
        }
示例#13
0
        /// <inheritdoc/>
        public SpanContext Extract <T>(T carrier, Func <T, string, IEnumerable <string> > getter)
        {
            if (carrier == null)
            {
                throw new ArgumentNullException(nameof(carrier));
            }

            if (getter == null)
            {
                throw new ArgumentNullException(nameof(getter));
            }

            try
            {
                TraceId traceId;
                var     traceIdStr = getter(carrier, XB3TraceId)?.FirstOrDefault();
                if (traceIdStr != null)
                {
                    if (traceIdStr.Length == TraceId.Size)
                    {
                        // This is an 8-byte traceID.
                        traceIdStr = UpperTraceId + traceIdStr;
                    }

                    traceId = TraceId.FromLowerBase16(traceIdStr);
                }
                else
                {
                    throw new SpanContextParseException("Missing X_B3_TRACE_ID.");
                }

                SpanId spanId;
                var    spanIdStr = getter(carrier, XB3SpanId)?.FirstOrDefault();
                if (spanIdStr != null)
                {
                    spanId = SpanId.FromLowerBase16(spanIdStr);
                }
                else
                {
                    throw new SpanContextParseException("Missing X_B3_SPAN_ID.");
                }

                var traceOptions = TraceOptions.Default;
                if (SampledValue.Equals(getter(carrier, XB3Sampled)?.FirstOrDefault()) ||
                    FlagsValue.Equals(getter(carrier, XB3Flags)?.FirstOrDefault()))
                {
                    traceOptions = TraceOptions.Builder().SetIsSampled(true).Build();
                }

                return(SpanContext.Create(traceId, spanId, traceOptions, Tracestate.Empty));
            }
            catch (Exception e)
            {
                throw new SpanContextParseException("Invalid input.", e);
            }
        }
示例#14
0
        public override ISpanContext Extract <C>(C carrier, IGetter <C> getter)
        {
            if (carrier == null)
            {
                throw new ArgumentNullException(nameof(carrier));
            }

            if (getter == null)
            {
                throw new ArgumentNullException(nameof(getter));
            }

            try
            {
                ITraceId traceId;
                string   traceIdStr = getter.Get(carrier, X_B3_TRACE_ID);
                if (traceIdStr != null)
                {
                    if (traceIdStr.Length == TraceId.SIZE)
                    {
                        // This is an 8-byte traceID.
                        traceIdStr = UPPER_TRACE_ID + traceIdStr;
                    }

                    traceId = TraceId.FromLowerBase16(traceIdStr);
                }
                else
                {
                    throw new SpanContextParseException("Missing X_B3_TRACE_ID.");
                }

                ISpanId spanId;
                string  spanIdStr = getter.Get(carrier, X_B3_SPAN_ID);
                if (spanIdStr != null)
                {
                    spanId = SpanId.FromLowerBase16(spanIdStr);
                }
                else
                {
                    throw new SpanContextParseException("Missing X_B3_SPAN_ID.");
                }

                TraceOptions traceOptions = TraceOptions.DEFAULT;
                if (SAMPLED_VALUE.Equals(getter.Get(carrier, X_B3_SAMPLED)) ||
                    FLAGS_VALUE.Equals(getter.Get(carrier, X_B3_FLAGS)))
                {
                    traceOptions = TraceOptions.Builder().SetIsSampled(true).Build();
                }

                return(SpanContext.Create(traceId, spanId, traceOptions));
            }
            catch (Exception e)
            {
                throw new SpanContextParseException("Invalid input.", e);
            }
        }
示例#15
0
        public void ParseMissingSampledAndMissingFlag()
        {
            IDictionary <String, String> headersNotSampled = new Dictionary <String, String>();

            headersNotSampled.Add(B3Format.X_B3_TRACE_ID, TRACE_ID_BASE16);
            headersNotSampled.Add(B3Format.X_B3_SPAN_ID, SPAN_ID_BASE16);
            ISpanContext spanContext = SpanContext.Create(TRACE_ID, SPAN_ID, TraceOptions.DEFAULT);

            Assert.Equal(spanContext, b3Format.Extract(headersNotSampled, getter));
        }
示例#16
0
        public void ParseEightBytesTraceId_NotSampledSpanContext()
        {
            IDictionary <string, string> headersEightBytes = new Dictionary <string, string>
            {
                { B3Format.X_B3_TRACE_ID, TRACE_ID_BASE16_EIGHT_BYTES },
                { B3Format.X_B3_SPAN_ID, SPAN_ID_BASE16 }
            };

            Assert.Equal(SpanContext.Create(TRACE_ID_EIGHT_BYTES, SPAN_ID, TraceOptions.DEFAULT), b3Format.Extract(headersEightBytes, Getter));
        }
示例#17
0
        public void Serialize_SampledContext()
        {
            IDictionary <String, String> carrier = new Dictionary <String, String>();

            b3Format.Inject(SpanContext.Create(TRACE_ID, SPAN_ID, TRACE_OPTIONS), carrier, setter);
            ContainsExactly(carrier, new Dictionary <string, string>()
            {
                { B3Format.X_B3_TRACE_ID, TRACE_ID_BASE16 }, { B3Format.X_B3_SPAN_ID, SPAN_ID_BASE16 }, { B3Format.X_B3_SAMPLED, "1" }
            });
        }
示例#18
0
 public void FromBinaryValue_UnsupportedFieldIdFirst()
 {
     Assert.Equal(
         SpanContext.Create(TraceId.INVALID, SpanId.INVALID, TraceOptions.DEFAULT),
         binaryFormat.FromByteArray(
             new byte[] {
         0, 4, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 1, 97, 98,
         99, 100, 101, 102, 103, 104, 2, 1
     }));
 }
        public void ParseMissingSampledAndMissingFlag()
        {
            IDictionary <String, String> headersNotSampled = new Dictionary <String, String>();

            headersNotSampled.Add(B3Format.XB3TraceId, TraceIdBase16);
            headersNotSampled.Add(B3Format.XB3SpanId, SpanIdBase16);
            var spanContext = SpanContext.Create(TraceId, SpanId, ActivityTraceFlags.None, Tracestate.Empty);

            Assert.Equal(spanContext, b3Format.Extract(headersNotSampled, getter));
        }
        public void ParseMissingSampledAndMissingFlag()
        {
            IDictionary <String, String> headersNotSampled = new Dictionary <String, String>();

            headersNotSampled.Add(B3Format.XB3TraceId, TRACE_ID_BASE16);
            headersNotSampled.Add(B3Format.XB3SpanId, SPAN_ID_BASE16);
            SpanContext spanContext = SpanContext.Create(TRACE_ID, SPAN_ID, TraceOptions.Default, Tracestate.Empty);

            Assert.Equal(spanContext, b3Format.Extract(headersNotSampled, getter));
        }
        public void Serialize_SampledContext()
        {
            IDictionary <String, String> carrier = new Dictionary <String, String>();

            b3Format.Inject(SpanContext.Create(TraceId, SpanId, TraceOptions, Tracestate.Empty), carrier, setter);
            ContainsExactly(carrier, new Dictionary <string, string>()
            {
                { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }, { B3Format.XB3Sampled, "1" }
            });
        }
        public void Serialize_SampledContext()
        {
            IDictionary <String, String> carrier = new Dictionary <String, String>();

            b3Format.Inject(SpanContext.Create(TRACE_ID, SPAN_ID, TRACE_OPTIONS, Tracestate.Empty), carrier, setter);
            ContainsExactly(carrier, new Dictionary <string, string>()
            {
                { B3Format.XB3TraceId, TRACE_ID_BASE16 }, { B3Format.XB3SpanId, SPAN_ID_BASE16 }, { B3Format.XB3Sampled, "1" }
            });
        }
示例#23
0
        public void ParseZeroFlag()
        {
            IDictionary <string, string> headersFlagNotSampled = new Dictionary <string, string>
            {
                { B3Format.X_B3_TRACE_ID, TRACE_ID_BASE16 },
                { B3Format.X_B3_SPAN_ID, SPAN_ID_BASE16 },
                { B3Format.X_B3_FLAGS, "0" }
            };

            Assert.Equal(SpanContext.Create(TRACE_ID, SPAN_ID, TraceOptions.DEFAULT), b3Format.Extract(headersFlagNotSampled, Getter));
        }
示例#24
0
 public InProcessSampledSpanStoreTest()
 {
     sampledSpanContext    = SpanContext.Create(TraceId.GenerateRandomId(random), SpanId.GenerateRandomId(random), TraceOptions.Builder().SetIsSampled(true).Build(), Tracestate.Empty);
     notSampledSpanContext = SpanContext.Create(TraceId.GenerateRandomId(random), SpanId.GenerateRandomId(random), TraceOptions.Default, Tracestate.Empty);
     parentSpanId          = SpanId.GenerateRandomId(random);
     startEndHandler       = new TestStartEndHandler(sampleStore);
     sampleStore.RegisterSpanNamesForCollection(new List <string>()
     {
         REGISTERED_SPAN_NAME
     });
 }
示例#25
0
        public void ParseSampled()
        {
            IDictionary <string, string> headersSampled = new Dictionary <string, string>
            {
                { B3Format.X_B3_TRACE_ID, TRACE_ID_BASE16 },
                { B3Format.X_B3_SPAN_ID, SPAN_ID_BASE16 },
                { B3Format.X_B3_SAMPLED, "1" }
            };

            Assert.Equal(SpanContext.Create(TRACE_ID, SPAN_ID, TRACE_OPTIONS), b3Format.Extract(headersSampled, Getter));
        }
示例#26
0
        public void ParseEightBytesTraceId()
        {
            IDictionary <string, string> headersEightBytes = new Dictionary <string, string>
            {
                { B3Format.X_B3_TRACE_ID, TRACE_ID_BASE16_EIGHT_BYTES },
                { B3Format.X_B3_SPAN_ID, SPAN_ID_BASE16 },
                { B3Format.X_B3_SAMPLED, "1" }
            };

            Assert.Equal(SpanContext.Create(TRACE_ID_EIGHT_BYTES, SPAN_ID, TRACE_OPTIONS), b3Format.Extract(headersEightBytes, Getter));
        }
        public void Serialize_NotSampledContext()
        {
            IDictionary <String, String> carrier = new Dictionary <String, String>();
            var context = SpanContext.Create(TraceId, SpanId, ActivityTraceFlags.None, Tracestate.Empty);

            _output.WriteLine(context.ToString());
            b3Format.Inject(context, carrier, setter);
            ContainsExactly(carrier, new Dictionary <string, string>()
            {
                { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }
            });
        }
        public void Serialize_NotSampledContext()
        {
            IDictionary <String, String> carrier = new Dictionary <String, String>();
            var context = SpanContext.Create(TRACE_ID, SPAN_ID, TraceOptions.Default, Tracestate.Empty);

            _output.WriteLine(context.ToString());
            b3Format.Inject(context, carrier, setter);
            ContainsExactly(carrier, new Dictionary <string, string>()
            {
                { B3Format.XB3TraceId, TRACE_ID_BASE16 }, { B3Format.XB3SpanId, SPAN_ID_BASE16 }
            });
        }
示例#29
0
        public void Serialize_NotSampledContext()
        {
            IDictionary <string, string> carrier = new Dictionary <string, string>();
            var context = SpanContext.Create(TRACE_ID, SPAN_ID, TraceOptions.DEFAULT);

            _output.WriteLine(context.ToString());
            b3Format.Inject(context, carrier, Setter);
            ContainsExactly(carrier, new Dictionary <string, string>()
            {
                { B3Format.X_B3_TRACE_ID, TRACE_ID_BASE16 }, { B3Format.X_B3_SPAN_ID, SPAN_ID_BASE16 }
            });
        }
示例#30
0
 public InProcessSampledSpanStoreTest()
 {
     timestamp             = Timestamp.FromDateTimeOffset(startTime);
     timestampConverter    = Timer.StartNew(startTime, () => interval);
     sampledSpanContext    = SpanContext.Create(TraceId.GenerateRandomId(random), SpanId.GenerateRandomId(random), TraceOptions.Builder().SetIsSampled(true).Build(), Tracestate.Empty);
     notSampledSpanContext = SpanContext.Create(TraceId.GenerateRandomId(random), SpanId.GenerateRandomId(random), TraceOptions.Default, Tracestate.Empty);
     parentSpanId          = SpanId.GenerateRandomId(random);
     startEndHandler       = new TestStartEndHandler(sampleStore);
     sampleStore.RegisterSpanNamesForCollection(new List <string>()
     {
         REGISTERED_SPAN_NAME
     });
 }