This project has a goal to demonstrate injection of the following devops-related things into .net core 3.1 apps:
- Logger configuration
- Distributed tracing for
- incoming http requests
- outgoing http requests
- publish masstransit messages
- consume masstransit messages
- Collect time execution metrics for:
- incoming http requests
- outgoing http requests
- masstransit publish
- masstransit consume
- EntityFrameworkCore queries
- Quartz scheduled jobs
- User-defined using
MonitorAttribute
(see https://github.com/ABaboshin/DotNetCoreProfiler/blob/master/src/Interception.Attributes/MonitorAttribute.cs)
- Cache using
CacheAttribute
- Store collected metrics in:
- prometheus
- jaeger
- Intercept creation of
IServiceProvider
and provide full access to the DI for the injected code - Validate method parameters, see i.e. https://github.com/ABaboshin/DotNetCoreProfiler/blob/master/src/Interception.Attributes/Validation/NotNullAttribute.cs
- Interceptors can be combined. See https://github.com/ABaboshin/DotNetCoreProfiler/blob/master/sample/MessageBus/MyMessageConsumer.cs#L54
- The order of interecepted is configuratble via
Priority
property.
Limitations
- Dynamic methods are not supported.
- If you want to use parameter validator, use the
ValidationAttribute
on the method. - In some cases to intercept the generic method you have to implement
IMethodFinder
(see https://github.com/ABaboshin/DotNetCoreProfiler/blob/master/src/Interception.MassTransit/ConsumeMethodFinder.cs#L13)
See src/profiler.
See samples/Interception:
ConfigureServicesBuilderInterceptor
intercept theStartup.ConfigureServices
call and injects i.e. logger configuration, general tracing configuration, observersConfigureBuilderInterceptor
intercepts theStartup.Configure
call and inject tracing middlewareCreateUsingRabbitMqInterceptor
intercepts the rabbitmq masstransit bus configuration and injects tracing into publishing pipelineMassTransitConsumerInterceptor
intercepts consuming of masstransit messages in order to handle the tracingQuartzJobExecuteInterceptor
intercepts the execution of the quartz jobsMonitoringInterceptor
finds the usage ofMonitorAttribute
and intercepts the marked calls with measuring execution time, In addition the following monitor parameters can be injected:- Customited metric name
- Passed parameters
- Return value
- For usage see https://github.com/ABaboshin/DotNetCoreProfiler/blob/master/sample/MessageBus/MyMessageConsumer.cs#L64
CacheInterceptor
finsd the usage ofCacheAttribute
and cache the results for the given amount of seconds, the parameters which have to be taken into accout can be configured:InvalidateCacheInterceptor
finds the usage ofInvalidateCacheAttribute
and invalidates the cache:
See src/Interception.Observers:
EntityFrameworkCoreObserver
observers and measure execution time of entity framework core queriesHttpHandlerDiagnostrics
observers and measure execution time of outgoing http requests
See src/Interception.Attributes:
NotNullAttribute
checks if a passed parameter value is not null,GreatThenZeroAttribute
checks if a passed int value is positive
See src/Interception.OpenTracing.Statd is an implementation of OpenTracing to report the metrics into statsd.
(max by (traceId) (finishDate{quantile="0.99"}) - on (traceId) min by (traceId) (startDate{quantile="0.99"})) * on(traceId) group_left(service, type) metric_info{quantile="0.99"}
See samples.
See devenv.md.