public static void Finish(IApmContext apmContext, ApmWebApiFinishInformation apmWebApiFinishInformation)
        {
            if (apmWebApiFinishInformation.Exception == null)
            {
                var message  = string.Format("SS - Finish success - {0} - {1} in {2} ms", apmWebApiFinishInformation.MethodIdentifier, apmWebApiFinishInformation.TraceId, apmWebApiFinishInformation.ResponseTime);
                var logger   = Log.Logger;
                var logEvent = new LoggingEvent(DeclaringType, logger.Repository, logger.Name, Level.Info, message, null);
                foreach (var property in apmContext)
                {
                    logEvent.Properties[property.Key] = property.Value;
                }
                logger.Log(logEvent);
            }
            else
            {
                var message = string.Format("SS - Finish failure - {0} - {1} in {2} ms", apmWebApiFinishInformation.MethodIdentifier, apmWebApiFinishInformation.TraceId, apmWebApiFinishInformation.ResponseTime);

                var logger   = Log.Logger;
                var logEvent = new LoggingEvent(DeclaringType, logger.Repository, logger.Name, Level.Error, message, apmWebApiFinishInformation.Exception);
                foreach (var property in apmContext)
                {
                    logEvent.Properties[property.Key] = property.Value;
                }
                logger.Log(logEvent);
            }
        }
 public static void Finish(IApmContext apmContext, ApmWebApiFinishInformation apmWebApiFinishInformation)
 {
     foreach (var counter in CounterHandlers)
     {
         counter.Finish(apmContext, apmWebApiFinishInformation);
     }
 }
예제 #3
0
 public ApmMethodHandlerBase(IApmContext apmContext, string applicationName, Action <IApmContext, ApmMethodHandlerStartInformation> startAction, Action <IApmContext, ApmMethodHandlerFinishInformation> finishAction)
 {
     _apmContext      = apmContext;
     _applicationName = applicationName;
     _startAction     = startAction;
     _finishAction    = finishAction;
 }
        public static ApmHttpClientDelegatingHandlerBase GetDelegatingHandler(this IApmContext apmContext)
        {
            if (!ApmHttpClientDelegatingHandlerFactories.Any())
            {
                return(null);
            }

            ApmHttpClientDelegatingHandlerBase apmHttpClientDelegatingHandler = null;

            foreach (var apmHttpClientDelegatingHandlerFactory in ApmHttpClientDelegatingHandlerFactories)
            {
                var currentApmHttpClientDelegatingHandler = apmHttpClientDelegatingHandlerFactory.Create(apmContext);
                if (apmHttpClientDelegatingHandler != null)
                {
                    currentApmHttpClientDelegatingHandler.InnerHandler = apmHttpClientDelegatingHandler;
                }
                else
                {
                    currentApmHttpClientDelegatingHandler.InnerHandler = new HttpClientHandler();
                }
                apmHttpClientDelegatingHandler = currentApmHttpClientDelegatingHandler;
            }

            return(apmHttpClientDelegatingHandler);
        }
예제 #5
0
        public static void Finish(IApmContext apmContext, ApmMethodHandlerFinishInformation apmMethodHandlerFinishInformation)
        {
            var message = string.Format("CR - Finish - {0} - {1} in {2} ms", apmMethodHandlerFinishInformation.EventName,
                                        apmMethodHandlerFinishInformation.TraceId, apmMethodHandlerFinishInformation.ResponseTime);

            Log.Log(message, LogLevel.Info, apmContext);
        }
        public void Start(IApmContext apmContext, ApmWebApiStartInformation apmWebApiStartInformation)
        {
            var key = string.Empty;

            object counterProperty;

            if (!apmContext.TryGetValue(AverageTimeTakenMsCounter, out counterProperty))
            {
                var categoryName = PerformanceCounterApmApiFilterAttribute.GetCategoryName(apmWebApiStartInformation.ApplicationName);
                var counterName  = GetCounterName(apmWebApiStartInformation.MethodIdentifier);

                var counter = Counters.GetOrAdd(key, s => GetCounter(categoryName, _instanceName, counterName));
                apmContext.Add(AverageTimeTakenMsCounter, counter);
            }

            object baseCounterProperty;

            if (!apmContext.TryGetValue(AverageTimeTakenMsBaseCounter, out baseCounterProperty))
            {
                var categoryName = PerformanceCounterApmApiFilterAttribute.GetCategoryName(apmWebApiStartInformation.ApplicationName);
                var counterName  = GetBaseCounterName(apmWebApiStartInformation.MethodIdentifier);
                var baseCounter  = BaseCounters.GetOrAdd(key, s => GetBaseCounter(categoryName, _instanceName, counterName));
                apmContext.Add(AverageTimeTakenMsBaseCounter, baseCounter);
            }
        }
        public void AddIncomingSpanId(HttpRequestMessage request, IApmContext apmContext)
        {
            object incomingSpanIdProperty;
            string incomingSpanId;

            if (request.Properties.TryGetValue(Constants.IncomingSpanIdPropertyKey, out incomingSpanIdProperty))
            {
                incomingSpanId = (string)incomingSpanIdProperty;
                apmContext[Constants.IncomingSpanIdPropertyKey] = incomingSpanId;
            }
            else
            {
                if (apmContext.ContainsKey(Constants.IncomingSpanIdPropertyKey))
                {
                    incomingSpanId = (string)apmContext[Constants.IncomingSpanIdPropertyKey];
                    request.Properties[Constants.IncomingSpanIdPropertyKey] = incomingSpanId;
                }
                else
                {
                    incomingSpanId = string.Empty;
                    apmContext[Constants.IncomingSpanIdPropertyKey]         = incomingSpanId;
                    request.Properties[Constants.IncomingSpanIdPropertyKey] = incomingSpanId;
                }
            }
        }
 public static void Start(IApmContext apmContext, ApmWebApiStartInformation apmWebApiStartInformation)
 {
     foreach (var counter in CounterHandlers)
     {
         counter.Start(apmContext, apmWebApiStartInformation);
     }
 }
        public void AddTraceId(HttpRequestMessage request, IApmContext apmContext)
        {
            object traceIdProperty;
            var    traceId = string.Empty;

            if (request.Properties.TryGetValue(Constants.TraceIdHeaderKey, out traceIdProperty))
            {
                traceId = (string)traceIdProperty;
                apmContext[Constants.TraceIdHeaderKey] = traceId;
            }
            else
            {
                if (apmContext.ContainsKey(Constants.TraceIdHeaderKey))
                {
                    traceId = (string)apmContext[Constants.TraceIdHeaderKey];
                    request.Properties[Constants.TraceIdHeaderKey] = traceId;
                }
                else
                {
                    traceId = string.Empty;
                    apmContext[Constants.TraceIdHeaderKey]         = traceId;
                    request.Properties[Constants.TraceIdHeaderKey] = traceId;
                }
            }
        }
        public void AddIncomingFlags(HttpRequestMessage request, IApmContext apmContext)
        {
            object incomingFlagsProperty;
            var    incomingFlags = string.Empty;

            if (request.Properties.TryGetValue(Constants.IncomingFlagsPropertyKey, out incomingFlagsProperty))
            {
                incomingFlags = (string)incomingFlagsProperty;
                apmContext[Constants.IncomingSampledPropertyKey] = incomingFlags;
            }
            else
            {
                if (apmContext.ContainsKey(Constants.IncomingSampledPropertyKey))
                {
                    incomingFlags = (string)apmContext[Constants.IncomingSampledPropertyKey];
                    request.Properties[Constants.IncomingSampledPropertyKey] = incomingFlags;
                }
                else
                {
                    incomingFlags = string.Empty;
                    apmContext[Constants.IncomingSampledPropertyKey]         = incomingFlags;
                    request.Properties[Constants.IncomingSampledPropertyKey] = incomingFlags;
                }
            }
        }
        public void AddParentSpanId(HttpRequestMessage request, IApmContext apmContext)
        {
            object parentSpanIdProperty;
            var    parentSpanId = string.Empty;

            if (request.Properties.TryGetValue(Constants.ParentSpanIdHeaderKey, out parentSpanIdProperty))
            {
                parentSpanId = (string)parentSpanIdProperty;
                apmContext[Constants.ParentSpanIdHeaderKey] = parentSpanId;
            }
            else
            {
                if (apmContext.ContainsKey(Constants.ParentSpanIdHeaderKey))
                {
                    parentSpanId = (string)apmContext[Constants.ParentSpanIdHeaderKey];
                    request.Properties[Constants.ParentSpanIdHeaderKey] = parentSpanId;
                }
                else
                {
                    parentSpanId = string.Empty;
                    apmContext[Constants.ParentSpanIdHeaderKey]         = parentSpanId;
                    request.Properties[Constants.ParentSpanIdHeaderKey] = parentSpanId;
                }
            }
        }
        public void AddSampled(HttpRequestMessage request, IApmContext apmContext)
        {
            object sampledProperty;
            var    sampled = string.Empty;

            if (request.Properties.TryGetValue(Constants.SampledHeaderKey, out sampledProperty))
            {
                sampled = (string)sampledProperty;
                apmContext[Constants.SampledHeaderKey] = sampled;
            }
            else
            {
                if (apmContext.ContainsKey(Constants.SampledHeaderKey))
                {
                    sampled = (string)apmContext[Constants.SampledHeaderKey];
                    request.Properties[Constants.SampledHeaderKey] = sampled;
                }
                else
                {
                    sampled = string.Empty;
                    apmContext[Constants.SampledHeaderKey]         = sampled;
                    request.Properties[Constants.SampledHeaderKey] = sampled;
                }
            }
        }
        public void AddFlags(HttpRequestMessage request, IApmContext apmContext)
        {
            object flagsProperty;
            var    flags = string.Empty;

            if (request.Properties.TryGetValue(Constants.FlagsHeaderKey, out flagsProperty))
            {
                flags = (string)flagsProperty;
                apmContext[Constants.FlagsHeaderKey] = flags;
            }
            else
            {
                if (apmContext.ContainsKey(Constants.FlagsHeaderKey))
                {
                    flags = (string)apmContext[Constants.FlagsHeaderKey];
                    request.Properties[Constants.FlagsHeaderKey] = flags;
                }
                else
                {
                    flags = string.Empty;
                    apmContext[Constants.FlagsHeaderKey]         = flags;
                    request.Properties[Constants.FlagsHeaderKey] = flags;
                }
            }
        }
 public ApmHttpClientDelegatingHandlerBase(IApmContext apmContext, string applicationName, Action <IApmContext, ApmHttpClientStartInformation> startAction, Action <IApmContext, ApmHttpClientFinishInformation> finishAction)
 {
     _apmContext      = apmContext;
     _applicationName = applicationName;
     _startAction     = startAction;
     _finishAction    = finishAction;
 }
예제 #15
0
        public void GetContext(IApmContext apmContext, MethodBase method)
        {
            if (HttpContext.Current == null)
            {
                return;
            }
            var request = HttpContext.Current.Items["MS_HttpRequestMessage"] as HttpRequestMessage;

            SetIncomingTracingForHttpRequestMessage(apmContext, request);
        }
        public void Finish(IApmContext apmContext, ApmMethodHandlerFinishInformation apmMethodHandlerFinishInformation)
        {
            object counterProperty;

            if (apmContext.TryGetValue(TotalCountCounter, out counterProperty))
            {
                var counter = (System.Diagnostics.PerformanceCounter)counterProperty;
                counter.Increment();
            }
        }
예제 #17
0
        public void Finish(IApmContext apmContext, ApmWebApiFinishInformation apmWebApiFinishInformation)
        {
            object counterProperty;

            if (apmContext.TryGetValue(LastOperationExecutionTimeMsCounter, out counterProperty))
            {
                var counter = (System.Diagnostics.PerformanceCounter)counterProperty;
                counter.Increment();
            }
        }
        public void Finish(IApmContext apmContext, ApmHttpClientFinishInformation apmHttpClientFinishInformation)
        {
            object counterProperty;

            if (apmContext.TryGetValue(LastOperationExecutionTimeMsCounter, out counterProperty))
            {
                var counter = (System.Diagnostics.PerformanceCounter)counterProperty;
                counter.RawValue = apmHttpClientFinishInformation.ResponseTime;
            }
        }
예제 #19
0
        public static void SetTracing(IApmContext apmContext)
        {
            var clientName      = apmContext.ContainsKey(Constants.ClientNamePropertyKey) ? (string)apmContext[Constants.ClientNamePropertyKey] : null;
            var incomingTraceId = apmContext.ContainsKey(Constants.IncomingTraceIdPropertyKey) ? (string)apmContext[Constants.IncomingTraceIdPropertyKey] : null;
            var incomingSpanId  = apmContext.ContainsKey(Constants.IncomingSpanIdPropertyKey) ? (string)apmContext[Constants.IncomingSpanIdPropertyKey] : null;
            var incomingFlags   = apmContext.ContainsKey(Constants.IncomingFlagsPropertyKey) ? (string)apmContext[Constants.IncomingFlagsPropertyKey] : null;
            var incomingSampled = apmContext.ContainsKey(Constants.IncomingSampledPropertyKey) ? (string)apmContext[Constants.IncomingSampledPropertyKey] : null;

            SetTracing(apmContext, clientName, incomingTraceId, incomingSpanId, incomingFlags, incomingSampled);
        }
예제 #20
0
 public static void Finish(IApmContext apmContext, ApmWebApiFinishInformation apmWebApiFinishInformation)
 {
     if (apmWebApiFinishInformation.Exception == null)
     {
         var message = string.Format("SS - Finish success - {0} - {1} in {2} ms", apmWebApiFinishInformation.MethodIdentifier, apmWebApiFinishInformation.TraceId, apmWebApiFinishInformation.ResponseTime);
         Log.Log(message, LogLevel.Info, apmContext);
     }
     else
     {
         var message = string.Format("SS - Finish failure - {0} - {1} in {2} ms", apmWebApiFinishInformation.MethodIdentifier, apmWebApiFinishInformation.TraceId, apmWebApiFinishInformation.ResponseTime);
         Log.Log(message, LogLevel.Error, apmContext, null, null, apmWebApiFinishInformation.Exception, null);
     }
 }
        public static void Finish(IApmContext apmContext, ApmHttpClientFinishInformation apmWebApiFinishInformation)
        {
            var message  = string.Format("CR - Finish - {0} - {1} in {2} ms", apmWebApiFinishInformation.EventName, apmWebApiFinishInformation.TraceId, apmWebApiFinishInformation.ResponseTime);
            var logger   = Log.Logger;
            var logEvent = new LoggingEvent(DeclaringType, logger.Repository, logger.Name, Level.Info, message, null);

            foreach (var property in apmContext)
            {
                logEvent.Properties[property.Key] = property.Value;
            }

            logger.Log(logEvent);
        }
        public static void Start(IApmContext apmContext, ApmHttpClientStartInformation apmWebApiStartInformation)
        {
            var message  = string.Format("CS - Start - {0} - {1}", apmWebApiStartInformation.EventName, apmWebApiStartInformation.TraceId);
            var logger   = Log.Logger;
            var logEvent = new LoggingEvent(DeclaringType, logger.Repository, logger.Name, Level.Info, message, null);

            foreach (var property in apmContext)
            {
                logEvent.Properties[property.Key] = property.Value;
            }

            logger.Log(logEvent);
        }
예제 #23
0
        public static void SetContext(IApmContext apmContext, MethodBase method, string eventName = "")
        {
            if (string.IsNullOrEmpty(eventName))
            {
                eventName = GetEventName(method);
            }
            var methodIdentifier = GetMethodIdentifier(method);
            var clientName       = GetClientName();

            apmContext[Constants.EventNamePropertyKey]        = eventName;
            apmContext[Constants.MethodIdentifierPropertyKey] = methodIdentifier;
            apmContext[Constants.ClientNamePropertyKey]       = clientName;
        }
        public void Start(IApmContext apmContext, ApmMethodHandlerStartInformation apmMethodHandlerStartInformation)
        {
            var key = string.Empty;

            object counterProperty;

            if (!apmContext.TryGetValue(TotalCountCounter, out counterProperty))
            {
                var categoryName = PerformanceCounterApmMethodHandler.GetCategoryName(apmMethodHandlerStartInformation.ApplicationName);
                var counterName  = GetCounterName(apmMethodHandlerStartInformation.MethodIdentifier);
                var counter      = Counters.GetOrAdd(key, s => GetCounter(categoryName, _instanceName, counterName));
                apmContext.Add(TotalCountCounter, counter);
            }
        }
        public void Start(IApmContext apmContext, ApmHttpClientStartInformation apmHttpClientStartInformation)
        {
            var key = string.Empty;

            object counterProperty;

            if (!apmContext.TryGetValue(LastOperationExecutionTimeMsCounter, out counterProperty))
            {
                var categoryName = PerformanceCounterApmHttpClientDelegatingHandler.GetCategoryName(apmHttpClientStartInformation.ApplicationName);
                var counterName  = GetCounterName(apmHttpClientStartInformation.MethodIdentifier);
                var counter      = Counters.GetOrAdd(key, s => GetCounter(categoryName, _instanceName, counterName));
                apmContext.Add(LastOperationExecutionTimeMsCounter, counter);
            }
        }
        public void AddEventName(HttpRequestMessage request, IApmContext apmContext)
        {
            object eventNameProperty;

            if (request.Properties.TryGetValue(Constants.EventNamePropertyKey, out eventNameProperty))
            {
                if (!apmContext.ContainsKey(Constants.EventNamePropertyKey))
                {
                    apmContext[Constants.EventNamePropertyKey] = (string)eventNameProperty;
                }
            }
            else
            {
                request.Properties[Constants.EventNamePropertyKey] = apmContext[Constants.EventNamePropertyKey];
            }
        }
        public void AddMethodIdentifier(HttpRequestMessage request, IApmContext apmContext)
        {
            object methodIdentifierProperty;

            if (request.Properties.TryGetValue(Constants.MethodIdentifierPropertyKey, out methodIdentifierProperty))
            {
                if (!apmContext.ContainsKey(Constants.MethodIdentifierPropertyKey))
                {
                    apmContext[Constants.MethodIdentifierPropertyKey] = (string)methodIdentifierProperty;
                }
            }
            else
            {
                request.Properties[Constants.MethodIdentifierPropertyKey] = apmContext[Constants.MethodIdentifierPropertyKey];
            }
        }
        public void Finish(IApmContext apmContext, ApmWebApiFinishInformation apmWebApiFinishInformation)
        {
            object counterProperty;

            if (apmContext.TryGetValue(AverageTimeTakenMsCounter, out counterProperty))
            {
                var counter = (System.Diagnostics.PerformanceCounter)counterProperty;
                counter.IncrementBy(apmWebApiFinishInformation.ResponseTime);
            }

            object baseCounterProperty;

            if (apmContext.TryGetValue(AverageTimeTakenMsBaseCounter, out baseCounterProperty))
            {
                var baseCounter = (System.Diagnostics.PerformanceCounter)baseCounterProperty;
                baseCounter.Increment();
            }
        }
        public void AddClientName(HttpRequestMessage request, IApmContext apmContext)
        {
            object clientNameProperty;
            var    clientName = string.Empty;

            if (request.Properties.TryGetValue(Constants.ClientNamePropertyKey, out clientNameProperty))
            {
                clientName = (string)clientNameProperty;
                if (!apmContext.ContainsKey(Constants.ClientNamePropertyKey))
                {
                    apmContext[Constants.ClientNamePropertyKey] = clientName;
                }
            }
            else
            {
                clientName = (string)apmContext[Constants.ClientNamePropertyKey];
                request.Properties[Constants.ClientNamePropertyKey] = clientName;
            }
        }
        public static ApmMethodHandlerBase GetMethodHander(this IApmContext apmContext)
        {
            if (!ApmMethodHttpFactories.Any())
            {
                return(null);
            }

            ApmMethodHandlerBase apmMethodHandler = null;

            foreach (var apmMethodHttpFactory in ApmMethodHttpFactories)
            {
                var currentApmMethod = apmMethodHttpFactory.Create(apmContext);
                if (apmMethodHandler != null)
                {
                    currentApmMethod.InnerHandler = apmMethodHandler;
                }

                apmMethodHandler = currentApmMethod;
            }

            return(apmMethodHandler);
        }