diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityRepoServices.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityRepoServices.java index 45da90d0b94..c81e99fe130 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityRepoServices.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityRepoServices.java @@ -31,7 +31,6 @@ import datadog.trace.civisibility.source.SourcePathResolver; import datadog.trace.civisibility.source.index.RepoIndexProvider; import datadog.trace.civisibility.source.index.RepoIndexSourcePathResolver; -import datadog.trace.civisibility.utils.ProcessHierarchyUtils; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Map; @@ -76,11 +75,12 @@ public class CiVisibilityRepoServices { codeowners = buildCodeowners(repoRoot); sourcePathResolver = buildSourcePathResolver(repoRoot, repoIndexProvider); - if (ProcessHierarchyUtils.isChild()) { + if (services.processHierarchy.isChild()) { executionSettingsFactory = buildExecutionSettingsFetcher(services.signalClientFactory); } else { executionSettingsFactory = buildExecutionSettingsFactory( + services.processHierarchy, services.config, services.metricCollector, services.backendApi, @@ -122,6 +122,7 @@ private static ExecutionSettingsFactory buildExecutionSettingsFetcher( } private static ExecutionSettingsFactory buildExecutionSettingsFactory( + ProcessHierarchy processHierarchy, Config config, CiVisibilityMetricCollector metricCollector, BackendApi backendApi, @@ -138,7 +139,7 @@ private static ExecutionSettingsFactory buildExecutionSettingsFactory( ExecutionSettingsFactoryImpl factory = new ExecutionSettingsFactoryImpl(config, configurationApi, gitDataUploader, repoRoot); - if (ProcessHierarchyUtils.isHeadless()) { + if (processHierarchy.isHeadless()) { return factory; } else { return new MultiModuleExecutionSettingsFactory(config, factory); diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityServices.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityServices.java index 31fd0ff0cfd..407b142b261 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityServices.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityServices.java @@ -28,7 +28,6 @@ import datadog.trace.civisibility.source.CompilerAidedMethodLinesResolver; import datadog.trace.civisibility.source.MethodLinesResolver; import datadog.trace.civisibility.source.index.*; -import datadog.trace.civisibility.utils.ProcessHierarchyUtils; import java.lang.reflect.Type; import java.net.InetSocketAddress; import java.nio.file.FileSystem; @@ -56,6 +55,7 @@ public class CiVisibilityServices { static final String DD_ENV_VARS_PROVIDER_KEY_HEADER = "DD-Env-Vars-Provider-Key"; + final ProcessHierarchy processHierarchy; final Config config; final CiVisibilityMetricCollector metricCollector; final BackendApi backendApi; @@ -72,6 +72,7 @@ public class CiVisibilityServices { CiVisibilityMetricCollector metricCollector, SharedCommunicationObjects sco, GitInfoProvider gitInfoProvider) { + this.processHierarchy = new ProcessHierarchy(); this.config = config; this.metricCollector = metricCollector; this.backendApi = @@ -91,8 +92,8 @@ public class CiVisibilityServices { new CILocalGitInfoBuilder(gitClientFactory, GIT_FOLDER_NAME)); gitInfoProvider.registerGitInfoBuilder(new GitClientGitInfoBuilder(config, gitClientFactory)); - if (ProcessHierarchyUtils.isChild()) { - InetSocketAddress signalServerAddress = ProcessHierarchyUtils.getSignalServerAddress(); + if (processHierarchy.isChild()) { + InetSocketAddress signalServerAddress = processHierarchy.getSignalServerAddress(); this.signalClientFactory = new SignalClient.Factory(signalServerAddress, config); RepoIndexProvider indexFetcher = new RepoIndexFetcher(signalClientFactory); diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilitySystem.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilitySystem.java index 5131c654258..14e101041ca 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilitySystem.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilitySystem.java @@ -33,7 +33,6 @@ import datadog.trace.civisibility.telemetry.CiVisibilityMetricCollectorImpl; import datadog.trace.civisibility.test.ExecutionStrategy; import datadog.trace.civisibility.utils.ConcurrentHashMapContextStore; -import datadog.trace.civisibility.utils.ProcessHierarchyUtils; import datadog.trace.util.throwable.FatalAgentMisconfigurationError; import java.lang.instrument.Instrumentation; import java.nio.file.Path; @@ -79,7 +78,7 @@ public static void start(Instrumentation inst, SharedCommunicationObjects sco) { InstrumentationBridge.registerBuildEventsHandlerFactory(buildEventsHandlerFactory(services)); CIVisibility.registerSessionFactory(manualApiSessionFactory(services)); - if (ProcessHierarchyUtils.isChild() || ProcessHierarchyUtils.isHeadless()) { + if (services.processHierarchy.isChild() || services.processHierarchy.isHeadless()) { CiVisibilityRepoServices repoServices = services.repoServices(getCurrentPath()); ExecutionSettings executionSettings = @@ -142,7 +141,7 @@ private TestEventsHandlerFactory( ExecutionSettings executionSettings) { this.services = services; this.repoServices = repoServices; - if (ProcessHierarchyUtils.isChild()) { + if (services.processHierarchy.isChild()) { sessionFactory = childTestFrameworkSessionFactory( services, repoServices, coverageServices, executionSettings); @@ -222,9 +221,6 @@ private static TestFrameworkSession.Factory childTestFrameworkSessionFactory( CiVisibilityCoverageServices.Child coverageServices, ExecutionSettings executionSettings) { return (String projectName, String component, Long startTime) -> { - long parentProcessSessionId = ProcessHierarchyUtils.getParentSessionId(); - long parentProcessModuleId = ProcessHierarchyUtils.getParentModuleId(); - String sessionName = services.config.getCiVisibilitySessionName(); String testCommand = services.config.getCiVisibilityTestCommand(); TestDecorator testDecorator = @@ -232,9 +228,9 @@ private static TestFrameworkSession.Factory childTestFrameworkSessionFactory( ExecutionStrategy executionStrategy = new ExecutionStrategy(services.config, executionSettings); + return new ProxyTestSession( - parentProcessSessionId, - parentProcessModuleId, + services.processHierarchy.parentProcessModuleContext, services.config, services.metricCollector, testDecorator, diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ProcessHierarchy.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ProcessHierarchy.java new file mode 100644 index 00000000000..e3bb987e894 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ProcessHierarchy.java @@ -0,0 +1,91 @@ +package datadog.trace.civisibility; + +import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.propagate; + +import datadog.trace.api.config.CiVisibilityConfig; +import datadog.trace.bootstrap.instrumentation.api.AgentPropagation; +import datadog.trace.bootstrap.instrumentation.api.AgentSpan; +import datadog.trace.util.Strings; +import java.net.InetSocketAddress; +import java.util.Properties; +import javax.annotation.Nullable; + +public class ProcessHierarchy { + + private static final class SystemPropertiesPropagationGetter + implements AgentPropagation.ContextVisitor { + static final AgentPropagation.ContextVisitor INSTANCE = + new SystemPropertiesPropagationGetter(); + + private SystemPropertiesPropagationGetter() {} + + @Override + public void forEachKey(Properties carrier, AgentPropagation.KeyClassifier classifier) { + for (String propertyName : carrier.stringPropertyNames()) { + if (!classifier.accept(propertyName, carrier.getProperty(propertyName))) { + return; + } + } + } + } + + @Nullable public final AgentSpan.Context.Extracted parentProcessModuleContext; + + ProcessHierarchy() { + parentProcessModuleContext = + propagate().extract(System.getProperties(), SystemPropertiesPropagationGetter.INSTANCE); + } + + /** + * Module span context is propagated from the parent process if it runs with the tracer attached. + * If module span context is note there, either we are in the build system, or we are in the tests + * JVM and the build system is not instrumented. + */ + public boolean isChild() { + return parentProcessModuleContext != null; + } + + /** + * Determines if current process runs in "headless mode", i.e. has no instrumented parent and is + * not one of the supported build system processes. + */ + public boolean isHeadless() { + return !isChild() && !isParent(); + } + + private boolean isParent() { + return isMavenParent() || isGradleDaemon(); + } + + private boolean isMavenParent() { + return System.getProperty("maven.home") != null + && System.getProperty("classworlds.conf") != null; + } + + private boolean isGradleDaemon() { + return ClassLoader.getSystemClassLoader() + .getResource("org/gradle/launcher/daemon/bootstrap/GradleDaemon.class") + != null + // double-check this is not a Gradle Worker + && System.getProperties().getProperty("org.gradle.internal.worker.tmpdir") == null; + } + + @Nullable + public InetSocketAddress getSignalServerAddress() { + // System.getProperty is used rather than Config, + // because system variables can be set after config was initialized + String host = + System.getProperty( + Strings.propertyNameToSystemPropertyName( + CiVisibilityConfig.CIVISIBILITY_SIGNAL_SERVER_HOST)); + String port = + System.getProperty( + Strings.propertyNameToSystemPropertyName( + CiVisibilityConfig.CIVISIBILITY_SIGNAL_SERVER_PORT)); + if (host != null && port != null) { + return new InetSocketAddress(host, Integer.parseInt(port)); + } else { + return null; + } + } +} diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/ConcurrentCoverageStore.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/ConcurrentCoverageStore.java index f10702be6e4..ab6bc6b8b89 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/ConcurrentCoverageStore.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/ConcurrentCoverageStore.java @@ -1,5 +1,6 @@ package datadog.trace.civisibility.coverage; +import datadog.trace.api.DDTraceId; import datadog.trace.api.civisibility.coverage.CoverageProbes; import datadog.trace.api.civisibility.coverage.CoverageStore; import datadog.trace.api.civisibility.coverage.TestReport; @@ -34,14 +35,14 @@ private T create(Thread thread) { } @Override - public boolean report(Long testSessionId, Long testSuiteId, long testSpanId) { + public boolean report(DDTraceId testSessionId, Long testSuiteId, long testSpanId) { report = report(testSessionId, testSuiteId, testSpanId, probes.values()); return report != null && report.isNotEmpty(); } @Nullable protected abstract TestReport report( - Long testSessionId, Long testSuiteId, long testSpanId, Collection probes); + DDTraceId testSessionId, Long testSuiteId, long testSpanId, Collection probes); @Nullable @Override diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/file/FileCoverageStore.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/file/FileCoverageStore.java index 8458a32324b..edf63121567 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/file/FileCoverageStore.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/file/FileCoverageStore.java @@ -1,5 +1,6 @@ package datadog.trace.civisibility.coverage.file; +import datadog.trace.api.DDTraceId; import datadog.trace.api.civisibility.config.TestIdentifier; import datadog.trace.api.civisibility.coverage.CoverageStore; import datadog.trace.api.civisibility.coverage.TestReport; @@ -45,7 +46,7 @@ private FileCoverageStore( @Nullable @Override protected TestReport report( - Long testSessionId, Long testSuiteId, long testSpanId, Collection probes) { + DDTraceId testSessionId, Long testSuiteId, long testSpanId, Collection probes) { try { Set> combinedClasses = Collections.newSetFromMap(new IdentityHashMap<>()); Collection combinedNonCodeResources = new HashSet<>(); diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/line/LineCoverageStore.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/line/LineCoverageStore.java index 4a4d4fba127..0036564f6d9 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/line/LineCoverageStore.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/line/LineCoverageStore.java @@ -1,5 +1,6 @@ package datadog.trace.civisibility.coverage.line; +import datadog.trace.api.DDTraceId; import datadog.trace.api.civisibility.config.TestIdentifier; import datadog.trace.api.civisibility.coverage.CoverageStore; import datadog.trace.api.civisibility.coverage.TestReport; @@ -51,7 +52,7 @@ private LineCoverageStore( @Nullable @Override protected TestReport report( - Long testSessionId, Long testSuiteId, long testSpanId, Collection probes) { + DDTraceId testSessionId, Long testSuiteId, long testSpanId, Collection probes) { try { Map, ExecutionDataAdapter> combinedExecutionData = new IdentityHashMap<>(); Collection combinedNonCodeResources = new HashSet<>(); diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/percentage/child/ChildProcessCoverageReporter.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/percentage/child/ChildProcessCoverageReporter.java index ae34de58843..dffc9b74520 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/percentage/child/ChildProcessCoverageReporter.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/percentage/child/ChildProcessCoverageReporter.java @@ -1,5 +1,6 @@ package datadog.trace.civisibility.coverage.percentage.child; +import datadog.trace.api.DDTraceId; import datadog.trace.civisibility.ipc.ModuleSignal; import javax.annotation.Nullable; @@ -12,5 +13,5 @@ */ public interface ChildProcessCoverageReporter { @Nullable - ModuleSignal createCoverageSignal(long sessionId, long moduleId); + ModuleSignal createCoverageSignal(DDTraceId sessionId, long moduleId); } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/percentage/child/JacocoChildProcessCoverageReporter.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/percentage/child/JacocoChildProcessCoverageReporter.java index 847f0f0e54b..a27947597ee 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/percentage/child/JacocoChildProcessCoverageReporter.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/percentage/child/JacocoChildProcessCoverageReporter.java @@ -1,5 +1,6 @@ package datadog.trace.civisibility.coverage.percentage.child; +import datadog.trace.api.DDTraceId; import datadog.trace.civisibility.ipc.ModuleCoverageDataJacoco; import datadog.trace.civisibility.ipc.ModuleSignal; import java.util.function.Supplier; @@ -15,7 +16,7 @@ public JacocoChildProcessCoverageReporter(Supplier coverageDataSupplier) @Nullable @Override - public ModuleSignal createCoverageSignal(long sessionId, long moduleId) { + public ModuleSignal createCoverageSignal(DDTraceId sessionId, long moduleId) { byte[] coverageData = coverageDataSupplier.get(); if (coverageData != null) { return new ModuleCoverageDataJacoco(sessionId, moduleId, coverageData); diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/AbstractTestModule.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/AbstractTestModule.java index 60a8ee09d16..cdf6d8da3a2 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/AbstractTestModule.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/AbstractTestModule.java @@ -19,7 +19,6 @@ public abstract class AbstractTestModule { protected final AgentSpan span; - protected final long sessionId; protected final String moduleName; protected final Config config; protected final CiVisibilityMetricCollector metricCollector; @@ -31,7 +30,6 @@ public abstract class AbstractTestModule { public AbstractTestModule( AgentSpan.Context sessionSpanContext, - long sessionId, String moduleName, @Nullable Long startTime, InstrumentationType instrumentationType, @@ -42,7 +40,6 @@ public AbstractTestModule( Codeowners codeowners, MethodLinesResolver methodLinesResolver, Consumer onSpanFinish) { - this.sessionId = sessionId; this.moduleName = moduleName; this.config = config; this.metricCollector = metricCollector; @@ -65,7 +62,7 @@ public AbstractTestModule( span.setTag(Tags.TEST_MODULE, moduleName); span.setTag(Tags.TEST_MODULE_ID, span.getSpanId()); - span.setTag(Tags.TEST_SESSION_ID, sessionId); + span.setTag(Tags.TEST_SESSION_ID, span.getTraceId()); // setting status to skip initially, // as we do not know in advance whether the module will have any children diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/AbstractTestSession.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/AbstractTestSession.java index 9fc0317fbae..97953d3c053 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/AbstractTestSession.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/AbstractTestSession.java @@ -64,7 +64,7 @@ public AbstractTestSession( span.setSpanType(InternalSpanTypes.TEST_SESSION_END); span.setTag(Tags.SPAN_KIND, Tags.SPAN_KIND_TEST_SESSION); - span.setTag(Tags.TEST_SESSION_ID, span.getSpanId()); + span.setTag(Tags.TEST_SESSION_ID, span.getTraceId()); // setting status to skip initially, // as we do not know in advance whether the session will have any children diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/TestImpl.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/TestImpl.java index 0fa63d2237b..82595f8e299 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/TestImpl.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/TestImpl.java @@ -4,6 +4,7 @@ import static datadog.trace.util.Strings.toJson; import datadog.trace.api.Config; +import datadog.trace.api.DDTraceId; import datadog.trace.api.civisibility.CIConstants; import datadog.trace.api.civisibility.DDTest; import datadog.trace.api.civisibility.InstrumentationBridge; @@ -44,14 +45,13 @@ public class TestImpl implements DDTest { private final CiVisibilityMetricCollector metricCollector; private final TestFrameworkInstrumentation instrumentation; private final AgentSpan span; - private final long sessionId; + private final DDTraceId sessionId; private final long suiteId; private final Consumer onSpanFinish; private final TestContext context; public TestImpl( - long sessionId, - long moduleId, + AgentSpan.Context moduleSpanContext, long suiteId, String moduleName, String testSuiteName, @@ -73,7 +73,7 @@ public TestImpl( Consumer onSpanFinish) { this.instrumentation = instrumentation; this.metricCollector = metricCollector; - this.sessionId = sessionId; + this.sessionId = moduleSpanContext.getTraceId(); this.suiteId = suiteId; this.onSpanFinish = onSpanFinish; @@ -108,8 +108,8 @@ public TestImpl( span.setTag(Tags.TEST_MODULE, moduleName); span.setTag(Tags.TEST_SUITE_ID, suiteId); - span.setTag(Tags.TEST_MODULE_ID, moduleId); - span.setTag(Tags.TEST_SESSION_ID, sessionId); + span.setTag(Tags.TEST_MODULE_ID, moduleSpanContext.getSpanId()); + span.setTag(Tags.TEST_SESSION_ID, moduleSpanContext.getTraceId()); span.setTag(Tags.TEST_STATUS, TestStatus.pass); diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/TestSuiteImpl.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/TestSuiteImpl.java index a7c722a418e..32c33f4cfc2 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/TestSuiteImpl.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/TestSuiteImpl.java @@ -26,9 +26,8 @@ public class TestSuiteImpl implements DDTestSuite { + private final AgentSpan.Context moduleSpanContext; private final AgentSpan span; - private final long sessionId; - private final long moduleId; private final String moduleName; private final String testSuiteName; private final String itrCorrelationId; @@ -46,9 +45,7 @@ public class TestSuiteImpl implements DDTestSuite { private final Consumer onSpanFinish; public TestSuiteImpl( - @Nullable AgentSpan.Context moduleSpanContext, - long sessionId, - long moduleId, + AgentSpan.Context moduleSpanContext, String moduleName, String testSuiteName, String itrCorrelationId, @@ -65,8 +62,7 @@ public TestSuiteImpl( MethodLinesResolver methodLinesResolver, CoverageStore.Factory coverageStoreFactory, Consumer onSpanFinish) { - this.sessionId = sessionId; - this.moduleId = moduleId; + this.moduleSpanContext = moduleSpanContext; this.moduleName = moduleName; this.testSuiteName = testSuiteName; this.itrCorrelationId = itrCorrelationId; @@ -96,8 +92,8 @@ public TestSuiteImpl( span.setTag(Tags.TEST_MODULE, moduleName); span.setTag(Tags.TEST_SUITE_ID, span.getSpanId()); - span.setTag(Tags.TEST_MODULE_ID, moduleId); - span.setTag(Tags.TEST_SESSION_ID, sessionId); + span.setTag(Tags.TEST_MODULE_ID, moduleSpanContext.getSpanId()); + span.setTag(Tags.TEST_SESSION_ID, moduleSpanContext.getTraceId()); // setting status to skip initially, // as we do not know in advance whether the suite will have any children @@ -196,8 +192,7 @@ public TestImpl testStart( @Nullable Method testMethod, @Nullable Long startTime) { return new TestImpl( - sessionId, - moduleId, + moduleSpanContext, span.getSpanId(), moduleName, testSuiteName, diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/buildsystem/BuildSystemModuleImpl.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/buildsystem/BuildSystemModuleImpl.java index d3c93486bda..7e2a052a789 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/buildsystem/BuildSystemModuleImpl.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/buildsystem/BuildSystemModuleImpl.java @@ -1,5 +1,7 @@ package datadog.trace.civisibility.domain.buildsystem; +import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.propagate; + import datadog.communication.ddagent.TracerVersion; import datadog.trace.api.Config; import datadog.trace.api.DDTags; @@ -10,6 +12,7 @@ import datadog.trace.api.civisibility.domain.JavaAgent; import datadog.trace.api.civisibility.telemetry.CiVisibilityMetricCollector; import datadog.trace.api.config.CiVisibilityConfig; +import datadog.trace.bootstrap.instrumentation.api.AgentPropagation; import datadog.trace.bootstrap.instrumentation.api.AgentSpan; import datadog.trace.bootstrap.instrumentation.api.Tags; import datadog.trace.civisibility.codeowners.Codeowners; @@ -29,11 +32,7 @@ import datadog.trace.util.Strings; import java.net.InetSocketAddress; import java.nio.file.Path; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; +import java.util.*; import java.util.concurrent.atomic.LongAdder; import java.util.function.Consumer; import javax.annotation.Nullable; @@ -51,7 +50,6 @@ public class BuildSystemModuleImpl extends AbstractTestModule implements BuildSy public BuildSystemModuleImpl( AgentSpan.Context sessionSpanContext, - long sessionId, String moduleName, String startCommand, @Nullable Long startTime, @@ -73,7 +71,6 @@ public BuildSystemModuleImpl( Consumer onSpanFinish) { super( sessionSpanContext, - sessionId, moduleName, startTime, InstrumentationType.BUILD, @@ -108,6 +105,19 @@ public BuildSystemModuleImpl( setTag(Tags.TEST_COMMAND, startCommand); } + private static final class ChildProcessPropertiesPropagationSetter + implements AgentPropagation.Setter> { + static final AgentPropagation.Setter> INSTANCE = + new ChildProcessPropertiesPropagationSetter(); + + private ChildProcessPropertiesPropagationSetter() {} + + @Override + public void set(Map carrier, String key, String value) { + carrier.put(key, value); + } + } + private Map getPropertiesPropagatedToChildProcess( String moduleName, String startCommand, @@ -165,12 +175,6 @@ private Map getPropertiesPropagatedToChildProcess( CiVisibilityConfig.CIVISIBILITY_INJECTED_TRACER_VERSION), TracerVersion.TRACER_VERSION); - propagatedSystemProperties.put( - Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_SESSION_ID), - String.valueOf(sessionId)); - propagatedSystemProperties.put( - Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_MODULE_ID), - String.valueOf(span.getSpanId())); propagatedSystemProperties.put( Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_MODULE_NAME), moduleName); @@ -207,6 +211,10 @@ private Map getPropertiesPropagatedToChildProcess( Boolean.toString(true)); } + // propagate module span context to child processes + propagate() + .inject(span, propagatedSystemProperties, ChildProcessPropertiesPropagationSetter.INSTANCE); + return propagatedSystemProperties; } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/buildsystem/BuildSystemSessionImpl.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/buildsystem/BuildSystemSessionImpl.java index baae7c56bb7..5712831cf2a 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/buildsystem/BuildSystemSessionImpl.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/buildsystem/BuildSystemSessionImpl.java @@ -181,7 +181,6 @@ public BuildSystemModuleImpl testModuleStart( ExecutionSettings executionSettings = executionSettingsFactory.create(jvmInfo, moduleName); return new BuildSystemModuleImpl( span.context(), - span.getSpanId(), moduleName, startCommand, startTime, diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/buildsystem/ProxyTestModule.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/buildsystem/ProxyTestModule.java index ab726880a57..a4f1d7f92e9 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/buildsystem/ProxyTestModule.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/buildsystem/ProxyTestModule.java @@ -1,6 +1,7 @@ package datadog.trace.civisibility.domain.buildsystem; import datadog.trace.api.Config; +import datadog.trace.api.DDTraceId; import datadog.trace.api.civisibility.config.TestIdentifier; import datadog.trace.api.civisibility.coverage.CoverageStore; import datadog.trace.api.civisibility.retry.TestRetryPolicy; @@ -40,8 +41,7 @@ public class ProxyTestModule implements TestFrameworkModule { private static final Logger log = LoggerFactory.getLogger(ProxyTestModule.class); - private final long parentProcessSessionId; - private final long parentProcessModuleId; + private final AgentSpan.Context parentProcessModuleContext; private final String moduleName; private final ExecutionStrategy executionStrategy; private final SignalClient.Factory signalClientFactory; @@ -56,8 +56,7 @@ public class ProxyTestModule implements TestFrameworkModule { private final Collection testFrameworks = ConcurrentHashMap.newKeySet(); public ProxyTestModule( - long parentProcessSessionId, - long parentProcessModuleId, + AgentSpan.Context parentProcessModuleContext, String moduleName, ExecutionStrategy executionStrategy, Config config, @@ -69,8 +68,7 @@ public ProxyTestModule( CoverageStore.Factory coverageStoreFactory, ChildProcessCoverageReporter childProcessCoverageReporter, SignalClient.Factory signalClientFactory) { - this.parentProcessSessionId = parentProcessSessionId; - this.parentProcessModuleId = parentProcessModuleId; + this.parentProcessModuleContext = parentProcessModuleContext; this.moduleName = moduleName; this.executionStrategy = executionStrategy; this.signalClientFactory = signalClientFactory; @@ -113,6 +111,9 @@ public void end(@Nullable Long endTime) { } private void sendModuleExecutionResult() { + DDTraceId parentProcessSessionId = parentProcessModuleContext.getTraceId(); + long parentProcessModuleId = parentProcessModuleContext.getSpanId(); + try (SignalClient signalClient = signalClientFactory.create()) { ModuleSignal coverageSignal = childProcessCoverageReporter.createCoverageSignal( @@ -156,9 +157,7 @@ public TestSuiteImpl testSuiteStart( boolean parallelized, TestFrameworkInstrumentation instrumentation) { return new TestSuiteImpl( - null, - parentProcessSessionId, - parentProcessModuleId, + parentProcessModuleContext, moduleName, testSuiteName, executionStrategy.getExecutionSettings().getItrCorrelationId(), diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/buildsystem/ProxyTestSession.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/buildsystem/ProxyTestSession.java index f4634bb7009..52c9f5e814e 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/buildsystem/ProxyTestSession.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/buildsystem/ProxyTestSession.java @@ -3,6 +3,7 @@ import datadog.trace.api.Config; import datadog.trace.api.civisibility.coverage.CoverageStore; import datadog.trace.api.civisibility.telemetry.CiVisibilityMetricCollector; +import datadog.trace.bootstrap.instrumentation.api.AgentSpan; import datadog.trace.bootstrap.instrumentation.api.AgentTracer; import datadog.trace.civisibility.codeowners.Codeowners; import datadog.trace.civisibility.coverage.percentage.child.ChildProcessCoverageReporter; @@ -22,8 +23,7 @@ */ public class ProxyTestSession implements TestFrameworkSession { - private final long parentProcessSessionId; - private final long parentProcessModuleId; + private final AgentSpan.Context parentProcessModuleContext; private final Config config; private final CiVisibilityMetricCollector metricCollector; private final TestDecorator testDecorator; @@ -36,8 +36,7 @@ public class ProxyTestSession implements TestFrameworkSession { private final ExecutionStrategy executionStrategy; public ProxyTestSession( - long parentProcessSessionId, - long parentProcessModuleId, + AgentSpan.Context parentProcessModuleContext, Config config, CiVisibilityMetricCollector metricCollector, TestDecorator testDecorator, @@ -48,8 +47,7 @@ public ProxyTestSession( ChildProcessCoverageReporter childProcessCoverageReporter, SignalClient.Factory signalClientFactory, ExecutionStrategy executionStrategy) { - this.parentProcessSessionId = parentProcessSessionId; - this.parentProcessModuleId = parentProcessModuleId; + this.parentProcessModuleContext = parentProcessModuleContext; this.config = config; this.metricCollector = metricCollector; this.testDecorator = testDecorator; @@ -73,8 +71,7 @@ public void end(Long startTime) { @Override public TestFrameworkModule testModuleStart(String moduleName, @Nullable Long startTime) { return new ProxyTestModule( - parentProcessSessionId, - parentProcessModuleId, + parentProcessModuleContext, moduleName, executionStrategy, config, diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/headless/HeadlessTestModule.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/headless/HeadlessTestModule.java index a824a99d157..662848bbd03 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/headless/HeadlessTestModule.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/headless/HeadlessTestModule.java @@ -40,7 +40,6 @@ public class HeadlessTestModule extends AbstractTestModule implements TestFramew public HeadlessTestModule( AgentSpan.Context sessionSpanContext, - long sessionId, String moduleName, @Nullable Long startTime, Config config, @@ -54,7 +53,6 @@ public HeadlessTestModule( Consumer onSpanFinish) { super( sessionSpanContext, - sessionId, moduleName, startTime, InstrumentationType.HEADLESS, @@ -129,8 +127,6 @@ public TestSuiteImpl testSuiteStart( TestFrameworkInstrumentation instrumentation) { return new TestSuiteImpl( span.context(), - sessionId, - span.getSpanId(), moduleName, testSuiteName, executionStrategy.getExecutionSettings().getItrCorrelationId(), diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/headless/HeadlessTestSession.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/headless/HeadlessTestSession.java index 67e51b663e4..46a7959d4a4 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/headless/HeadlessTestSession.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/headless/HeadlessTestSession.java @@ -66,7 +66,6 @@ public HeadlessTestSession( public HeadlessTestModule testModuleStart(String moduleName, @Nullable Long startTime) { return new HeadlessTestModule( span.context(), - span.getSpanId(), moduleName, startTime, config, diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/manualapi/ManualApiTestModule.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/manualapi/ManualApiTestModule.java index 6427059a086..588838cad5e 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/manualapi/ManualApiTestModule.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/manualapi/ManualApiTestModule.java @@ -27,7 +27,6 @@ public class ManualApiTestModule extends AbstractTestModule implements DDTestMod public ManualApiTestModule( AgentSpan.Context sessionSpanContext, - long sessionId, String moduleName, @Nullable Long startTime, Config config, @@ -40,7 +39,6 @@ public ManualApiTestModule( Consumer onSpanFinish) { super( sessionSpanContext, - sessionId, moduleName, startTime, InstrumentationType.MANUAL_API, @@ -62,8 +60,6 @@ public TestSuiteImpl testSuiteStart( boolean parallelized) { return new TestSuiteImpl( span.context(), - sessionId, - span.getSpanId(), moduleName, testSuiteName, null, diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/manualapi/ManualApiTestSession.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/manualapi/ManualApiTestSession.java index e7a3aa74d92..e0269b7b812 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/manualapi/ManualApiTestSession.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/manualapi/ManualApiTestSession.java @@ -51,7 +51,6 @@ public ManualApiTestSession( public ManualApiTestModule testModuleStart(String moduleName, @Nullable Long startTime) { return new ManualApiTestModule( span.context(), - span.getSpanId(), moduleName, startTime, config, diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ipc/ModuleCoverageDataJacoco.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ipc/ModuleCoverageDataJacoco.java index 6883c0af207..c386316716b 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ipc/ModuleCoverageDataJacoco.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ipc/ModuleCoverageDataJacoco.java @@ -1,5 +1,6 @@ package datadog.trace.civisibility.ipc; +import datadog.trace.api.DDTraceId; import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Objects; @@ -9,7 +10,8 @@ public class ModuleCoverageDataJacoco extends ModuleSignal { @Nonnull private final byte[] coverageData; - public ModuleCoverageDataJacoco(long sessionId, long moduleId, @Nonnull byte[] coverageData) { + public ModuleCoverageDataJacoco( + DDTraceId sessionId, long moduleId, @Nonnull byte[] coverageData) { super(sessionId, moduleId); this.coverageData = coverageData; } @@ -28,7 +30,8 @@ public boolean equals(Object o) { return false; } ModuleCoverageDataJacoco that = (ModuleCoverageDataJacoco) o; - return sessionId == that.sessionId + return sessionId.toLong() == that.sessionId.toLong() + && sessionId.toHighOrderLong() == that.sessionId.toHighOrderLong() && moduleId == that.moduleId && Arrays.equals(coverageData, that.coverageData); } @@ -51,14 +54,14 @@ public SignalType getType() { @Override public ByteBuffer serialize() { Serializer s = new Serializer(); - s.write(sessionId); + s.write(sessionId.toHexString()); s.write(moduleId); s.write(coverageData); return s.flush(); } public static ModuleCoverageDataJacoco deserialize(ByteBuffer buffer) { - long sessionId = Serializer.readLong(buffer); + DDTraceId sessionId = DDTraceId.fromHex(Serializer.readString(buffer)); long moduleId = Serializer.readLong(buffer); byte[] coverageData = Serializer.readByteArray(buffer); return new ModuleCoverageDataJacoco(sessionId, moduleId, coverageData); diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ipc/ModuleExecutionResult.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ipc/ModuleExecutionResult.java index fcbaca5ba88..9cec6f2711a 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ipc/ModuleExecutionResult.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ipc/ModuleExecutionResult.java @@ -1,5 +1,6 @@ package datadog.trace.civisibility.ipc; +import datadog.trace.api.DDTraceId; import java.nio.ByteBuffer; import java.util.Collection; import java.util.Objects; @@ -19,7 +20,7 @@ public class ModuleExecutionResult extends ModuleSignal { private final Collection testFrameworks; public ModuleExecutionResult( - long sessionId, + DDTraceId sessionId, long moduleId, boolean coverageEnabled, boolean testSkippingEnabled, @@ -69,7 +70,8 @@ public boolean equals(Object o) { return false; } ModuleExecutionResult that = (ModuleExecutionResult) o; - return sessionId == that.sessionId + return sessionId.toLong() == that.sessionId.toLong() + && sessionId.toHighOrderLong() == that.sessionId.toHighOrderLong() && moduleId == that.moduleId && coverageEnabled == that.coverageEnabled && testSkippingEnabled == that.testSkippingEnabled @@ -112,7 +114,7 @@ public SignalType getType() { @Override public ByteBuffer serialize() { Serializer s = new Serializer(); - s.write(sessionId); + s.write(sessionId.toHexString()); s.write(moduleId); byte flags = 0; @@ -137,7 +139,7 @@ public ByteBuffer serialize() { } public static ModuleExecutionResult deserialize(ByteBuffer buffer) { - long sessionId = Serializer.readLong(buffer); + DDTraceId sessionId = DDTraceId.fromHex(Serializer.readString(buffer)); long moduleId = Serializer.readLong(buffer); int flags = Serializer.readByte(buffer); diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ipc/ModuleSignal.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ipc/ModuleSignal.java index b77725ae870..2a6fbbb330a 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ipc/ModuleSignal.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ipc/ModuleSignal.java @@ -1,16 +1,18 @@ package datadog.trace.civisibility.ipc; +import datadog.trace.api.DDTraceId; + public abstract class ModuleSignal implements Signal { - protected final long sessionId; + protected final DDTraceId sessionId; protected final long moduleId; - protected ModuleSignal(long sessionId, long moduleId) { + protected ModuleSignal(DDTraceId sessionId, long moduleId) { this.sessionId = sessionId; this.moduleId = moduleId; } - public long getSessionId() { + public DDTraceId getSessionId() { return sessionId; } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/utils/ProcessHierarchyUtils.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/utils/ProcessHierarchyUtils.java deleted file mode 100644 index 54a1eac1afa..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/utils/ProcessHierarchyUtils.java +++ /dev/null @@ -1,90 +0,0 @@ -package datadog.trace.civisibility.utils; - -import datadog.trace.api.config.CiVisibilityConfig; -import datadog.trace.util.Strings; -import java.net.InetSocketAddress; -import javax.annotation.Nullable; - -public abstract class ProcessHierarchyUtils { - - private ProcessHierarchyUtils() {} - - /** - * Session ID and module ID are supplied by the parent process if it runs with the tracer - * attached. If session ID and module ID are not provided, either we are in the build system, or - * we are in the tests JVM and the build system is not instrumented. - */ - public static boolean isChild() { - return System.getProperty( - Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_SESSION_ID)) - != null; - } - - /** - * Determines if current process runs in "headless mode", i.e. has no instrumented parent and is - * not one of the supported build system processes. - */ - public static boolean isHeadless() { - return !isChild() && !isParent(); - } - - private static boolean isParent() { - return isMavenParent() || isGradleDaemon(); - } - - private static boolean isMavenParent() { - return System.getProperty("maven.home") != null - && System.getProperty("classworlds.conf") != null; - } - - private static boolean isGradleDaemon() { - return ClassLoader.getSystemClassLoader() - .getResource("org/gradle/launcher/daemon/bootstrap/GradleDaemon.class") - != null - // double-check this is not a Gradle Worker - && System.getProperties().getProperty("org.gradle.internal.worker.tmpdir") == null; - } - - public static long getParentSessionId() { - // System.getProperty is used rather than Config, - // because system variables can be set after config was initialized - String systemProp = - System.getProperty( - Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_SESSION_ID)); - if (systemProp == null) { - throw new IllegalStateException("Parent session ID not available"); - } - return Long.parseLong(systemProp); - } - - public static long getParentModuleId() { - // System.getProperty is used rather than Config, - // because system variables can be set after config was initialized - String systemProp = - System.getProperty( - Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_MODULE_ID)); - if (systemProp == null) { - throw new IllegalStateException("Parent module ID not available"); - } - return Long.parseLong(systemProp); - } - - @Nullable - public static InetSocketAddress getSignalServerAddress() { - // System.getProperty is used rather than Config, - // because system variables can be set after config was initialized - String host = - System.getProperty( - Strings.propertyNameToSystemPropertyName( - CiVisibilityConfig.CIVISIBILITY_SIGNAL_SERVER_HOST)); - String port = - System.getProperty( - Strings.propertyNameToSystemPropertyName( - CiVisibilityConfig.CIVISIBILITY_SIGNAL_SERVER_PORT)); - if (host != null && port != null) { - return new InetSocketAddress(host, Integer.parseInt(port)); - } else { - return null; - } - } -} diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/domain/TestImplTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/domain/TestImplTest.groovy index 900f6fc347a..e54ab6da838 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/domain/TestImplTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/domain/TestImplTest.groovy @@ -4,12 +4,14 @@ import datadog.trace.agent.test.asserts.ListWriterAssert import datadog.trace.agent.tooling.TracerInstaller import datadog.trace.api.Config import datadog.trace.api.DDSpanTypes +import datadog.trace.api.DDTraceId import datadog.trace.api.IdGenerationStrategy import datadog.trace.api.civisibility.config.TestIdentifier import datadog.trace.api.civisibility.coverage.CoverageProbes import datadog.trace.api.civisibility.coverage.CoverageStore import datadog.trace.api.civisibility.coverage.NoOpCoverageStore import datadog.trace.api.civisibility.telemetry.tag.TestFrameworkInstrumentation +import datadog.trace.bootstrap.instrumentation.api.AgentSpan import datadog.trace.bootstrap.instrumentation.api.AgentTracer import datadog.trace.civisibility.codeowners.NoCodeowners import datadog.trace.civisibility.decorator.TestDecoratorImpl @@ -128,8 +130,13 @@ class TestImplTest extends DDSpecification { private TestImpl givenATest( CoverageStore.Factory coverageStoreFactory = new NoOpCoverageStore.Factory()) { - def sessionId = 123 - def moduleId = 456 + + def traceId = Stub(DDTraceId) + traceId.toLong() >> 123 + + def moduleSpanContext = Stub(AgentSpan.Context) + moduleSpanContext.getSpanId() >> 456 + moduleSpanContext.getTraceId() >> traceId def suiteId = 789 def testFramework = TestFrameworkInstrumentation.OTHER @@ -139,8 +146,7 @@ class TestImplTest extends DDSpecification { def methodLinesResolver = { it -> MethodLinesResolver.MethodLines.EMPTY } def codeowners = NoCodeowners.INSTANCE new TestImpl( - sessionId, - moduleId, + moduleSpanContext, suiteId, "moduleName", "suiteName", diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/domain/buildsystem/ProxyTestModuleTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/domain/buildsystem/ProxyTestModuleTest.groovy index 881df45c760..a5cbe960caf 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/domain/buildsystem/ProxyTestModuleTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/domain/buildsystem/ProxyTestModuleTest.groovy @@ -1,6 +1,8 @@ package datadog.trace.civisibility.domain.buildsystem import datadog.trace.api.Config +import datadog.trace.api.DDTraceId +import datadog.trace.bootstrap.instrumentation.api.AgentSpan import datadog.trace.civisibility.config.EarlyFlakeDetectionSettings import datadog.trace.api.civisibility.config.TestIdentifier import datadog.trace.api.civisibility.coverage.CoverageStore @@ -29,10 +31,16 @@ class ProxyTestModuleTest extends DDSpecification { def executionStrategy = new ExecutionStrategy(config, executionSettings) + def traceId = Stub(DDTraceId) + traceId.toLong() >> 123 + + def moduleSpanContext = Stub(AgentSpan.Context) + moduleSpanContext.getSpanId() >> 456 + moduleSpanContext.getTraceId() >> traceId + given: def proxyTestModule = new ProxyTestModule( - 1L, - 1L, + moduleSpanContext, "test-module", executionStrategy, config, diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/domain/headless/HeadlessTestModuleTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/domain/headless/HeadlessTestModuleTest.groovy index 94047b9d44a..669db4126db 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/domain/headless/HeadlessTestModuleTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/domain/headless/HeadlessTestModuleTest.groovy @@ -33,7 +33,6 @@ class HeadlessTestModuleTest extends DDSpecification { given: def headlessTestModule = new HeadlessTestModule( Stub(AgentSpan.Context), - 1L, "test-module", null, config, diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ipc/ModuleCoverageDataJacocoTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ipc/ModuleCoverageDataJacocoTest.groovy index 84fa251cff4..26426a66766 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ipc/ModuleCoverageDataJacocoTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ipc/ModuleCoverageDataJacocoTest.groovy @@ -1,5 +1,7 @@ package datadog.trace.civisibility.ipc +import datadog.trace.api.DD128bTraceId +import datadog.trace.api.DDTraceId import spock.lang.Specification class ModuleCoverageDataJacocoTest extends Specification { @@ -14,9 +16,9 @@ class ModuleCoverageDataJacocoTest extends Specification { where: signal << [ - new ModuleCoverageDataJacoco(12345, 67890, null), - new ModuleCoverageDataJacoco(12345, 67890, new byte[]{}), - new ModuleCoverageDataJacoco(12345, 67890, new byte[]{ + new ModuleCoverageDataJacoco(DDTraceId.from(12345), 67890, null), + new ModuleCoverageDataJacoco(DDTraceId.from(12345), 67890, new byte[]{}), + new ModuleCoverageDataJacoco(DD128bTraceId.from(12345, 67890), 67890, new byte[]{ 1, 2, 3, 4, 5, 6 }) ] diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ipc/ModuleExecutionResultTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ipc/ModuleExecutionResultTest.groovy index a85e1fb648b..50de172483d 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ipc/ModuleExecutionResultTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ipc/ModuleExecutionResultTest.groovy @@ -1,5 +1,7 @@ package datadog.trace.civisibility.ipc +import datadog.trace.api.DD128bTraceId +import datadog.trace.api.DDTraceId import spock.lang.Specification class ModuleExecutionResultTest extends Specification { @@ -14,11 +16,11 @@ class ModuleExecutionResultTest extends Specification { where: signal << [ - new ModuleExecutionResult(12345, 67890, false, false, false, false, 0, Collections.emptyList()), - new ModuleExecutionResult(12345, 67890, true, false, true, true, 1, Collections.singletonList(new TestFramework("junit", "4.13.2"))), - new ModuleExecutionResult(12345, 67890, false, true, true, false, 2, Arrays.asList(new TestFramework("junit", "4.13.2"), new TestFramework("junit", "5.9.2"))), - new ModuleExecutionResult(12345, 67890, false, false, false, true, 3, Arrays.asList(new TestFramework("junit", null), new TestFramework("junit", "5.9.2"))), - new ModuleExecutionResult(12345, 67890, true, true, true, true, Integer.MAX_VALUE, Arrays.asList(new TestFramework("junit", "4.13.2"), new TestFramework(null, "5.9.2"))) + new ModuleExecutionResult(DDTraceId.from(12345), 67890, false, false, false, false, 0, Collections.emptyList()), + new ModuleExecutionResult(DDTraceId.from(12345), 67890, true, false, true, true, 1, Collections.singletonList(new TestFramework("junit", "4.13.2"))), + new ModuleExecutionResult(DDTraceId.from(12345), 67890, false, true, true, false, 2, Arrays.asList(new TestFramework("junit", "4.13.2"), new TestFramework("junit", "5.9.2"))), + new ModuleExecutionResult(DD128bTraceId.from(12345, 67890), 67890, false, false, false, true, 3, Arrays.asList(new TestFramework("junit", null), new TestFramework("junit", "5.9.2"))), + new ModuleExecutionResult(DD128bTraceId.from(12345, 67890), 67890, true, true, true, true, Integer.MAX_VALUE, Arrays.asList(new TestFramework("junit", "4.13.2"), new TestFramework(null, "5.9.2"))) ] } } diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ipc/SignalServerTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ipc/SignalServerTest.groovy index 2ab8e79ba27..4db02ff58cf 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ipc/SignalServerTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ipc/SignalServerTest.groovy @@ -1,5 +1,6 @@ package datadog.trace.civisibility.ipc +import datadog.trace.api.DDTraceId import spock.lang.Specification import java.util.concurrent.atomic.AtomicBoolean @@ -11,7 +12,7 @@ class SignalServerTest extends Specification { def "test message send and receive"() { given: def signalProcessed = new AtomicBoolean(false) - def signal = new ModuleExecutionResult(123, 456, true, true, false, false, 1, Collections.singletonList(new TestFramework("junit", "4.13.2"))) + def signal = new ModuleExecutionResult(DDTraceId.from(123), 456, true, true, false, false, 1, Collections.singletonList(new TestFramework("junit", "4.13.2"))) def server = new SignalServer() def received = new ArrayList() @@ -40,8 +41,8 @@ class SignalServerTest extends Specification { def "test multiple messages send and receive"() { given: - def signalA = new ModuleExecutionResult(123, 456, false, false, false, false, 0, Collections.singletonList(new TestFramework("junit", "4.13.2"))) - def signalB = new ModuleExecutionResult(234, 567, true, true, false, false, 1, Collections.singletonList(new TestFramework("junit", "4.13.2"))) + def signalA = new ModuleExecutionResult(DDTraceId.from(123), 456, false, false, false, false, 0, Collections.singletonList(new TestFramework("junit", "4.13.2"))) + def signalB = new ModuleExecutionResult(DDTraceId.from(234), 567, true, true, false, false, 1, Collections.singletonList(new TestFramework("junit", "4.13.2"))) def server = new SignalServer() def received = new ArrayList() @@ -69,8 +70,8 @@ class SignalServerTest extends Specification { def "test multiple clients send and receive"() { given: - def signalA = new ModuleExecutionResult(123, 456, true, false, true, false, 1, Collections.singletonList(new TestFramework("junit", "4.13.2"))) - def signalB = new ModuleExecutionResult(234, 567, false, true, false, true, 0, Collections.singletonList(new TestFramework("junit", "4.13.2"))) + def signalA = new ModuleExecutionResult(DDTraceId.from(123), 456, true, false, true, false, 1, Collections.singletonList(new TestFramework("junit", "4.13.2"))) + def signalB = new ModuleExecutionResult(DDTraceId.from(234), 567, false, true, false, true, 0, Collections.singletonList(new TestFramework("junit", "4.13.2"))) def server = new SignalServer() def received = new ArrayList() @@ -117,7 +118,7 @@ class SignalServerTest extends Specification { when: def address = server.getAddress() try (def client = new SignalClient(address, clientTimeoutMillis)) { - client.send(new ModuleExecutionResult(123, 456, false, false, false, false, 0, Collections.singletonList(new TestFramework("junit", "4.13.2")))) + client.send(new ModuleExecutionResult(DDTraceId.from(123), 456, false, false, false, false, 0, Collections.singletonList(new TestFramework("junit", "4.13.2")))) } then: @@ -129,7 +130,7 @@ class SignalServerTest extends Specification { def "test error response receipt"() { given: - def signal = new ModuleExecutionResult(123, 456, true, true, false, false, 1, Collections.singletonList(new TestFramework("junit", "4.13.2"))) + def signal = new ModuleExecutionResult(DDTraceId.from(123), 456, true, true, false, false, 1, Collections.singletonList(new TestFramework("junit", "4.13.2"))) def server = new SignalServer() def errorResponse = new ErrorResponse("An error occurred while processing the signal") diff --git a/dd-java-agent/instrumentation/junit-5.3/spock-junit-5/src/test/resources/test-itr-not-skipping-parameterized-spec-setup/events.ftl b/dd-java-agent/instrumentation/junit-5.3/spock-junit-5/src/test/resources/test-itr-not-skipping-parameterized-spec-setup/events.ftl index 51448849cd8..5af7df7c710 100644 --- a/dd-java-agent/instrumentation/junit-5.3/spock-junit-5/src/test/resources/test-itr-not-skipping-parameterized-spec-setup/events.ftl +++ b/dd-java-agent/instrumentation/junit-5.3/spock-junit-5/src/test/resources/test-itr-not-skipping-parameterized-spec-setup/events.ftl @@ -130,7 +130,7 @@ "type" : "span", "version" : 1, "content" : { - "trace_id" : ${content_trace_id_3}, + "trace_id" : ${content_test_session_id}, "span_id" : ${content_span_id_3}, "parent_id" : ${content_test_suite_id}, "service" : "worker.org.gradle.process.internal.worker.gradleworkermain", @@ -215,4 +215,4 @@ "test.itr.tests_skipping.enabled" : "true" } } -} ] \ No newline at end of file +} ] diff --git a/dd-java-agent/instrumentation/junit-5.3/spock-junit-5/src/test/resources/test-itr-not-skipping-spec-setup/events.ftl b/dd-java-agent/instrumentation/junit-5.3/spock-junit-5/src/test/resources/test-itr-not-skipping-spec-setup/events.ftl index cf27963ec29..2c907c0d807 100644 --- a/dd-java-agent/instrumentation/junit-5.3/spock-junit-5/src/test/resources/test-itr-not-skipping-spec-setup/events.ftl +++ b/dd-java-agent/instrumentation/junit-5.3/spock-junit-5/src/test/resources/test-itr-not-skipping-spec-setup/events.ftl @@ -128,7 +128,7 @@ "type" : "span", "version" : 1, "content" : { - "trace_id" : ${content_trace_id_3}, + "trace_id" : ${content_test_session_id}, "span_id" : ${content_span_id_3}, "parent_id" : ${content_test_suite_id}, "service" : "worker.org.gradle.process.internal.worker.gradleworkermain", @@ -213,4 +213,4 @@ "test.itr.tests_skipping.enabled" : "true" } } -} ] \ No newline at end of file +} ] diff --git a/dd-java-agent/instrumentation/junit-5.3/spock-junit-5/src/test/resources/test-itr-skipping-parameterized-spec-setup/events.ftl b/dd-java-agent/instrumentation/junit-5.3/spock-junit-5/src/test/resources/test-itr-skipping-parameterized-spec-setup/events.ftl index 62461f62870..6e4d0d470ab 100644 --- a/dd-java-agent/instrumentation/junit-5.3/spock-junit-5/src/test/resources/test-itr-skipping-parameterized-spec-setup/events.ftl +++ b/dd-java-agent/instrumentation/junit-5.3/spock-junit-5/src/test/resources/test-itr-skipping-parameterized-spec-setup/events.ftl @@ -145,7 +145,7 @@ "type" : "span", "version" : 1, "content" : { - "trace_id" : ${content_trace_id_3}, + "trace_id" : ${content_test_session_id}, "span_id" : ${content_span_id_3}, "parent_id" : ${content_test_suite_id}, "service" : "worker.org.gradle.process.internal.worker.gradleworkermain", @@ -239,4 +239,4 @@ "test.itr.tests_skipping.enabled" : "true" } } -} ] \ No newline at end of file +} ] diff --git a/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java b/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java index a929649e703..0a42f179e3e 100644 --- a/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java +++ b/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java @@ -9,8 +9,6 @@ public final class CiVisibilityConfig { public static final String CIVISIBILITY_AGENTLESS_ENABLED = "civisibility.agentless.enabled"; public static final String CIVISIBILITY_AGENTLESS_URL = "civisibility.agentless.url"; public static final String CIVISIBILITY_SOURCE_DATA_ENABLED = "civisibility.source.data.enabled"; - public static final String CIVISIBILITY_SESSION_ID = "civisibility.session.id"; - public static final String CIVISIBILITY_MODULE_ID = "civisibility.module.id"; public static final String CIVISIBILITY_BUILD_INSTRUMENTATION_ENABLED = "civisibility.build.instrumentation.enabled"; public static final String CIVISIBILITY_AGENT_JAR_URI = "civisibility.agent.jar.uri"; diff --git a/dd-trace-core/src/main/java/datadog/trace/civisibility/writer/ddintake/CiTestCovMapperV2.java b/dd-trace-core/src/main/java/datadog/trace/civisibility/writer/ddintake/CiTestCovMapperV2.java index fe8f23f2632..77118385bf2 100644 --- a/dd-trace-core/src/main/java/datadog/trace/civisibility/writer/ddintake/CiTestCovMapperV2.java +++ b/dd-trace-core/src/main/java/datadog/trace/civisibility/writer/ddintake/CiTestCovMapperV2.java @@ -7,6 +7,7 @@ import datadog.communication.serialization.GrowableBuffer; import datadog.communication.serialization.Writable; import datadog.communication.serialization.msgpack.MsgPackWriter; +import datadog.trace.api.DDTraceId; import datadog.trace.api.civisibility.InstrumentationBridge; import datadog.trace.api.civisibility.coverage.TestReport; import datadog.trace.api.civisibility.coverage.TestReportFileEntry; @@ -77,7 +78,7 @@ public void map(List> trace, Writable writable) { continue; } - Long testSessionId = testReport.getTestSessionId(); + DDTraceId testSessionId = testReport.getTestSessionId(); Long testSuiteId = testReport.getTestSuiteId(); int fieldCount = 2 + (testSessionId != null ? 1 : 0) + (testSuiteId != null ? 1 : 0); @@ -86,7 +87,7 @@ public void map(List> trace, Writable writable) { if (testSessionId != null) { writable.writeUTF8(TEST_SESSION_ID); - writable.writeLong(testSessionId); + writable.writeLong(testSessionId.toLong()); } if (testSuiteId != null) { diff --git a/dd-trace-core/src/main/java/datadog/trace/civisibility/writer/ddintake/CiTestCycleMapperV1.java b/dd-trace-core/src/main/java/datadog/trace/civisibility/writer/ddintake/CiTestCycleMapperV1.java index ef7c31575ef..7d1ec19b786 100644 --- a/dd-trace-core/src/main/java/datadog/trace/civisibility/writer/ddintake/CiTestCycleMapperV1.java +++ b/dd-trace-core/src/main/java/datadog/trace/civisibility/writer/ddintake/CiTestCycleMapperV1.java @@ -6,6 +6,7 @@ import datadog.communication.serialization.GrowableBuffer; import datadog.communication.serialization.Writable; import datadog.communication.serialization.msgpack.MsgPackWriter; +import datadog.trace.api.DDTraceId; import datadog.trace.api.civisibility.CiVisibilityWellKnownTags; import datadog.trace.api.civisibility.InstrumentationBridge; import datadog.trace.api.civisibility.telemetry.CiVisibilityDistributionMetric; @@ -24,12 +25,7 @@ import java.nio.ByteBuffer; import java.nio.channels.WritableByteChannel; import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import okhttp3.RequestBody; public class CiTestCycleMapperV1 implements RemoteMapper { @@ -41,6 +37,12 @@ public class CiTestCycleMapperV1 implements RemoteMapper { private static final byte[] ENV = "env".getBytes(StandardCharsets.UTF_8); private static final byte[] TYPE = "type".getBytes(StandardCharsets.UTF_8); private static final byte[] CONTENT = "content".getBytes(StandardCharsets.UTF_8); + private static final byte[] TEST_SESSION_ID = + Tags.TEST_SESSION_ID.getBytes(StandardCharsets.UTF_8); + private static final byte[] TEST_MODULE_ID = Tags.TEST_MODULE_ID.getBytes(StandardCharsets.UTF_8); + private static final byte[] TEST_SUITE_ID = Tags.TEST_SUITE_ID.getBytes(StandardCharsets.UTF_8); + private static final byte[] ITR_CORRELATION_ID = + Tags.ITR_CORRELATION_ID.getBytes(StandardCharsets.UTF_8); private static final byte[] RUNTIME_NAME = Tags.RUNTIME_NAME.getBytes(StandardCharsets.UTF_8); private static final byte[] RUNTIME_VENDOR = Tags.RUNTIME_VENDOR.getBytes(StandardCharsets.UTF_8); @@ -58,7 +60,6 @@ public class CiTestCycleMapperV1 implements RemoteMapper { Tags.TEST_SESSION_ID, Tags.TEST_MODULE_ID, Tags.TEST_SUITE_ID, Tags.ITR_CORRELATION_ID); private final CiVisibilityWellKnownTags wellKnownTags; - private final Collection topLevelTags; private final int size; private final GrowableBuffer headerBuffer; private final MsgPackWriter headerWriter; @@ -67,17 +68,8 @@ public class CiTestCycleMapperV1 implements RemoteMapper { private int serializationTimeMillis; public CiTestCycleMapperV1(CiVisibilityWellKnownTags wellKnownTags, boolean compressionEnabled) { - this(wellKnownTags, DEFAULT_TOP_LEVEL_TAGS, 5 << 20, compressionEnabled); - } - - private CiTestCycleMapperV1( - CiVisibilityWellKnownTags wellKnownTags, - Collection topLevelTags, - int size, - boolean compressionEnabled) { this.wellKnownTags = wellKnownTags; - this.topLevelTags = topLevelTags; - this.size = size; + this.size = 5 << 20; this.compressionEnabled = compressionEnabled; headerBuffer = new GrowableBuffer(16); headerWriter = new MsgPackWriter(headerBuffer); @@ -88,11 +80,30 @@ public void map(List> trace, Writable writable) { long serializationStartTimestamp = System.currentTimeMillis(); for (final CoreSpan span : trace) { + DDTraceId testSessionId = span.getTag(Tags.TEST_SESSION_ID); + span.removeTag(Tags.TEST_SESSION_ID); + + Number testModuleId = span.getTag(Tags.TEST_MODULE_ID); + span.removeTag(Tags.TEST_MODULE_ID); + + Number testSuiteId = span.getTag(Tags.TEST_SUITE_ID); + span.removeTag(Tags.TEST_SUITE_ID); + + String itrCorrelationId = span.getTag(Tags.ITR_CORRELATION_ID); + span.removeTag(Tags.ITR_CORRELATION_ID); + int topLevelTagsCount = 0; - for (String topLevelTag : topLevelTags) { - if (span.getTag(topLevelTag) != null) { - topLevelTagsCount++; - } + if (testSessionId != null) { + topLevelTagsCount++; + } + if (testModuleId != null) { + topLevelTagsCount++; + } + if (testSuiteId != null) { + topLevelTagsCount++; + } + if (itrCorrelationId != null) { + topLevelTagsCount++; } UTF8BytesString type; @@ -170,20 +181,21 @@ public void map(List> trace, Writable writable) { writable.writeUTF8(PARENT_ID); writable.writeUnsignedLong(parentId); } - - for (String topLevelTag : topLevelTags) { - Object tagValue = span.getTag(topLevelTag); - if (tagValue != null) { - writable.writeString(topLevelTag, null); - - if (tagValue instanceof Number) { - writable.writeObject(tagValue, null); - } else { - writable.writeObjectString(tagValue, null); - } - - span.removeTag(topLevelTag); - } + if (testSessionId != null) { + writable.writeUTF8(TEST_SESSION_ID); + writable.writeObject(testSessionId.toLong(), null); + } + if (testModuleId != null) { + writable.writeUTF8(TEST_MODULE_ID); + writable.writeObject(testModuleId, null); + } + if (testSuiteId != null) { + writable.writeUTF8(TEST_SUITE_ID); + writable.writeObject(testSuiteId, null); + } + if (itrCorrelationId != null) { + writable.writeUTF8(ITR_CORRELATION_ID); + writable.writeObjectString(itrCorrelationId, null); } /* 1 */ diff --git a/dd-trace-core/src/test/groovy/datadog/trace/civisibility/writer/ddintake/CiTestCovMapperV2Test.groovy b/dd-trace-core/src/test/groovy/datadog/trace/civisibility/writer/ddintake/CiTestCovMapperV2Test.groovy index 9fd280294c7..cdbe02fb3cc 100644 --- a/dd-trace-core/src/test/groovy/datadog/trace/civisibility/writer/ddintake/CiTestCovMapperV2Test.groovy +++ b/dd-trace-core/src/test/groovy/datadog/trace/civisibility/writer/ddintake/CiTestCovMapperV2Test.groovy @@ -3,6 +3,7 @@ package datadog.trace.civisibility.writer.ddintake import com.fasterxml.jackson.databind.ObjectMapper import datadog.communication.serialization.GrowableBuffer import datadog.communication.serialization.msgpack.MsgPackWriter +import datadog.trace.api.DDTraceId import datadog.trace.api.civisibility.coverage.CoverageProbes import datadog.trace.api.civisibility.coverage.CoverageStore import datadog.trace.api.civisibility.coverage.NoOpProbes @@ -27,7 +28,7 @@ class CiTestCovMapperV2Test extends DDCoreSpecification { def "test writes message"() { given: - def trace = givenTrace(new TestReport(1, 2, 3, [new TestReportFileEntry("source", BitSet.valueOf(new long[] { + def trace = givenTrace(new TestReport(DDTraceId.from(1), 2, 3, [new TestReportFileEntry("source", BitSet.valueOf(new long[] { 3, 5, 8 }))])) @@ -55,7 +56,7 @@ class CiTestCovMapperV2Test extends DDCoreSpecification { def "test writes message with multiple files and multiple lines"() { given: - def trace = givenTrace(new TestReport(1, 2, 3, [ + def trace = givenTrace(new TestReport(DDTraceId.from(1), 2, 3, [ new TestReportFileEntry("sourceA", BitSet.valueOf(new long[] { 3, 5, 8 })), @@ -93,12 +94,12 @@ class CiTestCovMapperV2Test extends DDCoreSpecification { def "test writes message with multiple reports"() { given: def trace = givenTrace( - new TestReport(1, 2, 3, [ + new TestReport(DDTraceId.from(1), 2, 3, [ new TestReportFileEntry("sourceA", BitSet.valueOf(new long[] { 2, 17, 41 })) ]), - new TestReport(1, 2, 4, [ + new TestReport(DDTraceId.from(1), 2, 4, [ new TestReportFileEntry("sourceB", BitSet.valueOf(new long[] { 11, 13, 55 })) @@ -140,7 +141,7 @@ class CiTestCovMapperV2Test extends DDCoreSpecification { def "skips spans that have no reports"() { given: - def trace = givenTrace(null, new TestReport(1, 2, 3, [new TestReportFileEntry("source", BitSet.valueOf(new long[] { + def trace = givenTrace(null, new TestReport(DDTraceId.from(1), 2, 3, [new TestReportFileEntry("source", BitSet.valueOf(new long[] { 83, 25, 48 }))]), null) @@ -169,12 +170,12 @@ class CiTestCovMapperV2Test extends DDCoreSpecification { def "skips empty reports"() { given: def trace = givenTrace( - new TestReport(1, 2, 3, [ + new TestReport(DDTraceId.from(1), 2, 3, [ new TestReportFileEntry("source", BitSet.valueOf(new long[] { 33, 53, 87 })) ]), - new TestReport(1, 2, 4, []) + new TestReport(DDTraceId.from(1), 2, 4, []) ) when: @@ -203,7 +204,7 @@ class CiTestCovMapperV2Test extends DDCoreSpecification { given: def trace = new ArrayList() - def report = new TestReport(1, 2, 3, [new TestReportFileEntry("source", BitSet.valueOf(new long[] { + def report = new TestReport(DDTraceId.from(1), 2, 3, [new TestReportFileEntry("source", BitSet.valueOf(new long[] { 3, 5, 8 }))]) @@ -269,7 +270,7 @@ class CiTestCovMapperV2Test extends DDCoreSpecification { } @Override - boolean report(Long testSessionId, Long testSuiteId, long spanId) { + boolean report(DDTraceId testSessionId, Long testSuiteId, long spanId) { return false } diff --git a/dd-trace-core/src/test/groovy/datadog/trace/civisibility/writer/ddintake/CiTestCycleMapperV1PayloadTest.groovy b/dd-trace-core/src/test/groovy/datadog/trace/civisibility/writer/ddintake/CiTestCycleMapperV1PayloadTest.groovy index 0795d8815c3..0e209201158 100644 --- a/dd-trace-core/src/test/groovy/datadog/trace/civisibility/writer/ddintake/CiTestCycleMapperV1PayloadTest.groovy +++ b/dd-trace-core/src/test/groovy/datadog/trace/civisibility/writer/ddintake/CiTestCycleMapperV1PayloadTest.groovy @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper import datadog.communication.serialization.ByteBufferConsumer import datadog.communication.serialization.FlushingBuffer import datadog.communication.serialization.msgpack.MsgPackWriter +import datadog.trace.api.DDTraceId import datadog.trace.api.civisibility.CiVisibilityWellKnownTags import datadog.trace.bootstrap.instrumentation.api.InternalSpanTypes import datadog.trace.bootstrap.instrumentation.api.Tags @@ -91,7 +92,7 @@ class CiTestCycleMapperV1PayloadTest extends DDSpecification { def "verify test_suite_id, test_module_id, and test_session_id are written as top level tags in test event"() { setup: def span = generateRandomSpan(InternalSpanTypes.TEST, [ - (Tags.TEST_SESSION_ID): 123, + (Tags.TEST_SESSION_ID): DDTraceId.from(123), (Tags.TEST_MODULE_ID) : 456, (Tags.TEST_SUITE_ID) : 789 ]) @@ -100,7 +101,7 @@ class CiTestCycleMapperV1PayloadTest extends DDSpecification { Map deserializedSpan = whenASpanIsWritten(span) then: - verifyTopLevelTags(deserializedSpan, 123, 456, 789) + verifyTopLevelTags(deserializedSpan, DDTraceId.from(123), 456, 789) def spanContent = (Map) deserializedSpan.get("content") assert spanContent.containsKey("trace_id") @@ -111,7 +112,7 @@ class CiTestCycleMapperV1PayloadTest extends DDSpecification { def "verify test_suite_end event is written correctly"() { setup: def span = generateRandomSpan(InternalSpanTypes.TEST_SUITE_END, [ - (Tags.TEST_SESSION_ID): 123, + (Tags.TEST_SESSION_ID): DDTraceId.from(123), (Tags.TEST_MODULE_ID) : 456, (Tags.TEST_SUITE_ID) : 789 ]) @@ -120,7 +121,7 @@ class CiTestCycleMapperV1PayloadTest extends DDSpecification { Map deserializedSpan = whenASpanIsWritten(span) then: - verifyTopLevelTags(deserializedSpan, 123, 456, 789) + verifyTopLevelTags(deserializedSpan, DDTraceId.from(123), 456, 789) def spanContent = (Map) deserializedSpan.get("content") assert !spanContent.containsKey("trace_id") @@ -131,7 +132,7 @@ class CiTestCycleMapperV1PayloadTest extends DDSpecification { def "verify test_module_end event is written correctly"() { setup: def span = generateRandomSpan(InternalSpanTypes.TEST_MODULE_END, [ - (Tags.TEST_SESSION_ID): 123, + (Tags.TEST_SESSION_ID): DDTraceId.from(123), (Tags.TEST_MODULE_ID) : 456, ]) @@ -139,7 +140,7 @@ class CiTestCycleMapperV1PayloadTest extends DDSpecification { Map deserializedSpan = whenASpanIsWritten(span) then: - verifyTopLevelTags(deserializedSpan, 123, 456, null) + verifyTopLevelTags(deserializedSpan, DDTraceId.from(123), 456, null) def spanContent = (Map) deserializedSpan.get("content") assert !spanContent.containsKey("trace_id") @@ -147,13 +148,13 @@ class CiTestCycleMapperV1PayloadTest extends DDSpecification { assert !spanContent.containsKey("parent_id") } - private static void verifyTopLevelTags(Map deserializedSpan, Long testSessionId, Long testModuleId, Long testSuiteId) { + private static void verifyTopLevelTags(Map deserializedSpan, DDTraceId testSessionId, Long testModuleId, Long testSuiteId) { Map deserializedSpanContent = (Map) deserializedSpan.get("content") Map deserializedMetrics = (Map) deserializedSpanContent.get("metrics") Map deserializedMeta = (Map) deserializedSpanContent.get("meta") if (testSessionId != null) { - assert deserializedSpanContent.get(Tags.TEST_SESSION_ID) == testSessionId + assert deserializedSpanContent.get(Tags.TEST_SESSION_ID) == testSessionId.toLong() } else { assert !deserializedSpanContent.containsKey(Tags.TEST_SESSION_ID) } diff --git a/internal-api/src/main/java/datadog/trace/api/Config.java b/internal-api/src/main/java/datadog/trace/api/Config.java index f43a5fb0af6..d376eef3d92 100644 --- a/internal-api/src/main/java/datadog/trace/api/Config.java +++ b/internal-api/src/main/java/datadog/trace/api/Config.java @@ -309,8 +309,6 @@ public static String getHostName() { private final boolean ciVisibilitySourceDataEnabled; private final boolean ciVisibilityBuildInstrumentationEnabled; - private final Long ciVisibilitySessionId; - private final Long ciVisibilityModuleId; private final String ciVisibilityAgentJarUri; private final boolean ciVisibilityAutoConfigurationEnabled; private final String ciVisibilityAdditionalChildProcessJvmArgs; @@ -1309,9 +1307,6 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment()) CIVISIBILITY_BUILD_INSTRUMENTATION_ENABLED, DEFAULT_CIVISIBILITY_BUILD_INSTRUMENTATION_ENABLED); - ciVisibilitySessionId = configProvider.getLong(CIVISIBILITY_SESSION_ID); - ciVisibilityModuleId = configProvider.getLong(CIVISIBILITY_MODULE_ID); - final String ciVisibilityAgentlessUrlStr = configProvider.getString(CIVISIBILITY_AGENTLESS_URL); URI parsedCiVisibilityUri = null; if (ciVisibilityAgentlessUrlStr != null && !ciVisibilityAgentlessUrlStr.isEmpty()) { @@ -2581,14 +2576,6 @@ public boolean isCiVisibilityBuildInstrumentationEnabled() { return ciVisibilityBuildInstrumentationEnabled; } - public Long getCiVisibilitySessionId() { - return ciVisibilitySessionId; - } - - public Long getCiVisibilityModuleId() { - return ciVisibilityModuleId; - } - public String getCiVisibilityAgentJarUri() { return ciVisibilityAgentJarUri; } diff --git a/internal-api/src/main/java/datadog/trace/api/civisibility/coverage/CoverageStore.java b/internal-api/src/main/java/datadog/trace/api/civisibility/coverage/CoverageStore.java index 5305ec6c79a..013b519a18f 100644 --- a/internal-api/src/main/java/datadog/trace/api/civisibility/coverage/CoverageStore.java +++ b/internal-api/src/main/java/datadog/trace/api/civisibility/coverage/CoverageStore.java @@ -1,5 +1,6 @@ package datadog.trace.api.civisibility.coverage; +import datadog.trace.api.DDTraceId; import datadog.trace.api.civisibility.config.TestIdentifier; import javax.annotation.Nullable; @@ -8,7 +9,7 @@ public interface CoverageStore extends TestReportHolder { CoverageProbes getProbes(); /** @return {@code true} if coverage was gathered successfully */ - boolean report(Long testSessionId, Long testSuiteId, long testSpanId); + boolean report(DDTraceId testSessionId, Long testSuiteId, long testSpanId); interface Factory extends Registry { CoverageStore create(@Nullable TestIdentifier testIdentifier); diff --git a/internal-api/src/main/java/datadog/trace/api/civisibility/coverage/NoOpCoverageStore.java b/internal-api/src/main/java/datadog/trace/api/civisibility/coverage/NoOpCoverageStore.java index 3b9859b9b5b..c2b677f416f 100644 --- a/internal-api/src/main/java/datadog/trace/api/civisibility/coverage/NoOpCoverageStore.java +++ b/internal-api/src/main/java/datadog/trace/api/civisibility/coverage/NoOpCoverageStore.java @@ -1,5 +1,6 @@ package datadog.trace.api.civisibility.coverage; +import datadog.trace.api.DDTraceId; import datadog.trace.api.civisibility.config.TestIdentifier; import javax.annotation.Nullable; @@ -15,7 +16,7 @@ public CoverageProbes getProbes() { } @Override - public boolean report(Long testSessionId, Long testSuiteId, long testSpanId) { + public boolean report(DDTraceId testSessionId, Long testSuiteId, long testSpanId) { return true; } diff --git a/internal-api/src/main/java/datadog/trace/api/civisibility/coverage/TestReport.java b/internal-api/src/main/java/datadog/trace/api/civisibility/coverage/TestReport.java index 62ef2c7d9ff..3030989a1d2 100644 --- a/internal-api/src/main/java/datadog/trace/api/civisibility/coverage/TestReport.java +++ b/internal-api/src/main/java/datadog/trace/api/civisibility/coverage/TestReport.java @@ -1,17 +1,18 @@ package datadog.trace.api.civisibility.coverage; +import datadog.trace.api.DDTraceId; import java.util.Collection; import javax.annotation.Nonnull; public class TestReport { - private final Long testSessionId; + private final DDTraceId testSessionId; private final Long testSuiteId; private final long spanId; private final Collection testReportFileEntries; public TestReport( - Long testSessionId, + DDTraceId testSessionId, Long testSuiteId, long spanId, @Nonnull Collection testReportFileEntries) { @@ -21,7 +22,7 @@ public TestReport( this.testReportFileEntries = testReportFileEntries; } - public Long getTestSessionId() { + public DDTraceId getTestSessionId() { return testSessionId; } diff --git a/internal-api/src/test/groovy/datadog/trace/api/ConfigCollectorTest.groovy b/internal-api/src/test/groovy/datadog/trace/api/ConfigCollectorTest.groovy index b69288b8729..5c502c3c3b0 100644 --- a/internal-api/src/test/groovy/datadog/trace/api/ConfigCollectorTest.groovy +++ b/internal-api/src/test/groovy/datadog/trace/api/ConfigCollectorTest.groovy @@ -41,7 +41,7 @@ class ConfigCollectorTest extends DDSpecification { // ConfigProvider.getInteger JmxFetchConfig.JMX_FETCH_CHECK_PERIOD | "60" // ConfigProvider.getLong - CiVisibilityConfig.CIVISIBILITY_MODULE_ID | "450273" + CiVisibilityConfig.CIVISIBILITY_GIT_COMMAND_TIMEOUT_MILLIS | "450273" // ConfigProvider.getFloat GeneralConfig.TELEMETRY_HEARTBEAT_INTERVAL | "1.5" // ConfigProvider.getDouble @@ -112,7 +112,7 @@ class ConfigCollectorTest extends DDSpecification { GeneralConfig.APPLICATION_KEY, TraceInstrumentationConfig.RESOLVER_USE_URL_CACHES, JmxFetchConfig.JMX_FETCH_CHECK_PERIOD, - CiVisibilityConfig.CIVISIBILITY_MODULE_ID, + CiVisibilityConfig.CIVISIBILITY_DEBUG_PORT, TracerConfig.TRACE_SAMPLE_RATE, TraceInstrumentationConfig.JMS_PROPAGATION_DISABLED_TOPICS, TracerConfig.PROXY_NO_PROXY,