Skip to content

Commit 886d5c4

Browse files
authored
bump + try catch (#64)
1 parent 66a963a commit 886d5c4

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dependencies {
3535
implementation 'io.opentracing:opentracing-api:0.33.0'
3636
implementation 'io.opentracing:opentracing-util:0.33.0'
3737
implementation 'com.datadoghq:dd-trace-api:0.90.0'
38-
implementation 'com.datadoghq:java-dogstatsd-client:2.13.0'
38+
implementation 'com.datadoghq:java-dogstatsd-client:3.0.0'
3939

4040
// Use JUnit test framework
4141
testImplementation 'junit:junit:4.13.2'

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

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,36 @@ class ExtensionMetricWriter extends MetricWriter{
4040
private StatsDClient client;
4141

4242
public ExtensionMetricWriter() {
43-
this.client = new NonBlockingStatsDClientBuilder()
44-
.prefix("")
45-
.hostname("127.0.0.1")
46-
.port(8125)
47-
.build();
43+
try {
44+
this.client = new NonBlockingStatsDClientBuilder()
45+
.prefix("")
46+
.hostname("127.0.0.1")
47+
.port(8125)
48+
.enableTelemetry(false)
49+
.telemetryFlushInterval(0)
50+
.build();
51+
} catch (Exception e) {
52+
DDLogger.getLoggerImpl().error("Could not create StatsDClient " + e.getMessage());
53+
this.client = null;
54+
}
4855
}
4956

57+
58+
5059
@Override
5160
public void write(CustomMetric cm){
52-
StringBuilder tagsSb = new StringBuilder();
53-
if (cm.getTags() != null) {
54-
cm.getTags().forEach((k, val) ->
55-
tagsSb.append(k.toLowerCase())
56-
.append(":")
57-
.append(val.toString().toLowerCase()));
61+
if(null != client) {
62+
StringBuilder tagsSb = new StringBuilder();
63+
if (cm.getTags() != null) {
64+
cm.getTags().forEach((k, val) ->
65+
tagsSb.append(k.toLowerCase())
66+
.append(":")
67+
.append(val.toString().toLowerCase()));
68+
}
69+
client.distribution(cm.getName(), cm.getValue(), tagsSb.toString());
70+
} else {
71+
DDLogger.getLoggerImpl().error("Could not write the metric because the client is null");
5872
}
59-
client.distribution(cm.getName(), cm.getValue(), tagsSb.toString());
6073
}
6174

6275
@Override

0 commit comments

Comments
 (0)