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
IServiceProviderand 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
Priorityproperty.
Limitations
- Dynamic methods are not supported.
- If you want to use parameter validator, use the
ValidationAttributeon 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:
ConfigureServicesBuilderInterceptorintercept theStartup.ConfigureServicescall and injects i.e. logger configuration, general tracing configuration, observersConfigureBuilderInterceptorintercepts theStartup.Configurecall and inject tracing middlewareCreateUsingRabbitMqInterceptorintercepts the rabbitmq masstransit bus configuration and injects tracing into publishing pipelineMassTransitConsumerInterceptorintercepts consuming of masstransit messages in order to handle the tracingQuartzJobExecuteInterceptorintercepts the execution of the quartz jobsMonitoringInterceptorfinds the usage ofMonitorAttributeand 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
CacheInterceptorfinsd the usage ofCacheAttributeand cache the results for the given amount of seconds, the parameters which have to be taken into accout can be configured:InvalidateCacheInterceptorfinds the usage ofInvalidateCacheAttributeand invalidates the cache:
See src/Interception.Observers:
EntityFrameworkCoreObserverobservers and measure execution time of entity framework core queriesHttpHandlerDiagnostricsobservers and measure execution time of outgoing http requests
See src/Interception.Attributes:
NotNullAttributechecks if a passed parameter value is not null,GreatThenZeroAttributechecks 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.