|
33 | 33 | @Immutable |
34 | 34 | public interface Attributes { |
35 | 35 |
|
36 | | - /** Returns the value for the given {@link AttributeKey}, or {@code null} if not found. */ |
| 36 | + /** |
| 37 | + * Returns the value for the given {@link AttributeKey}, or {@code null} if not found. |
| 38 | + * |
| 39 | + * <p>Simple attributes (i.e. anything other than {@link Value} attributes) SHOULD be used |
| 40 | + * whenever possible. Instrumentations SHOULD assume that backends do not index individual |
| 41 | + * properties of complex attributes, that querying or aggregating on such properties is |
| 42 | + * inefficient and complicated, and that reporting complex attributes carries higher performance |
| 43 | + * overhead. |
| 44 | + * |
| 45 | + * <p>Note: when passing a key of type {@link AttributeType#VALUE}, the returned value will match |
| 46 | + * a narrower type with the given key if one exists. This is the inverse of {@link |
| 47 | + * AttributesBuilder#put(AttributeKey, Object)} when the key is {@link AttributeType#VALUE}. |
| 48 | + * |
| 49 | + * <ul> |
| 50 | + * <li>If {@code put(AttributeKey.stringKey("key"), "a")} was called, then {@code |
| 51 | + * get(AttributeKey.valueKey("key"))} returns {@code Value.of("a")}. |
| 52 | + * <li>If {@code put(AttributeKey.longKey("key"), 1L)} was called, then {@code |
| 53 | + * get(AttributeKey.valueKey("key"))} returns {@code Value.of(1L)}. |
| 54 | + * <li>If {@code put(AttributeKey.doubleKey("key"), 1.0)} was called, then {@code |
| 55 | + * get(AttributeKey.valueKey("key"))} returns {@code Value.of(1.0)}. |
| 56 | + * <li>If {@code put(AttributeKey.booleanKey("key"), true)} was called, then {@code |
| 57 | + * get(AttributeKey.valueKey("key"))} returns {@code Value.of(true)}. |
| 58 | + * <li>If {@code put(AttributeKey.stringArrayKey("key"), Arrays.asList("a", "b"))} was called, |
| 59 | + * then {@code get(AttributeKey.valueKey("key"))} returns {@code Value.of(Value.of("a"), |
| 60 | + * Value.of("b"))}. |
| 61 | + * <li>If {@code put(AttributeKey.longArrayKey("key"), Arrays.asList(1L, 2L))} was called, then |
| 62 | + * {@code get(AttributeKey.valueKey("key"))} returns {@code Value.of(Value.of(1L), |
| 63 | + * Value.of(2L))}. |
| 64 | + * <li>If {@code put(AttributeKey.doubleArrayKey("key"), Arrays.asList(1.0, 2.0))} was called, |
| 65 | + * then {@code get(AttributeKey.valueKey("key"))} returns {@code Value.of(Value.of(1.0), |
| 66 | + * Value.of(2.0))}. |
| 67 | + * <li>If {@code put(AttributeKey.booleanArrayKey("key"), Arrays.asList(true, false))} was |
| 68 | + * called, then {@code get(AttributeKey.valueKey("key"))} returns {@code |
| 69 | + * Value.of(Value.of(true), Value.of(false))}. |
| 70 | + * </ul> |
| 71 | + */ |
37 | 72 | @Nullable |
38 | 73 | <T> T get(AttributeKey<T> key); |
39 | 74 |
|
|
0 commit comments