Esempio n. 1
0
        public override async void OnEntry(MethodExecutionArgs args)
        {
            var traceId = GetTraceId(args.Instance);
            var methodId = Guid.NewGuid().ToString();
            var parentMethodId = PeekAndPushParentMethodId(methodId, args.Instance);

            var windowsUser = System.Security.Principal.WindowsIdentity.GetCurrent();

            var message = new TraceMessage
            {
                TraceId = traceId,
                MethodId = methodId,
                ParentMethodId = parentMethodId,
                TraceEvent = TraceEvent.OnMethodEntry,
                Timestamp = DateTime.Now,
                MethodName = _methodName,
                Arguments = args.GetMethodArguments(),
                MachineName = Environment.MachineName,
                WindowsUsername = windowsUser != null ? windowsUser.Name : "Unknown",
            };

            message.Broadcast();

            // ensure TraceId and ParentMethodId are passed across http boundaries
            foreach (var argument in args.Arguments.Where(a => a is HttpRequestMessage))
            {
                var httpRequest = argument as HttpRequestMessage;
                if (httpRequest == null) continue;

                if (!httpRequest.Headers.Contains(TraceIdHeaderKey)) httpRequest.Headers.Add(TraceIdHeaderKey, traceId);
                if (!httpRequest.Headers.Contains(ParentMethodHeaderKey)) httpRequest.Headers.Add(ParentMethodHeaderKey, methodId);

                var httpBoundaryRequestMessage = new TraceHttpBoundaryRequestMessage
                {
                    TraceId = traceId,
                    MethodId = methodId,
                    Uri = httpRequest.RequestUri.ToString(),
                    HttpMethod = httpRequest.Method.ToString(),
                    Timestamp = DateTime.Now,
                    MachineName = Environment.MachineName,
                    Headers = httpRequest.Headers.GetHeaders(),
                    Content = (httpRequest.Content != null) ? await httpRequest.Content.ReadAsStringAsync() : "",
                };

                httpBoundaryRequestMessage.Broadcast();
            }

            args.MethodExecutionTag = new TraceAttributeContext(traceId, methodId, parentMethodId);
        }
Esempio n. 2
0
 public void SendHttpBoundaryRequest(TraceHttpBoundaryRequestMessage message)
 {
     Clients.All.broadcastHttpRequestMessage(message);
 }