8000 Add capabilities tagging by daniel-mohedano · Pull Request #8499 · DataDog/dd-trace-java · GitHub
[go: up one dir, main page]

Skip to content

Add capabilities tagging #8499

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 44 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
8e9bb96
introduce seperate test events handlers in junit5 instrumentations
daniel-mohedano Feb 25, 2025
7ab85a0
clear junit5 handler map on close
daniel-mohedano Feb 25, 2025
b8c748f
introduce separate test events handlers in junit4 instrumentations
daniel-mohedano Feb 25, 2025
45735e6
junit4 instrumentation fixes
daniel-mohedano Feb 26, 2025
ee63fa7
fix muzzle checks for junit5 instrumentation
daniel-mohedano Feb 26, 2025
8ec555d
fix double close of default handler in junit5 instrumentation
daniel-mohedano Feb 26, 2025
04a8084
pr fixes
daniel-mohedano Feb 26, 2025
408a7d3
fix code quality violation
daniel-mohedano Feb 27, 2025
7d28e5a
use framework as component in junit4 and junit5 instrumentations
daniel-mohedano Feb 27, 2025
cfd4fda
update test fixtures with new component string
daniel-mohedano Feb 27, 2025
7877125
update smoke test fixtures with new component string
daniel-mohedano Feb 27, 2025
5a796b9
update selenium test fixtures and fix fixture generation
daniel-mohedano Feb 27, 2025
9a320be
fix codenarc issue
daniel-mohedano Feb 27, 2025
02c6bcc
Merge branch 'master' into daniel.mohedano/instrumentation-test-handl…
daniel-mohedano Feb 28, 2025
568f709
implements capabilities tagging logic
daniel-mohedano Feb 28, 2025
2b25ea8
update weaver instrumentation
daniel-mohedano Feb 28, 2025
ef2664d
update karate instrumentation
daniel-mohedano Feb 28, 2025
3538287
unify karate version in KarateUtils
daniel-mohedano Feb 28, 2025
a52cc21
update testng instrumentation
daniel-mohedano Feb 28, 2025
bc0d0b3
add testng ordering to capabilities
daniel-mohedano Feb 28, 2025
c9a0114
backport ComparableVersion from maven artifact to avoid packaging it
daniel-mohedano Feb 28, 2025
8129852
update junit5 instrumentations
daniel-mohedano Feb 28, 2025
103a089
update junit4 instrumentations
daniel-mohedano Feb 28, 2025
6685a5b
extend headless test session to ensure all capabilities are propagated
daniel-mohedano Feb 28, 2025
79df146
update scalatest instrumentation
daniel-mohedano Feb 28, 2025
063b82a
tag ignoring in span assertion and update smoke test fixtures
daniel-mohedano Mar 4, 2025
c0cf509
jacoco test coverage excludes
daniel-mohedano Mar 4, 2025
e12b7c8
Merge branch 'master' into daniel.mohedano/library-capabilities-tagging
daniel-mohedano Mar 4, 2025
6792874
fix code quality violations
daniel-mohedano Mar 4, 2025
2bee4c2
remove leftover maven dependency for karate
daniel-mohedano Mar 4, 2025
bc8ab0c
bugs and spotless fix
daniel-mohedano Mar 4, 2025
bf6d237
ignore tags with JsonPaths instead of custom implementation
daniel-mohedano Mar 4, 2025
b073736
clean up arePresent and areNotPresent in TagsAssert
daniel-mohedano Mar 4, 2025
0de9f87
add check for null framework versions
daniel-mohedano Mar 4, 2025
877fc63
remove capabilites propagation
daniel-mohedano Mar 4, 2025
8f6e0d7
remove unused test name for execution strategy
daniel-mohedano Mar 4, 2025
2e9d18c
PR changes
daniel-mohedano Mar 5, 2025
4238c3b
fix execution settings tests with sys config injection
daniel-mohedano Mar 5, 2025
0dcea22
fix TestImplTest
daniel-mohedano Mar 5, 2025
c31a7d7
Merge branch 'master' into daniel.mohedano/library-capabilities-tagging
daniel-mohedano Mar 5, 2025
f7aa755
fix master merge
daniel-mohedano Mar 5, 2025
28c2310
remove library capability utils
daniel-mohedano Mar 5, 2025
bd09eef
spotless !
daniel-mohedano Mar 5, 2025
02fa357
change empty map call
daniel-mohedano Mar 6, 2025
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
Prev Previous commit
Next Next commit
update junit5 instrumentations
  • Loading branch information
daniel-mohedano committed Feb 28, 2025
commit 8129852c4ebf1a73be1e4f5514194ad9601fc8cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import datadog.trace.agent.test.asserts.ListWriterAssert
import datadog.trace.api.DDSpanTypes
import datadog.trace.api.DDTags
import datadog.trace.api.DisableTestTrace
import datadog.trace.api.civisibility.config.TestFQN
import datadog.trace.api.civisibility.config.TestIdentifier
import datadog.trace.civisibility.CiVisibilityInstrumentationTest
import datadog.trace.civisibility.CiVisibilityTestUtils
import datadog.trace.civisibility.config.LibraryCapabilityUtils
import datadog.trace.instrumentation.junit5.TestEventsHandlerHolder
import io.cucumber.core.api.TypeRegistry
import io.cucumber.core.options.Constants
Expand Down Expand Up @@ -210,6 +215,29 @@ class CucumberTest extends CiVisibilityInstrumentationTest {
]
}

def "test capabilities tagging #testcaseName"() {
def notPresentTags = new HashSet<>(LibraryCapabilityUtils.CAPABILITY_TAG_MAP.values())
notPresentTags.removeAll(presentTags)

runFeatures(["org/example/cucumber/calculator/basic_arithmetic.feature"], false, true)

ListWriterAssert.assertTraces(TEST_WRITER, 4, true, new CiVisibilityTestUtils.SortTracesByType(), {
trace(1) {
span(0) {
spanType DDSpanTypes.TEST_SESSION_END
tags(false) {
arePresent(presentTags)
areNotPresent(notPresentTags)
}
}
}
})

where:
testcaseName | presentTags
"test-capabilities-base" | [DDTags.LIBRARY_CAPABILITIES_TIA, DDTags.LIBRARY_CAPABILITIES_ATR, DDTags.LIBRARY_CAPABILITIES_EFD, DDTags.LIBRARY_CAPABILITIES_QUARANTINE, DDTags.LIBRARY_CAPABILITIES_DISABLED, DDTags.LIBRARY_CAPABILITIES_ATTEMPT_TO_FIX]
}

private String parameterizedTestNameSuffix() {
// older releases report different example names
version() == "5.4.0" ? "Example #1" : "Example #1.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import datadog.trace.agent.test.asserts.ListWriterAssert
import datadog.trace.api.DDSpanTypes
import datadog.trace.api.DDTags
import datadog.trace.api.DisableTestTrace
import datadog.trace.api.civisibility.CIConstants
import datadog.trace.civisibility.CiVisibilityInstrumentationTest
import datadog.trace.civisibility.CiVisibilityTestUtils
import datadog.trace.civisibility.config.LibraryCapabilityUtils
import datadog.trace.instrumentation.junit5.JUnitPlatformUtils
import datadog.trace.instrumentation.junit5.TestEventsHandlerHolder
import org.example.*
import org.junit.jupiter.api.Assumptions
import org.junit.jupiter.api.ClassOrderer
import org.junit.jupiter.api.MethodOrderer
import org.junit.jupiter.engine.Constants
Expand Down Expand Up @@ -82,6 +89,31 @@ class JUnit58Test extends CiVisibilityInstrumentationTest {
]
}

def "test capabilities tagging #testcaseName"() {
Assumptions.assumeTrue(assumption)

def notPresentTags = new HashSet<>(LibraryCapabilityUtils.CAPABILITY_TAG_MAP.values())
notPresentTags.removeAll(presentTags)

runTests([TestSucceed], true)

ListWriterAssert.assertTraces(TEST_WRITER, 5, true, new CiVisibilityTestUtils.SortTracesByType(), {
trace(1) {
span(0) {
spanType DDSpanTypes.TEST_SESSION_END
tags(false) {
arePresent(presentTags)
areNotPresent(notPresentTags)
}
}
}
})

where:
testcaseName | presentTags | assumption
"test-capabilities-ordering" | [DDTags.LIBRARY_CAPABILITIES_TIA, DDTags.LIBRARY_CAPABILITIES_ATR, DDTags.LIBRARY_CAPABILITIES_EFD, DDTags.LIBRARY_CAPABILITIES_IMPACTED_TESTS, DDTags.LIBRARY_CAPABILITIES_QUARANTINE, DDTags.LIBRARY_CAPABILITIES_DISABLED, DDTags.LIBRARY_CAPABILITIES_ATTEMPT_TO_FIX, DDTags.LIBRARY_CAPABILITIES_FAIL_FAST_TEST_ORDER] | JUnitPlatformUtils.isJunitTestOrderingSupported(instrumentedLibraryVersion())
}

private static void runTests(List<Class<?>> tests, boolean expectSuccess = true) {
DiscoverySelector[] selectors = new DiscoverySelector[tests.size()]
for (i in 0..<tests.size()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class SpockTracingListener implements EngineExecutionListener {

public SpockTracingListener(TestEngine testEngine) {
testFramework = testEngine.getId();
testFrameworkVersion = testEngine.getVersion().orElse(null);
testFrameworkVersion = JUnitPlatformUtils.getFrameworkVersion(testEngine);
}

@Override
Expand Down
6D4E
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import datadog.trace.agent.test.asserts.ListWriterAssert
import datadog.trace.api.DDSpanTypes
import datadog.trace.api.DDTags
import datadog.trace.api.DisableTestTrace
import datadog.trace.api.civisibility.config.TestFQN
import datadog.trace.api.civisibility.config.TestIdentifier
import datadog.trace.civisibility.CiVisibilityInstrumentationTest
import datadog.trace.civisibility.CiVisibilityTestUtils
import datadog.trace.civisibility.config.LibraryCapabilityUtils
import datadog.trace.civisibility.diff.FileDiff
import datadog.trace.civisibility.diff.LineDiff
import datadog.trace.instrumentation.junit5.JUnitPlatformUtils
import datadog.trace.instrumentation.junit5.TestEventsHandlerHolder
import org.example.TestFailedParameterizedSpock
import org.example.TestFailedSpock
Expand All @@ -18,6 +24,7 @@ import org.example.TestSucceedSpockSlow
import org.example.TestSucceedSpockUnskippable
import org.example.TestSucceedSpockUnskippableSuite
import org.example.TestSucceedSpockVerySlow
import org.junit.jupiter.api.Assumptions
import org.junit.platform.engine.DiscoverySelector
import org.junit.platform.engine.TestExecutionResult
import org.junit.platform.launcher.TestExecutionListener
Expand Down Expand Up @@ -210,6 +217,29 @@ class SpockTest extends CiVisibilityInstrumentationTest {
"test-attempt-to-fix-disabled-succeeded" | true | [TestSucceedSpock] | [new TestFQN("org.example.TestSucceedSpock", "test success")] | [] | [new TestFQN("org.example.TestSucceedSpock", "test success")]
}

def "test capabilities tagging #testcaseName"() {
def notPresentTags = new HashSet<>(LibraryCapabilityUtils.CAPABILITY_TAG_MAP.values())
notPresentTags.removeAll(presentTags)

runTests([TestSucceedSpock], true)

ListWriterAssert.assertTraces(TEST_WRITER, 4, true, new CiVisibilityTestUtils.SortTracesByType(), {
trace(1) {
span(0) {
spanType DDSpanTypes.TEST_SESSION_END
tags(false) {
arePresent(presentTags)
areNotPresent(notPresentTags)
}
}
}
})

where:
testcaseName | presentTags
"test-capabilities-base" | [DDTags.LIBRARY_CAPABILITIES_TIA, DDTags.LIBRARY_CAPABILITIES_ATR, DDTags.LIBRARY_CAPABILITIES_EFD, DDTags.LIBRARY_CAPABILITIES_IMPACTED_TESTS, DDTags.LIBRARY_CAPABILITIES_QUARANTINE, DDTags.LIBRARY_CAPABILITIES_DISABLED, DDTags.LIBRARY_CAPABILITIES_ATTEMPT_TO_FIX]
}

private static void runTests(List<Class<?>> classes, boolean expectSuccess = true) {
DiscoverySelector[] selectors = new DiscoverySelector[classes.size()]
for (i in 0..<classes.size()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

import static datadog.json.JsonMapper.toJson;

import datadog.trace.api.civisibility.config.LibraryCapability;
import datadog.trace.api.civisibility.config.TestIdentifier;
import datadog.trace.api.civisibility.config.TestSourceData;
import datadog.trace.api.civisibility.telemetry.tag.TestFrameworkInstrumentation;
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
import datadog.trace.bootstrap.instrumentation.api.InternalSpanTypes;
import datadog.trace.util.ComparableVersion;
import datadog.trace.util.MethodHandles;
import java.lang.invoke.MethodHandle;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -44,6 +48,8 @@ public abstract class JUnitPlatformUtils {
public static final String ENGINE_ID_CUCUMBER = "cucumber";
public static final String ENGINE_ID_SPOCK = "spock";

public static final ComparableVersion junitV58 = new ComparableVersion("5.8");

private JUnitPlatformUtils() {}

private static final MethodHandles METHOD_HANDLES =
Expand Down Expand Up @@ -245,4 +251,65 @@ public static TestFrameworkInstrumentation engineIdToFramework(String engineId)
return TestFrameworkInstrumentation.JUNIT5;
}
}

// only used in junit5 and spock, cucumber has its own utils method
@Nullable
public static String getFrameworkVersion(TestEngine testEngine) {
return testEngine.getVersion().orElse(null);
}

public static boolean isJunitTestOrderingSupported(String version) {
return version != null && junitV58.compareTo(new ComparableVersion(version)) <= 0;
}

private static List<LibraryCapability> junitCapabilities(String version) {
List<LibraryCapability> baseCapabilities =
new ArrayList<>(
Arrays.asList(
LibraryCapability.TIA,
LibraryCapability.ATR,
LibraryCapability.EFD,
LibraryCapability.IMPACTED,
LibraryCapability.QUARANTINE,
LibraryCapability.DISABLED,
LibraryCapability.ATTEMPT_TO_FIX));

if (isJunitTestOrderingSupported(version)) {
baseCapabilities.add(LibraryCapability.FAIL_FAST);
}

return baseCapabilities;
}

private static List<LibraryCapability> spockCapabilities() {
return Arrays.asList(
LibraryCapability.TIA,
LibraryCapability.ATR,
LibraryCapability.EFD,
LibraryCapability.IMPACTED,
LibraryCapability.QUARANTINE,
LibraryCapability.DISABLED,
LibraryCapability.ATTEMPT_TO_FIX);
}

private static List<LibraryCapability> cucumberCapabilities() {
return Arrays.asList(
LibraryCapability.TIA,
LibraryCapability.ATR,
LibraryCapability.EFD,
LibraryCapability.QUARANTINE,
LibraryCapability.DISABLED,
LibraryCapability.ATTEMPT_TO_FIX);
}

public static List<LibraryCapability> availableCapabilities(TestEngine testEngine) {
TestFrameworkInstrumentation framework = engineToFramework(testEngine);
if (framework.equals(TestFrameworkInstrumentation.CUCUMBER)) {
return cucumberCapabilities();
} else if (framework.equals(TestFrameworkInstrumentation.SPOCK)) {
return spockCapabilities();
} else {
return junitCapabilities(getFrameworkVersion(testEngine));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ public static synchronized void start(
if (handler == null) {
handler =
InstrumentationBridge.createTestEventsHandler(
framework.name().toLowerCase(), suiteStore, testStore);
framework.name().toLowerCase(),
suiteStore,
testStore,
JUnitPlatformUtils.availableCapabilities(testEngine));
HANDLERS.put(framework, handler);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TracingListener implements EngineExecutionListener {
public TracingListener(TestEngine testEngine) {
String engineId = testEngine.getId();
testFramework = engineId == null || engineId.startsWith("junit") ? "junit5" : engineId;
testFrameworkVersion = testEngine.getVersion().orElse(null);
testFrameworkVersion = JUnitPlatformUtils.getFrameworkVersion(testEngine);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import datadog.trace.agent.test.asserts.ListWriterAssert
import datadog.trace.api.DDSpanTypes
import datadog.trace.api.DDTags
import datadog.trace.api.DisableTestTrace
import datadog.trace.api.civisibility.config.TestFQN
import datadog.trace.api.civisibility.config.TestIdentifier
import datadog.trace.civisibility.CiVisibilityInstrumentationTest
import datadog.trace.civisibility.CiVisibilityTestUtils
import datadog.trace.civisibility.config.LibraryCapabilityUtils
import datadog.trace.civisibility.diff.FileDiff
import datadog.trace.civisibility.diff.LineDiff
import datadog.trace.instrumentation.junit5.JUnitPlatformUtils
import datadog.trace.instrumentation.junit5.TestEventsHandlerHolder
import org.example.TestAssumption
import org.example.TestAssumptionAndSucceed
Expand Down Expand Up @@ -35,6 +41,7 @@ import org.example.TestSucceedVerySlow
import org.example.TestSucceedWithCategories
import org.example.TestSuiteSetUpAssumption
import org.example.TestTemplate
import org.junit.jupiter.api.Assumptions
import org.junit.jupiter.engine.JupiterTestEngine
import org.junit.platform.engine.DiscoverySelector
import org.junit.platform.engine.TestExecutionResult
Expand Down Expand Up @@ -243,6 +250,31 @@ class JUnit5Test extends CiVisibilityInstrumentationTest {
"test-attempt-to-fix-disabled-succeeded" | true | [TestSucceed] | [new TestFQN("org.example.TestSucceed", "test_succeed")] | [] | [new TestFQN("org.example.TestSucceed", "test_succeed")]
}

def "test capabilities tagging #testcaseName"() {
Assumptions.assumeTrue(assumption)

def notPresentTags = new HashSet<>(LibraryCapabilityUtils.CAPABILITY_TAG_MAP.values())
notPresentTags.removeAll(presentTags)

runTests([TestSucceed], true)

ListWriterAssert.assertTraces(TEST_WRITER, 4, true, new CiVisibilityTestUtils.SortTracesByType(), {
trace(1) {
span(0) {
spanType DDSpanTypes.TEST_SESSION_END
tags(false) {
arePresent(presentTags)
areNotPresent(notPresentTags)
}
}
}
})

where:
testcaseName | presentTags | assumption
"test-capabilities-base" | [DDTags.LIBRARY_CAPABILITIES_TIA, DDTags.LIBRARY_CAPABILITIES_ATR, DDTags.LIBRARY_CAPABILITIES_EFD, DDTags.LIBRARY_CAPABILITIES_IMPACTED_TESTS, DDTags.LIBRARY_CAPABILITIES_QUARANTINE, DDTags.LIBRARY_CAPABILITIES_DISABLED, DDTags.LIBRARY_CAPABILITIES_ATTEMPT_TO_FIX] | !JUnitPlatformUtils.isJunitTestOrderingSupported(instrumentedLibraryVersion())
}

protected void runTests(List<Class<?>> tests, boolean expectSuccess = true) {
DiscoverySelector[] selectors = new DiscoverySelector[tests.size()]
for (i in 0..<tests.size()) {
Expand Down
0