Skip to content

Latest commit

 

History

History
61 lines (47 loc) · 1.54 KB

README.md

File metadata and controls

61 lines (47 loc) · 1.54 KB

statsd-helper-webapi

Filter attributes to allow easy metrics gathering based on Response Codes.

See https://github.com/paybyphone/statsd-helper configuring the statsd-helper itself.

Along with the prefix generated by the statsd-helper, the metric will append the action name and status code to the metric.

For example:

com.example.servername.api.validate.404

You can also return the latency of the request in the response headers:

X-ExecutionTime : 123ms

This is configurable by an appsetting, it is off by default.

<add key="StatsD.WebApi.Response.LatencyHeader.Enabled" value="true" />

Usage:

Add the InstrumentActionMessageHandler into your WebAPI pipeline

    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            ...
            config.ConfigureInstrumentFilters();
            ...
        }

        private static void ConfigureInstrumentFilters(this HttpConfiguration config)
        {
            config.MessageHandlers.Add(new InstrumentActionMessageHandler());
        }
    }

Reponse instrumentation in the message handler will run after all controller logic and exception filters. This means metrics will be generated based the response after any controller level execption handling has taken place.

If you want to instrument only specific actions the InstrumentStatusCodeFilterAttribute can be used.

    public class ApiController
    {
		[InstrumentStatusCodeFilter]
        public void ApiAction()
        {
        }
    }