Interface AttributesBuilder


public interface AttributesBuilder
A builder of Attributes supporting an arbitrary number of key-value pairs.
  • Method Details

    • build

      Attributes build()
      Create the Attributes from this.
    • put

      <T> AttributesBuilder put(AttributeKey<Long> key, int value)
      Puts a AttributeKey with associated value into this.

      The type parameter is unused.

    • put

      <T> AttributesBuilder put(AttributeKey<T> key, @Nullable T value)
      Puts an AttributeKey with an associated value into this if the value is non-null. Providing a null value does not remove or unset previously set values.

      Simple attributes (AttributeType.STRING, AttributeType.LONG, AttributeType.DOUBLE, AttributeType.BOOLEAN, AttributeType.STRING_ARRAY, AttributeType.LONG_ARRAY, AttributeType.DOUBLE_ARRAY, AttributeType.BOOLEAN_ARRAY) SHOULD be used whenever possible. Instrumentations SHOULD assume that backends do not index individual properties of complex attributes, that querying or aggregating on such properties is inefficient and complicated, and that reporting complex attributes carries higher performance overhead.

      Note: This method will automatically convert complex attributes (AttributeType.VALUE) to simple attributes when possible.

      • Calling put(AttributeKey.valueKey("key"), Value.of("a")) is equivalent to calling put(AttributeKey.stringKey("key"), "a").
      • Calling put(AttributeKey.valueKey("key"), Value.of(1L)) is equivalent to calling put(AttributeKey.longKey("key"), 1L).
      • Calling put(AttributeKey.valueKey("key"), Value.of(1.0)) is equivalent to calling put(AttributeKey.doubleKey("key"), 1.0).
      • Calling put(AttributeKey.valueKey("key"), Value.of(true)) is equivalent to calling put(AttributeKey.booleanKey("key"), true).
      • Calling put(AttributeKey.valueKey("key"), Value.of(Value.of("a"), Value.of("b"))) is equivalent to calling put(AttributeKey.stringArrayKey("key"), Arrays.asList("a", "b")).
      • Calling put(AttributeKey.valueKey("key"), Value.of(Value.of(1L), Value.of(2L))) is equivalent to calling put(AttributeKey.longArrayKey("key"), Arrays.asList(1L, 2L)).
      • Calling put(AttributeKey.valueKey("key"), Value.of(Value.of(1.0), Value.of(2.0))) is equivalent to calling put(AttributeKey.doubleArrayKey("key"), Arrays.asList(1.0, 2.0)).
      • Calling put(AttributeKey.valueKey("key"), Value.of(Value.of(true), Value.of(false))) is equivalent to calling put(AttributeKey.booleanArrayKey("key"), Arrays.asList(true, false)).
    • put

      default AttributesBuilder put(String key, @Nullable String value)
      Puts a String attribute into this if the value is non-null. Providing a null value does not remove or unset previously set values.

      Note: It is strongly recommended to use put(AttributeKey, Object), and pre-allocate your keys, if possible.

      Returns:
      this Builder
    • put

      default AttributesBuilder put(String key, long value)
      Puts a long attribute into this.

      Note: It is strongly recommended to use put(AttributeKey, Object), and pre-allocate your keys, if possible.

      Returns:
      this Builder
    • put

      default AttributesBuilder put(String key, double value)
      Puts a double attribute into this.

      Note: It is strongly recommended to use put(AttributeKey, Object), and pre-allocate your keys, if possible.

      Returns:
      this Builder
    • put

      default AttributesBuilder put(String key, boolean value)
      Puts a boolean attribute into this.

      Note: It is strongly recommended to use put(AttributeKey, Object), and pre-allocate your keys, if possible.

      Returns:
      this Builder
    • put

      default AttributesBuilder put(String key, String... value)
      Puts a String array attribute into this.

      Note: It is strongly recommended to use put(AttributeKey, Object), and pre-allocate your keys, if possible.

      Returns:
      this Builder
    • put

      default <T> AttributesBuilder put(AttributeKey<List<T>> key, T... value)
      Puts a List attribute into this.
      Returns:
      this Builder
    • put

      default AttributesBuilder put(String key, long... value)
      Puts a Long array attribute into this.

      Note: It is strongly recommended to use put(AttributeKey, Object), and pre-allocate your keys, if possible.

      Returns:
      this Builder
    • put

      default AttributesBuilder put(String key, double... value)
      Puts a Double array attribute into this.

      Note: It is strongly recommended to use put(AttributeKey, Object), and pre-allocate your keys, if possible.

      Returns:
      this Builder
    • put

      default AttributesBuilder put(String key, boolean... value)
      Puts a Boolean array attribute into this.

      Note: It is strongly recommended to use put(AttributeKey, Object), and pre-allocate your keys, if possible.

      Returns:
      this Builder
    • put

      default AttributesBuilder put(String key, Value<?> value)
      Puts a Value attribute into this. See put(AttributeKey, Object) for details on how this method will automatically convert Value attributes to simple attributes when possible.

      Note: It is strongly recommended to use put(AttributeKey, Object), and pre-allocate your keys, if possible.

      Returns:
      this Builder
      Since:
      1.59.0
    • putAll

      AttributesBuilder putAll(Attributes attributes)
      Puts all the provided attributes into this Builder.
      Returns:
      this Builder
    • remove

      default <T> AttributesBuilder remove(AttributeKey<T> key)
      Remove all attributes where AttributeKey.getKey() and AttributeKey.getType() match the key.
      Returns:
      this Builder
    • removeIf

      default AttributesBuilder removeIf(Predicate<AttributeKey<?>> filter)
      Remove all attributes that satisfy the given predicate. Errors or runtime exceptions thrown by the predicate are relayed to the caller.
      Returns:
      this Builder