/// <summary>
        /// Creates a client-side HTTP request activity.
        /// </summary>
        /// <param name="method">A HTTP method of a request.</param>
        /// <param name="uri">A HTTP uri of a request.</param>
        /// <returns>A new instance of <see cref="ClientRequestActivity"/>.</returns>
        public static ClientRequestActivity Create(string method, Uri uri)
        {
            if (string.IsNullOrWhiteSpace(method))
            {
                throw new ArgumentNullException(nameof(method));
            }
            if (uri == null)
            {
                throw new ArgumentNullException(nameof(uri));
            }

            ClientRequestActivity context = new ClientRequestActivity();

            if (context._relatedActivityId == Guid.Empty)
            {
                Log.Send(context._activityId, method, uri.ToString());
            }
            else
            {
                Log.BeginTransfer(context._relatedActivityId);
                Log.Send(context._activityId, method, uri.ToString());
                Log.EndTransfer(context._activityId, context._relatedActivityId);
            }

            return(context);
        }
Esempio n. 2
0
        /// <inheritdoc/>
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request,
                                                                      CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            HttpResponseMessage response = null;
            string method = request.Method.Method;

            using (ClientRequestActivity activity = ClientRequestActivity.Create(method, request.RequestUri))
            {
                request.Headers.Add(MessageHeaderKeys.ActivityId, activity.Id.ToString("N"));
                response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);

                // todo: user id resolver
                activity.SetResponse((int)response.StatusCode, Guid.Empty);
            }


            return(response);
        }