1414import static io .opentelemetry .api .common .AttributeKey .longKey ;
1515import static io .opentelemetry .api .common .AttributeKey .stringArrayKey ;
1616import static io .opentelemetry .api .common .AttributeKey .stringKey ;
17- import static io .opentelemetry .api .common .AttributeKey .valueKey ;
1817
1918import java .util .Arrays ;
2019import java .util .List ;
@@ -40,6 +39,32 @@ public interface AttributesBuilder {
4039 /**
4140 * Puts an {@link AttributeKey} with an associated value into this if the value is non-null.
4241 * Providing a null value does not remove or unset previously set values.
42+ *
43+ * <p>Note: when passing a key of type {@link AttributeType#VALUE}, the call will be coerced into
44+ * a narrower type if possible.
45+ *
46+ * <ul>
47+ * <li>Calling {@code put(AttributeKey.valueKey("key"), Value.of("a"))} is equivalent to calling
48+ * {@code put(AttributeKey.stringKey("key"), "a")}.
49+ * <li>Calling {@code put(AttributeKey.valueKey("key"), Value.of(1L))} is equivalent to calling
50+ * {@code put(AttributeKey.longKey("key"), 1L)}.
51+ * <li>Calling {@code put(AttributeKey.valueKey("key"), Value.of(1.0))} is equivalent to calling
52+ * {@code put(AttributeKey.doubleKey("key"), 1.0)}.
53+ * <li>Calling {@code put(AttributeKey.valueKey("key"), Value.of(true))} is equivalent to
54+ * calling {@code put(AttributeKey.booleanKey("key"), true)}.
55+ * <li>Calling {@code put(AttributeKey.valueKey("key"), Value.of(Value.of("a"), Value.of("b")))}
56+ * is equivalent to calling {@code put(AttributeKey.stringArrayKey("key"),
57+ * Arrays.asList("a", "b"))}.
58+ * <li>Calling {@code put(AttributeKey.valueKey("key"), Value.of(Value.of(1L), Value.of(2L)))}
59+ * is equivalent to calling {@code put(AttributeKey.longArrayKey("key"), Arrays.asList(1L,
60+ * 2L))}.
61+ * <li>Calling {@code put(AttributeKey.valueKey("key"), Value.of(Value.of(1.0), Value.of(2.0)))}
62+ * is equivalent to calling {@code put(AttributeKey.doubleArrayKey("key"),
63+ * Arrays.asList(1.0, 2.0))}.
64+ * <li>Calling {@code put(AttributeKey.valueKey("key"), Value.of(Value.of(true),
65+ * Value.of(false)))} is equivalent to calling {@code
66+ * put(AttributeKey.booleanArrayKey("key"), Arrays.asList(true, false))}.
67+ * </ul>
4368 */
4469 <T > AttributesBuilder put (AttributeKey <T > key , @ Nullable T value );
4570
0 commit comments