예제 #1
0
 /// <summary>
 /// Контекст трассировки
 /// </summary>
 /// <param name="id">идентификатор трассировки</param>
 /// <param name="root">корневое событие трассировки</param>
 internal TraceContext(TraceId id
                       , TraceEvent root)
 {
     if (id == null)
     {
         throw new ArgumentNullException("id");
     }
     _id   = id;
     _root = root;
     if (_root == null)
     {
         _root = TraceEvent.Create(_id, _id.Name);
     }
 }
예제 #2
0
        /// <summary>
        /// Добавить событие
        /// </summary>
        /// <param name="name">сообщение</param>
        /// <param name="type">тип</param>
        public static void AddEvent(string name)
        {
            var current = Current;

            var @event = TraceEvent.Create(current.Id, name);

            current.Root.AddEvent(@event);

            var h = current.OnEvent;

            if (h != null)
            {
                h(current, new OnAppendEventArgs(@event));
            }
        }
예제 #3
0
        /// <summary>
        /// Окружение контекста трассировки
        /// </summary>
        /// <param name="eventName">имя события</param>
        /// <param name="mode"></param>
        public TraceContextScope(string eventName
                                 , TraceContextMode mode = TraceContextMode.Add)
        {
            if (Current != null)
            {
                Id = Current.Id;
            }
            else
            {
                Id = TraceId.Create(eventName);
            }

            Root = TraceEvent.Create(id: Id, name: eventName);
            Mode = mode;

            PushScope();
        }
예제 #4
0
        /// <summary>
        /// Перед отправкой сообщения включаем в заголовок информацию о текущей трассировке
        /// </summary>
        /// <param name="request">запрос</param>
        /// <param name="channel">канал</param>
        /// <returns></returns>
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            var scope = TraceContextScope.Current;

            if (scope == null)
            {
                return(null);
            }

            var action = request.Headers.Action;

            action = action.Replace("http://tempuri.org/", "");

            var id     = scope.Id;
            var @event = TraceEvent.Create(id: id
                                           , name: "call> " + action);

            var callScope = new TraceContextScope(id, @event, TraceContextMode.Add);

            var index = request.Headers.FindHeader(TraceMeHeader.HeaderName, Namespace.Main);

            if (index > -1)
            {
                request.Headers.RemoveAt(index);
            }

            var header = MessageHeader.CreateHeader(
                TraceMeHeader.HeaderName, Namespace.Main
                , new TraceMeHeader()
            {
                Id = id,
            });

            request.Headers.Add(header);
            return(callScope);
        }
예제 #5
0
        /// <summary>
        /// После принятия запроса если присутствует флаг TraceMe, создаем окружение трассировки
        /// </summary>
        /// <param name="request"></param>
        /// <param name="channel"></param>
        /// <param name="instanceContext"></param>
        /// <returns></returns>
        public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
        {
            var index = request.Headers.FindHeader(TraceMeHeader.HeaderName, Namespace.Main);

            if (index < 0)
            {
                return(null);
            }

            var header = request.Headers.GetHeader <TraceMeHeader>(index);

            if (header == null)
            {
                return(null);
            }

            var @event = TraceEvent.Create(
                id: header.Id
                , name: "disp> " + instanceContext.Host.Description.Name);

            @event["host"] = HostName;

            return(new TraceContextScope(header.Id, @event, TraceContextMode.Add));
        }