コード例 #1
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);
                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);
            }
        }
コード例 #2
0
 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;
 }
コード例 #4
0
        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);
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        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;
                }
            }
        }
コード例 #8
0
 public static void Start(IApmContext apmContext, ApmWebApiStartInformation apmWebApiStartInformation)
 {
     foreach (var counter in CounterHandlers)
     {
         counter.Start(apmContext, apmWebApiStartInformation);
     }
 }
コード例 #9
0
        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;
                }
            }
        }
コード例 #10
0
        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;
                }
            }
        }
コード例 #11
0
        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;
                }
            }
        }
コード例 #12
0
        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;
                }
            }
        }
コード例 #13
0
        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;
                }
            }
        }
コード例 #14
0
 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);
        }
コード例 #16
0
        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);
     }
 }
コード例 #21
0
        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);
        }
コード例 #22
0
        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;
        }
コード例 #24
0
        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);
            }
        }
コード例 #26
0
        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];
            }
        }
コード例 #27
0
        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];
            }
        }
コード例 #28
0
        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();
            }
        }
コード例 #29
0
        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;
            }
        }
コード例 #30
0
        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);
        }