public static IMotorHostBuilder ConfigureSerilog(this IMotorHostBuilder hostBuilder, Action <HostBuilderContext, LoggerConfiguration>?configuration = null) { return((IMotorHostBuilder)hostBuilder .ConfigureSentry() .UseSerilog((hostingContext, loggerConfiguration) => { var sentryOptions = new SentrySerilogOptions(); hostingContext.Configuration.GetSection("Sentry").Bind(sentryOptions); loggerConfiguration .ReadFrom.Configuration(hostingContext.Configuration) .Enrich.FromLogContext() .WriteTo.Console(new JsonFormatter(renderMessage: true)) .WriteTo.Sentry(opts => { opts.Dsn = sentryOptions.Dsn; opts.MinimumEventLevel = sentryOptions.MinimumEventLevel; opts.MinimumBreadcrumbLevel = sentryOptions.MinimumBreadcrumbLevel; opts.InitializeSdk = false; }); configuration?.Invoke(hostingContext, loggerConfiguration); }) .ConfigureServices((_, services) => { services.AddLogging(loggingBuilder => { loggingBuilder .AddSerilog(dispose: true); }); })); }
public static IMotorHostBuilder ConfigureJaegerTracing(this IMotorHostBuilder hostBuilder) { hostBuilder .ConfigureServices((hostContext, services) => { services.Configure <JaegerExporterOptions>(hostContext.Configuration.GetSection(JaegerExporter)); services.Configure <OpenTelemetryOptions>(hostContext.Configuration.GetSection(OpenTelemetry)); services.AddOpenTelemetryTracing((provider, builder) => { var jaegerOptions = provider.GetService <IOptions <JaegerExporterOptions> >() ?? throw new InvalidConstraintException($"{nameof(JaegerExporterOptions)} is not configured."); var openTelemetryOptions = provider.GetService <IOptions <OpenTelemetryOptions> >()?.Value ?? new OpenTelemetryOptions(); var applicationNameService = provider.GetService <IApplicationNameService>() ?? throw new InvalidConstraintException($"{nameof(IApplicationNameService)} is not configured."); var logger = provider.GetService <ILogger <OpenTelemetryOptions> >() ?? throw new InvalidConstraintException($"{nameof(ILogger<OpenTelemetryOptions>)} is not configured."); builder .AddAspNetCoreInstrumentation() .AddSource(typeof(TracingDelegatingMessageHandler <>).FullName !) .SetMotorSampler(openTelemetryOptions) .AddExporter(logger, jaegerOptions.Value, applicationNameService, hostContext); }); }); return(hostBuilder); }
public static IMotorHostBuilder ConfigureNoOutputService <TInput>(this IMotorHostBuilder hostBuilder, string healthCheckConfigSection = "HealthChecks", string messageProcessingHealthCheckName = nameof(MessageProcessingHealthCheck <TInput>), string tooManyTemporaryFailuresHealthCheckName = nameof(TooManyTemporaryFailuresHealthCheck <TInput>)) where TInput : class { return(hostBuilder .AddHealthCheck <MessageProcessingHealthCheck <TInput> >(messageProcessingHealthCheckName) .AddHealthCheck <TooManyTemporaryFailuresHealthCheck <TInput> >(tooManyTemporaryFailuresHealthCheckName) .ConfigureServices((hostContext, services) => { services.AddQueuedGenericService <TInput>(); services.AddTransient <DelegatingMessageHandler <TInput>, TelemetryDelegatingMessageHandler <TInput> >(); services .AddTransient <DelegatingMessageHandler <TInput>, PrometheusDelegatingMessageHandler <TInput> >(); services.Configure <MessageProcessingOptions>( hostContext.Configuration.GetSection(healthCheckConfigSection) .GetSection(messageProcessingHealthCheckName)); services.AddSingleton <TooManyTemporaryFailuresStatistics <TInput> >(); services .AddTransient <DelegatingMessageHandler <TInput>, TooManyTemporaryFailuresDelegatingMessageHandler <TInput> >(); services.Configure <TooManyTemporaryFailuresOptions>( hostContext.Configuration.GetSection(healthCheckConfigSection) .GetSection(tooManyTemporaryFailuresHealthCheckName)); })); }
public static IMotorHostBuilder ConfigureJaegerTracing(this IMotorHostBuilder hostBuilder) { hostBuilder .ConfigureServices((hostContext, services) => { services.Configure <JaegerExporterOptions>(hostContext.Configuration.GetSection(JaegerExporter)); services.Configure <OpenTelemetryOptions>(hostContext.Configuration.GetSection(OpenTelemetry)); services.AddOpenTelemetryTracing((provider, builder) => { var jaegerOptions = provider.GetService <IOptions <JaegerExporterOptions> >() ?? throw new InvalidConstraintException($"{nameof(JaegerExporterOptions)} is not configured."); var openTelemetryOptions = provider.GetService <IOptions <OpenTelemetryOptions> >()?.Value ?? new OpenTelemetryOptions(); var applicationNameService = provider.GetService <IApplicationNameService>() ?? throw new InvalidConstraintException($"{nameof(IApplicationNameService)} is not configured."); var logger = provider.GetService <ILogger <OpenTelemetryOptions> >() ?? throw new InvalidConstraintException($"{nameof(ILogger<OpenTelemetryOptions>)} is not configured."); builder .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() .AddSource(openTelemetryOptions.Sources.ToArray()) .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(applicationNameService.GetFullName(), serviceVersion: applicationNameService.GetVersion())) .SetMotorSampler(openTelemetryOptions) .AddExporter(logger, jaegerOptions.Value, applicationNameService, hostContext); }); }); return(hostBuilder); }
public static IMotorHostBuilder ConfigurePrometheus(this IMotorHostBuilder hostBuilder) { hostBuilder.ConfigureServices((_, services) => { services.AddSingleton(typeof(IMetricsFactory <>), typeof(MetricsFactory <>)); services.AddSingleton <IMotorMetricsFactory, MotorMetricsFactory>(); }); return(hostBuilder); }
public static IMotorHostBuilder ConfigureSentry(this IMotorHostBuilder hostBuilder) { return(hostBuilder .ConfigureServices((context, services) => { var sentryOptions = new SentrySerilogOptions(); context.Configuration.GetSection("Sentry").Bind(sentryOptions); SentrySdk.Init(sentryOptions); services.AddTransient <IOptions <SentrySerilogOptions> >(_ => MSOptions.Create(sentryOptions)); })); }
public static IMotorHostBuilder ConfigurePublisher <TOutput>(this IMotorHostBuilder hostBuilder, Action <HostBuilderContext, IPublisherBuilder <TOutput> > action) where TOutput : class { hostBuilder.ConfigureServices((context, collection) => { var consumerBuilder = new PublisherBuilder <TOutput>(collection, context); consumerBuilder.Build(action); }); return(hostBuilder); }
public static IMotorHostBuilder ConfigureConsumer <TInput>(this IMotorHostBuilder hostBuilder, Action <HostBuilderContext, IConsumerBuilder <TInput> > action) where TInput : class { hostBuilder.ConfigureServices((context, collection) => { var consumerBuilder = new ConsumerBuilder <TInput>(collection, context); collection.AddHostedService <TypedConsumerService <TInput> >(); action.Invoke(context, consumerBuilder); }); return(hostBuilder); }
public static IMotorHostBuilder ConfigureMultiOutputService <TInput, TOutput>( this IMotorHostBuilder hostBuilder) where TOutput : class where TInput : class { return(hostBuilder .ConfigureNoOutputService <TInput>() .ConfigureServices((hostContext, services) => { services.AddTransient <INoOutputService <TInput>, MultiOutputServiceAdapter <TInput, TOutput> >(); })); }
public static IMotorHostBuilder ConfigureTimer(this IMotorHostBuilder hostBuilder, string configSection = "Timer") { return(hostBuilder .ConfigureNoOutputService <IJobExecutionContext>() .ConfigureServices((hostContext, services) => { var config = hostContext.Configuration.GetSection(configSection); services.Configure <TimerConfig>(config); services.AddHostedService <Timer>(); })); }
public static IMotorHostBuilder ConfigureNoOutputService <TInput>(this IMotorHostBuilder hostBuilder, string healthCheckConfigSection = "HealthCheck") where TInput : class { return(hostBuilder .AddHealthCheck <MessageProcessingHealthCheck <TInput> >(nameof(MessageProcessingHealthCheck <TInput>)) .ConfigureServices((hostContext, services) => { services.AddQueuedGenericService <TInput>(); services.AddTransient <DelegatingMessageHandler <TInput>, TracingDelegatingMessageHandler <TInput> >(); services.Configure <MessageProcessingHealthCheckConfig>( hostContext.Configuration.GetSection(healthCheckConfigSection)); services .AddTransient <DelegatingMessageHandler <TInput>, PrometheusDelegatingMessageHandler <TInput> >(); })); }
public static IMotorHostBuilder ConfigurePublisher <TOutput>(this IMotorHostBuilder hostBuilder, Action <HostBuilderContext, IPublisherBuilder <TOutput> > action) where TOutput : class { hostBuilder.ConfigureServices((context, collection) => { var consumerBuilder = new PublisherBuilder <TOutput>(collection, context); action.Invoke(context, consumerBuilder); if (consumerBuilder.PublisherImplType == null) { throw new ArgumentNullException(nameof(consumerBuilder.PublisherImplType)); } collection.AddTransient(typeof(ITypedMessagePublisher <TOutput>), consumerBuilder.PublisherImplType); }); return(hostBuilder); }
public static IMotorHostBuilder ConfigureSerilog(this IMotorHostBuilder hostBuilder, Action <HostBuilderContext, LoggerConfiguration>?configuration = null) { return((IMotorHostBuilder)hostBuilder .UseSerilog((hostingContext, loggerConfiguration) => { loggerConfiguration .ReadFrom.Configuration(hostingContext.Configuration) .Enrich.FromLogContext() .WriteTo.Console(new JsonFormatter(renderMessage: true)); configuration?.Invoke(hostingContext, loggerConfiguration); }) .ConfigureServices((hostContext, services) => { services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog(dispose: true)); })); }
public static IMotorHostBuilder ConfigureMultiOutputService <TInput, TOutput>( this IMotorHostBuilder hostBuilder, string healthCheckConfigSection = "HealthChecks", string messageProcessingHealthCheckName = nameof(MessageProcessingHealthCheck <TInput>), string tooManyTemporaryFailuresHealthCheckName = nameof(TooManyTemporaryFailuresHealthCheck <TInput>)) where TOutput : class where TInput : class { return(hostBuilder .ConfigureNoOutputService <TInput>( healthCheckConfigSection, messageProcessingHealthCheckName, tooManyTemporaryFailuresHealthCheckName) .ConfigureServices((_, services) => { services.AddTransient <INoOutputService <TInput>, MultiOutputServiceAdapter <TInput, TOutput> >(); })); }
public static IMotorHostBuilder ConfigureAppConfiguration(this IMotorHostBuilder hostBuilder, Action <HostBuilderContext, IConfigurationBuilder> configureDelegate) { hostBuilder.ConfigureAppConfiguration(configureDelegate); return(hostBuilder); }
public static IMotorHostBuilder ConfigureServices(this IMotorHostBuilder hostBuilder, Action <IServiceCollection> configureDelegate) { hostBuilder.ConfigureServices((context, collection) => configureDelegate(collection)); return(hostBuilder); }
public static IMotorHostBuilder ConfigureOpenTelemetry(this IMotorHostBuilder hostBuilder) { hostBuilder .ConfigureServices((hostContext, services) => { var usedExport = UsedExporter.Jaeger; if (hostContext.Configuration.GetSection(OtlpExporter).Exists()) { services.Configure <OtlpExporterOptions>(hostContext.Configuration.GetSection(OtlpExporter)); usedExport = UsedExporter.Oltp; } else { services.Configure <JaegerExporterOptions>(hostContext.Configuration.GetSection(JaegerExporter)); } var telemetryOptions = new OpenTelemetryOptions(); hostContext.Configuration.GetSection(OpenTelemetry).Bind(telemetryOptions); services.AddSingleton(telemetryOptions); services.AddOpenTelemetryTracing(builder => { builder .AddAspNetCoreInstrumentation(options => { options.Filter = TelemetryRequestFilter(telemetryOptions); }) .Configure((provider, providerBuilder) => { var httpClientInstrumentationOptions = provider.GetService <IOptions <HttpClientInstrumentationOptions> >()?.Value ?? new HttpClientInstrumentationOptions(); var applicationNameService = provider.GetRequiredService <IApplicationNameService>(); var logger = provider.GetRequiredService <ILogger <OpenTelemetryOptions> >(); providerBuilder = providerBuilder .AddHttpClientInstrumentation(options => { options.Enrich = httpClientInstrumentationOptions.Enrich; options.Filter = httpClientInstrumentationOptions.Filter; options.SetHttpFlavor = httpClientInstrumentationOptions.SetHttpFlavor; }) .AddSource(OpenTelemetryOptions.DefaultActivitySourceName) .AddSource(telemetryOptions.Sources.ToArray()) .SetResourceBuilder(ResourceBuilder.CreateDefault() .AddService(applicationNameService.GetFullName(), serviceVersion: applicationNameService.GetVersion()) .AddAttributes(new Dictionary <string, object> { { AttributeMotorNetEnvironment, hostContext.HostingEnvironment.EnvironmentName.ToLower() }, { AttributeMotorNetLibraryVersion, applicationNameService.GetLibVersion() } })) .SetMotorSampler(telemetryOptions); switch (usedExport) { case UsedExporter.Oltp: providerBuilder.AddOtlpExporter(logger, provider); break; default: providerBuilder.AddJaegerExporter(logger, provider); break; } }); }); }); return(hostBuilder); }
public static IMotorHostBuilder ConfigureJaegerTracing(this IMotorHostBuilder hostBuilder) { return(hostBuilder.ConfigureOpenTelemetry()); }