示例#1
0
        public async Task <ClusterResult> ExecuteAsync(IRequestContext context, Func <IRequestContext, Task <ClusterResult> > next)
        {
            var spanBuilder = config.Tracer.BeginHttpClusterSpan();

            var traceContext = config.Tracer.CurrentContext;

            if (traceContext != null)
            {
                spanBuilder.SetTargetDetails(TargetServiceProvider?.Invoke(), TargetEnvironmentProvider?.Invoke());
                spanBuilder.SetRequestDetails(context.Request);
                spanBuilder.SetAnnotation(WellKnownAnnotations.Common.Component, Constants.Component);

                var strategy = context.Parameters.Strategy;
                if (strategy != null)
                {
                    spanBuilder.SetClusterStrategy(strategy.ToString());
                }
            }

            var result = await next(context).ConfigureAwait(false);

            if (traceContext != null)
            {
                // (kungurtsev): SetResponseDetails will dispose spanBuilder
                result = spanBuilder.SetResponseDetails(result);
            }
            else
            {
                spanBuilder.Dispose();
            }

            return(result);
        }
示例#2
0
        public async Task <Response> SendAsync(Request request, TimeSpan?connectionTimeout, TimeSpan timeout, CancellationToken cancellationToken)
        {
            var spanBuilder = configuration.Tracer.BeginHttpClientSpan();

            var traceContext = configuration.Tracer.CurrentContext;

            if (traceContext != null)
            {
                spanBuilder.SetTargetDetails(TargetServiceProvider?.Invoke(), TargetEnvironmentProvider?.Invoke());
                spanBuilder.SetRequestDetails(request);
                spanBuilder.SetAnnotation(WellKnownAnnotations.Common.Component, Constants.Component);

                if (configuration.AdditionalRequestTransformation != null)
                {
                    request = configuration.AdditionalRequestTransformation(request, traceContext);
                }
            }

            var response = await transport
                           .SendAsync(request, connectionTimeout, timeout, cancellationToken)
                           .ConfigureAwait(false);

            if (traceContext != null)
            {
                response = spanBuilder.SetResponseDetails(response);
            }
            else
            {
                spanBuilder.Dispose();
            }

            return(response);
        }