public static ApmComponentOptions AddHttpProfiler(this ApmComponentOptions apmComponent)
 {
     if (apmComponent == null)
     {
         throw new ArgumentNullException(nameof(apmComponent));
     }
     apmComponent.Services.AddType <IProfiler <HttpProfilingContext>, HttpProfiler>(Lifetime.Singleton);
     return(apmComponent);
 }
        public static ApmComponentOptions AddApplicationProfiler(this ApmComponentOptions apmComponent, Action <ApplicationProfilingOptions> configure)
        {
            if (apmComponent == null)
            {
                throw new ArgumentNullException(nameof(apmComponent));
            }
            var options = new ApplicationProfilingOptions();

            configure?.Invoke(options);
            apmComponent.Services.AddType <IOptionAccessor <ApplicationProfilingOptions>, ApplicationProfilingOptions>(Lifetime.Singleton);
            apmComponent.Services.AddType <IProfilerSetup, ApplicationProfilerSetup>(Lifetime.Singleton);
            apmComponent.Services.AddType <IProfiler <ApplicationGCProfilingContext>, ApplicationGCProfiler>(Lifetime.Singleton);
            apmComponent.Services.AddType <IProfiler <ApplicationThreadingProfilingContext>, ApplicationThreadingProfiler>(Lifetime.Singleton);
            return(apmComponent);
        }
        public static ApmComponentOptions AddLineProtocolCollector(this ApmComponentOptions apmComponent, Action <LineProtocolClientOptions> configure)
        {
            if (apmComponent == null)
            {
                throw new ArgumentNullException(nameof(apmComponent));
            }
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }
            apmComponent.Services.AddType <IPayloadClientProvider, LineProtocolPayloadClientProvider>(Lifetime.Singleton);
            var lineProtocolClientOptions = new LineProtocolClientOptions();

            configure(lineProtocolClientOptions);
            apmComponent.Services.AddInstance <IOptionAccessor <LineProtocolClientOptions> >(lineProtocolClientOptions);
            return(apmComponent);
        }
        public static ApmComponentOptions AddRedisProfiler(this ApmComponentOptions apmComponent, Action <RedisProfilingOptions> configure)
        {
            if (apmComponent == null)
            {
                throw new ArgumentNullException(nameof(apmComponent));
            }
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }
            var redisConfigurationOptions = new RedisProfilingOptions();

            configure(redisConfigurationOptions);
            apmComponent.Services.AddInstance <IOptionAccessor <RedisProfilingOptions> >(redisConfigurationOptions);
            apmComponent.Services.AddType <IConnectionMultiplexerProvider, ConnectionMultiplexerProvider>(Lifetime.Singleton);
            apmComponent.Services.AddDelegate <IConnectionMultiplexer>(r => r.ResolveRequired <IConnectionMultiplexerProvider>().ConnectionMultiplexer, Lifetime.Singleton);
            apmComponent.Services.Configure(ConfigureRedisProfiler);
            apmComponent.Services.AddType <IProfiler <RedisProfilingContext>, RedisProfiler>(Lifetime.Singleton);
            return(apmComponent);
        }
Beispiel #5
0
        public static IServiceCollection AddAspectCoreAPM(this IServiceCollection services, Action <ApmComponentOptions> componentOptions, Action <ApplicationOptions> applicationOptions = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }
            if (componentOptions == null)
            {
                throw new ArgumentNullException(nameof(componentOptions));
            }

            var apmComponent = new ApmComponentOptions();

            apmComponent.AddAPMCore(applicationOptions);
            componentOptions(apmComponent);

            foreach (var service in apmComponent.Services)
            {
                var descriptor = GetServiceDescriptor(service);
                if (descriptor != null)
                {
                    services.Add(descriptor);
                }
            }

            services.AddDynamicProxy(config =>
            {
                foreach (var interceptor in apmComponent.Services.Configuration.Interceptors)
                {
                    config.Interceptors.Add(interceptor);
                }
            });

            services.AddTransient <IInternalLogger, InternalLogger>();

            return(services);
        }
 public static ApmComponentOptions AddApplicationProfiler(this ApmComponentOptions apmComponent)
 {
     return(AddApplicationProfiler(apmComponent, null));
 }