|
5 | 5 |
|
6 | 6 | package io.opentelemetry.api.logs; |
7 | 7 |
|
| 8 | +import static io.opentelemetry.api.common.AttributeKey.booleanKey; |
| 9 | +import static io.opentelemetry.api.common.AttributeKey.doubleKey; |
| 10 | +import static io.opentelemetry.api.common.AttributeKey.longKey; |
| 11 | +import static io.opentelemetry.api.common.AttributeKey.stringKey; |
| 12 | + |
8 | 13 | import io.opentelemetry.api.common.AttributeKey; |
9 | 14 | import io.opentelemetry.api.common.Attributes; |
10 | 15 | import io.opentelemetry.api.common.Value; |
@@ -98,9 +103,91 @@ default LogRecordBuilder setAllAttributes(Attributes attributes) { |
98 | 103 | return this; |
99 | 104 | } |
100 | 105 |
|
101 | | - /** Sets an attribute. */ |
| 106 | + /** |
| 107 | + * Sets an attribute on the {@code LogRecord}. If the {@code LogRecord} previously contained a |
| 108 | + * mapping for the key, the old value is replaced by the specified value. |
| 109 | + * |
| 110 | + * @param key the key for this attribute. |
| 111 | + * @param value the value for this attribute. |
| 112 | + * @return this. |
| 113 | + */ |
102 | 114 | <T> LogRecordBuilder setAttribute(AttributeKey<T> key, T value); |
103 | 115 |
|
| 116 | + /** |
| 117 | + * Sets a String attribute on the {@code LogRecord}. If the {@code LogRecord} previously contained |
| 118 | + * a mapping for the key, the old value is replaced by the specified value. |
| 119 | + * |
| 120 | + * <p>Note: It is strongly recommended to use {@link #setAttribute(AttributeKey, Object)}, and |
| 121 | + * pre-allocate your keys, if possible. |
| 122 | + * |
| 123 | + * @param key the key for this attribute. |
| 124 | + * @param value the value for this attribute. |
| 125 | + * @return this. |
| 126 | + */ |
| 127 | + default LogRecordBuilder setAttribute(String key, String value) { |
| 128 | + return setAttribute(stringKey(key), value); |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * Sets a Long attribute on the {@code LogRecord}. If the {@code LogRecord} previously contained a |
| 133 | + * mapping for the key, the old value is replaced by the specified value. |
| 134 | + * |
| 135 | + * <p>Note: It is strongly recommended to use {@link #setAttribute(AttributeKey, Object)}, and |
| 136 | + * pre-allocate your keys, if possible. |
| 137 | + * |
| 138 | + * @param key the key for this attribute. |
| 139 | + * @param value the value for this attribute. |
| 140 | + * @return this. |
| 141 | + */ |
| 142 | + default LogRecordBuilder setAttribute(String key, long value) { |
| 143 | + return setAttribute(longKey(key), value); |
| 144 | + } |
| 145 | + |
| 146 | + /** |
| 147 | + * Sets a Double attribute on the {@code LogRecord}. If the {@code LogRecord} previously contained |
| 148 | + * a mapping for the key, the old value is replaced by the specified value. |
| 149 | + * |
| 150 | + * <p>Note: It is strongly recommended to use {@link #setAttribute(AttributeKey, Object)}, and |
| 151 | + * pre-allocate your keys, if possible. |
| 152 | + * |
| 153 | + * @param key the key for this attribute. |
| 154 | + * @param value the value for this attribute. |
| 155 | + * @return this. |
| 156 | + */ |
| 157 | + default LogRecordBuilder setAttribute(String key, double value) { |
| 158 | + return setAttribute(doubleKey(key), value); |
| 159 | + } |
| 160 | + |
| 161 | + /** |
| 162 | + * Sets a Boolean attribute on the {@code LogRecord}. If the {@code LogRecord} previously |
| 163 | + * contained a mapping for the key, the old value is replaced by the specified value. |
| 164 | + * |
| 165 | + * <p>Note: It is strongly recommended to use {@link #setAttribute(AttributeKey, Object)}, and |
| 166 | + * pre-allocate your keys, if possible. |
| 167 | + * |
| 168 | + * @param key the key for this attribute. |
| 169 | + * @param value the value for this attribute. |
| 170 | + * @return this. |
| 171 | + */ |
| 172 | + default LogRecordBuilder setAttribute(String key, boolean value) { |
| 173 | + return setAttribute(booleanKey(key), value); |
| 174 | + } |
| 175 | + |
| 176 | + /** |
| 177 | + * Sets an Integer attribute on the {@code LogRecord}. If the {@code LogRecord} previously |
| 178 | + * contained a mapping for the key, the old value is replaced by the specified value. |
| 179 | + * |
| 180 | + * <p>Note: It is strongly recommended to use {@link #setAttribute(AttributeKey, Object)}, and |
| 181 | + * pre-allocate your keys, if possible. |
| 182 | + * |
| 183 | + * @param key the key for this attribute. |
| 184 | + * @param value the value for this attribute. |
| 185 | + * @return this. |
| 186 | + */ |
| 187 | + default LogRecordBuilder setAttribute(String key, int value) { |
| 188 | + return setAttribute(key, (long) value); |
| 189 | + } |
| 190 | + |
104 | 191 | /** Emit the log record. */ |
105 | 192 | void emit(); |
106 | 193 | } |
0 commit comments