Пример #1
0
        private void Init(ActionExecutingContext actionContext)
        {
            SetEventPolicy();
            SetPublishCounterPolicy();
            SetErrorPolicy();

            if (InstanceNameProviderType != null)
            {
                _instanceNameProvider = (IInstanceNameProvider)Activator.CreateInstance(InstanceNameProviderType);
            }

            if (InstrumentationContextProviderType != null)
            {
                _instrumentationContextProvider = (IInstrumentationContextProvider)Activator.CreateInstance(InstrumentationContextProviderType);
            }

            var instanceName = InstanceName;

            if (_instanceNameProvider != null)
            {
                instanceName = _instanceNameProvider.GetInstanceName(actionContext);
            }

            if (instanceName == null)
            {
                InstanceName = PerfItRuntime.GetCounterInstanceName(
                    actionContext.ActionDescriptor.ControllerDescriptor.ControllerType,
                    actionContext.ActionDescriptor.ActionName);
            }

            _instrumentor = new SimpleInstrumentor(Info);
        }
Пример #2
0
        internal static IEnumerable <IInstrumentationInfo> FindAllInfos(Assembly assembly)
        {
            var apiControllers = assembly.GetExportedTypes()
                                 .Where(t => typeof(ApiController).IsAssignableFrom(t) &&
                                        !t.IsAbstract).ToArray();

            Trace.TraceInformation("Found '{0}' controllers", apiControllers.Length);

            foreach (var apiController in apiControllers)
            {
                var methodInfos = apiController.GetMethods(BindingFlags.Instance | BindingFlags.Public);
                foreach (var methodInfo in methodInfos)
                {
                    var attr = methodInfo.GetCustomAttributes <PerfItFilterAttribute>(true).FirstOrDefault();

                    if (attr == null)
                    {
                        continue;
                    }

                    // !!! NOTE: default name - this is just a hacky fallback to get install working runtime instance name could be different
                    if (string.IsNullOrEmpty(attr.InstanceName))
                    {
                        var actionNameAttr = methodInfo.GetCustomAttributes <ActionNameAttribute>(true).FirstOrDefault();
                        var actionName     = actionNameAttr == null ? methodInfo.Name : actionNameAttr.Name;
                        attr.InstanceName = PerfItRuntime.GetCounterInstanceName(apiController, actionName);
                    }

                    Trace.TraceInformation("Added '{0}' to the list", string.Join(", ", attr.Counters));

                    yield return(attr.Info);
                }
            }
        }
Пример #3
0
        internal static IEnumerable <IInstrumentationInfo> FindAllAttributes(
            Assembly assembly)
        {
            var attributes = new List <PerfItAttribute>();
            var components = assembly.GetExportedTypes()
                             .Where(t => !t.IsAbstract).ToArray();

            Trace.TraceInformation("Found '{0}' components", components.Length);

            foreach (var component in components)
            {
                var methodInfos = component.GetMethods(BindingFlags.Instance | BindingFlags.Public);
                foreach (var methodInfo in methodInfos)
                {
                    var attr = (PerfItAttribute)FindAttribute(methodInfo);

                    if (attr != null)
                    {
                        if (string.IsNullOrEmpty(attr.InstanceName)) // !!! NOTE: default name - this is just a hacky fallback to get install working runtime instance name could be different
                        {
                            string actionName = methodInfo.Name;
                            attr.InstanceName = PerfItRuntime.GetCounterInstanceName(component, actionName);
                        }

                        attributes.Add(attr);
                        Trace.TraceInformation("Added '{0}' to the list", attr.Counters);
                    }
                }
            }

            return(attributes);
        }
Пример #4
0
        // TODO: TBD: this could potentially be a cross cutting concern, without needing to repeat the GetCustomAttributes in different places
        internal static IEnumerable <IInstrumentationInfo> FindAllInfos(Assembly assembly)
        {
            var components = assembly.GetExportedTypes().Where(t => !t.IsAbstract).ToArray();

            Trace.TraceInformation("Found '{0}' components", components.Length);

            foreach (var component in components)
            {
                // TODO: TBD: only public methods? also properties? protected? internal? private? static?
                var methodInfos = component.GetMethods(BindingFlags.Instance | BindingFlags.Public);
                foreach (var methodInfo in methodInfos)
                {
                    var attr = methodInfo.GetCustomAttributes <PerfItAttribute>(true).FirstOrDefault();

                    if (attr == null)
                    {
                        continue;
                    }

                    // !!! NOTE: default name - this is just a hacky fallback to get install working runtime instance name could be different
                    if (string.IsNullOrEmpty(attr.InstanceName))
                    {
                        var actionName = methodInfo.Name;
                        attr.InstanceName = PerfItRuntime.GetCounterInstanceName(component, actionName);
                    }

                    Trace.TraceInformation("Added '{0}' to the list", string.Join(", ", attr.Counters));

                    yield return(attr.Info);
                }
            }
        }
Пример #5
0
        private void Init(ActionExecutingContext actionContext)
        {
            SetEventPolicy();
            SetPublishCounterPolicy();
            SetErrorPolicy();
            SetSamplingRate();

            if (SamplingRate == default(double))
            {
                SamplingRate = Constants.DefaultSamplingRate;
            }

            if (InstanceNameProviderType != null)
            {
                _instanceNameProvider = (IInstanceNameProvider)Activator.CreateInstance(InstanceNameProviderType);
            }

            if (InstrumentationContextProviderType != null)
            {
                _instrumentationContextProvider = (IInstrumentationContextProvider)Activator.CreateInstance(InstrumentationContextProviderType);
            }

            if (Counters == null || Counters.Length == 0)
            {
                Counters = CounterTypes.StandardCounters;
            }

            var instanceName = InstanceName;

            if (_instanceNameProvider != null)
            {
                instanceName = _instanceNameProvider.GetInstanceName(actionContext);
            }

            if (instanceName == null)
            {
                instanceName =
                    PerfItRuntime.GetCounterInstanceName(actionContext.ActionDescriptor.ControllerDescriptor.ControllerType,
                                                         actionContext.ActionDescriptor.ActionName);
            }

            _instrumentor = new SimpleInstrumentor(new InstrumentationInfo()
            {
                Description        = Description,
                Counters           = Counters,
                InstanceName       = instanceName,
                CategoryName       = CategoryName,
                SamplingRate       = SamplingRate,
                PublishCounters    = PublishCounters,
                PublishEvent       = PublishEvent,
                RaisePublishErrors = RaisePublishErrors,
                CorrelationIdKey   = CorrelationIdKey
            });
        }
Пример #6
0
        private void Init(ActionExecutingContext actionContext)
        {
            SetErrorPolicy();
            SetSamplingRate();

            if (SamplingRate == default(double))
            {
                SamplingRate = Constants.DefaultSamplingRate;
            }

            if (InstanceNameProviderType != null)
            {
                _instanceNameProvider = (IInstanceNameProvider)Activator.CreateInstance(InstanceNameProviderType);
            }

            _instanceNameProvider = _instanceNameProvider ??
                                    (IInstanceNameProvider)actionContext.HttpContext.RequestServices.GetService(typeof(IInstanceNameProvider));

            if (InstrumentationContextProviderType != null)
            {
                _instrumentationContextProvider = (IInstrumentationContextProvider)Activator.CreateInstance(InstrumentationContextProviderType);
            }

            _instrumentationContextProvider = _instrumentationContextProvider ??
                                              (IInstrumentationContextProvider)actionContext.HttpContext.RequestServices.GetService(typeof(IInstrumentationContextProvider));

            var instanceName = InstanceName;

            if (_instanceNameProvider != null)
            {
                instanceName = _instanceNameProvider.GetInstanceName(actionContext);
            }

            if (instanceName == null)
            {
                instanceName =
                    PerfItRuntime.GetCounterInstanceName(actionContext.Controller.GetType(),
                                                         actionContext.ActionDescriptor.DisplayName);
            }

            var inst = new SimpleInstrumentor(new InstrumentationInfo()
            {
                Description        = Description,
                InstanceName       = instanceName,
                CategoryName       = CategoryName,
                SamplingRate       = SamplingRate,
                RaisePublishErrors = RaisePublishErrors
            });

            _instrumentor = inst;
        }
Пример #7
0
        private void Init(HttpActionContext actionContext)
        {
            SetEventPolicy();
            SetPublish();
            SetErrorPolicy();

            if (InstanceNameProviderType != null)
            {
                _instanceNameProvider = (IInstanceNameProvider)Activator.CreateInstance(InstanceNameProviderType);
            }

            if (InstrumentationContextProviderType != null)
            {
                _instrumentationContextProvider = (IInstrumentationContextProvider)Activator.CreateInstance(InstrumentationContextProviderType);
            }

            if (Counters == null || Counters.Length == 0)
            {
                Counters = CounterTypes.StandardCounters;
            }

            var instanceName = InstanceName;

            if (_instanceNameProvider != null)
            {
                instanceName = _instanceNameProvider.GetInstanceName(actionContext);
            }

            if (instanceName == null)
            {
                instanceName =
                    PerfItRuntime.GetCounterInstanceName(actionContext.ControllerContext.ControllerDescriptor.ControllerType,
                                                         actionContext.ActionDescriptor.ActionName);
            }

            _instrumentor = new SimpleInstrumentor(new InstrumentationInfo()
            {
                Description  = Description,
                Counters     = Counters,
                InstanceName = instanceName,
                CategoryName = CategoryName
            }, PublishCounters, PublishEvent, RaisePublishErrors);
        }
Пример #8
0
        private void Init(ActionExecutingContext actionContext)
        {
            SetPublishCounterPolicy();
            SetErrorPolicy();
            SetSamplingRate();

            if (SamplingRate == default(double))
            {
                SamplingRate = Constants.DefaultSamplingRate;
            }

            if (InstanceNameProviderType != null)
            {
                _instanceNameProvider = (IInstanceNameProvider)Activator.CreateInstance(InstanceNameProviderType);
            }

            if (InstrumentationContextProviderType != null)
            {
                _instrumentationContextProvider = (IInstrumentationContextProvider)Activator.CreateInstance(InstrumentationContextProviderType);
            }

            if (Counters == null || Counters.Length == 0)
            {
                Counters = CounterTypes.StandardCounters;
            }

            var instanceName = InstanceName;

            if (_instanceNameProvider != null)
            {
                instanceName = _instanceNameProvider.GetInstanceName(actionContext);
            }

            if (instanceName == null)
            {
                instanceName =
                    PerfItRuntime.GetCounterInstanceName(actionContext.ActionDescriptor.ControllerDescriptor.ControllerType,
                                                         actionContext.ActionDescriptor.ActionName);
            }

            var inst = new SimpleInstrumentor(new InstrumentationInfo()
            {
                Description        = Description,
                Counters           = Counters,
                InstanceName       = instanceName,
                CategoryName       = CategoryName,
                SamplingRate       = SamplingRate,
                PublishCounters    = PublishCounters,
                RaisePublishErrors = RaisePublishErrors
            });

            _instrumentor = inst;

            if (TracerTypes != null)
            {
                foreach (var tt in TracerTypes)
                {
                    inst.Tracers.Add(tt.FullName, (ITwoStageTracer)Activator.CreateInstance(tt));
                }
            }
        }