Skip to content

Commit a0b2edd

Browse files
authored
Merge branch 'master' into nicholas.hulston/dynamodb-span-pointers
2 parents 250e6b8 + 71cbb06 commit a0b2edd

File tree

150 files changed

+2819
-1021
lines changed

Some content is hidden

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

150 files changed

+2819
-1021
lines changed

.circleci/config.continue.yml.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ instrumentation_modules: &instrumentation_modules "dd-java-agent/instrumentation
3636
debugger_modules: &debugger_modules "dd-java-agent/agent-debugger|dd-java-agent/agent-bootstrap|dd-java-agent/agent-builder|internal-api|communication|dd-trace-core"
3737
profiling_modules: &profiling_modules "dd-java-agent/agent-profiling"
3838

39-
default_system_tests_commit: &default_system_tests_commit 6980534f333b3f7a35d83df2230f00f4e26642f5
39+
default_system_tests_commit: &default_system_tests_commit 590162e1f5223cbbcd2876fdb820837cb13a85e1
4040

4141
parameters:
4242
nightly:
@@ -891,6 +891,7 @@ jobs:
891891
for log_dir in logs*; do
892892
tar -cvzf ../artifacts/${log_dir}_<< parameters.weblog-variant >>.tar.gz $log_dir
893893
done
894+
when: always
894895
895896
- store_artifacts:
896897
path: artifacts
@@ -980,6 +981,7 @@ jobs:
980981
for dir in system-tests/logs*/; do
981982
cp -r "$dir" logs_debugger
982983
done
984+
when: always
983985
984986
- store_test_results:
985987
path: logs_debugger

.gitlab-ci.yml

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ default:
4242
- export DATADOG_API_KEY_PROD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.DATADOG_API_KEY_PROD --with-decryption --query "Parameter.Value" --out text)
4343
- export DATADOG_API_KEY_DDSTAGING=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.dd_api_key --with-decryption --query "Parameter.Value" --out text)
4444

45+
# CI_NODE_INDEX and CI_NODE_TOTAL are 1-indexed and not always set. These steps normalize the numbers for jobs
46+
.normalize_node_index: &normalize_node_index
47+
- echo "CI_NODE_TOTAL=$CI_NODE_TOTAL , CI_NODE_INDEX=$CI_NODE_INDEX"
48+
- export NORMALIZED_NODE_TOTAL=${CI_NODE_TOTAL:-1}
49+
- ONE_INDEXED_NODE_INDEX=${CI_NODE_INDEX:-1}; export NORMALIZED_NODE_INDEX=$((ONE_INDEXED_NODE_INDEX - 1))
50+
- echo "NORMALIZED_NODE_TOTAL=$NORMALIZED_NODE_TOTAL , NORMALIZED_NODE_INDEX=$NORMALIZED_NODE_INDEX"
51+
4552
.gradle_build: &gradle_build
4653
image: ghcr.io/datadog/dd-trace-java-docker-build:${JAVA_BUILD_IMAGE_VERSION}-base
4754
stage: build
@@ -68,6 +75,7 @@ default:
6875
before_script:
6976
- export GRADLE_USER_HOME=`pwd`/.gradle
7077
- export GRADLE_ARGS=" --build-cache --stacktrace --no-daemon --parallel --max-workers=$GRADLE_WORKERS"
78+
- *normalize_node_index
7179
# for weird reasons, gradle will always "chmod 700" the .gradle folder
7280
# with Gitlab caching, .gradle is always owned by root and thus gradle's chmod invocation fails
7381
# This dance is a hack to have .gradle owned by the Gitlab runner user
@@ -143,6 +151,49 @@ test_published_artifacts:
143151
paths:
144152
- ./check_reports
145153

154+
.check_job:
155+
extends: .gradle_build
156+
needs: [ build ]
157+
stage: tests
158+
variables:
159+
BUILD_CACHE_TYPE: lib
160+
script:
161+
- ./gradlew $GRADLE_TARGET -PskipTests -PrunBuildSrcTests -PskipSpotless -PtaskPartitionCount=$NORMALIZED_NODE_TOTAL -PtaskPartition=$NORMALIZED_NODE_INDEX $GRADLE_ARGS
162+
after_script:
163+
- .circleci/collect_reports.sh --destination ./check_reports --move
164+
artifacts:
165+
when: always
166+
paths:
167+
- ./check_reports
168+
- '.gradle/daemon/*/*.out.log'
169+
170+
check_base:
171+
extends: .check_job
172+
variables:
173+
GRADLE_TARGET: ":baseCheck"
174+
175+
check_inst:
176+
extends: .check_job
177+
parallel: 4
178+
variables:
179+
GRADLE_TARGET: ":instrumentationCheck"
180+
181+
check_smoke:
182+
extends: .check_job
183+
parallel: 4
184+
variables:
185+
GRADLE_TARGET: ":smokeCheck"
186+
187+
check_profiling:
188+
extends: .check_job
189+
variables:
190+
GRADLE_TARGET: ":profilingCheck"
191+
192+
check_debugger:
193+
extends: .check_job
194+
variables:
195+
GRADLE_TARGET: ":debuggerCheck"
196+
146197
muzzle:
147198
extends: .gradle_build
148199
needs: [ build ]
@@ -154,13 +205,10 @@ muzzle:
154205
BUILD_CACHE_TYPE: test
155206
script:
156207
- export SKIP_BUILDSCAN="true"
157-
- echo CI_NODE_INDEX=$CI_NODE_INDEX
158-
- echo CI_NODE_TOTAL=CI_NODE_TOTAL
159208
- ./gradlew writeMuzzleTasksToFile $GRADLE_ARGS
160209
- sort workspace/build/muzzleTasks > sortedMuzzleTasks
161-
- split --number=l/$CI_NODE_TOTAL --suffix-length=1 --numeric-suffixes sortedMuzzleTasks muzzleSplit
162-
- export NODE_ZERO_INDEX=$((CI_NODE_INDEX - 1))
163-
- ./gradlew `cat muzzleSplit${NODE_ZERO_INDEX} | xargs` $GRADLE_ARGS
210+
- split --number=l/$NORMALIZED_NODE_TOTAL --suffix-length=1 --numeric-suffixes sortedMuzzleTasks muzzleSplit
211+
- ./gradlew `cat muzzleSplit${NORMALIZED_NODE_INDEX} | xargs` $GRADLE_ARGS
164212
after_script:
165213
- .circleci/collect_reports.sh
166214
artifacts:
@@ -260,6 +308,16 @@ required:
260308
optional: true
261309
- job: agent_integration_tests
262310
optional: true
311+
- job: check_base
312+
optional: true
313+
- job: check_inst
314+
optional: true
315+
- job: check_smoke
316+
optional: true
317+
- job: check_profiling
318+
optional: true
319+
- job: check_debugger
320+
optional: true
263321

264322
deploy_to_profiling_backend:
265323
stage: publish

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ private enum AgentFeature {
9696
CIVISIBILITY_AGENTLESS(CiVisibilityConfig.CIVISIBILITY_AGENTLESS_ENABLED, false),
9797
USM(UsmConfig.USM_ENABLED, false),
9898
TELEMETRY(GeneralConfig.TELEMETRY_ENABLED, true),
99-
DYNAMIC_INSTRUMENTATION(DebuggerConfig.DYNAMIC_INSTRUMENTATION_ENABLED, false),
100-
EXCEPTION_REPLAY(DebuggerConfig.EXCEPTION_REPLAY_ENABLED, false),
101-
CODE_ORIGIN(TraceInstrumentationConfig.CODE_ORIGIN_FOR_SPANS_ENABLED, false),
99+
DEBUGGER(DebuggerConfig.DYNAMIC_INSTRUMENTATION_ENABLED, false),
100+
EXCEPTION_DEBUGGING(DebuggerConfig.EXCEPTION_REPLAY_ENABLED, false),
101+
SPAN_ORIGIN(TraceInstrumentationConfig.CODE_ORIGIN_FOR_SPANS_ENABLED, false),
102102
DATA_JOBS(GeneralConfig.DATA_JOBS_ENABLED, false),
103103
AGENTLESS_LOG_SUBMISSION(GeneralConfig.AGENTLESS_LOG_SUBMISSION_ENABLED, false);
104104

@@ -149,10 +149,9 @@ public boolean isEnabledByDefault() {
149149
private static boolean ciVisibilityEnabled = false;
150150
private static boolean usmEnabled = false;
151151
private static boolean telemetryEnabled = true;
152-
private static boolean dynamicInstrumentationEnabled = false;
153-
private static boolean exceptionReplayEnabled = false;
154-
private static boolean codeOriginEnabled = false;
155-
private static boolean distributedDebuggerEnabled = false;
152+
private static boolean debuggerEnabled = false;
153+
private static boolean exceptionDebuggingEnabled = false;
154+
private static boolean spanOriginEnabled = false;
156155
private static boolean agentlessLogSubmissionEnabled = false;
157156

158157
/**
@@ -262,9 +261,9 @@ public static void start(
262261
|| isFeatureEnabled(AgentFeature.DEPRECATED_REMOTE_CONFIG);
263262
cwsEnabled = isFeatureEnabled(AgentFeature.CWS);
264263
telemetryEnabled = isFeatureEnabled(AgentFeature.TELEMETRY);
265-
dynamicInstrumentationEnabled = isFeatureEnabled(AgentFeature.DYNAMIC_INSTRUMENTATION);
266-
exceptionReplayEnabled = isFeatureEnabled(AgentFeature.EXCEPTION_REPLAY);
267-
codeOriginEnabled = isFeatureEnabled(AgentFeature.CODE_ORIGIN);
264+
debuggerEnabled = isFeatureEnabled(AgentFeature.DEBUGGER);
265+
exceptionDebuggingEnabled = isFeatureEnabled(AgentFeature.EXCEPTION_DEBUGGING);
266+
spanOriginEnabled = isFeatureEnabled(AgentFeature.SPAN_ORIGIN);
268267
agentlessLogSubmissionEnabled = isFeatureEnabled(AgentFeature.AGENTLESS_LOG_SUBMISSION);
269268

270269
if (profilingEnabled) {
@@ -1115,10 +1114,7 @@ private static void shutdownProfilingAgent(final boolean sync) {
11151114
}
11161115

11171116
private static void maybeStartDebugger(Instrumentation inst, Class<?> scoClass, Object sco) {
1118-
if (isExplicitlyDisabled(DebuggerConfig.DYNAMIC_INSTRUMENTATION_ENABLED)
1119-
&& isExplicitlyDisabled(DebuggerConfig.EXCEPTION_REPLAY_ENABLED)
1120-
&& isExplicitlyDisabled(TraceInstrumentationConfig.CODE_ORIGIN_FOR_SPANS_ENABLED)
1121-
&& isExplicitlyDisabled(DebuggerConfig.DISTRIBUTED_DEBUGGER_ENABLED)) {
1117+
if (!debuggerEnabled && !exceptionDebuggingEnabled && !spanOriginEnabled) {
11221118
return;
11231119
}
11241120
if (!remoteConfigEnabled) {
@@ -1128,11 +1124,6 @@ && isExplicitlyDisabled(DebuggerConfig.DISTRIBUTED_DEBUGGER_ENABLED)) {
11281124
startDebuggerAgent(inst, scoClass, sco);
11291125
}
11301126

1131-
private static boolean isExplicitlyDisabled(String booleanKey) {
1132-
return Config.get().configProvider().isSet(booleanKey)
1133-
&& !Config.get().configProvider().getBoolean(booleanKey);
1134-
}
1135-
11361127
private static synchronized void startDebuggerAgent(
11371128
Instrumentation inst, Class<?> scoClass, Object sco) {
11381129
StaticEventLogger.begin("Debugger");

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import datadog.trace.api.civisibility.execution.TestExecutionPolicy;
66
import datadog.trace.api.civisibility.telemetry.tag.SkipReason;
77
import datadog.trace.api.civisibility.telemetry.tag.TestFrameworkInstrumentation;
8+
import java.util.Collection;
89
import javax.annotation.Nonnull;
910
import javax.annotation.Nullable;
1011

@@ -47,7 +48,8 @@ TestSuiteImpl testSuiteStart(
4748
SkipReason skipReason(TestIdentifier test);
4849

4950
@Nonnull
50-
TestExecutionPolicy executionPolicy(TestIdentifier test, TestSourceData testSource);
51+
TestExecutionPolicy executionPolicy(
52+
TestIdentifier test, TestSourceData testSource, Collection<String> testTags);
5153

5254
/**
5355
* Returns the priority of the test execution that can be used for ordering tests. The higher the

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import datadog.trace.api.civisibility.telemetry.tag.SkipReason;
3030
import datadog.trace.api.civisibility.telemetry.tag.TestFrameworkInstrumentation;
3131
import datadog.trace.api.gateway.RequestContextSlot;
32-
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
3332
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
3433
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext;
3534
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
@@ -230,23 +229,22 @@ public void setSkipReason(String skipReason) {
230229
public void end(@Nullable Long endTime) {
231230
closeOutstandingSpans();
232231

233-
final AgentScope scope = AgentTracer.activeScope();
234-
if (scope == null) {
232+
final AgentSpan activeSpan = AgentTracer.activeSpan();
233+
if (activeSpan == null) {
235234
throw new IllegalStateException(
236-
"No active scope present, it is possible that end() was called multiple times");
235+
"No active span present, it is possible that end() was called multiple times");
237236
}
238237

239-
AgentSpan scopeSpan = scope.span();
240-
if (scopeSpan != span) {
238+
if (activeSpan != this.span) {
241239
throw new IllegalStateException(
242-
"Active scope does not correspond to the finished test, "
240+
"Active span does not correspond to the finished test, "
243241
+ "it is possible that end() was called multiple times "
244242
+ "or an operation that was started by the test is still in progress; "
245-
+ "active scope span is: "
246-
+ scopeSpan
243+
+ "active span is: "
244+
+ activeSpan
247245
+ "; "
248246
+ "expected span is: "
249-
+ span);
247+
+ this.span);
250248
}
251249

252250
InstrumentationTestBridge.fireBeforeTestEnd(context);
@@ -263,7 +261,7 @@ public void end(@Nullable Long endTime) {
263261
}
264262
}
265263

266-
scope.close();
264+
AgentTracer.closeActive();
267265

268266
onSpanFinish.accept(span);
269267

@@ -310,18 +308,17 @@ public void end(@Nullable Long endTime) {
310308
* spans stack until it encounters a CI Visibility span or the stack is empty.
311309
*/
312310
private void closeOutstandingSpans() {
313-
AgentScope scope;
314-
while ((scope = AgentTracer.activeScope()) != null) {
315-
AgentSpan span = scope.span();
311+
AgentSpan activeSpan;
312+
while ((activeSpan = AgentTracer.activeSpan()) != null) {
316313

317-
if (span == this.span || span.getTag(Tags.TEST_SESSION_ID) != null) {
314+
if (activeSpan == this.span || activeSpan.getTag(Tags.TEST_SESSION_ID) != null) {
318315
// encountered this span or another CI Visibility span (test, suite, module, session)
319316
break;
320317
}
321318

322-
log.debug("Closing outstanding span: {}", span);
323-
scope.close();
324-
span.finish();
319+
log.debug("Closing outstanding span: {}", activeSpan);
320+
AgentTracer.closeActive();
321+
activeSpan.finish();
325322
}
326323
}
327324
}

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import datadog.trace.api.civisibility.telemetry.CiVisibilityMetricCollector;
1212
import datadog.trace.api.civisibility.telemetry.tag.EventType;
1313
import datadog.trace.api.civisibility.telemetry.tag.TestFrameworkInstrumentation;
14-
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
1514
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
1615
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext;
1716
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
@@ -193,26 +192,25 @@ public void setSkipReason(String skipReason) {
193192
@Override
194193
public void end(@Nullable Long endTime) {
195194
if (!parallelized) {
196-
final AgentScope scope = AgentTracer.activeScope();
197-
if (scope == null) {
195+
final AgentSpan activeSpan = AgentTracer.activeSpan();
196+
if (activeSpan == null) {
198197
throw new IllegalStateException(
199-
"No active scope present, it is possible that end() was called multiple times");
198+
"No active span present, it is possible that end() was called multiple times");
200199
}
201200

202-
AgentSpan scopeSpan = scope.span();
203-
if (scopeSpan != span) {
201+
if (activeSpan != this.span) {
204202
throw new IllegalStateException(
205-
"Active scope does not correspond to the finished suite, "
203+
"Active span does not correspond to the finished suite, "
206204
+ "it is possible that end() was called multiple times "
207205
+ "or an operation that was started by the suite is still in progress; "
208-
+ "active scope span is: "
209-
+ scopeSpan
206+
+ "active span is: "
207+
+ activeSpan
210208
+ "; "
211209
+ "expected span is: "
212-
+ span);
210+
+ this.span);
213211
}
214212

215-
scope.close();
213+
AgentTracer.closeActive();
216214
}
217215

218216
onSpanFinish.accept(span);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ public SkipReason skipReason(TestIdentifier test) {
127127

128128
@Override
129129
@Nonnull
130-
public TestExecutionPolicy executionPolicy(TestIdentifier test, TestSourceData testSource) {
131-
return executionStrategy.executionPolicy(test, testSource);
130+
public TestExecutionPolicy executionPolicy(
131+
TestIdentifier test, TestSourceData testSource, Collection<String> testTags) {
132+
return executionStrategy.executionPolicy(test, testSource, testTags);
132133
}
133134

134135
@Override

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import datadog.trace.civisibility.test.ExecutionResults;
2828
import datadog.trace.civisibility.test.ExecutionStrategy;
2929
import datadog.trace.civisibility.utils.SpanUtils;
30+
import java.util.Collection;
3031
import java.util.function.Consumer;
3132
import javax.annotation.Nonnull;
3233
import javax.annotation.Nullable;
@@ -112,8 +113,9 @@ public SkipReason skipReason(TestIdentifier test) {
112113

113114
@Override
114115
@Nonnull
115-
public TestExecutionPolicy executionPolicy(TestIdentifier test, TestSourceData testSource) {
116-
return executionStrategy.executionPolicy(test, testSource);
116+
public TestExecutionPolicy executionPolicy(
117+
TestIdentifier test, TestSourceData testSource, Collection<String> testTags) {
118+
return executionStrategy.executionPolicy(test, testSource, testTags);
117119
}
118120

119121
@Override

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/events/NoOpTestEventsHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ public SkipReason skipReason(TestIdentifier test) {
100100

101101
@NotNull
102102
@Override
103-
public TestExecutionPolicy executionPolicy(TestIdentifier test, TestSourceData source) {
103+
public TestExecutionPolicy executionPolicy(
104+
TestIdentifier test, TestSourceData source, Collection<String> testTags) {
104105
return Regular.INSTANCE;
105106
}
106107

0 commit comments

Comments
 (0)