示例#1
0
        private ITwoStageInstrumentor InitInstrumentor(MethodInfo methodInfo)
        {
            string instrumentationContext = "";
            var    instrumentationInfo    = GetInstrumentationInfo(methodInfo);

            if (instrumentationInfo != null)
            {
                var instanceName = instrumentationInfo.InstanceName;
                PublishCounters = instrumentationInfo.PublishCounters;


                if (string.IsNullOrEmpty(instanceName) && _instanceNameProvider != null)
                {
                    instanceName = _instanceNameProvider.GetInstanceName(methodInfo);
                }

                if (string.IsNullOrEmpty(instanceName))
                {
                    throw new InvalidOperationException("Either InstanceName or InstanceNameProviderType must be supplied.");
                }

                if (_instrumentationContextProvider != null)
                {
                    instrumentationContext = _instrumentationContextProvider.GetContext(methodInfo);
                }
                else
                {
                    throw new InvalidOperationException("The Instrumentation Context Cannot be Null. Define a InstrumentationContextProvider implementation.");
                }

                SetEventPolicy();
                SetPublishCounterPolicy();
                SetErrorPolicy();

                var instrumentor = new SimpleInstrumentor(new InstrumentationInfo()
                {
                    Description        = instrumentationInfo.Description,
                    Counters           = instrumentationInfo.Counters,
                    InstanceName       = instanceName,
                    CategoryName       = string.IsNullOrEmpty(this.CategoryName) ? instrumentationInfo.CategoryName : this.CategoryName,
                    SamplingRate       = SamplingRate,
                    PublishCounters    = PublishCounters,
                    PublishEvent       = PublishEvent,
                    RaisePublishErrors = RaisePublishErrors
                });

                _instrumentors.AddOrUpdate(instrumentationContext, instrumentor, (key, inst) => instrumentor);
                return(instrumentor);
            }
            else
            {
                return(null);
            }
        }
示例#2
0
        private ITwoStageInstrumentor InitInstrumentor(MethodInfo methodInfo)
        {
            // ReSharper disable once RedundantAssignment
            var instrumentationContext = string.Empty;
            var instrumentationInfo    = GetInstrumentationInfo(methodInfo);

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

            var instanceName = instrumentationInfo.InstanceName;

            PublishCounters = instrumentationInfo.PublishCounters;

            if (string.IsNullOrEmpty(instanceName) && _instanceNameProvider != null)
            {
                instanceName = _instanceNameProvider.GetInstanceName(methodInfo);
            }

            if (string.IsNullOrEmpty(instanceName))
            {
                throw new InvalidOperationException(
                          "Either InstanceName or InstanceNameProviderType must be supplied.");
            }

            if (_instrumentationContextProvider != null)
            {
                instrumentationContext = _instrumentationContextProvider.GetContext(methodInfo);
            }
            else
            {
                throw new InvalidOperationException(
                          "The Instrumentation Context Cannot be Null. Define a InstrumentationContextProvider implementation.");
            }

            SetEventPolicy();
            SetPublishCounterPolicy();
            SetErrorPolicy();

            var e = new InstrumentorRequiredEventArgs(CategoryName, instrumentationInfo);

            RaiseInstrumentorRequired(e);

            _instrumentors.AddOrUpdate(instrumentationContext, e.Instrumentor, (ictx, i) => e.Instrumentor);

            return(e.Instrumentor);
        }
示例#3
0
        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            base.OnActionExecuted(actionExecutedContext);

            try
            {
                var instrumentationContext = string.Format("{0}_{1}", actionExecutedContext.Request.Method,
                                                           actionExecutedContext.Request.RequestUri);
                if (_instrumentationContextProvider != null)
                {
                    instrumentationContext = _instrumentationContextProvider.GetContext(actionExecutedContext);
                }

                if (actionExecutedContext.Request.Properties.ContainsKey(PerfItTwoStageKey))
                {
                    var token = actionExecutedContext.Request.Properties[PerfItTwoStageKey] as InstrumentationToken;
                    if (actionExecutedContext.Exception != null && token != null)
                    {
                        token.Contexts.Item2.SetContextToErrorState();
                    }
                    _instrumentor.Finish(token, instrumentationContext);
                }
            }
            catch (Exception exception)
            {
                Trace.TraceError(exception.ToString());
                if (RaisePublishErrors)
                {
                    throw;
                }
            }
        }
        public override void OnActionExecuted(ActionExecutedContext actionExecutedContext)
        {
            base.OnActionExecuted(actionExecutedContext);

            try
            {
                var instrumentationContext = string.Format("{0}_{1}", actionExecutedContext.ActionDescriptor.ActionName,
                                                           actionExecutedContext.HttpContext.Request.Url);

                if (_instrumentationContextProvider != null)
                {
                    instrumentationContext = _instrumentationContextProvider.GetContext(actionExecutedContext);
                }

                if (!actionExecutedContext.HttpContext.Items.Contains(PerfItTwoStageKey))
                {
                    return;
                }

                var token = actionExecutedContext.HttpContext.Items[PerfItTwoStageKey] as InstrumentationToken;

                if (!(actionExecutedContext.Exception == null || token == null))
                {
                    token.Context.Data.SetContextToErrorState();
                }

                _instrumentor.Finish(token, instrumentationContext);
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
                if (RaisePublishErrors)
                {
                    throw;
                }
            }
        }
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            base.OnActionExecuted(context);

            try
            {
                var instrumentationContext = new InstrumentationContext
                {
                    Text1 = string.Format("{0}_{1}", context.ActionDescriptor.DisplayName,
                                          context.HttpContext.Request.Path)
                };

                if (_instrumentationContextProvider != null)
                {
                    instrumentationContext = _instrumentationContextProvider.GetContext(context);
                }

                if (context.HttpContext.Items.ContainsKey(PerfItTwoStageKey))
                {
                    var token = context.HttpContext.Items[PerfItTwoStageKey] as InstrumentationToken;
                    if (context.Exception != null && token != null)
                    {
                        token.Contexts.SetContextToErrorState();
                    }

                    _instrumentor.Finish(token, instrumentationContext);
                }
            }
            catch (Exception exception)
            {
                if (RaisePublishErrors)
                {
                    throw;
                }
            }
        }