Skip to content

Commit 9af02e9

Browse files
committed
Add telemetry collector and methods to RumInjector
1 parent dc92b28 commit 9af02e9

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

internal-api/src/main/java/datadog/trace/api/rum/RumInjector.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public final class RumInjector {
2727
private final DDCache<String, byte[]> markerCache;
2828
private final Function<String, byte[]> snippetBytes;
2929

30+
// Health metrics telemetry collector (set by CoreTracer)
31+
private static volatile RumTelemetryCollector telemetryCollector = RumTelemetryCollector.NO_OP;
32+
3033
RumInjector(Config config) {
3134
boolean rumEnabled = config.isRumEnabled();
3235
RumInjectorConfig injectorConfig = config.getRumInjectorConfig();
@@ -120,4 +123,23 @@ public byte[] getMarkerBytes(String encoding) {
120123
}
121124
return this.markerCache.computeIfAbsent(encoding, MARKER_BYTES);
122125
}
126+
127+
public static void setTelemetryCollector(RumTelemetryCollector collector) {
128+
telemetryCollector = collector != null ? collector : RumTelemetryCollector.NO_OP;
129+
}
130+
131+
// report that the RUM injector succeeded in injecting the SDK in an HTTP response
132+
public static void reportInjectionSucceed() {
133+
telemetryCollector.onInjectionSucceed();
134+
}
135+
136+
// report that the RUM injector failed to inject the SDK in an HTTP response
137+
public static void reportInjectionFailed() {
138+
telemetryCollector.onInjectionFailed();
139+
}
140+
141+
// report that the RUM injector skipped injecting the SDK in an HTTP response
142+
public static void reportInjectionSkipped() {
143+
telemetryCollector.onInjectionSkipped();
144+
}
123145
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package datadog.trace.api.rum;
2+
3+
// Collect RUM injection telemetry
4+
public interface RumTelemetryCollector {
5+
6+
RumTelemetryCollector NO_OP =
7+
new RumTelemetryCollector() {
8+
@Override
9+
public void onInjectionSucceed() {}
10+
11+
@Override
12+
public void onInjectionFailed() {}
13+
14+
@Override
15+
public void onInjectionSkipped() {}
16+
};
17+
18+
// call when RUM injection succeeds
19+
void onInjectionSucceed();
20+
21+
// call when RUM injection fails
22+
void onInjectionFailed();
23+
24+
// call when RUM injection is skipped
25+
void onInjectionSkipped();
26+
}

0 commit comments

Comments
 (0)