Skip to content

Commit 97837c7

Browse files
Fix tags concatenation in custom metric (#77)
Co-authored-by: vmakarevich <[email protected]>
1 parent 56d2cf1 commit 97837c7

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/main/java/com/datadoghq/datadog_lambda_java/MetricWriter.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.timgroup.statsd.NonBlockingStatsDClientBuilder;
44
import com.timgroup.statsd.StatsDClient;
55

6+
import java.util.stream.Collectors;
7+
68
abstract class MetricWriter {
79
private static MetricWriter IMPL;
810
public static synchronized MetricWriter getMetricWriterImpl(){
@@ -59,14 +61,17 @@ public ExtensionMetricWriter() {
5961
@Override
6062
public void write(CustomMetric cm){
6163
if(null != client) {
62-
StringBuilder tagsSb = new StringBuilder();
64+
String tags = "";
6365
if (cm.getTags() != null) {
64-
cm.getTags().forEach((k, val) ->
65-
tagsSb.append(k.toLowerCase())
66-
.append(":")
67-
.append(val.toString().toLowerCase()));
66+
tags = cm
67+
.getTags()
68+
.entrySet()
69+
.stream()
70+
.map(
71+
entry -> entry.getKey().toLowerCase() + ":" + entry.getValue().toString().toLowerCase()
72+
).collect(Collectors.joining(","));
6873
}
69-
client.distribution(cm.getName(), cm.getValue(), tagsSb.toString());
74+
client.distribution(cm.getName(), cm.getValue(), tags);
7075
} else {
7176
DDLogger.getLoggerImpl().error("Could not write the metric because the client is null");
7277
}

src/test/java/com/datadoghq/datadog_lambda_java/CustomMetricTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void run() {
9090
if (null == text[0] || text[0].equals("notYetReceived")) {
9191
Thread.sleep(1000);
9292
} else {
93-
assertTrue(text[0].startsWith("foo:24.3|d|#firsttag:firsttagvaluesecondtag:100.34"));
93+
assertTrue(text[0].startsWith("foo:24.3|d|#firsttag:firsttagvalue,secondtag:100.34"));
9494
break;
9595
}
9696
}

0 commit comments

Comments
 (0)