public void AfterFinished(ITraceSegment traceSegment)
 {
     if (!traceSegment.IsIgnore)
     {
         _dispatcher.Dispatch(traceSegment.Transform());
     }
 }
Ejemplo n.º 2
0
        public async void AfterFinished(ITraceSegment traceSegment)
        {
            var segment             = traceSegment.Transform();
            var traceSegmentService =
                new TraceSegmentService.TraceSegmentServiceClient(GrpcChannelManager.Instance.Channel);

            using (var asyncClientStreamingCall = traceSegmentService.collect())
            {
                await asyncClientStreamingCall.RequestStream.WriteAsync(segment);

                await asyncClientStreamingCall.RequestStream.CompleteAsync();
            }
        }
        public async void AfterFinished(ITraceSegment traceSegment)
        {
            if (traceSegment.IsIgnore)
            {
                return;
            }

            var availableConnection = GrpcConnectionManager.Instance.GetAvailableConnection();

            if (availableConnection == null)
            {
                _logger.Warning(
                    $"Transform and send UpstreamSegment to collector fail. {GrpcConnectionManager.NotFoundErrorMessage}");
                return;
            }

            try
            {
                var segment             = traceSegment.Transform();
                var traceSegmentService =
                    new TraceSegmentService.TraceSegmentServiceClient(availableConnection.GrpcChannel);
                using (var asyncClientStreamingCall = traceSegmentService.collect())
                {
                    await asyncClientStreamingCall.RequestStream.WriteAsync(segment);

                    await asyncClientStreamingCall.RequestStream.CompleteAsync();

                    await asyncClientStreamingCall.ResponseAsync;
                }

                _logger.Debug(
                    $"Transform and send UpstreamSegment to collector. [TraceSegmentId] = {traceSegment.TraceSegmentId} [GlobalTraceId] = {traceSegment.RelatedGlobalTraces.FirstOrDefault()}");
            }
            catch (Exception e)
            {
                _logger.Warning($"Transform and send UpstreamSegment to collector fail. {e.Message}");
                availableConnection?.Failure();
            }
        }