Class MetricThreadHelper


  • public class MetricThreadHelper
    extends Object
    Used to set tags and report time for metrics reported on the current thread.
    • Method Detail

      • setReportTime

        public static void setReportTime​(Instant time)
        Sets the time which metrics will be reported with. This only has effect on non aggregated collectors like the BagCollector.
        Parameters:
        time - Timestamp to report the metric
      • clearReportTime

        public static void clearReportTime()
        Clears the report time from the thread. It is a good idea to pair this with the setReportTime so you don't accidentally override the metric report time by other metrics this thread may report in the future.
      • getReportTime

        public static Instant getReportTime()
        Returns the set report time or Instance.MIN if not set.
        Returns:
        Report time for metric
      • addTag

        public static void addTag​(String name,
                                  String value)
        Adds a tag to all metrics that will be reported from the current thread.
        Parameters:
        name - Name of tag
        value - Value of tag
      • getTag

        public static String getTag​(String name)
        Returns a value of a tag if set on the thread, null otherwise.
        Parameters:
        name - Name of tag
        Returns:
        Value of tag
      • removeTag

        public static void removeTag​(String name)
        Removes a single tag from the thread.
        Parameters:
        name - Name of tag
      • clearTags

        public static void clearTags()
        Clears all tags from the thread. It is a good idea to add this to the end of any calls a thread is making to make sure the thread doesn't take the tags with it when doing other work.
      • getTagIterator

        public static Iterator<Map.Entry<String,​String>> getTagIterator()
        Iterator of all tags set on the thread.
        Returns:
        Iterator of all tag keys and values