Ejemplo n.º 1
0
        public async Task ReportAsync(IReadOnlyCollection <SegmentRequest> segmentRequests,
                                      CancellationToken cancellationToken = default(CancellationToken))
        {
            if (!_connectionManager.Ready)
            {
                return;
            }

            var connection = _connectionManager.GetConnection();

            try
            {
                var stopwatch = Stopwatch.StartNew();
                var client    = new TraceSegmentReportService.TraceSegmentReportServiceClient(connection);
                using (var asyncClientStreamingCall =
                           client.collect(null, _config.GetReportTimeout(), cancellationToken))
                {
                    foreach (var segment in segmentRequests)
                    {
                        await asyncClientStreamingCall.RequestStream.WriteAsync(SegmentV6Helpers.Map(segment));
                    }
                    await asyncClientStreamingCall.RequestStream.CompleteAsync();

                    await asyncClientStreamingCall.ResponseAsync;
                }

                stopwatch.Stop();
                _logger.Information($"Report {segmentRequests.Count} trace segment. cost: {stopwatch.Elapsed}s");
            }
            catch (Exception ex)
            {
                _logger.Error("Report trace segment fail.", ex);
                _connectionManager.Failure(ex);
            }
        }
Ejemplo n.º 2
0
        private void trace(Channel channel, int serviceId, int serviceInstanceId)
        {
            var client = new TraceSegmentReportService.TraceSegmentReportServiceClient(channel);

            using (var asyncClientStreamingCall = client.collect())
            {
                SegmentContextMapper context = new SegmentContextMapper();

                SegmentRequest segment = context.Map(serviceId, serviceInstanceId, this.txtInputValue.Text);

                asyncClientStreamingCall.RequestStream.WriteAsync(SegmentV6Helpers.Map(segment));

                asyncClientStreamingCall.RequestStream.CompleteAsync();

                //cli
                //CommandLineApplication
                var var2 = Task.Run(async() =>
                {
                    return(await asyncClientStreamingCall.ResponseAsync);
                }).Result;
            }
        }