Skip to content

Commit 31bfef0

Browse files
Merge branch 'master' into vzakharov/event_tracking_api_3
2 parents 2c49332 + 3516d09 commit 31bfef0

467 files changed

Lines changed: 11609 additions & 2371 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.circleci/config.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,15 @@ commands:
9191
9292
if [[ -n "${CIRCLE_PR_NUMBER}" ]]
9393
then
94-
FETCH_REFS="${FETCH_REFS} +refs/pull/${CIRCLE_PR_NUMBER}/merge:pr/${CIRCLE_PR_NUMBER}/merge"
94+
FETCH_REFS="${FETCH_REFS} +refs/pull/${CIRCLE_PR_NUMBER}/merge:refs/pull/${CIRCLE_PR_NUMBER}/merge +refs/pull/${CIRCLE_PR_NUMBER}/head:refs/pull/${CIRCLE_PR_NUMBER}/head"
9595
git fetch -u origin ${FETCH_REFS}
96-
git checkout "pr/${CIRCLE_PR_NUMBER}/merge"
96+
97+
if git merge-base --is-ancestor $(git show-ref --hash refs/pull/${CIRCLE_PR_NUMBER}/head) $(git show-ref --hash refs/pull/${CIRCLE_PR_NUMBER}/merge); then
98+
git checkout "pull/${CIRCLE_PR_NUMBER}/merge"
99+
else
100+
echo "[WARN] There is a merge conflict between master and PR ${CIRCLE_PR_NUMBER}, merge branch cannot be checked out."
101+
git checkout "pull/${CIRCLE_PR_NUMBER}/head"
102+
fi
97103
fi
98104
99105
# Everything falls back to the main cache

.github/CODEOWNERS

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ dd-smoke-tests/profiling-integration-tests/
1515
dd-java-agent/appsec/ @DataDog/appsec-java @ValentinZakharov
1616

1717
# @DataDog/ci-app-libraries-java
18-
internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/ci/ @DataDog/ci-app-libraries-java
19-
dd-trace-core/src/main/java/datadog/trace/civisibility/ @DataDog/ci-app-libraries-java
20-
dd-java-agent/instrumentation/junit-4.10/ @DataDog/ci-app-libraries-java
21-
dd-java-agent/instrumentation/junit-5.3/ @DataDog/ci-app-libraries-java
22-
dd-java-agent/instrumentation/testng-6.4/ @DataDog/ci-app-libraries-java
18+
internal-api/src/main/java/datadog/trace/api/civisibility/ @DataDog/ci-app-libraries-java
19+
dd-trace-core/src/main/java/datadog/trace/civisibility/ @DataDog/ci-app-libraries-java
20+
dd-java-agent/agent-ci-visibility/ @DataDog/ci-app-libraries-java
21+
dd-java-agent/instrumentation/junit-4.10/ @DataDog/ci-app-libraries-java
22+
dd-java-agent/instrumentation/junit-5.3/ @DataDog/ci-app-libraries-java
23+
dd-java-agent/instrumentation/testng-6.4/ @DataDog/ci-app-libraries-java
2324

2425
# @DataDog/debugger-java (Live Debugger)
2526
dd-java-agent/agent-debugger/ @DataDog/debugger-java

.github/workflows/lib-injection.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ jobs:
2727
- name: Set up Docker Buildx
2828
id: buildx
2929
uses: docker/setup-buildx-action@dc7b9719a96d48369863986a06765841d7ea23f6 # 2.0.0
30+
with:
31+
version: v0.9.1 # https://github.com/docker/buildx/issues/1533
3032

3133
- name: Set up Docker platforms
3234
id: buildx-platforms
@@ -37,7 +39,7 @@ jobs:
3739
3840
- name: lib-injection-tags
3941
id: lib-injection-tags
40-
uses: DataDog/system-tests/lib-injection/docker-tags@main
42+
uses: DataDog/system-tests/lib-injection/docker-tags@3dc6d51b9b2fda8721697c3590a327f6aefe54c0 # main
4143
with:
4244
init-image-name: 'dd-lib-java-init'
4345
main-branch-name: 'master'
@@ -76,11 +78,13 @@ jobs:
7678
LIBRARY_INJECTION_ADMISSION_CONTROLLER: ${{ matrix.lib-injection-use-admission-controller }}
7779
DOCKER_REGISTRY_IMAGES_PATH: ghcr.io/datadog
7880
DOCKER_IMAGE_TAG: ${{ github.sha }}
81+
MODE: manual
7982
steps:
8083
- name: lib-injection test runner
8184
id: lib-injection-test-runner
82-
uses: DataDog/system-tests/lib-injection/runner@main
85+
uses: DataDog/system-tests/lib-injection/runner@cd16b189820c94d37a1a3ed6ffceedf5ad2441cf # main
8386
with:
8487
docker-registry: ghcr.io
8588
docker-registry-username: ${{ github.repository_owner }}
8689
docker-registry-password: ${{ secrets.GITHUB_TOKEN }}
90+
test-script: ./lib-injection/run-manual-lib-injection.sh

.gitlab-ci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,26 @@ deploy_to_profiling_backend:
103103
UPSTREAM_TAG: $CI_COMMIT_TAG
104104
FORCE_TRIGGER: $FORCE_TRIGGER
105105

106+
deploy_to_di_backend:
107+
stage: deploy
108+
rules:
109+
- if: '$POPULATE_CACHE'
110+
when: never
111+
- when: manual
112+
allow_failure: true
113+
trigger:
114+
project: DataDog/debugger-backend
115+
branch: main
116+
variables:
117+
UPSTREAM_PACKAGE_JOB: build
118+
UPSTREAM_PROJECT_ID: $CI_PROJECT_ID
119+
UPSTREAM_PROJECT_NAME: $CI_PROJECT_NAME
120+
UPSTREAM_PIPELINE_ID: $CI_PIPELINE_ID
121+
UPSTREAM_BRANCH: $CI_COMMIT_BRANCH
122+
UPSTREAM_TAG: $CI_COMMIT_TAG
123+
UPSTREAM_COMMIT_AUTHOR: $CI_COMMIT_AUTHOR
124+
FORCE_TRIGGER: $FORCE_TRIGGER
125+
106126
deploy_to_sonatype:
107127
<<: *gradle_build
108128
stage: deploy

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/Agent.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ public void execute() {
399399
installDatadogTracer(scoClass, sco);
400400
maybeStartAppSec(scoClass, sco);
401401
maybeStartIast(scoClass, sco);
402+
maybeStartCiVisibility(scoClass, sco);
402403
// start debugger before remote config to subscribe to it before starting to poll
403404
maybeStartDebugger(instrumentation, scoClass, sco);
404405
maybeStartRemoteConfig(scoClass, sco);
@@ -686,6 +687,23 @@ private static void startIast(SubscriptionService ss, Class<?> scoClass, Object
686687
}
687688
}
688689

690+
private static void maybeStartCiVisibility(Class<?> scoClass, Object o) {
691+
if (ciVisibilityEnabled) {
692+
StaticEventLogger.begin("CI Visibility");
693+
694+
try {
695+
final Class<?> ciVisibilitySysClass =
696+
AGENT_CLASSLOADER.loadClass("datadog.trace.civisibility.CiVisibilitySystem");
697+
final Method ciVisibilityInstallerMethod = ciVisibilitySysClass.getMethod("start");
698+
ciVisibilityInstallerMethod.invoke(null);
699+
} catch (final Throwable e) {
700+
log.warn("Not starting CI Visibility subsystem", e);
701+
}
702+
703+
StaticEventLogger.end("CI Visibility");
704+
}
705+
}
706+
689707
private static void startTelemetry(Instrumentation inst, Class<?> scoClass, Object sco) {
690708
StaticEventLogger.begin("Telemetry");
691709

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator/TestDecorator.java

Lines changed: 67 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,41 @@
11
package datadog.trace.bootstrap.instrumentation.decorator;
22

3+
import static datadog.trace.util.Strings.toJson;
4+
5+
import datadog.trace.api.Config;
36
import datadog.trace.api.DDTags;
7+
import datadog.trace.api.civisibility.InstrumentationBridge;
8+
import datadog.trace.api.civisibility.codeowners.Codeowners;
9+
import datadog.trace.api.civisibility.source.MethodLinesResolver;
10+
import datadog.trace.api.civisibility.source.SourcePathResolver;
411
import datadog.trace.api.sampling.PrioritySampling;
512
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
613
import datadog.trace.bootstrap.instrumentation.api.InternalSpanTypes;
714
import datadog.trace.bootstrap.instrumentation.api.Tags;
815
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
9-
import datadog.trace.bootstrap.instrumentation.ci.CIProviderInfoFactory;
10-
import datadog.trace.bootstrap.instrumentation.ci.CITagsProvider;
11-
import datadog.trace.bootstrap.instrumentation.ci.CITagsProviderImpl;
12-
import datadog.trace.bootstrap.instrumentation.ci.git.info.CILocalGitInfoBuilder;
13-
import datadog.trace.bootstrap.instrumentation.ci.git.info.UserSuppliedGitInfoBuilder;
1416
import java.lang.annotation.Annotation;
1517
import java.lang.reflect.Method;
1618
import java.util.ArrayList;
19+
import java.util.Collection;
1720
import java.util.List;
1821
import java.util.Map;
19-
import org.slf4j.Logger;
20-
import org.slf4j.LoggerFactory;
2122

2223
public abstract class TestDecorator extends BaseDecorator {
2324

24-
private static final Logger log = LoggerFactory.getLogger(TestDecorator.class);
25-
2625
public static final String TEST_TYPE = "test";
2726
public static final String TEST_PASS = "pass";
2827
public static final String TEST_FAIL = "fail";
2928
public static final String TEST_SKIP = "skip";
3029
public static final UTF8BytesString CIAPP_TEST_ORIGIN = UTF8BytesString.create("ciapp-test");
3130

32-
private static final String GIT_FOLDER_NAME = ".git";
33-
34-
private final boolean isCI;
35-
private final Map<String, String> ciTags;
36-
37-
public TestDecorator() {
38-
this(
39-
new CITagsProviderImpl(
40-
CIProviderInfoFactory.createCIProviderInfo(),
41-
new CILocalGitInfoBuilder(),
42-
new UserSuppliedGitInfoBuilder(),
43-
GIT_FOLDER_NAME));
44-
}
45-
46-
TestDecorator(final CITagsProvider ciTagsProvider) {
47-
isCI = ciTagsProvider.isCI();
48-
ciTags = ciTagsProvider.getCiTags();
49-
}
31+
public TestDecorator() {}
5032

5133
public boolean isCI() {
52-
return isCI;
34+
return InstrumentationBridge.isCi();
5335
}
5436

5537
public Map<String, String> getCiTags() {
56-
return ciTags;
38+
return InstrumentationBridge.getCiTags();
5739
}
5840

5941
protected abstract String testFramework();
@@ -113,32 +95,83 @@ public AgentSpan afterStart(final AgentSpan span) {
11395
span.setTag(Tags.OS_VERSION, osVersion());
11496
span.setTag(DDTags.ORIGIN_KEY, CIAPP_TEST_ORIGIN);
11597

98+
Map<String, String> ciTags = InstrumentationBridge.getCiTags();
11699
for (final Map.Entry<String, String> ciTag : ciTags.entrySet()) {
117100
span.setTag(ciTag.getKey(), ciTag.getValue());
118101
}
119102

120103
return super.afterStart(span);
121104
}
122105

123-
public AgentSpan afterStart(final AgentSpan span, final String version) {
106+
protected AgentSpan afterTestStart(
107+
final AgentSpan span,
108+
final String testSuiteName,
109+
final String testName,
110+
final String testParameters,
111+
final String version,
112+
final Class<?> testClass,
113+
final Method testMethod) {
114+
115+
span.setResourceName(testSuiteName + "." + testName);
116+
span.setTag(Tags.TEST_SUITE, testSuiteName);
117+
span.setTag(Tags.TEST_NAME, testName);
118+
119+
if (testParameters != null) {
120+
span.setTag(Tags.TEST_PARAMETERS, testParameters);
121+
}
122+
124123
// Version can be null. The testing framework version extraction is best-effort basis.
125124
if (version != null) {
126125
span.setTag(Tags.TEST_FRAMEWORK_VERSION, version);
127126
}
127+
128+
if (Config.get().isCiVisibilitySourceDataEnabled()) {
129+
populateSourceDataTags(span, testClass, testMethod);
130+
}
131+
128132
return afterStart(span);
129133
}
130134

131-
public List<String> testNames(
135+
private void populateSourceDataTags(AgentSpan span, Class<?> testClass, Method testMethod) {
136+
if (testClass == null) {
137+
return;
138+
}
139+
140+
SourcePathResolver sourcePathResolver = InstrumentationBridge.getSourcePathResolver();
141+
String sourcePath = sourcePathResolver.getSourcePath(testClass);
142+
if (sourcePath == null || sourcePath.isEmpty()) {
143+
return;
144+
}
145+
146+
span.setTag(Tags.TEST_SOURCE_FILE, sourcePath);
147+
148+
if (testMethod != null) {
149+
MethodLinesResolver methodLinesResolver = InstrumentationBridge.getMethodLinesResolver();
150+
MethodLinesResolver.MethodLines testMethodLines = methodLinesResolver.getLines(testMethod);
151+
if (testMethodLines.isValid()) {
152+
span.setTag(Tags.TEST_SOURCE_START, testMethodLines.getStartLineNumber());
153+
span.setTag(Tags.TEST_SOURCE_END, testMethodLines.getFinishLineNumber());
154+
}
155+
}
156+
157+
Codeowners codeowners = InstrumentationBridge.getCodeowners();
158+
Collection<String> testCodeOwners = codeowners.getOwners(sourcePath);
159+
if (testCodeOwners != null) {
160+
span.setTag(Tags.TEST_CODEOWNERS, toJson(testCodeOwners));
161+
}
162+
}
163+
164+
public List<Method> testMethods(
132165
final Class<?> testClass, final Class<? extends Annotation> testAnnotation) {
133-
final List<String> testNames = new ArrayList<>();
166+
final List<Method> testMethods = new ArrayList<>();
134167

135168
final Method[] methods = testClass.getMethods();
136169
for (final Method method : methods) {
137170
if (method.getAnnotation(testAnnotation) != null) {
138-
testNames.add(method.getName());
171+
testMethods.add(method);
139172
}
140173
}
141-
return testNames;
174+
return testMethods;
142175
}
143176

144177
public boolean isTestSpan(final AgentSpan activeSpan) {

dd-java-agent/agent-bootstrap/src/main/java11/datadog/trace/bootstrap/instrumentation/jfr/exceptions/ExceptionProfiling.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,22 @@ public static ExceptionProfiling getInstance() {
2424

2525
private final ExceptionHistogram histogram;
2626
private final ExceptionSampler sampler;
27+
private final boolean recordExceptionMessage;
2728

2829
private ExceptionProfiling(final Config config) {
29-
this(new ExceptionSampler(config), new ExceptionHistogram(config));
30+
this(
31+
new ExceptionSampler(config),
32+
new ExceptionHistogram(config),
33+
config.isProfilingRecordExceptionMessage());
3034
}
3135

32-
ExceptionProfiling(final ExceptionSampler sampler, final ExceptionHistogram histogram) {
36+
ExceptionProfiling(
37+
final ExceptionSampler sampler,
38+
final ExceptionHistogram histogram,
39+
boolean recordExceptionMessage) {
3340
this.sampler = sampler;
3441
this.histogram = histogram;
42+
this.recordExceptionMessage = recordExceptionMessage;
3543
}
3644

3745
public ExceptionSampleEvent process(final Throwable t) {
@@ -44,4 +52,8 @@ public ExceptionSampleEvent process(final Throwable t) {
4452
}
4553
return null;
4654
}
55+
56+
boolean recordExceptionMessage() {
57+
return recordExceptionMessage;
58+
}
4759
}

dd-java-agent/agent-bootstrap/src/main/java11/datadog/trace/bootstrap/instrumentation/jfr/exceptions/ExceptionSampleEvent.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ public ExceptionSampleEvent(Throwable e, boolean sampled, boolean firstOccurrenc
5050
}
5151

5252
private static String getMessage(Throwable t) {
53-
try {
54-
return t.getMessage();
55-
} catch (Throwable ignored) {
56-
// apparently there might be exceptions throwing at least NPE when trying to get the message
53+
if (ExceptionProfiling.getInstance().recordExceptionMessage()) {
54+
try {
55+
return t.getMessage();
56+
} catch (Throwable ignored) {
57+
// apparently there might be exceptions throwing at least NPE when trying to get the message
58+
}
5759
}
5860
return null;
5961
}

dd-java-agent/agent-bootstrap/src/test/groovy/datadog/trace/bootstrap/instrumentation/decorator/TestDecoratorTest.groovy

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
package datadog.trace.bootstrap.instrumentation.decorator
22

33
import datadog.trace.api.DDTags
4+
import datadog.trace.api.civisibility.InstrumentationBridge
5+
import datadog.trace.api.civisibility.codeowners.Codeowners
6+
import datadog.trace.api.civisibility.source.MethodLinesResolver
7+
import datadog.trace.api.civisibility.source.SourcePathResolver
48
import datadog.trace.api.sampling.PrioritySampling
59
import datadog.trace.bootstrap.instrumentation.api.AgentSpan
610
import datadog.trace.bootstrap.instrumentation.api.Tags
7-
import datadog.trace.bootstrap.instrumentation.ci.CITagsProvider
811

912
class TestDecoratorTest extends BaseDecoratorTest {
1013

14+
def setupSpec() {
15+
InstrumentationBridge.ci = true
16+
InstrumentationBridge.ciTags = Collections.singletonMap("sample-ci-key", "sample-ci-value")
17+
InstrumentationBridge.codeowners = Stub(Codeowners)
18+
InstrumentationBridge.sourcePathResolver = Stub(SourcePathResolver)
19+
InstrumentationBridge.methodLinesResolver = Stub(MethodLinesResolver)
20+
}
21+
1122
def span = Mock(AgentSpan)
1223

1324
def "test afterStart"() {
@@ -53,7 +64,7 @@ class TestDecoratorTest extends BaseDecoratorTest {
5364

5465
@Override
5566
def newDecorator() {
56-
return new TestDecorator(newMockCiInfo()) {
67+
return new TestDecorator() {
5768
@Override
5869
protected String testFramework() {
5970
return "test-framework"
@@ -80,20 +91,4 @@ class TestDecoratorTest extends BaseDecoratorTest {
8091
}
8192
}
8293
}
83-
84-
def newMockCiInfo() {
85-
return new CITagsProvider() {
86-
@Override
87-
boolean isCI() {
88-
return true
89-
}
90-
91-
@Override
92-
Map<String, String> getCiTags() {
93-
def mockCiTags = new HashMap()
94-
mockCiTags.put("sample-ci-key", "sample-ci-value")
95-
return mockCiTags
96-
}
97-
}
98-
}
9994
}

0 commit comments

Comments
 (0)