/// <summary>
        /// Invokes a simple remote call asynchronously.
        /// </summary>
        public override AsyncUnaryCall <TResponse> AsyncUnaryCall <TRequest, TResponse>(Method <TRequest, TResponse> method, string host, CallOptions options, TRequest request)
        {
            var trace = this.ResolveTraceSpan().Child();

            trace.Record(Annotations.ClientSend());
            trace.Record(Annotations.ServiceName(_serviceName));
            trace.Record(Annotations.Rpc("grpc"));

            var channel = new Channel(_target, ChannelCredentials.Insecure);
            var call    = CreateCall(channel, method, host, options, trace);

            try
            {
                trace.Record(Annotations.Tag("grpc.host", _target));
                trace.Record(Annotations.Tag("grpc.request", JsonConvert.SerializeObject(request)));
                var response = Calls.AsyncUnaryCall(call, request);
                trace.Record(Annotations.Tag("grpc.response", JsonConvert.SerializeObject(response)));
                return(response);
            }
            finally
            {
                trace.Record(Annotations.ClientRecv());
                channel.ShutdownAsync();
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> PostFlickrImage()
        {
            PhotoSearchOptions photoSearchOptions = new PhotoSearchOptions
            {
                // See for List of Available Machine Tags
                //https://api-attractions.navigatorglass.com/swagger/#!/MachineKey/ApiMachineKeyPredicatesGet

                MachineTags = "machine_tags => nycparks:",
                //MachineTags = "machine_tags => nychalloffame:",
                //MachineTags = "machine_tags => nycparks:m010=",
                //MachineTags = "machine_tags => nycparks:m089=",
                //MachineTags = "machine_tags => nycparks:q436=",
                // MachineTags = "machine_tags => nycparks:m010=114",
                // UserId = "",
                //PhotoSize = "q",   //150x150
                //PhotoSize = "z",   // Medium 640
                //PhotoSize = "q", //width="1024" height="768
            };

            Log.Information("Begin Zipkin Trace Here");
            _trace.Record(Annotations.ClientSend());
            _trace.Record(Annotations.ServiceName("FlickrSearch:PostFlickrImage"));
            _trace.Record(Annotations.Rpc("Post"));
            var photos = await _flickrSearchService.SearchPhotosAsync(photoSearchOptions);

            _trace.Record(Annotations.ClientRecv());
            _logger.LogInformation("Total Photos:{PhotoCount}", photos.Count);


            HttpContext.Response.Headers.Add("Access-Control-Expose-Headers", "X-InlineCount");
            HttpContext.Response.Headers.Add("X-InlineCount", photos.Count.ToString(CultureInfo.InvariantCulture));
            return(Ok(photos));
        }
Esempio n. 3
0
        protected ITransmissionResponse SendHttpRequest(HttpPost httpPost)
        {
            Trace span = this.root.Child();

            span.Record(Annotations.ServiceName("execute"));

            try
            {
                var httpClient = new HttpClient();
                var response   = httpClient.Execute(httpPost);


                var result = this.HandleResponse(response);
                span.Record(Annotations.ClientRecv());
                return(result);
            }
            catch (Exception e)
            {
                span.Record(Annotations.Tag("exception", e.Message));
                throw new HyperwayTransmissionException(this.transmissionRequest.GetEndpoint().Address, e);
            }
            finally
            {
                span.Record(Annotations.ClientRecv());
            }
        }
Esempio n. 4
0
 public void DurationAndSpanStartedSetWhenSetAsComplete()
 {
     VerifySpanDurationComputedWhenSetAsComplete(Annotations.ClientSend(), Annotations.ClientRecv(), isRootSpan: false, isSpanStartedAndDurationSet: true);
     VerifySpanDurationComputedWhenSetAsComplete(Annotations.ServerRecv(), Annotations.ServerSend(), isRootSpan: true, isSpanStartedAndDurationSet: true);
     VerifySpanDurationComputedWhenSetAsComplete(Annotations.ServerRecv(), Annotations.ServerSend(), isRootSpan: false, isSpanStartedAndDurationSet: false);
     VerifySpanDurationComputedWhenSetAsComplete(Annotations.LocalOperationStart("Operation"), Annotations.LocalOperationStop(), isRootSpan: false, isSpanStartedAndDurationSet: true);
 }
Esempio n. 5
0
        public void SpansAreLoggedAfterEndAnnotationClientRecv()
        {
            var trace = Trace.Create();

            Record(trace, Annotations.ClientSend());
            Record(trace, Annotations.ClientRecv());

            _reporter.Verify(r => r.Report(It.IsAny <Span>()), Times.Once());
        }
Esempio n. 6
0
        public void SpansAreLoggedAfterEndAnnotationClientRecv()
        {
            var trace = Trace.Create();

            Record(trace, Annotations.ClientSend());
            Record(trace, Annotations.ClientRecv());

            _spanSerializer.Verify(s => s.SerializeTo(It.IsAny <Stream>(), It.IsAny <Span>()), Times.Once());
            _spanSender.Verify(sender => sender.Send(It.IsAny <byte[]>()), Times.Once());
        }
Esempio n. 7
0
 public void SimpleAnnotationsCorrectlyAdded()
 {
     AnnotationCorrectlyAdded(Annotations.ClientSend(), zipkinCoreConstants.CLIENT_SEND, false, false);
     AnnotationCorrectlyAdded(Annotations.ClientRecv(), zipkinCoreConstants.CLIENT_RECV, false, true);
     AnnotationCorrectlyAdded(Annotations.ServerRecv(), zipkinCoreConstants.SERVER_RECV, false, false);
     AnnotationCorrectlyAdded(Annotations.ServerSend(), zipkinCoreConstants.SERVER_SEND, false, true);
     AnnotationCorrectlyAdded(Annotations.WireRecv(), zipkinCoreConstants.WIRE_RECV, false, false);
     AnnotationCorrectlyAdded(Annotations.WireSend(), zipkinCoreConstants.WIRE_SEND, false, false);
     AnnotationCorrectlyAdded(Annotations.LocalOperationStart("Operation"), zipkinCoreConstants.LOCAL_COMPONENT, true, false);
 }
Esempio n. 8
0
        public TransmissionResult Call()
        {
            Trace span = Trace.Create();

            span.Record(Annotations.ServiceName("standalone"));
            span.Record(Annotations.ClientSend());

            try
            {
                ITransmissionResponse transmissionResponse;
                long duration = 0;

                if (this.parameters.UseFactory)
                {
                    using (Stream inputStream = File.Open(this.xmlPayloadFile.FullName, FileMode.Open, FileAccess.Read))
                    {
                        transmissionResponse = this.parameters.HyperwayOutboundComponent.GetTransmissionService()
                                               .Send(inputStream, span);
                    }
                }
                else
                {
                    ITransmissionRequest transmissionRequest = this.CreateTransmissionRequest(span);

                    ITransmitter transmitter;
                    Trace        span1 = span.Child();
                    span1.Record(Annotations.ServiceName("get transmitter"));
                    span1.Record(Annotations.ClientSend());
                    try
                    {
                        transmitter = this.parameters.HyperwayOutboundComponent.GetTransmitter();
                    }
                    finally
                    {
                        span1.Record(Annotations.ClientRecv());
                    }

                    // Performs the transmission
                    var watch = new Stopwatch();
                    watch.Start();
                    transmissionResponse = this.PerformTransmission(
                        this.parameters.EvidencePath, transmitter, transmissionRequest, span);
                    watch.Stop();

                    return(new TransmissionResult(watch.ElapsedMilliseconds, transmissionResponse.GetTransmissionIdentifier()));
                }

                return(new TransmissionResult(duration, transmissionResponse.GetTransmissionIdentifier()));
            }
            finally
            {
                span.Record(Annotations.ClientRecv());
            }
        }
Esempio n. 9
0
        public void SpanDoesntHaveDurationIfIncomplete()
        {
            const int offset = 10;

            Assert.False(GetSpanDuration(offset, Annotations.ServerRecv()).HasValue);
            Assert.False(GetSpanDuration(offset, Annotations.ServerSend()).HasValue);
            Assert.False(GetSpanDuration(offset, Annotations.ClientRecv()).HasValue);
            Assert.False(GetSpanDuration(offset, Annotations.ClientSend()).HasValue);
            Assert.False(GetSpanDuration(offset, Annotations.LocalOperationStart("Operation")).HasValue);
            Assert.False(GetSpanDuration(offset, Annotations.LocalOperationStop()).HasValue);
        }
Esempio n. 10
0
        public async Task <IActionResult> Get()
        {
            _trace.Record(Annotations.ClientSend());
            _trace.Record(Annotations.ServiceName("FlickrSearch:PhotoInfo"));
            _trace.Record(Annotations.Rpc("GET"));

            var result = await _flickrSearchService.GetPhotoInfoAsync("7012518889");

            _trace.Record(Annotations.ClientRecv());

            return(Ok(result));
        }
Esempio n. 11
0
        public static void RecordAnnotation(Trace trace, ZKAnnotations annotationType, String serviceName = null, string requestType = null)
        {
            switch (annotationType)
            {
            case ZKAnnotations.CS:
                trace.Record(Annotations.ClientSend());
                if (!String.IsNullOrEmpty(serviceName))
                {
                    trace.Record(Annotations.ServiceName(serviceName));
                }
                if (!String.IsNullOrEmpty(requestType))
                {
                    trace.Record(Annotations.Rpc("GET"));
                }
                break;

            case ZKAnnotations.CR:
                trace.Record(Annotations.ClientRecv());
                if (!String.IsNullOrEmpty(serviceName))
                {
                    trace.Record(Annotations.ServiceName(serviceName));
                }
                if (!String.IsNullOrEmpty(requestType))
                {
                    trace.Record(Annotations.Rpc("GET"));
                }
                break;

            case ZKAnnotations.SS:
                trace.Record(Annotations.ServerSend());
                if (!String.IsNullOrEmpty(serviceName))
                {
                    trace.Record(Annotations.ServiceName(serviceName));
                }
                if (!String.IsNullOrEmpty(requestType))
                {
                    trace.Record(Annotations.Rpc("GET"));
                }
                break;

            case ZKAnnotations.SR:
                trace.Record(Annotations.ServerRecv());
                if (!String.IsNullOrEmpty(serviceName))
                {
                    trace.Record(Annotations.ServiceName(serviceName));
                }
                if (!String.IsNullOrEmpty(requestType))
                {
                    trace.Record(Annotations.Rpc("GET"));
                }
                break;
            }
        }
Esempio n. 12
0
        public void FlagSampledShouldForward()
        {
            var dispatcher = new Mock <IRecordDispatcher>();

            TraceManager.Start(new VoidLogger(), dispatcher.Object);

            var spanState = new SpanState(1, 0, 1, isSampled: true, isDebug: false);
            var trace     = Trace.CreateFromId(spanState);

            trace.Record(Annotations.ClientRecv());

            dispatcher.Verify(d => d.Dispatch(It.IsAny <Record>()), Times.Once());
        }
Esempio n. 13
0
        public void FlagUnsetShouldForwardForBackwardCompatibility()
        {
            var dispatcher = new Mock <IRecordDispatcher>();

            TraceManager.Start(new VoidLogger(), dispatcher.Object);

            var spanState = new SpanState(1, 0, 1, SpanFlags.None);
            var trace     = Trace.CreateFromId(spanState);

            trace.Record(Annotations.ClientRecv());

            dispatcher.Verify(d => d.Dispatch(It.IsAny <Record>()), Times.Once());
        }
Esempio n. 14
0
        public void FlagNotSampledShouldNotForward()
        {
            var dispatcher = new Mock <IRecordDispatcher>();

            TraceManager.Start(new VoidLogger(), dispatcher.Object);

            var spanState = new SpanState(1, 0, 1, SpanFlags.SamplingKnown);
            var trace     = Trace.CreateFromId(spanState);

            trace.Record(Annotations.ClientRecv());

            dispatcher.Verify(d => d.Dispatch(It.IsAny <Record>()), Times.Never);
        }
Esempio n. 15
0
        private static Span CreateClientSpan()
        {
            var trace = Trace.Create();

            trace.Record(Annotations.ClientSend());
            trace.Record(Annotations.Rpc("query"));
            trace.Record(Annotations.ServiceName("zipkin-client"));
            trace.Record(Annotations.Tag("jdbc.query", "select distinct `zipkin_spans`.`trace_id` from `zipkin_spans` join `zipkin_annotations` on (`zipkin_spans`.`trace_id` = `zipkin_annotations`.`trace_id` and `zipkin_spans`.`id` = `zipkin_annotations`.`span_id`) where (`zipkin_annotations`.`endpoint_service_name` = ? and `zipkin_spans`.`start_ts` between ? and ?) order by `zipkin_spans`.`start_ts` desc limit ?"));
            trace.Record(Annotations.Tag("ca", "frontend"));
            trace.Record(Annotations.Tag("sa", "backend"));
            trace.Record(Annotations.ClientRecv());
            return(new Span(trace.CurrentSpan, new DateTime()));
        }
Esempio n. 16
0
 public void SimpleAnnotationsCorrectlyAdded()
 {
     AnnotationCorrectlyAdded(Annotations.ClientSend(), zipkinCoreConstants.CLIENT_SEND, false, false);
     AnnotationCorrectlyAdded(Annotations.ClientRecv(), zipkinCoreConstants.CLIENT_RECV, false, true);
     AnnotationCorrectlyAdded(Annotations.ServerRecv(), zipkinCoreConstants.SERVER_RECV, false, false);
     AnnotationCorrectlyAdded(Annotations.ServerSend(), zipkinCoreConstants.SERVER_SEND, false, true);
     AnnotationCorrectlyAdded(Annotations.WireRecv(), zipkinCoreConstants.WIRE_RECV, false, false);
     AnnotationCorrectlyAdded(Annotations.WireSend(), zipkinCoreConstants.WIRE_SEND, false, false);
     AnnotationCorrectlyAdded(Annotations.LocalOperationStart("Operation"), zipkinCoreConstants.LOCAL_COMPONENT, true, false);
     AnnotationCorrectlyAdded(Annotations.ConsumerStart(), zipkinCoreConstants.MESSAGE_RECV, false, false);
     AnnotationCorrectlyAdded(Annotations.ProducerStart(), zipkinCoreConstants.MESSAGE_SEND, false, false);
     AnnotationCorrectlyAdded(Annotations.MessageAddr("service", new IPEndPoint(0, 1)), zipkinCoreConstants.MESSAGE_ADDR, true, false);
 }
Esempio n. 17
0
        public void SpanHasDurationOnlyIfValueIsPositive(int offset, bool shouldHaveDuration)
        {
            var duration = GetSpanDuration(offset, Annotations.ClientSend(), Annotations.ClientRecv());

            if (shouldHaveDuration)
            {
                Assert.AreEqual(offset, (int)duration.Value.TotalMilliseconds);
            }
            else
            {
                Assert.False(duration.HasValue);
            }
        }
Esempio n. 18
0
 public void FactoryReturnsCorrectTypes()
 {
     Assert.IsInstanceOf <TagAnnotation>(Annotations.Tag("", ""));
     Assert.IsInstanceOf <ClientRecv>(Annotations.ClientRecv());
     Assert.IsInstanceOf <ClientSend>(Annotations.ClientSend());
     Assert.IsInstanceOf <LocalAddr>(Annotations.LocalAddr(null));
     Assert.IsInstanceOf <Rpc>(Annotations.Rpc(""));
     Assert.IsInstanceOf <ServerRecv>(Annotations.ServerRecv());
     Assert.IsInstanceOf <ServerSend>(Annotations.ServerSend());
     Assert.IsInstanceOf <ServiceName>(Annotations.ServiceName(""));
     Assert.IsInstanceOf <Event>(Annotations.Event(""));
     Assert.IsInstanceOf <ClientAddr>(Annotations.ClientAddr(null));
     Assert.IsInstanceOf <ServerAddr>(Annotations.ServerAddr(null, null));
 }
Esempio n. 19
0
        public ITransmissionResponse Send(Stream inputStream)
        {
            var trace = Trace.Create();

            trace.Record(Annotations.ServiceName("TransmissionService"));
            trace.Record(Annotations.ClientSend());
            try
            {
                return(this.Send(inputStream, trace));
            }
            finally
            {
                trace.Record(Annotations.ClientRecv());
            }
        }
Esempio n. 20
0
        public ITransmissionRequest Build(Trace root)
        {
            Trace span = root.Child();

            span.Record(Annotations.ServiceName("build"));
            span.Record(Annotations.ClientSend());
            try
            {
                return(this.Build());
            }
            finally
            {
                span.Record(Annotations.ClientRecv());
            }
        }
Esempio n. 21
0
        /// <inheritdoc />
        public ITransmissionResponse Transmit(ITransmissionMessage transmissionMessage)
        {
            Trace root = Trace.Create();

            root.Record(Annotations.ServiceName("transmit"));
            root.Record(Annotations.ClientSend());
            try
            {
                return(this.Perform(transmissionMessage, root));
            }
            finally
            {
                root.Record(Annotations.ClientRecv());
            }
        }
Esempio n. 22
0
        public ITransmissionMessage NewInstance(Stream inputStream)
        {
            Trace trace = Trace.Create();

            trace.Record(Annotations.ServiceName(this.GetType().Name));
            trace.Record(Annotations.ClientSend());
            try
            {
                return(this.Perform(inputStream, trace));
            }
            finally
            {
                trace.Record(Annotations.ClientRecv());
            }
        }
Esempio n. 23
0
        /// <inheritdoc />
        public ITransmissionResponse Transmit(ITransmissionMessage transmissionMessage, Trace root)
        {
            Trace span = root.Child();

            span.Record(Annotations.ServiceName("transmit"));
            span.Record(Annotations.ClientSend());
            try
            {
                return(this.Perform(transmissionMessage, span));
            }
            finally
            {
                span.Record(Annotations.ClientRecv());
            }
        }
Esempio n. 24
0
        public ITransmissionMessage NewInstance(Stream inputStream, Trace root)
        {
            var trace = root.Child();

            trace.Record(Annotations.ServiceName(this.GetType().Name));
            trace.Record(Annotations.ClientSend());
            try
            {
                return(this.Perform(inputStream, root));
            }
            finally
            {
                trace.Record(Annotations.ClientRecv());
            }
        }
Esempio n. 25
0
        public void TraceCreatesCorrectRecord()
        {
            var trace = Trace.Create();

            trace.ForceSampled();

            var dispatcher = new Mock <IRecordDispatcher>();

            TraceManager.Start(new VoidLogger(), dispatcher.Object);

            var someAnnotation = Annotations.ClientRecv();

            trace.Record(someAnnotation);

            dispatcher.Verify(d => d.Dispatch(It.Is <Record>(r => r.Annotation.Equals(someAnnotation) && r.SpanState.Equals(trace.CurrentSpan))), Times.Once());
        }
Esempio n. 26
0
        public void TraceCreatesCorrectRecordWithTimeSpecified()
        {
            var trace = Trace.Create();

            trace.ForceSampled();

            var dispatcher = new Mock <IRecordDispatcher>();

            TraceManager.Start(new VoidLogger(), dispatcher.Object);

            var someAnnotation = Annotations.ClientRecv();
            var recordTime     = new DateTime(2010, 2, 3, 14, 3, 1, DateTimeKind.Utc);

            trace.Record(someAnnotation, recordTime);

            dispatcher.Verify(d => d.Dispatch(It.Is <Record>(r => r.Annotation.Equals(someAnnotation) && r.SpanState.Equals(trace.CurrentSpan) && r.Timestamp.Equals(recordTime))), Times.Once());
        }
Esempio n. 27
0
        private static IAnnotation GetClosingAnnotation(OtSpanKind spanKind)
        {
            switch (spanKind)
            {
            case OtSpanKind.Client:
                return(Annotations.ClientRecv());

            case OtSpanKind.Server:
                return(Annotations.ServerSend());

            case OtSpanKind.Local:
                return(Annotations.LocalOperationStop());

            default:
                throw new NotSupportedException("SpanKind: " + spanKind + " unknown.");
            }
        }
Esempio n. 28
0
        public void Persist(
            ITransmissionRequest transmissionRequest,
            ITransmissionResponse transmissionResponse,
            Trace root)
        {
            Trace span = root.Child();

            span.Record(Annotations.ServiceName("persist statistics"));
            span.Record(Annotations.ClientSend());
            try
            {
                RawStatisticsBuilder builder = new RawStatisticsBuilder()
                                               .AccessPointIdentifier(this.ourAccessPointIdentifier).Direction(Direction.OUT)
                                               .DocumentType(transmissionResponse.GetHeader().DocumentType)
                                               .Sender(transmissionResponse.GetHeader().Sender)
                                               .Receiver(transmissionResponse.GetHeader().Receiver)
                                               .Profile(transmissionResponse.GetHeader().Process)
                                               .Date(transmissionResponse.GetTimestamp()); // Time stamp of reception of the receipt

                // If we know the CN name of the destination AP, supply that
                // as the channel id otherwise use the protocol name
                if (transmissionRequest.GetEndpoint().Certificate != null)
                {
                    String accessPointIdentifierValue =
                        CertificateUtils.ExtractCommonName(transmissionRequest.GetEndpoint().Certificate);
                    builder.Channel(new ChannelId(accessPointIdentifierValue));
                }
                else
                {
                    String protocolName = transmissionRequest.GetEndpoint().TransportProfile.Identifier;
                    builder.Channel(new ChannelId(protocolName));
                }

                DefaultRawStatistics rawStatistics = builder.Build();
                this.rawStatisticsRepository.Persist(rawStatistics);
            }
            catch (Exception ex)
            {
                span.Record(Annotations.Tag("exception", ex.Message));
                Logger.Error($"Persisting DefaultRawStatistics about oubound transmission failed : {ex.Message}", ex);
            }
            finally
            {
                span.Record(Annotations.ClientRecv());
            }
        }
Esempio n. 29
0
 public void FactoryReturnsCorrectTypes()
 {
     Assert.IsInstanceOf <TagAnnotation>(Annotations.Tag("", ""));
     Assert.IsInstanceOf <ClientRecv>(Annotations.ClientRecv());
     Assert.IsInstanceOf <ClientSend>(Annotations.ClientSend());
     Assert.IsInstanceOf <LocalAddr>(Annotations.LocalAddr(null));
     Assert.IsInstanceOf <Rpc>(Annotations.Rpc(""));
     Assert.IsInstanceOf <ServerRecv>(Annotations.ServerRecv());
     Assert.IsInstanceOf <ServerSend>(Annotations.ServerSend());
     Assert.IsInstanceOf <ServiceName>(Annotations.ServiceName(""));
     Assert.IsInstanceOf <Event>(Annotations.Event(""));
     Assert.IsInstanceOf <ClientAddr>(Annotations.ClientAddr(null));
     Assert.IsInstanceOf <ServerAddr>(Annotations.ServerAddr(null, null));
     Assert.IsInstanceOf <MessageAddr>(Annotations.MessageAddr(null, null));
     Assert.IsInstanceOf <ConsumerStart>(Annotations.ConsumerStart());
     Assert.IsInstanceOf <ConsumerStop>(Annotations.ConsumerStop());
     Assert.IsInstanceOf <ProducerStart>(Annotations.ProducerStart());
     Assert.IsInstanceOf <ProducerStop>(Annotations.ProducerStop());
     Assert.IsInstanceOf <LocalOperationStart>(Annotations.LocalOperationStart(""));
     Assert.IsInstanceOf <LocalOperationStop>(Annotations.LocalOperationStop());
 }
Esempio n. 30
0
        public ITransmissionResponse Send(ITransmissionRequest request, Trace traceParent)
        {
            this.transmissionRequest = request;

            this.root = traceParent.Child();
            this.root.Record(Annotations.ServiceName("Send AS2 message"));
            this.root.Record(Annotations.ClientSend());
            try
            {
                return(this.SendHttpRequest(this.PrepareHttpRequest()));
            }
            catch (HyperwayTransmissionException e)
            {
                this.root.Record(Annotations.Tag("exception", e.Message));
                throw;
            }
            finally
            {
                this.root.Record(Annotations.ClientRecv());
            }
        }