use of io.helidon.metrics.serviceapi.PostRequestMetricsSupport in project helidon by oracle.
the class MetricsSupport method configureVendorMetrics.
/**
* Configure vendor metrics on the provided routing. This method is
* exclusive to {@link #update(io.helidon.webserver.Routing.Rules)} (e.g.
* you should not use both, as otherwise you would duplicate the metrics)
*
* @param routingName name of the routing (may be null)
* @param rules routing builder or routing rules
*/
@Override
public void configureVendorMetrics(String routingName, Routing.Rules rules) {
String metricPrefix = metricsNamePrefix(routingName);
KeyPerformanceIndicatorSupport.Metrics kpiMetrics = KeyPerformanceIndicatorMetricsImpls.get(metricPrefix, metricsSettings.keyPerformanceIndicatorSettings());
rules.any((req, res) -> {
KeyPerformanceIndicatorSupport.Context kpiContext = kpiContext(req);
PostRequestMetricsSupport prms = PostRequestMetricsSupport.create();
req.context().register(prms);
kpiContext.requestHandlingStarted(kpiMetrics);
res.whenSent().thenAccept(r -> postRequestProcessing(prms, req, r, null, kpiContext)).exceptionallyAccept(t -> postRequestProcessing(prms, req, res, t, kpiContext));
Exception exception = null;
try {
req.next();
} catch (Exception e) {
exception = e;
throw e;
} finally {
// Perform updates which depend on completion of request *handling* (after the server has begun request
// *processing* but, in the case of async requests, possibly before processing has finished).
kpiContext.requestHandlingCompleted(exception == null);
}
});
}
Aggregations