Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package datadog.trace.common.metrics;

import static java.nio.charset.StandardCharsets.ISO_8859_1;

import datadog.communication.serialization.GrowableBuffer;
import datadog.communication.serialization.WritableFormatter;
import datadog.communication.serialization.msgpack.MsgPackWriter;
import datadog.trace.api.ProcessTags;
import datadog.trace.api.WellKnownTags;
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;

import java.util.List;

import static java.nio.charset.StandardCharsets.ISO_8859_1;

public final class SerializingMetricWriter implements MetricWriter {

private static final byte[] SEQUENCE = "Seq".getBytes(ISO_8859_1);
Expand All @@ -35,6 +36,9 @@ public final class SerializingMetricWriter implements MetricWriter {
private static final byte[] IS_TRACE_ROOT = "IsTraceRoot".getBytes(ISO_8859_1);
private static final byte[] SPAN_KIND = "SpanKind".getBytes(ISO_8859_1);
private static final byte[] PEER_TAGS = "PeerTags".getBytes(ISO_8859_1);
// Is trace root is a tristate (0 unknown, 1 true, 2 false)
public static final int IS_TRACE_ROOT_TRUE = 1;
public static final int IS_TRACE_ROOT_FALSE = 2;

private final WellKnownTags wellKnownTags;
private final WritableFormatter writer;
Expand Down Expand Up @@ -118,7 +122,7 @@ public void add(MetricKey key, AggregateMetric aggregate) {
writer.writeBoolean(key.isSynthetics());

writer.writeUTF8(IS_TRACE_ROOT);
writer.writeInt(key.isTraceRoot() ? 1 : 2); // tristate (0 unknown, 1 true, 2 false)
writer.writeInt(key.isTraceRoot() ? IS_TRACE_ROOT_TRUE : IS_TRACE_ROOT_FALSE);

writer.writeUTF8(SPAN_KIND);
writer.writeUTF8(key.getSpanKind());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import static java.util.concurrent.TimeUnit.SECONDS

class SerializingMetricWriterTest extends DDSpecification {

public static final int IS_TRACE_ROOT_TRUE = 1
public static final int IS_TRACE_ROOT_FALSE = 2

def "should produce correct message #iterationIndex with process tags enabled #withProcessTags" () {
setup:
if (withProcessTags) {
Expand Down Expand Up @@ -177,7 +180,7 @@ class SerializingMetricWriterTest extends DDSpecification {
assert unpacker.unpackBoolean() == key.isSynthetics()
++elementCount
assert unpacker.unpackString() == "IsTraceRoot"
assert unpacker.unpackInt() == (key.isTraceRoot() ? 1 : 2)
assert unpacker.unpackInt() == (key.isTraceRoot() ? IS_TRACE_ROOT_TRUE : IS_TRACE_ROOT_FALSE)
++elementCount
assert unpacker.unpackString() == "SpanKind"
assert unpacker.unpackString() == key.getSpanKind() as String
Expand Down
Loading