Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies {
implementation 'io.opentracing:opentracing-api:0.33.0'
implementation 'io.opentracing:opentracing-util:0.33.0'
implementation 'com.datadoghq:dd-trace-api:0.90.0'
implementation 'com.datadoghq:java-dogstatsd-client:2.13.0'
implementation 'com.datadoghq:java-dogstatsd-client:3.0.0'

// Use JUnit test framework
testImplementation 'junit:junit:4.13.2'
Expand Down
37 changes: 25 additions & 12 deletions src/main/java/com/datadoghq/datadog_lambda_java/MetricWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,36 @@ class ExtensionMetricWriter extends MetricWriter{
private StatsDClient client;

public ExtensionMetricWriter() {
this.client = new NonBlockingStatsDClientBuilder()
.prefix("")
.hostname("127.0.0.1")
.port(8125)
.build();
try {
this.client = new NonBlockingStatsDClientBuilder()
.prefix("")
.hostname("127.0.0.1")
.port(8125)
.enableTelemetry(false)
.telemetryFlushInterval(0)
.build();
} catch (Exception e) {
DDLogger.getLoggerImpl().error("Could not create StatsDClient " + e.getMessage());
this.client = null;
}
}



@Override
public void write(CustomMetric cm){
StringBuilder tagsSb = new StringBuilder();
if (cm.getTags() != null) {
cm.getTags().forEach((k, val) ->
tagsSb.append(k.toLowerCase())
.append(":")
.append(val.toString().toLowerCase()));
if(null != client) {
StringBuilder tagsSb = new StringBuilder();
if (cm.getTags() != null) {
cm.getTags().forEach((k, val) ->
tagsSb.append(k.toLowerCase())
.append(":")
.append(val.toString().toLowerCase()));
}
client.distribution(cm.getName(), cm.getValue(), tagsSb.toString());
} else {
DDLogger.getLoggerImpl().error("Could not write the metric because the client is null");
}
client.distribution(cm.getName(), cm.getValue(), tagsSb.toString());
}

@Override
Expand Down