Class ViewBuilder


  • public final class ViewBuilder
    extends Object
    Builder of metric Views.
    • Method Detail

      • setName

        public ViewBuilder setName​(String name)
        sets the name of the resulting metric.
        Parameters:
        name - metric name or null if the underlying instrument name should be used.
        Returns:
        this Builder.
      • setDescription

        public ViewBuilder setDescription​(String description)
        sets the name of the resulting metric.
        Parameters:
        description - metric description or null if the underlying instrument description should be used.
        Returns:
        this Builder.
      • setAggregation

        public ViewBuilder setAggregation​(Aggregation aggregation)
        Parameters:
        aggregation - aggregation to use.
        Returns:
        this Builder.
      • setAttributesProcessor

        public ViewBuilder setAttributesProcessor​(io.opentelemetry.sdk.metrics.internal.view.AttributesProcessor processor)
        Specify the attributes processor for this view.

        Note: This resets all attribute filters, baggage appending and other processing.

        Visible for testing.

        Parameters:
        processor - The pre-processor for measurement attributes.
        Returns:
        this Builder.
      • filterAttributes

        public ViewBuilder filterAttributes​(Predicate<String> keyFilter)
        Filters measurement attributes using a given filter.

        Note: This runs after all other attribute processing added so far.

        Parameters:
        keyFilter - filter for key names to include.
        Returns:
        this Builder.
      • filterAttributes

        public ViewBuilder filterAttributes​(Pattern keyPattern)
        Filters measurement attributes using a given regex.

        Note: This runs after all other attribute processing added so far.

        Parameters:
        keyPattern - the regular expression for selecting attributes by key name.
        Returns:
        this Builder.
      • appendAttributes

        public ViewBuilder appendAttributes​(io.opentelemetry.api.common.Attributes extraAttributes)
        Appends a static set of attributes to all measurements.

        Note: This runs after all other attribute processing added so far.

        Parameters:
        extraAttributes - The static attributes to append to measurements.
        Returns:
        this Builder.
      • appendFilteredBaggageAttributes

        public ViewBuilder appendFilteredBaggageAttributes​(Predicate<String> keyFilter)
        Appends key-values from baggage to all measurements.

        Note: This runs after all other attribute processing added so far.

        Parameters:
        keyFilter - Only baggage key values pairs where the key matches this predicate will be appended.
        Returns:
        this Builder.
      • appendFilteredBaggageAttributesByPattern

        public ViewBuilder appendFilteredBaggageAttributesByPattern​(Pattern keyPattern)
        Appends key-values from baggage to all measurements.

        Note: This runs after all other attribute processing added so far.

        Parameters:
        keyPattern - Only baggage key values pairs where the key matches this regex will be appended.
        Returns:
        this Builder.
      • appendAllBaggageAttributes

        public ViewBuilder appendAllBaggageAttributes()
        Appends all key-values from baggage to all measurements.

        Note: This runs after all other attribute processing added so far.

        Returns:
        this Builder.
      • build

        public View build()
        Returns the resulting View.