private Metric.Context contextFor(Request request) {
        return metricContexts.computeIfAbsent(
                new MetricContextKey(
                        handlerBinding(request).orElse(null),
                        handlerClassName,
                        request.headers().containsKey("Host") ? request.headers().get("Host").get(0) : null,
                        request.getUri().getPort()),
                key -> {
                    Map<String, String> dimensions = new HashMap<>();
                    if (key.handlerBinding != null) dimensions.put("handler", key.handlerBinding);
                    dimensions.put("handler-name", key.handlerClassName);
                    if (key.endpoint != null) dimensions.put("endpoint", key.endpoint);
                    dimensions.put("port", String.valueOf(key.port));
                    return metric.createContext(dimensions);
                }
        );
    }
Common HTTP request handler metrics code.

@author jonmv
@author bjorncs
container-core/src/main/java/com/yahoo/container/core/HandlerMetricContextUtil.java