Skip to content

Commit eacde60

Browse files
feat: add test event finished FTR telemetry
1 parent f931654 commit eacde60

File tree

6 files changed

+28
-23
lines changed

6 files changed

+28
-23
lines changed

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/AbstractTestSession.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ public AbstractTestSession(
132132
config.isAgentlessLogSubmissionEnabled() ? AgentlessLogSubmissionEnabled.TRUE : null,
133133
CIConstants.FAIL_FAST_TEST_ORDER.equalsIgnoreCase(config.getCiVisibilityTestOrder())
134134
? FailFastTestOrderEnabled.TRUE
135-
: null,
136-
null);
135+
: null);
137136

138137
if (instrumentationType == InstrumentationType.MANUAL_API) {
139138
metricCollector.add(CiVisibilityCountMetric.MANUAL_API_EVENTS, 1, EventType.SESSION);

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/TestImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import datadog.trace.api.civisibility.telemetry.TagValue;
2121
import datadog.trace.api.civisibility.telemetry.tag.BrowserDriver;
2222
import datadog.trace.api.civisibility.telemetry.tag.EventType;
23+
import datadog.trace.api.civisibility.telemetry.tag.FailedTestReplayEnabled;
2324
import datadog.trace.api.civisibility.telemetry.tag.HasFailedAllRetries;
2425
import datadog.trace.api.civisibility.telemetry.tag.IsAttemptToFix;
2526
import datadog.trace.api.civisibility.telemetry.tag.IsDisabled;
@@ -305,7 +306,9 @@ public void end(@Nullable Long endTime) {
305306
span.getTag(Tags.TEST_IS_RETRY) != null ? IsRetry.TRUE : null,
306307
span.getTag(Tags.TEST_HAS_FAILED_ALL_RETRIES) != null ? HasFailedAllRetries.TRUE : null,
307308
retryReason instanceof TagValue ? (TagValue) retryReason : null,
308-
null,
309+
span.getTag(Tags.ERROR_DEBUG_INFO_CAPTURED) != null
310+
? FailedTestReplayEnabled.TestMetric.TRUE
311+
: null,
309312
span.getTag(Tags.TEST_IS_RUM_ACTIVE) != null ? IsRum.TRUE : null,
310313
CIConstants.SELENIUM_BROWSER_DRIVER.equals(span.getTag(Tags.TEST_BROWSER_DRIVER))
311314
? BrowserDriver.SELENIUM

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/DefaultExceptionDebugger.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import datadog.trace.bootstrap.debugger.DebuggerContext;
1414
import datadog.trace.bootstrap.debugger.DebuggerContext.ClassNameFilter;
1515
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
16+
import datadog.trace.bootstrap.instrumentation.api.Tags;
1617
import datadog.trace.util.AgentTaskScheduler;
1718
import java.time.Duration;
1819
import java.util.ArrayDeque;
@@ -32,7 +33,6 @@ public class DefaultExceptionDebugger implements DebuggerContext.ExceptionDebugg
3233
public static final String DD_DEBUG_ERROR_EXCEPTION_ID = DD_DEBUG_ERROR_PREFIX + "exception_id";
3334
public static final String DD_DEBUG_ERROR_EXCEPTION_HASH =
3435
DD_DEBUG_ERROR_PREFIX + "exception_hash";
35-
public static final String ERROR_DEBUG_INFO_CAPTURED = "error.debug_info_captured";
3636
public static final String SNAPSHOT_ID_TAG_FMT = DD_DEBUG_ERROR_PREFIX + "%d.snapshot_id";
3737

3838
// Test Optimization / Failed Test Replay specific
@@ -179,19 +179,21 @@ private static void processSnapshotsAndSetTags(
179179
span.setTag(tagName, snapshot.getId());
180180
LOGGER.debug("add tag to span[{}]: {}: {}", span.getSpanId(), tagName, snapshot.getId());
181181

182-
StackTraceElement stackFrame = innerTrace[currentIdx];
183-
String fileTag = String.format(TEST_DEBUG_ERROR_FILE_TAG_FMT, frameIndex);
184-
String lineTag = String.format(TEST_DEBUG_ERROR_LINE_TAG_FMT, frameIndex);
185-
span.setTag(fileTag, stackFrame.getFileName());
186-
span.setTag(lineTag, stackFrame.getLineNumber());
182+
if (Config.get().isCiVisibilityFailedTestReplayActive()) {
183+
StackTraceElement stackFrame = innerTrace[currentIdx];
184+
String fileTag = String.format(TEST_DEBUG_ERROR_FILE_TAG_FMT, frameIndex);
185+
String lineTag = String.format(TEST_DEBUG_ERROR_LINE_TAG_FMT, frameIndex);
186+
span.setTag(fileTag, stackFrame.getFileName());
187+
span.setTag(lineTag, stackFrame.getLineNumber());
187188

188-
LOGGER.debug(
189-
"add ftr debug tags to span[{}]: {}={}, {}={}",
190-
span.getSpanId(),
191-
fileTag,
192-
stackFrame.getFileName(),
193-
lineTag,
194-
stackFrame.getLineNumber());
189+
LOGGER.debug(
190+
"add ftr debug tags to span[{}]: {}={}, {}={}",
191+
span.getSpanId(),
192+
fileTag,
193+
stackFrame.getFileName(),
194+
lineTag,
195+
stackFrame.getLineNumber());
196+
}
195197

196198
if (!state.isSnapshotSent()) {
197199
DebuggerAgent.getSink().addSnapshot(snapshot);
@@ -206,7 +208,7 @@ private static void processSnapshotsAndSetTags(
206208
span.getSpanId(),
207209
DD_DEBUG_ERROR_EXCEPTION_ID,
208210
state.getExceptionId());
209-
span.setTag(ERROR_DEBUG_INFO_CAPTURED, true);
211+
span.setTag(Tags.ERROR_DEBUG_INFO_CAPTURED, true);
210212
span.setTag(DD_DEBUG_ERROR_EXCEPTION_HASH, fingerprint);
211213
}
212214
}

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/exception/ExceptionProbeInstrumentationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static com.datadog.debugger.agent.ConfigurationAcceptor.Source.REMOTE_CONFIG;
44
import static com.datadog.debugger.exception.DefaultExceptionDebugger.DD_DEBUG_ERROR_EXCEPTION_HASH;
55
import static com.datadog.debugger.exception.DefaultExceptionDebugger.DD_DEBUG_ERROR_EXCEPTION_ID;
6-
import static com.datadog.debugger.exception.DefaultExceptionDebugger.ERROR_DEBUG_INFO_CAPTURED;
76
import static com.datadog.debugger.exception.DefaultExceptionDebugger.SNAPSHOT_ID_TAG_FMT;
87
import static com.datadog.debugger.util.MoshiSnapshotTestHelper.getValue;
98
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -38,6 +37,7 @@
3837
import datadog.trace.bootstrap.debugger.ProbeId;
3938
import datadog.trace.bootstrap.debugger.ProbeLocation;
4039
import datadog.trace.bootstrap.debugger.ProbeRateLimiter;
40+
import datadog.trace.bootstrap.instrumentation.api.Tags;
4141
import datadog.trace.core.CoreTracer;
4242
import java.io.IOException;
4343
import java.lang.instrument.ClassFileTransformer;
@@ -157,7 +157,7 @@ public void instrumentAndCaptureSnapshots() throws Exception {
157157
MutableSpan span = traceInterceptor.getFirstSpan();
158158
assertEquals(snapshot0.getExceptionId(), span.getTags().get(DD_DEBUG_ERROR_EXCEPTION_ID));
159159
assertEquals(fingerprint, span.getTags().get(DD_DEBUG_ERROR_EXCEPTION_HASH));
160-
assertEquals(Boolean.TRUE, span.getTags().get(ERROR_DEBUG_INFO_CAPTURED));
160+
assertEquals(Boolean.TRUE, span.getTags().get(Tags.ERROR_DEBUG_INFO_CAPTURED));
161161
assertEquals(snapshot0.getId(), span.getTags().get(String.format(SNAPSHOT_ID_TAG_FMT, 0)));
162162
assertEquals(1, probeSampler.getCallCount());
163163
assertEquals(1, globalSampler.getCallCount());
@@ -198,11 +198,11 @@ public void differentExceptionsSameStack() throws Exception {
198198
assertExceptionMsg("illegal argument", snapshot1);
199199
MutableSpan span0 = traceInterceptor.getAllTraces().get(0).get(0);
200200
assertEquals(snapshot0.getExceptionId(), span0.getTags().get(DD_DEBUG_ERROR_EXCEPTION_ID));
201-
assertEquals(Boolean.TRUE, span0.getTags().get(ERROR_DEBUG_INFO_CAPTURED));
201+
assertEquals(Boolean.TRUE, span0.getTags().get(Tags.ERROR_DEBUG_INFO_CAPTURED));
202202
assertEquals(snapshot0.getId(), span0.getTags().get(String.format(SNAPSHOT_ID_TAG_FMT, 0)));
203203
MutableSpan span1 = traceInterceptor.getAllTraces().get(1).get(0);
204204
assertEquals(snapshot1.getExceptionId(), span1.getTags().get(DD_DEBUG_ERROR_EXCEPTION_ID));
205-
assertEquals(Boolean.TRUE, span1.getTags().get(ERROR_DEBUG_INFO_CAPTURED));
205+
assertEquals(Boolean.TRUE, span1.getTags().get(Tags.ERROR_DEBUG_INFO_CAPTURED));
206206
assertEquals(snapshot1.getId(), span1.getTags().get(String.format(SNAPSHOT_ID_TAG_FMT, 0)));
207207
}
208208

internal-api/src/main/java/datadog/trace/api/civisibility/telemetry/CiVisibilityCountMetric.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ public enum CiVisibilityCountMetric {
5454
Provider.class,
5555
AutoInjected.class,
5656
AgentlessLogSubmissionEnabled.class,
57-
FailFastTestOrderEnabled.class,
58-
FailedTestReplayEnabled.SessionMetric.class),
57+
FailFastTestOrderEnabled.class),
5958
/** The number of events created */
6059
EVENT_CREATED(
6160
"event_created",

internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api/Tags.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public class Tags {
107107
public static final String TEST_TEST_MANAGEMENT_ATTEMPT_TO_FIX_PASSED =
108108
"test.test_management.attempt_to_fix_passed";
109109

110+
public static final String ERROR_DEBUG_INFO_CAPTURED = "error.debug_info_captured";
111+
110112
public static final String CI_PROVIDER_NAME = "ci.provider.name";
111113
public static final String CI_PIPELINE_ID = "ci.pipeline.id";
112114
public static final String CI_PIPELINE_NAME = "ci.pipeline.name";

0 commit comments

Comments
 (0)