Skip to content
Draft
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 @@ -7,6 +7,7 @@
import datadog.trace.api.civisibility.telemetry.CiVisibilityCountMetric;
import datadog.trace.api.civisibility.telemetry.CiVisibilityMetricCollector;
import datadog.trace.api.civisibility.telemetry.tag.EventType;
import datadog.trace.api.civisibility.telemetry.tag.IsAndroid;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext;
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
Expand Down Expand Up @@ -114,6 +115,10 @@ public void end(@Nullable Long endTime) {
span.finish();
}

metricCollector.add(CiVisibilityCountMetric.EVENT_FINISHED, 1, EventType.MODULE);
metricCollector.add(
CiVisibilityCountMetric.EVENT_FINISHED,
1,
EventType.MODULE,
span.getTag(Tags.TEST_IS_ANDROID) != null ? IsAndroid.TRUE : null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import datadog.trace.api.civisibility.telemetry.tag.FailFastTestOrderEnabled;
import datadog.trace.api.civisibility.telemetry.tag.FailedTestReplayEnabled;
import datadog.trace.api.civisibility.telemetry.tag.HasCodeowner;
import datadog.trace.api.civisibility.telemetry.tag.IsAndroid;
import datadog.trace.api.civisibility.telemetry.tag.IsHeadless;
import datadog.trace.api.civisibility.telemetry.tag.IsUnsupportedCI;
import datadog.trace.api.civisibility.telemetry.tag.Provider;
Expand Down Expand Up @@ -200,6 +201,9 @@ protected Collection<TagValue> additionalTelemetryTags() {
if (span.getTag(DDTags.TEST_HAS_FAILED_TEST_REPLAY) != null) {
tags.add(FailedTestReplayEnabled.SessionMetric.TRUE);
}
if (span.getTag(Tags.TEST_IS_ANDROID) != null) {
tags.add(IsAndroid.TRUE);
}
return tags;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ private void onModuleFinish(AgentSpan moduleSpan) {
TagMergeSpec.of(Tags.TEST_ITR_TESTS_SKIPPING_COUNT, Long::sum),
TagMergeSpec.of(DDTags.CI_ITR_TESTS_SKIPPED, Boolean::logicalOr),
TagMergeSpec.of(Tags.TEST_TEST_MANAGEMENT_ENABLED, Boolean::logicalOr),
TagMergeSpec.of(Tags.TEST_IS_ANDROID, Boolean::logicalOr),
TagMergeSpec.of(DDTags.TEST_HAS_FAILED_TEST_REPLAY, Boolean::logicalOr),
TagMergeSpec.of(DDTags.CI_LIBRARY_CONFIGURATION_ERROR_SETTINGS, Boolean::logicalOr),
TagMergeSpec.of(DDTags.CI_LIBRARY_CONFIGURATION_ERROR_SKIPPABLE_TESTS, Boolean::logicalOr),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import datadog.trace.api.civisibility.domain.BuildSessionSettings;
import datadog.trace.api.civisibility.domain.JavaAgent;
import datadog.trace.api.civisibility.events.BuildEventsHandler;
import datadog.trace.bootstrap.instrumentation.api.Tags;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -111,9 +112,22 @@ public void beforeExecute(@Nonnull Task task) {
List<Path> classpath = GradleUtils.getClasspath(task);
JavaAgent jacocoAgent = GradleUtils.getJacocoAgent(task);

// "com.android.base" is applied transitively by every Android Gradle Plugin, so it is a
// reliable single marker for an Android project regardless of how its tests are executed.
Map<String, Object> additionalTags =
project.getPluginManager().hasPlugin("com.android.base")
? Collections.singletonMap(Tags.TEST_IS_ANDROID, true)
: Collections.emptyMap();

BuildModuleSettings moduleSettings =
buildEventsHandler.onTestModuleStart(
gradle, taskPath, moduleLayout, jvmExecutable, classpath, jacocoAgent, null);
gradle,
taskPath,
moduleLayout,
jvmExecutable,
classpath,
jacocoAgent,
additionalTags);
Map<String, String> systemProperties = moduleSettings.getSystemProperties();
GradleProjectConfigurator.INSTANCE.configureTracer(task, systemProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ public void beforeExecute(TaskIdentity<?> taskIdentity) {
Project project = gradle.getRootProject().project(projectPath);
Test task = (Test) project.getTasks().getByName(taskIdentity.name);

// "com.android.base" is applied transitively by every Android Gradle Plugin
// (application/library/dynamic-feature/test), so it is a reliable single marker for an
// Android project regardless of how its tests are executed.
boolean isAndroid = project.getPluginManager().hasPlugin("com.android.base");

Map<String, Object> inputProperties = task.getInputs().getProperties();
BuildModuleLayout moduleLayout =
(BuildModuleLayout) inputProperties.get(CiVisibilityPluginExtension.MODULE_LAYOUT_PROPERTY);
Expand All @@ -197,7 +202,7 @@ public void beforeExecute(TaskIdentity<?> taskIdentity) {
List<Path> taskClasspath = CiVisibilityPluginExtension.getClasspath(task);

ciVisibilityService.onModuleStart(
taskPath, moduleLayout, jvmExecutable, taskClasspath, jacocoAgent);
taskPath, isAndroid, moduleLayout, jvmExecutable, taskClasspath, jacocoAgent);
}

private JavaAgent getJacocoAgent(Test task) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,21 @@ public void onBuildTaskFinish(String taskPath, @Nullable Throwable failure) {

public void onModuleStart(
String taskPath,
boolean isAndroid,
BuildModuleLayout moduleLayout,
Path jvmExecutable,
Collection<Path> taskClasspath,
JavaAgent jacocoAgent) {
Map<String, Object> additionalTags =
isAndroid ? Collections.singletonMap(Tags.TEST_IS_ANDROID, true) : Collections.emptyMap();
buildEventsHandler.onTestModuleStart(
SESSION_KEY, taskPath, moduleLayout, jvmExecutable, taskClasspath, jacocoAgent, null);
SESSION_KEY,
taskPath,
moduleLayout,
jvmExecutable,
taskClasspath,
jacocoAgent,
additionalTags);
}

public void onModuleFinish(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void testNew(

@TableTest({
"scenario | gradleVersion | projectName | expectedTraces",
"robolectric-latest | latest | test-succeed-robolectric | 6 "
"robolectric-latest | latest | test-succeed-robolectric | 7 "
})
@ParameterizedTest
void testRobolectric(String gradleVersion, String projectName, int expectedTraces)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import org.gradle.api.attributes.CompatibilityCheckDetails
import org.gradle.api.attributes.LibraryElements

apply plugin: 'java'
// Inert stand-in for the Android Gradle Plugin (see buildSrc/): real AGP needs the Android SDK,
// which is absent in the smoke-test environment. Our build-level Android detection only checks for
// the 'com.android.base' plugin id, so applying an id-only stand-in exercises it.
apply plugin: 'com.android.base'

repositories {
mavenLocal()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apply plugin: 'java'

repositories {
mavenLocal()

def proxyUrl = System.getenv("MAVEN_REPOSITORY_PROXY")
if (proxyUrl) {
maven {
url = proxyUrl
allowInsecureProtocol = true
}
}

mavenCentral()
}

dependencies {
// Plugin<Project> lives in the Gradle API; the CI Visibility javac plugin is auto-injected into
// this compile task too, so the repositories above must be able to resolve it.
implementation gradleApi()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package datadog.smoke.gradle;

import org.gradle.api.Plugin;
import org.gradle.api.Project;

/**
* No-op stand-in for the Android Gradle Plugin's {@code com.android.base} plugin.
*
* <p>Real AGP requires the Android SDK to be installed, which is not available in the smoke-test
* environment. The CI Visibility build-level Android detection only checks whether a plugin
* registered under the {@code com.android.base} id has been applied (see {@code
* CiVisibilityGradleListener}); every AGP variant applies {@code com.android.base} transitively.
* Registering an inert plugin under that exact id therefore exercises the detection, the
* module→session tag propagation and the {@code is_android} telemetry faithfully, without pulling
* in AGP or the SDK.
*/
public class AndroidBaseStandInPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
// intentionally empty: only the plugin id matters for detection
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
implementation-class=datadog.smoke.gradle.AndroidBaseStandInPlugin
Loading