Beispiel #1
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request,
                                                                      CancellationToken cancellationToken)
        {
            var peer           = $"{request.RequestUri.Host}:{request.RequestUri.Port}";
            var contextCarrier = _contextCarrierFactory.Create();
            var span           = ContextManager.CreateExitSpan(request.RequestUri.ToString(), contextCarrier, peer);

            try
            {
                Tags.Url.Set(span, request.RequestUri.ToString());
                span.AsHttp();
                span.SetComponent(ComponentsDefine.HttpClient);
                Tags.HTTP.Method.Set(span, request.Method.ToString());
                foreach (var item in contextCarrier.Items)
                {
                    request.Headers.Add(item.HeadKey, item.HeadValue);
                }
                var response = await base.SendAsync(request, cancellationToken);

                Tags.StatusCode.Set(span, response.StatusCode.ToString());
                return(response);
            }
            catch (Exception e)
            {
                span.ErrorOccurred().Log(e);
                throw;
            }
            finally
            {
                ContextManager.StopSpan(span);
            }
        }
        public void BeginRequest([Property] HttpContext httpContext)
        {
            if (IgnoredRoute(httpContext.Request.Path))
            {
                return;
            }

            var carrier = _contextCarrierFactory.Create();

            foreach (var item in carrier.Items)
            {
                item.HeadValue = httpContext.Request.Headers[item.HeadKey];
            }

            var httpRequestSpan = ContextManager.CreateEntrySpan($"{_skrTraceOptions.ApplicationCode} {httpContext.Request.Path}", carrier);

            httpRequestSpan.AsHttp();
            httpRequestSpan.SetComponent(SpanComponent.AspNetCore);
            httpRequestSpan.Tags.Server()
            .HttpMethod(httpContext.Request.Method)
            .HttpUrl(httpContext.Request.GetDisplayUrl());

            httpRequestSpan.Log(LogField.CreateNew().Event("AspNetCore Hosting BeginRequest")
                                .Message($"Request starting {httpContext.Request.Protocol} {httpContext.Request.Method} {httpContext.Request.GetDisplayUrl()}"));
        }
Beispiel #3
0
        public void BeginRequest([Property] HttpContext httpContext)
        {
            var carrier = _contextCarrierFactory.Create();

            foreach (var item in carrier.Items)
            {
                item.HeadValue = httpContext.Request.Headers[item.HeadKey];
            }
            var httpRequestSpan = ContextManager.CreateEntrySpan(httpContext.Request.Path, carrier);

            httpRequestSpan.AsHttp();
            httpRequestSpan.SetComponent(ComponentsDefine.AspNetCore);
            Tags.Url.Set(httpRequestSpan, httpContext.Request.Path);
            Tags.HTTP.Method.Set(httpRequestSpan, httpContext.Request.Method);
            httpRequestSpan.Log(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
                                new Dictionary <string, object>
            {
                { "event", "AspNetCore Hosting BeginRequest" },
                {
                    "message",
                    $"Request starting {httpContext.Request.Protocol} {httpContext.Request.Method} {httpContext.Request.GetDisplayUrl()}"
                }
            });
            httpContext.Items[HttpContextDiagnosticStrings.SpanKey] = httpRequestSpan;
        }
Beispiel #4
0
        public void ApplicationOnBeginRequest(object sender, EventArgs e)
        {
            var httpApplication = sender as HttpApplication;
            var httpContext     = httpApplication.Context;

            if (httpContext.Request.HttpMethod == "OPTIONS")
            {
                //asp.net Exclude OPTIONS request
                return;
            }

            var carrier = _contextCarrierFactory.Create();

            foreach (var item in carrier.Items)
            {
                item.HeadValue = httpContext.Request.Headers[item.HeadKey];
            }
            var httpRequestSpan = ContextManager.CreateEntrySpan($"{_config.ApplicationCode} {httpContext.Request.Path}", carrier);

            httpRequestSpan.AsHttp();
            httpRequestSpan.SetComponent(ComponentsDefine.AspNet);
            Tags.Url.Set(httpRequestSpan, httpContext.Request.Path);
            Tags.HTTP.Method.Set(httpRequestSpan, httpContext.Request.HttpMethod);
            httpRequestSpan.Log(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
                                new Dictionary <string, object>
            {
                { "event", "AspNet BeginRequest" },
                { "message", $"Request starting {httpContext.Request.Url.Scheme} {httpContext.Request.HttpMethod} {httpContext.Request.Url.OriginalString}" }
            });
        }
        public void BeginRequest([Property] HttpContext httpContext)
        {
//            Console.WriteLine($"{Activity.Current.Id} {Activity.Current.ParentId} {Activity.Current.RootId}");
            var carrier = _contextCarrierFactory.Create();

            foreach (var item in carrier.Items)
            {
                item.HeadValue = httpContext.Request.Headers[item.HeadKey];
            }
            var httpRequestSpan = ConcurrentContextManager.CreateEntrySpan($"{_config.ApplicationCode} {httpContext.Request.Path}", carrier, Activity.Current.Id, Activity.Current.ParentId);

            httpRequestSpan.AsHttp();
            httpRequestSpan.SetComponent(ComponentsDefine.AspNetCore);
            Tags.Url.Set(httpRequestSpan, httpContext.Request.Path);
            Tags.HTTP.Method.Set(httpRequestSpan, httpContext.Request.Method);
            httpRequestSpan.Log(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
                                new Dictionary <string, object>
            {
                { "event", "AspNetCore Hosting BeginRequest" },
                { "currentActivityId", Activity.Current.Id },
                { "currentThreadId", Thread.CurrentThread.ManagedThreadId },
                { "Priority", Thread.CurrentThread.Priority },
                { "GlobalTraceId", ConcurrentContextManager.GlobalTraceId },
                { "message", $"Request starting {httpContext.Request.Protocol} {httpContext.Request.Method} {httpContext.Request.GetDisplayUrl()}" }
            });
            httpContext.Items[HttpContextDiagnosticStrings.SpanKey] = httpRequestSpan;
        }
        public void ServerRequest([Object] GrpcEventData eventData)
        {
            var contextCarrier = _contextCarrierFactory.Create();

            foreach (var item in contextCarrier.Items)
            {
                item.HeadValue = eventData.Headers.Where(t => t.Key == item.HeadKey).FirstOrDefault()?.Value;
            }

            var span = ContextManager.CreateExitSpan(eventData.Operation, contextCarrier, "");

            span.Tag("", "");
        }
        public void HttpRequest([Property(Name = "Request")] HttpRequestMessage request)
        {
            var contextCarrier = _contextCarrierFactory.Create();
            var peer           = $"{request.RequestUri.Host}:{request.RequestUri.Port}";
            var span           = ContextManager.CreateExitSpan(request.RequestUri.ToString(), contextCarrier, peer);

            Tags.Url.Set(span, request.RequestUri.ToString());
            span.AsHttp();
            span.SetComponent(ComponentsDefine.HttpClient);
            Tags.HTTP.Method.Set(span, request.Method.ToString());
            foreach (var item in contextCarrier.Items)
            {
                request.Headers.Add(item.HeadKey, item.HeadValue);
            }
        }
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request,
                                                                      CancellationToken cancellationToken)
        {
            var peer           = $"{request.RequestUri.Host}:{request.RequestUri.Port}";
            var contextCarrier = _contextCarrierFactory.Create();
            var span           = ContextManager.CreateExitSpan(request.RequestUri.ToString(), contextCarrier, peer);

            try
            {
                Tags.Url.Set(span, request.RequestUri.ToString());
                span.AsHttp();
                span.SetComponent(ComponentsDefine.HttpClient);
                Tags.HTTP.Method.Set(span, request.Method.ToString());
                foreach (var item in contextCarrier.Items)
                {
                    request.Headers.Add(item.HeadKey, item.HeadValue);
                }

                if (request.Method.Method != "GET")
                {
                    // record request body data
                    if (!request.Content.Headers.ContentType?.MediaType.ToLower().Contains("multipart/form-data") ?? false)
                    {
                        string bodyStr = await request.Content.ReadAsStringAsync();

                        span.Log(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), new Dictionary <string, object> {
                            { "Body", bodyStr }
                        });
                    }
                }

                var response = await base.SendAsync(request, cancellationToken);

                Tags.StatusCode.Set(span, response.StatusCode.ToString());
                return(response);
            }
            catch (Exception e)
            {
                span.ErrorOccurred().Log(e);
                throw;
            }
            finally
            {
                ContextManager.StopSpan(span);
            }
        }
Beispiel #9
0
        public void HttpRequest([Property(Name = "Request")] HttpRequestMessage request)
        {
            var contextCarrier = _contextCarrierFactory.Create();
            var peer           = $"{request.RequestUri.Host}:{request.RequestUri.Port}";
            var span           = ContextManager.CreateExitSpan(request.RequestUri.AbsolutePath, contextCarrier, peer);

            span.AsHttp();
            span.SetComponent(SpanComponent.HttpClient);
            span.Tags.Client()
            .HttpMethod(request.Method.Method)
            .HttpUrl(request.RequestUri.OriginalString);
            if (_skrTraceOptions.TraceHttpBody && request.Method == HttpMethod.Post && request.Content != null)
            {
                span.Tags.HttpRequest(request.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult());
            }
            foreach (var item in contextCarrier.Items)
            {
                request.Headers.Add(item.HeadKey, item.HeadValue);
            }
        }