Exemple #1
0
        public MockSpan(
            MockTracer tracer,
            string operationName,
            DateTimeOffset startTimestamp,
            Dictionary <string, object> initialTags,
            List <Reference> references)
        {
            _mockTracer    = tracer;
            OperationName  = operationName;
            StartTimestamp = startTimestamp;

            _tags = initialTags == null
                ? new Dictionary <string, object>()
                : new Dictionary <string, object>(initialTags);

            _references = references == null
                ? new List <Reference>()
                : references.ToList();

            var parentContext = FindPreferredParentRef(_references);

            if (parentContext == null)
            {
                // we are a root span
                _context = new MockSpanContext(NextId(), NextId(), new Dictionary <string, string>());
                ParentId = 0;
            }
            else
            {
                // we are a child span
                _context = new MockSpanContext(parentContext.TraceId, NextId(), MergeBaggages(_references));
                ParentId = parentContext.SpanId;
            }
        }
Exemple #2
0
 public ISpan SetBaggageItem(string key, string value)
 {
     lock (_lock)
     {
         CheckForFinished("Adding baggage [{0}:{1}] to already finished span.", key, value);
         _context = _context.WithBaggageItem(key, value);
         return(this);
     }
 }
Exemple #3
0
 public void Inject <TCarrier>(MockSpanContext context, IFormat <TCarrier> format, TCarrier carrier)
 {
     if (carrier is IBinary stream)
     {
         var contextObject = new BinaryContext
         {
             SpanId = context.SpanId, TraceId = context.TraceId
         };
         var serialContext = Serialize(contextObject);
         stream.Set(serialContext);
     }
     else
     {
         throw new InvalidOperationException($"Unknown carrier [{carrier.GetType()}]");
     }
 }
        public void Inject <TCarrier>(MockSpanContext context, IFormat <TCarrier> format, TCarrier carrier)
        {
            if (carrier is ITextMap text)
            {
                foreach (var entry in context.GetBaggageItems())
                {
                    text.Set(BaggageKeyPrefix + entry.Key, entry.Value);
                }

                text.Set(SpanIdKey, context.SpanId.ToString());
                text.Set(TraceIdKey, context.TraceId.ToString());
            }
            else
            {
                throw new InvalidOperationException($"Unknown carrier [{carrier.GetType()}]");
            }
        }
Exemple #5
0
 public Reference(MockSpanContext context, string referenceType)
 {
     Context       = context ?? throw new ArgumentNullException(nameof(context));
     ReferenceType = referenceType ?? throw new ArgumentNullException(nameof(referenceType));
 }
 public void Inject <TCarrier>(MockSpanContext context, IFormat <TCarrier> format, TCarrier carrier)
 {
     Console.WriteLine($"Inject({context}, {format}, {carrier}");
 }