001package io.prometheus.client.spring.web;
002
003import java.lang.annotation.ElementType;
004import java.lang.annotation.Retention;
005import java.lang.annotation.RetentionPolicy;
006import java.lang.annotation.Target;
007
008/**
009 * Enable Spring-AOP-based automated method timing for the annotated method. The timings will be recorded in a
010 * {@link io.prometheus.client.Summary} with a name specified by the required {@code name} parameter, and help
011 * specified by the {@code help} parameter.
012 *
013 * To properly work, {@link EnablePrometheusTiming} must be specified somewhere in your application configuration.
014 *
015 *  <pre><code>
016 * {@literal @}Controller
017 *  public class MyController {
018 *    {@literal @}RequestMapping("/")
019 *    {@literal @}ResponseBody
020 *    {@literal @}PrometheusTimeMethod(name = "my_method_seconds", help = "The number of seconds taken by the main handler")
021 *    public Object handleRequest() {
022 *      // Each invocation will be timed and recorded.
023 *      return database.withCache().get("some_data");
024 *    }
025 *  }
026 * </code></pre>
027 *
028 *
029 * @author Andrew Stuart
030 */
031@Retention(RetentionPolicy.RUNTIME)
032@Target({ElementType.METHOD})
033public @interface PrometheusTimeMethod {
034    /**
035     * The metric name to use for recording latencies
036     * @return A metric name specific to your use case.
037     */
038    String name();
039
040    /**
041     * The help message to show in prometheus metrics
042     * @return A help string
043     */
044    String help();
045}