Skip to content

Commit

Permalink
Move 'recordEvent' method to StatsDClient interface (#7267)
Browse files Browse the repository at this point in the history
* Move 'recordEvent' method to StatsDClient interface

* Remove dangling debug output
  • Loading branch information
jbachorik authored Jul 2, 2024
1 parent 38e8294 commit 16dbb60
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,10 @@ public void serviceCheck(
connection.statsd.recordServiceCheckRun(serviceCheck);
}

/**
* Record a statsd event
*
* @param type the type of event (error, warning, info, success - @see Event.AlertType)
* @param source the source of the event (e.g. java, myapp, CrashTracking, Telemetry, etc)
* @param eventName the name of the event (or title)
* @param message the message of the event
* @param tags the tags to attach to the event
*/
@Override
public void recordEvent(
String type, String source, String eventName, String message, String... tags) {
Event.AlertType alertType = Event.AlertType.valueOf(type.toUpperCase());
log.debug(
"Recording event: {} - {} - {} - {} [{}]", alertType, source, eventName, message, tags);
Event.Builder eventBuilder =
Event.builder()
.withTitle(eventName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public final class LoggingStatsDClient implements StatsDClient {
private static final String HISTOGRAM_FORMAT = "{}:{}|h{}";
private static final String DISTRIBUTION_FORMAT = "{}:{}|d{}";
private static final String SERVICE_CHECK_FORMAT = "_sc|{}|{}{}{}";
private static final String EVENT_FORMAT = "_e|{}|{}|{}|{}|{}";

private static final DecimalFormat DECIMAL_FORMAT;

Expand Down Expand Up @@ -111,6 +112,12 @@ public int getErrorCount() {
return 0;
}

@Override
public void recordEvent(
String type, String source, String eventName, String message, String... tags) {
log.info(EVENT_FORMAT, type, source, eventName, message, join(tagMapping.apply(tags)));
}

@Override
public void close() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public CrashUploader() {

ConfigProvider configProvider = config.configProvider();

System.out.println("===> telemetryUrl: " + telemetryUrl);
telemetryClient =
OkHttpUtils.buildHttpClient(
config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static datadog.communication.monitor.DDAgentStatsDClientManager.statsDClientManager;

import datadog.communication.monitor.DDAgentStatsDClient;
import datadog.trace.api.StatsDClient;
import de.thetaphi.forbiddenapis.SuppressForbidden;
import java.util.concurrent.locks.LockSupport;
import org.slf4j.Logger;
Expand All @@ -14,9 +14,8 @@ public final class OOMENotifier {
// This method is called via CLI so we don't need to be paranoid about the forbiddend APIs
@SuppressForbidden
public static void sendOomeEvent(String taglist) {
try (DDAgentStatsDClient client =
(DDAgentStatsDClient)
statsDClientManager().statsDClient(null, null, null, null, null, false)) {
try (StatsDClient client =
statsDClientManager().statsDClient(null, null, null, null, null, false)) {
String[] tags = taglist.split(",");
client.recordEvent(
"error",
Expand Down
12 changes: 12 additions & 0 deletions internal-api/src/main/java/datadog/trace/api/StatsDClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ public interface StatsDClient extends Closeable {

int getErrorCount();

/**
* Record a statsd event
*
* @param type the type of event (error, warning, info, success - @see Event.AlertType)
* @param source the source of the event (e.g. java, myapp, CrashTracking, Telemetry, etc)
* @param eventName the name of the event (or title)
* @param message the message of the event
* @param tags the tags to attach to the event
*/
default void recordEvent(
String type, String source, String eventName, String message, String... tags) {};

@Override
void close();
}

0 comments on commit 16dbb60

Please sign in to comment.