|
7 | 7 | import datadog.communication.serialization.Writable;
|
8 | 8 | import datadog.communication.serialization.WritableFormatter;
|
9 | 9 | import datadog.communication.serialization.msgpack.MsgPackWriter;
|
| 10 | +import datadog.trace.api.ProcessTags; |
10 | 11 | import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags;
|
11 | 12 | import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
|
12 | 13 | import datadog.trace.common.writer.Payload;
|
@@ -78,7 +79,8 @@ public void map(final List<? extends CoreSpan<?>> trace, final Writable writable
|
78 | 79 | span.processTagsAndBaggage(
|
79 | 80 | metaWriter
|
80 | 81 | .withWritable(writable)
|
81 |
| - .withWriteSamplingPriority(i == 0 || i == trace.size() - 1)); |
| 82 | + .forFirstSpanInChunk(i == 0) |
| 83 | + .forLastSpanInChunk(i == trace.size() - 1)); |
82 | 84 | /* 12 */
|
83 | 85 | writeDictionaryEncoded(writable, span.getType());
|
84 | 86 | }
|
@@ -179,25 +181,35 @@ private List<ByteBuffer> toList() {
|
179 | 181 | private final class MetaWriter implements MetadataConsumer {
|
180 | 182 |
|
181 | 183 | private Writable writable;
|
182 |
| - private boolean writeSamplingPriority; |
| 184 | + private boolean firstSpanInChunk; |
| 185 | + private boolean lastSpanInChunk; |
183 | 186 |
|
184 | 187 | MetaWriter withWritable(final Writable writable) {
|
185 | 188 | this.writable = writable;
|
186 | 189 | return this;
|
187 | 190 | }
|
188 | 191 |
|
189 |
| - MetaWriter withWriteSamplingPriority(final boolean writeSamplingPriority) { |
190 |
| - this.writeSamplingPriority = writeSamplingPriority; |
| 192 | + MetaWriter forFirstSpanInChunk(final boolean firstSpanInChunk) { |
| 193 | + this.firstSpanInChunk = firstSpanInChunk; |
| 194 | + return this; |
| 195 | + } |
| 196 | + |
| 197 | + MetaWriter forLastSpanInChunk(final boolean lastSpanInChunk) { |
| 198 | + this.lastSpanInChunk = lastSpanInChunk; |
191 | 199 | return this;
|
192 | 200 | }
|
193 | 201 |
|
194 | 202 | @Override
|
195 | 203 | public void accept(Metadata metadata) {
|
| 204 | + final boolean writeSamplingPriority = firstSpanInChunk || lastSpanInChunk; |
| 205 | + final UTF8BytesString processTags = |
| 206 | + firstSpanInChunk ? ProcessTags.getTagsForSerialization() : null; |
196 | 207 | int metaSize =
|
197 | 208 | metadata.getBaggage().size()
|
198 | 209 | + metadata.getTags().size()
|
199 | 210 | + (null == metadata.getHttpStatusCode() ? 0 : 1)
|
200 | 211 | + (null == metadata.getOrigin() ? 0 : 1)
|
| 212 | + + (null == processTags ? 0 : 1) |
201 | 213 | + 1;
|
202 | 214 | int metricsSize =
|
203 | 215 | (writeSamplingPriority && metadata.hasSamplingPriority() ? 1 : 0)
|
@@ -234,6 +246,10 @@ public void accept(Metadata metadata) {
|
234 | 246 | writeDictionaryEncoded(writable, ORIGIN_KEY);
|
235 | 247 | writeDictionaryEncoded(writable, metadata.getOrigin());
|
236 | 248 | }
|
| 249 | + if (null != processTags) { |
| 250 | + writeDictionaryEncoded(writable, PROCESS_TAGS_KEY); |
| 251 | + writeDictionaryEncoded(writable, processTags); |
| 252 | + } |
237 | 253 | for (Map.Entry<String, Object> entry : metadata.getTags().entrySet()) {
|
238 | 254 | String key = entry.getKey();
|
239 | 255 | Object value = entry.getValue();
|
|
0 commit comments