|
15 | 15 | import datadog.communication.serialization.SimpleUtf8Cache; |
16 | 16 | import datadog.communication.serialization.StreamingBuffer; |
17 | 17 | import datadog.trace.api.Config; |
| 18 | +import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString; |
18 | 19 | import datadog.trace.bootstrap.otel.common.OtelInstrumentationScope; |
19 | 20 | import java.nio.ByteBuffer; |
20 | 21 | import java.util.List; |
@@ -45,6 +46,10 @@ private OtlpCommonProto() {} |
45 | 46 | ? new GenerationalUtf8Cache(Config.get().getTagValueUtf8CacheSize()) |
46 | 47 | : null; |
47 | 48 |
|
| 49 | + public static void recalibrateCaches() { |
| 50 | + VALUE_CACHE.recalibrate(); |
| 51 | + } |
| 52 | + |
48 | 53 | public static int sizeVarInt(int value) { |
49 | 54 | return 1 + (31 - Integer.numberOfLeadingZeros(value)) / 7; |
50 | 55 | } |
@@ -153,8 +158,13 @@ public static void writeInstrumentationScope( |
153 | 158 | } |
154 | 159 |
|
155 | 160 | @SuppressWarnings("unchecked") |
156 | | - public static void writeAttribute(StreamingBuffer buf, int type, String key, Object value) { |
157 | | - byte[] keyUtf8 = keyUtf8(key); |
| 161 | + public static void writeAttribute(StreamingBuffer buf, int type, CharSequence key, Object value) { |
| 162 | + byte[] keyUtf8; |
| 163 | + if (key instanceof UTF8BytesString) { |
| 164 | + keyUtf8 = ((UTF8BytesString) key).getUtf8Bytes(); |
| 165 | + } else { |
| 166 | + keyUtf8 = keyUtf8(key.toString()); |
| 167 | + } |
158 | 168 | switch (type) { |
159 | 169 | case STRING: |
160 | 170 | writeStringAttribute(buf, keyUtf8, valueUtf8((String) value)); |
@@ -185,6 +195,19 @@ public static void writeAttribute(StreamingBuffer buf, int type, String key, Obj |
185 | 195 | } |
186 | 196 | } |
187 | 197 |
|
| 198 | + public static void writeAttribute( |
| 199 | + StreamingBuffer buf, UTF8BytesString key, UTF8BytesString value) { |
| 200 | + writeStringAttribute(buf, key.getUtf8Bytes(), value.getUtf8Bytes()); |
| 201 | + } |
| 202 | + |
| 203 | + public static void writeAttribute(StreamingBuffer buf, UTF8BytesString key, String value) { |
| 204 | + writeStringAttribute(buf, key.getUtf8Bytes(), valueUtf8(value)); |
| 205 | + } |
| 206 | + |
| 207 | + public static void writeAttribute(StreamingBuffer buf, UTF8BytesString key, long value) { |
| 208 | + writeLongAttribute(buf, key.getUtf8Bytes(), value); |
| 209 | + } |
| 210 | + |
188 | 211 | private static byte[] keyUtf8(String key) { |
189 | 212 | return KEY_CACHE != null ? KEY_CACHE.getUtf8(key) : key.getBytes(UTF_8); |
190 | 213 | } |
|
0 commit comments