public void TestNegativeChildSampling()
        {
            // Create tracer that samples all spans
            var tracer = new WavefrontTracer
                         .Builder(new ConsoleReporter("source"), BuildApplicationTags())
                         .WithSampler(new ConstantSampler(true))
                         .Build();

            // Create parentContext with sampled set to false
            var parentContext =
                new WavefrontSpanContext(Guid.NewGuid(), Guid.NewGuid(), null, false);

            // Verify span created AsChildOf parentContext inherits parent sampling decision
            var span = (WavefrontSpan)tracer.BuildSpan("testOp").AsChildOf(parentContext).Start();

            var  spanContext = (WavefrontSpanContext)span.Context;
            long traceId     = TraceIdToLong(spanContext.GetTraceId());

            Assert.True(tracer.Sample(span.GetOperationName(), traceId, 0));
            Assert.NotNull(span);
            Assert.Equal(parentContext.TraceId, spanContext.TraceId);
            Assert.True(spanContext.IsSampled());
            bool?samplingDecision = spanContext.GetSamplingDecision();

            Assert.True(samplingDecision.HasValue);
            Assert.False(samplingDecision.Value);
        }
        public void TestInvalidTraceIdExtract()
        {
            string val        = ":7499dd16d98ab60e:3771de7e09c55ae8:1";
            var    dictionary = new Dictionary <string, string>();

            dictionary.Add(JaegerHeader, val);
            var textMapExtractAdapter = new TextMapExtractAdapter(dictionary);
            WavefrontSpanContext ctx  = wfJaegerPropagator.Extract(textMapExtractAdapter);

            Assert.Null(ctx);
        }
        /// <summary>
        ///     Extracts traceId and spanId from a WavefrontSpanContext and constructs a Jaeger
        ///     client compatible header of the form traceId:spanId:parentId:samplingDecision.
        /// </summary>
        private string ContextToTraceIdHeader(WavefrontSpanContext context)
        {
            string traceId          = GuidToHex(context.GetTraceId());
            string spanId           = GuidToHex(context.GetSpanId());
            bool   samplingDecision = context.GetSamplingDecision() ?? false;
            string decision         = samplingDecision ? "1" : "0";
            string parentId         = Guid.TryParse(context.GetBaggageItem(ParentIdKey), out Guid guid) ?
                                      GuidToHex(guid) : "0";

            return($"{traceId}:{spanId}:{parentId}:{decision}");
        }
        public void TestTraceIdExtractEncoded()
        {
            string val        = "3871de7e09c53ae8%3A7499dd16d98ab60e%3A3771de7e09c55ae8%3A1";
            var    dictionary = new Dictionary <string, string>();

            dictionary.Add(JaegerHeader, val);
            var textMapExtractAdapter = new TextMapExtractAdapter(dictionary);
            WavefrontSpanContext ctx  = wfJaegerPropagator.Extract(textMapExtractAdapter);

            Assert.NotNull(ctx);
            Assert.Equal("00000000-0000-0000-3871-de7e09c53ae8", ctx.TraceId);
            Assert.Equal("00000000-0000-0000-7499-dd16d98ab60e", ctx.SpanId);
            Assert.Equal("00000000-0000-0000-7499-dd16d98ab60e", ctx.GetBaggageItem(ParentIdKey));
            Assert.True(ctx.GetSamplingDecision() ?? false);
        }
Ejemplo n.º 5
0
 /// <inheritdoc />
 public void Inject <TCarrier>(WavefrontSpanContext spanContext, TCarrier carrier)
 {
     if (carrier is ITextMap textMap)
     {
         textMap.Set(TraceId, spanContext.TraceId);
         textMap.Set(SpanId, spanContext.SpanId);
         foreach (var entry in spanContext.GetBaggageItems())
         {
             textMap.Set(BaggagePrefix + entry.Key, entry.Value);
         }
     }
     else
     {
         throw new ArgumentException("Invalid carrier " + carrier.GetType());
     }
 }
        public void TestBaggageItems()
        {
            var tracer = new WavefrontTracer
                         .Builder(new ConsoleReporter("source"), BuildApplicationTags())
                         .Build();

            // Create parentContext with baggage items
            var bag = new Dictionary <string, string>
            {
                { "foo", "bar" },
                { "user", "name" }
            };
            var parentContext = new WavefrontSpanContext(Guid.NewGuid(), Guid.NewGuid(), bag, true);

            var span = (WavefrontSpan)tracer.BuildSpan("testOp").AsChildOf(parentContext).Start();

            Assert.Equal("bar", span.GetBaggageItem("foo"));
            Assert.Equal("name", span.GetBaggageItem("user"));

            // Create follows
            var items = new Dictionary <string, string>
            {
                { "tracker", "id" },
                { "db.name", "name" }
            };
            var follows = new WavefrontSpanContext(Guid.NewGuid(), Guid.NewGuid(), items, true);

            span = (WavefrontSpan)tracer.BuildSpan("testOp")
                   .AsChildOf(parentContext)
                   .AsChildOf(follows)
                   .Start();
            Assert.Equal("bar", span.GetBaggageItem("foo"));
            Assert.Equal("name", span.GetBaggageItem("user"));
            Assert.Equal("id", span.GetBaggageItem("tracker"));
            Assert.Equal("name", span.GetBaggageItem("db.name"));

            // Validate root span
            span = (WavefrontSpan)tracer.BuildSpan("testOp").Start();
            IDictionary <string, string> baggage = ((WavefrontSpanContext)span.Context).GetBaggage();

            Assert.NotNull(baggage);
            Assert.Empty(baggage);
        }
 /// <inheritdoc />
 public void Inject <TCarrier>(WavefrontSpanContext spanContext, TCarrier carrier)
 {
     if (carrier is ITextMap textMap)
     {
         textMap.Set(traceIdHeader, ContextToTraceIdHeader(spanContext));
         foreach (var entry in spanContext.GetBaggageItems())
         {
             textMap.Set(baggagePrefix + entry.Key, entry.Value);
         }
         if (spanContext.IsSampled())
         {
             textMap.Set(SamplingDecisionKey, spanContext.GetSamplingDecision().ToString());
         }
     }
     else
     {
         throw new ArgumentException("Invalid carrier " + carrier.GetType());
     }
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="Reference"/> class for a given
 ///     span context and a given reference type.
 /// </summary>
 /// <param name="spanContext">The <see cref="WavefrontSpanContext"/>.</param>
 /// <param name="type">The reference type.</param>
 public Reference(WavefrontSpanContext spanContext, string type)
 {
     SpanContext = spanContext;
     Type        = type;
 }