Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move 'recordEvent' method to StatsDClient interface #7267

Merged
merged 2 commits into from
Jul 2, 2024
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
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();
}
Loading