Ejemplo n.º 1
0
        public void Inject(IContextCarrier carrier)
        {
            var span = InternalActiveSpan();

            if (!span.IsExit)
            {
                throw new InvalidOperationException("Inject can be done only in Exit Span");
            }
            var spanWithPeer = span as IWithPeerInfo;

            carrier.PeerHost       = spanWithPeer.Peer;
            carrier.TraceSegmentId = _segment.TraceSegmentId;
            carrier.SpanId         = span.SpanId;
            carrier.Identity       = _segment.Identity;

            carrier.ParentApplicationCode = _segment.ApplicationCode;

            var refs      = _segment.Refs;
            var firstSpan = _activeSpanStacks.Last();

            carrier.ParentOperationName = firstSpan.OperationName;

            var metaValue = GetMetaValue(refs);

            carrier.EntryApplicationCode = metaValue.entryApplicationCode;
            carrier.EntryOperationName   = metaValue.operationName;
        }
Ejemplo n.º 2
0
        public static ISpan CreateExitSpan(string operationName, IContextCarrier carrier, string remotePeer, string activityId, string parentId, string rootId)
        {
            var context = GetOrCreateContext(operationName, false);
            var span    = context.CreateExitSpan(operationName, remotePeer, activityId, parentId);

            context.Inject(carrier, activityId, rootId);
            return(span);
        }
Ejemplo n.º 3
0
        public static ISpan CreateExitSpan(string operationName, IContextCarrier carrier, string remotePeer)
        {
            var context = GetOrCreateContext(operationName, false);
            var span    = context.CreateExitSpan(operationName, remotePeer);

            context.Inject(carrier);
            return(span);
        }
Ejemplo n.º 4
0
        [Test] public void SubmitCopiesContextBeforeExecutesAction()
        {
            IContextCarrier cc     = SetupContextCarrier();
            var             future = _sut.Submit(_action, TestData <T> .One);

            Assert.IsTrue(future.IsDone);
            Assert.That(future.GetResult(), Is.EqualTo(TestData <T> .One));

            Mockery.Assert(cc.ActivityOf(x => x.Restore()) < _action.ActivityOf(x => x()));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Inject the context into the given carrier, only when the active span is an exit one.
        /// </summary>
        public void Inject(IContextCarrier carrier)
        {
            var span = InternalActiveSpan();

            if (!span.IsExit)
            {
                throw new InvalidOperationException("Inject can be done only in Exit Span");
            }

            var spanWithPeer = span as IWithPeerInfo;
            var peer         = spanWithPeer.Peer;
            var peerId       = spanWithPeer.PeerId;

            carrier.TraceSegmentId = _segment.TraceSegmentId;
            carrier.SpanId         = span.SpanId;
            carrier.ParentApplicationInstanceId = _segment.ApplicationInstanceId;

            if (DictionaryUtil.IsNull(peerId))
            {
                carrier.PeerHost = peer;
            }
            else
            {
                carrier.PeerId = peerId;
            }

            var refs      = _segment.Refs;
            var firstSpan = _activeSpanStacks.Last();

            var metaValue = GetMetaValue(refs);

            carrier.EntryApplicationInstanceId = metaValue.entryApplicationInstanceId;

            if (DictionaryUtil.IsNull(metaValue.operationId))
            {
                carrier.EntryOperationName = metaValue.operationName;
            }
            else
            {
                carrier.EntryOperationId = metaValue.operationId;
            }

            var parentOperationId = firstSpan.OperationId;

            if (DictionaryUtil.IsNull(parentOperationId))
            {
                carrier.ParentOperationName = firstSpan.OperationName;
            }
            else
            {
                carrier.ParentOperationId = parentOperationId;
            }

            carrier.SetDistributedTraceIds(_segment.RelatedGlobalTraces);
        }
Ejemplo n.º 6
0
 public TraceSegmentRef(IContextCarrier carrier)
 {
     _traceSegmentId        = carrier.TraceSegmentId;
     _spanId                = carrier.SpanId;
     _parentApplicationCode = carrier.ParentApplicationCode;
     _entryApplicationCode  = carrier.EntryApplicationCode;
     _peerAddress           = carrier.PeerHost;
     _entryOperationName    = carrier.EntryOperationName;
     _parentOperationName   = carrier.ParentOperationName;
     _identity              = carrier.Identity;
 }
        /// <summary>
        /// Inject the context into the given carrier, only when the active span is an exit one.
        /// </summary>
        public void Inject(IContextCarrier carrier, string activityId, string rootId)
        {
            var span = InternalActiveSpan(activityId);

            if (!span.IsExit)
            {
                throw new InvalidOperationException("Inject can be done only in Exit Span");
            }

            var spanWithPeer = span as IWithPeerInfo;
            var peer         = spanWithPeer.Peer;
            var peerId       = spanWithPeer.PeerId;

            carrier.TraceSegmentId = _segment.TraceSegmentId;
            carrier.SpanId         = span.SpanId;
            carrier.ParentApplicationInstanceId = _segment.ApplicationInstanceId;

            if (peerId == 0)
            {
                carrier.PeerHost = peer;
            }
            else
            {
                carrier.PeerId = peerId;
            }

            var refs = _segment.Refs;

            var metaValue = GetMetaValue(refs, rootId);

            carrier.EntryApplicationInstanceId = metaValue.entryApplicationInstanceId;

            if (metaValue.operationId == 0)
            {
                carrier.EntryOperationName = metaValue.operationName;
            }
            else
            {
                carrier.EntryOperationId = metaValue.operationId;
            }

            var parentOperationId = RootSpan(rootId).OperationId;

            if (parentOperationId == 0)
            {
                carrier.ParentOperationName = RootSpan(rootId).OperationName;
            }
            else
            {
                carrier.ParentOperationId = parentOperationId;
            }

            carrier.SetDistributedTraceIds(_segment.RelatedGlobalTraces);
        }
Ejemplo n.º 8
0
        [Test] public void SubmitCopiesContextBeforeExecutesCallable()
        {
            IContextCarrier cc = SetupContextCarrier();

            _callable.Stub(x => x.Call()).Return(TestData <T> .Two);
            var future = _sut.Submit(_callable);

            Assert.IsTrue(future.IsDone);
            Assert.That(future.GetResult(), Is.EqualTo(TestData <T> .Two));

            Mockery.Assert(cc.ActivityOf(x => x.Restore()) < _callable.ActivityOf(x => x.Call()));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Extract the carrier to build the reference for the pre segment.
        /// </summary>
        public void Extract(IContextCarrier carrier)
        {
            var traceSegmentRef = new TraceSegmentRef(carrier);

            _segment.Ref(traceSegmentRef);
            _segment.RelatedGlobalTrace(carrier.DistributedTraceId);
            var span = InternalActiveSpan();

            if (span is EntrySpan)
            {
                span.Ref(traceSegmentRef);
            }
        }
Ejemplo n.º 10
0
 public static ISpan CreateEntrySpan(string operationName, IContextCarrier carrier)
 {
     if (carrier != null && carrier.IsValid)
     {
         var context = GetOrCreateContext();
         var span    = context.CreateEntrySpan(operationName);
         context.Extract(carrier);
         return(span);
     }
     else
     {
         var context = GetOrCreateContext();
         return(context.CreateEntrySpan(operationName));
     }
 }
Ejemplo n.º 11
0
        public void Extract(IContextCarrier carrier)
        {
            var traceSegmentRef = new TraceSegmentRef(carrier);

            _segment.Ref(traceSegmentRef);
            _segment.Identity       = carrier.Identity;
            _segment.TraceSegmentId = carrier.TraceSegmentId;
            var span = InternalActiveSpan();

            if (span is EntrySpan)
            {
                span.ParentSpanId = carrier.SpanId;
                span.Ref(traceSegmentRef);
            }
        }
Ejemplo n.º 12
0
        public static ISpan CreateEntrySpan(string operationName, IContextCarrier carrier, string activityId, string parentId)
        {
            var samplingService = DefaultSampler.Instance;

            if (carrier != null && carrier.IsValid)
            {
                samplingService.ForceSampled();
                var context = GetOrCreateContext(operationName, true);
                var span    = context.CreateEntrySpan(operationName, activityId, parentId);
                context.Extract(carrier, activityId);
                return(span);
            }
            else
            {
                var context = GetOrCreateContext(operationName, false);

                return(context.CreateEntrySpan(operationName, activityId, parentId));
            }
        }
Ejemplo n.º 13
0
        public static ISpan CreateEntrySpan(string operationName, IContextCarrier carrier)
        {
            var samplingService = ServiceManager.Instance.GetService <SamplingService>();

            if (carrier != null && carrier.IsValid)
            {
                samplingService.ForceSampled();
                var context = GetOrCreateContext(operationName, true);
                var span    = context.CreateEntrySpan(operationName);
                context.Extract(carrier);
                return(span);
            }
            else
            {
                var context = GetOrCreateContext(operationName, false);

                return(context.CreateEntrySpan(operationName));
            }
        }
Ejemplo n.º 14
0
        public TraceSegmentRef(IContextCarrier carrier)
        {
            _type           = SegmentRefType.CrossProcess;
            _traceSegmentId = carrier.TraceSegmentId;
            _spanId         = carrier.SpanId;
            _parentApplicationInstanceId = carrier.ParentApplicationInstanceId;
            _entryApplicationInstanceId  = carrier.EntryApplicationInstanceId;
            string host = carrier.PeerHost;

            if (host.ToCharArray()[0] == '#')
            {
                _peerHost = host.Substring(1);
            }
            else
            {
                int.TryParse(host, out _peerId);
            }

            string entryOperationName = carrier.EntryOperationName;

            if (entryOperationName.First() == '#')
            {
                _entryOperationName = entryOperationName.Substring(1);
            }
            else
            {
                int.TryParse(entryOperationName, out _entryOperationId);
            }

            string parentOperationName = carrier.EntryOperationName;

            if (parentOperationName.First() == '#')
            {
                _parentOperationName = parentOperationName.Substring(1);
            }
            else
            {
                int.TryParse(parentOperationName, out _parentOperationId);
            }
        }
Ejemplo n.º 15
0
 [SetUp] public void SetUp()
 {
     _runnable       = MockRepository.GenerateStub <IRunnable>();
     _contextCarrier = MockRepository.GenerateStub <IContextCarrier>();
     _sut            = new ContextCopyingRunnable(_runnable, _contextCarrier);
 }
 public void Inject(IContextCarrier carrier, string activityId, string rootId)
 {
 }
Ejemplo n.º 17
0
 public ContextCopyingRunnable(IRunnable runnable, IContextCarrier contextCarrier)
     : base(ExtractAction(runnable))
 {
     _contextCarrier = contextCarrier;
 }
Ejemplo n.º 18
0
 public ContextCopyingRunnable(IRunnable runnable, IContextCarrier contextCarrier)
     : base(ExtractAction(runnable))
 {
     _contextCarrier = contextCarrier;
 }
 public void Extract(IContextCarrier carrier, string activityId)
 {
 }
Ejemplo n.º 20
0
 public void Inject(IContextCarrier carrier)
 {
 }
Ejemplo n.º 21
0
 public SW3CarrierItem(IContextCarrier carrier, CarrierItem next)
     : base(HEADER_NAME, carrier.Serialize(), next)
 {
     _carrier = carrier;
 }
Ejemplo n.º 22
0
 public static void Inject(IContextCarrier carrier, string activityId, string rootId)
 {
     Context?.Inject(carrier, activityId, rootId);
 }
Ejemplo n.º 23
0
 public static void Extract(IContextCarrier carrier, string activityId)
 {
     Context?.Extract(carrier, activityId);
 }
Ejemplo n.º 24
0
 public void Extract(IContextCarrier carrier)
 {
 }
 public void SetUp()
 {
     _runnable = MockRepository.GenerateStub<IRunnable>();
     _contextCarrier = MockRepository.GenerateStub<IContextCarrier>();
     _sut = new ContextCopyingRunnable(_runnable, _contextCarrier);
 }
Ejemplo n.º 26
0
 public static void Extract(IContextCarrier carrier)
 {
     Context?.Extract(carrier);
 }
Ejemplo n.º 27
0
 public static void Inject(IContextCarrier carrier)
 {
     Context?.Inject(carrier);
 }
Ejemplo n.º 28
0
 public SW3CarrierItem(IContextCarrier carrier, CarrierItem next, string @namespace)
     : base(HEADER_NAME, carrier.Serialize(), next, @namespace)
 {
     _carrier = carrier;
 }