예제 #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;
            }
        }
예제 #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);
     }
 }
예제 #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()}]");
     }
 }
예제 #4
0
        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()}]");
            }
        }
예제 #5
0
 public Reference(MockSpanContext context, string referenceType)
 {
     Context       = context ?? throw new ArgumentNullException(nameof(context));
     ReferenceType = referenceType ?? throw new ArgumentNullException(nameof(referenceType));
 }
예제 #6
0
 public void Inject <TCarrier>(MockSpanContext context, IFormat <TCarrier> format, TCarrier carrier)
 {
     Console.WriteLine($"Inject({context}, {format}, {carrier}");
 }