Skip to content

Commit 8389804

Browse files
authored
Merge branch 'master' into mtoff/stable_cfg_2
2 parents a62edd3 + 4f278de commit 8389804

File tree

16 files changed

+94
-38
lines changed

16 files changed

+94
-38
lines changed

.circleci/config.continue.yml.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ jobs:
414414
name: Check Project
415415
command: >-
416416
MAVEN_OPTS="-Xms64M -Xmx256M"
417-
GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx3G -Xms2G -XX:ErrorFile=/tmp/hs_err_pid%p.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp'"
417+
GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx2G -Xms2G -XX:ErrorFile=/tmp/hs_err_pid%p.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp'"
418418
./gradlew
419419
<< parameters.gradleTarget >>
420420
-PskipTests
@@ -1105,7 +1105,7 @@ build_test_jobs: &build_test_jobs
11051105
requires:
11061106
- ok_to_test
11071107
name: check_inst
1108-
parallelism: 4
1108+
parallelism: 5
11091109
gradleTarget: ":instrumentationCheck"
11101110
cacheType: inst
11111111
triggeredBy: *instrumentation_modules

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import datadog.trace.api.config.UsmConfig;
3232
import datadog.trace.api.gateway.RequestContextSlot;
3333
import datadog.trace.api.gateway.SubscriptionService;
34+
import datadog.trace.api.git.EmbeddedGitInfoBuilder;
35+
import datadog.trace.api.git.GitInfoProvider;
3436
import datadog.trace.api.profiling.ProfilingEnablement;
3537
import datadog.trace.api.scopemanager.ScopeListener;
3638
import datadog.trace.bootstrap.benchmark.StaticEventLogger;
@@ -225,6 +227,12 @@ public static void start(
225227
}
226228
}
227229

230+
// Enable automatic fetching of git tags from datadog_git.properties only if CI Visibility is
231+
// not enabled
232+
if (!ciVisibilityEnabled) {
233+
GitInfoProvider.INSTANCE.registerGitInfoBuilder(new EmbeddedGitInfoBuilder());
234+
}
235+
228236
boolean dataJobsEnabled = isFeatureEnabled(AgentFeature.DATA_JOBS);
229237
if (dataJobsEnabled) {
230238
log.info("Data Jobs Monitoring enabled, enabling spark integrations");

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package datadog.trace.civisibility.domain;
22

33
import static datadog.json.JsonMapper.toJson;
4-
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
4+
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpanWithoutScope;
55
import static datadog.trace.civisibility.Constants.CI_VISIBILITY_INSTRUMENTATION_NAME;
66

77
import datadog.trace.api.Config;
@@ -116,7 +116,7 @@ public TestImpl(
116116

117117
span = spanBuilder.start();
118118

119-
activateSpan(span);
119+
activateSpanWithoutScope(span);
120120

121121
span.setSpanType(InternalSpanTypes.TEST);
122122
span.setTag(Tags.SPAN_KIND, Tags.SPAN_KIND_TEST);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package datadog.trace.civisibility.domain;
22

33
import static datadog.json.JsonMapper.toJson;
4-
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
4+
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpanWithoutScope;
55
import static datadog.trace.civisibility.Constants.CI_VISIBILITY_INSTRUMENTATION_NAME;
66

77
import datadog.trace.api.Config;
@@ -130,7 +130,7 @@ public TestSuiteImpl(
130130
testDecorator.afterStart(span);
131131

132132
if (!parallelized) {
133-
activateSpan(span);
133+
activateSpanWithoutScope(span);
134134
}
135135

136136
metricCollector.add(CiVisibilityCountMetric.EVENT_CREATED, 1, instrumentation, EventType.SUITE);

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/DebuggerAgent.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ public static void startDynamicInstrumentation() {
172172
} else {
173173
LOGGER.debug("No configuration poller available from SharedCommunicationObjects");
174174
}
175+
LOGGER.info("Started Dynamic Instrumentation");
175176
}
176177

177178
public static void stopDynamicInstrumentation() {
@@ -205,6 +206,7 @@ public static void startExceptionReplay() {
205206
Duration.ofSeconds(config.getDebuggerExceptionCaptureInterval()),
206207
config.getDebuggerMaxExceptionPerSecond());
207208
DebuggerContext.initExceptionDebugger(exceptionDebugger);
209+
LOGGER.info("Started Exception Replay");
208210
}
209211

210212
public static void stopExceptionReplay() {
@@ -230,6 +232,7 @@ public static void startCodeOriginForSpans() {
230232
initClassNameFilter();
231233
DebuggerContext.initClassNameFilter(classNameFilter);
232234
DebuggerContext.initCodeOrigin(new DefaultCodeOriginRecorder(config, configurationUpdater));
235+
LOGGER.info("Started Code Origin for spans");
233236
}
234237

235238
public static void stopCodeOriginForSpans() {

dd-java-agent/instrumentation/aws-java-sdk-1.11.0/src/main/java/datadog/trace/instrumentation/aws/v0/TracingRequestHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import static datadog.trace.api.datastreams.DataStreamsContext.create;
44
import static datadog.trace.bootstrap.instrumentation.api.AgentPropagation.XRAY_TRACING_CONCERN;
5-
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
5+
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpanWithoutScope;
66
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.blackholeSpan;
77
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
88
import static datadog.trace.core.datastreams.TagsProcessor.DIRECTION_IN;
@@ -55,7 +55,7 @@ public void beforeRequest(final Request<?> request) {
5555
if (!AWS_LEGACY_TRACING && isPollingRequest(request.getOriginalRequest())) {
5656
// SQS messages spans are created by aws-java-sqs-1.0 - replace client scope with no-op,
5757
// so we can tell when receive call is complete without affecting the rest of the trace
58-
activateSpan(blackholeSpan());
58+
activateSpanWithoutScope(blackholeSpan());
5959
} else {
6060
span = requestSpanStore.remove(request.getOriginalRequest());
6161
if (span != null) {
@@ -78,9 +78,9 @@ public void beforeRequest(final Request<?> request) {
7878
}
7979
// This scope will be closed by AwsHttpClientInstrumentation
8080
if (AWS_LEGACY_TRACING) {
81-
activateSpan(span);
81+
activateSpanWithoutScope(span);
8282
} else {
83-
activateSpan(blackholeSpan());
83+
activateSpanWithoutScope(blackholeSpan());
8484
}
8585
}
8686
}

dd-java-agent/instrumentation/aws-java-sdk-2.2/src/main/java/datadog/trace/instrumentation/aws/v2/TracingExecutionInterceptor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static datadog.trace.bootstrap.instrumentation.api.AgentPropagation.XRAY_TRACING_CONCERN;
44
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
5+
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpanWithoutScope;
56
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.blackholeSpan;
67
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
78
import static datadog.trace.instrumentation.aws.v2.AwsSdkClientDecorator.AWS_LEGACY_TRACING;
@@ -93,7 +94,7 @@ public void beforeTransmission(
9394
if (span != null) {
9495
// This scope will be closed by AwsHttpClientInstrumentation since ExecutionInterceptor API
9596
// doesn't provide a way to run code in same thread after transmission has been scheduled.
96-
activateSpan(span);
97+
activateSpanWithoutScope(span);
9798
}
9899
}
99100

dd-java-agent/instrumentation/karate/src/main/java/datadog/trace/instrumentation/karate/KarateTracingHook.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import datadog.trace.api.civisibility.telemetry.tag.SkipReason;
2323
import datadog.trace.api.civisibility.telemetry.tag.TestFrameworkInstrumentation;
2424
import datadog.trace.bootstrap.ContextStore;
25-
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
2625
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
2726
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
2827
import datadog.trace.bootstrap.instrumentation.api.Tags;
@@ -198,7 +197,7 @@ public boolean beforeStep(Step step, ScenarioRuntime sr) {
198197
return true;
199198
}
200199
AgentSpan span = AgentTracer.startSpan("karate", KARATE_STEP_SPAN_NAME);
201-
AgentScope scope = AgentTracer.activateSpan(span);
200+
AgentTracer.activateSpanWithoutScope(span);
202201
String stepName = step.getPrefix() + " " + step.getText();
203202
span.setResourceName(stepName);
204203
span.setTag(Tags.COMPONENT, "karate");

dd-java-agent/instrumentation/undertow/undertow-2.0/src/main/java/datadog/trace/instrumentation/undertow/HttpRequestParserInstrumentation.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
55
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
66
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
7-
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.closeActive;
87
import static datadog.trace.instrumentation.undertow.UndertowDecorator.DECORATE;
98
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
109
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
@@ -92,7 +91,7 @@ public static void afterRequestParse(
9291
if (scope != null) {
9392
scope.close();
9493
} else {
95-
closeActive();
94+
// span was already active, scope will be closed by HandlerInstrumentation
9695
}
9796
}
9897
}

dd-smoke-tests/debugger-integration-tests/src/main/java/datadog/smoketest/debugger/ServerDebuggerTestApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected void stop() {
7676
}
7777

7878
protected void waitForInstrumentation(String className) {
79-
System.out.println("waitForInstrumentation on " + className + " from: " + lastMatchedLine);
79+
System.out.println("waitForInstrumentation on " + className);
8080
try {
8181
lastMatchedLine =
8282
TestApplicationHelper.waitForInstrumentation(LOG_FILENAME, className, lastMatchedLine);

dd-smoke-tests/debugger-integration-tests/src/test/java/datadog/smoketest/InProductEnablementIntegrationTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static datadog.smoketest.debugger.TestApplicationHelper.waitForSpecificLine;
44

55
import com.datadog.debugger.probe.LogProbe;
6-
import datadog.trace.test.util.Flaky;
76
import java.io.IOException;
87
import java.nio.file.Path;
98
import java.util.ArrayList;
@@ -53,7 +52,6 @@ void testDynamicInstrumentationEnablementStaticallyDisabled() throws Exception {
5352
waitForSpecificLine(appUrl, "Feature dynamic.instrumentation.enabled is explicitly disabled");
5453
}
5554

56-
@Flaky
5755
@Test
5856
@DisplayName("testExceptionReplayEnablement")
5957
void testExceptionReplayEnablement() throws Exception {
@@ -70,7 +68,7 @@ void testExceptionReplayEnablement() throws Exception {
7068
}
7169

7270
private void waitForFeatureStarted(String appUrl, String feature) throws IOException {
73-
String line = "INFO com.datadog.debugger.agent.DebuggerAgent - Starting " + feature;
71+
String line = "INFO com.datadog.debugger.agent.DebuggerAgent - Started " + feature;
7472
waitForSpecificLine(appUrl, line);
7573
LOG.info("feature {} started", feature);
7674
}

dd-trace-core/src/main/java/datadog/trace/core/CoreTracer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,12 @@ public AgentScope activateManualSpan(final AgentSpan span) {
916916
return scopeManager.activateManualSpan(span);
917917
}
918918

919+
@Override
920+
@SuppressWarnings("resource")
921+
public void activateSpanWithoutScope(AgentSpan span) {
922+
scopeManager.activateSpan(span);
923+
}
924+
919925
@Override
920926
public AgentScope.Continuation captureActiveSpan() {
921927
return scopeManager.captureActiveSpan();

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ okhttp = "3.12.15" # Datadog fork to support Java 7
66
okhttp-legacy = "[3.0,3.12.12]" # 3.12.x is last version to support Java7
77
okio = "1.17.6" # Datadog fork
88

9-
spock = "2.2-groovy-3.0"
9+
spock = "2.3-groovy-3.0"
1010
groovy = "3.0.17"
1111
junit5 = "5.9.2"
1212
logback = "1.2.3"

internal-api/src/main/java/datadog/trace/api/git/EmbeddedGitInfoBuilder.java

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.io.IOException;
44
import java.io.InputStream;
5+
import java.util.Arrays;
6+
import java.util.List;
57
import java.util.Properties;
68
import javax.annotation.Nullable;
79
import org.slf4j.Logger;
@@ -11,29 +13,44 @@ public class EmbeddedGitInfoBuilder implements GitInfoBuilder {
1113

1214
private static final Logger log = LoggerFactory.getLogger(EmbeddedGitInfoBuilder.class);
1315

14-
private static final String EMBEDDED_GIT_PROPERTIES_FILE_NAME = "git.properties";
15-
16-
private final String resourceName;
16+
private final List<String> resourceNames;
1717

1818
public EmbeddedGitInfoBuilder() {
19-
this(EMBEDDED_GIT_PROPERTIES_FILE_NAME);
19+
// Order is important here, from the most reliable sources to the least reliable ones
20+
this(
21+
Arrays.asList(
22+
// Spring boot fat jars and wars should have the git.properties file in the following
23+
// specific paths, guaranteeing that it's not coming from a dependency
24+
"BOOT-INF/classes/datadog_git.properties",
25+
"BOOT-INF/classes/git.properties",
26+
"WEB-INF/classes/datadog_git.properties",
27+
"WEB-INF/classes/git.properties",
28+
// If we can't find the files above, probably because we're not in a spring context, we
29+
// can look at the root of the classpath. Since it could be tainted by dependencies,
30+
// we're looking for a specific datadog_git.properties file.
31+
"datadog_git.properties"));
2032
}
2133

22-
EmbeddedGitInfoBuilder(String resourceName) {
23-
this.resourceName = resourceName;
34+
EmbeddedGitInfoBuilder(List<String> resourceNames) {
35+
this.resourceNames = resourceNames;
2436
}
2537

2638
@Override
2739
public GitInfo build(@Nullable String repositoryPath) {
2840
Properties gitProperties = new Properties();
29-
try (InputStream is = ClassLoader.getSystemResourceAsStream(resourceName)) {
30-
if (is != null) {
31-
gitProperties.load(is);
32-
} else {
33-
log.debug("Could not find embedded Git properties resource: {}", resourceName);
41+
42+
for (String resourceName : resourceNames) {
43+
try (InputStream is = ClassLoader.getSystemResourceAsStream(resourceName)) {
44+
if (is != null) {
45+
gitProperties.load(is);
46+
// stop at the first git properties file found
47+
break;
48+
} else {
49+
log.debug("Could not find embedded Git properties resource: {}", resourceName);
50+
}
51+
} catch (IOException e) {
52+
log.error("Error reading embedded Git properties from {}", resourceName, e);
3453
}
35-
} catch (IOException e) {
36-
log.error("Error reading embedded Git properties from {}", resourceName, e);
3754
}
3855

3956
String commitSha = gitProperties.getProperty("git.commit.id");

internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api/AgentTracer.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ public static AgentScope activateSpan(final AgentSpan span) {
8787
return get().activateSpan(span);
8888
}
8989

90+
/**
91+
* Activate a span which will be closed by {@link #closeActive()} instead of a scope.
92+
*
93+
* @deprecated This should only be used when the instrumented code doesn't align with a scope.
94+
*/
95+
@Deprecated
96+
public static void activateSpanWithoutScope(final AgentSpan span) {
97+
get().activateSpanWithoutScope(span);
98+
}
99+
90100
/**
91101
* When asynchronous propagation is enabled, prevent the currently active trace from reporting
92102
* until the returned Continuation is either activated (and the returned scope is closed) or the
@@ -142,8 +152,8 @@ public static void rollbackActiveToCheckpoint() {
142152
/**
143153
* Closes the scope for the currently active span.
144154
*
145-
* @deprecated This should only be used when an instrumentation does not have access to the
146-
* original scope returned by {@link #activateSpan}.
155+
* @deprecated This should only be used when the span was previously activated with {@link
156+
* #activateSpanWithoutScope} because the instrumented code didn't align with a scope.
147157
*/
148158
@Deprecated
149159
public static void closeActive() {
@@ -338,6 +348,9 @@ AgentSpan startSpan(
338348
/** Activate a span from outside auto-instrumentation, i.e. a manual or custom span. */
339349
AgentScope activateManualSpan(AgentSpan span);
340350

351+
/** Activate a span which will be closed by {@link #closeActive()} instead of a scope. */
352+
void activateSpanWithoutScope(AgentSpan span);
353+
341354
@Override
342355
AgentScope.Continuation captureActiveSpan();
343356

@@ -483,6 +496,9 @@ public AgentScope activateManualSpan(final AgentSpan span) {
483496
return NoopScope.INSTANCE;
484497
}
485498

499+
@Override
500+
public void activateSpanWithoutScope(final AgentSpan span) {}
501+
486502
@Override
487503
public AgentScope.Continuation captureActiveSpan() {
488504
return NoopContinuation.INSTANCE;

internal-api/src/test/groovy/datadog/trace/api/git/EmbeddedGitInfoBuilderTest.groovy

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class EmbeddedGitInfoBuilderTest extends Specification {
77

88
def "test no embedded git info"() {
99
when:
10-
def gitInfo = new EmbeddedGitInfoBuilder("non-existent-git.properties").build(null)
10+
def gitInfo = new EmbeddedGitInfoBuilder(["non-existent-git.properties"]).build(null)
1111

1212
then:
1313
gitInfo.isEmpty()
@@ -16,7 +16,7 @@ class EmbeddedGitInfoBuilderTest extends Specification {
1616
def "test maven-plugin-generated git info"() {
1717
when:
1818
def mavenGitProperties = "datadog/trace/bootstrap/git/maven-git.properties"
19-
def gitInfo = new EmbeddedGitInfoBuilder(mavenGitProperties).build(null)
19+
def gitInfo = new EmbeddedGitInfoBuilder([mavenGitProperties]).build(null)
2020

2121
then:
2222
gitInfo.repositoryURL == "[email protected]:DataDog/ciapp-test-resources.git"
@@ -35,7 +35,7 @@ class EmbeddedGitInfoBuilderTest extends Specification {
3535
def "test gradle-plugin-generated git info"() {
3636
when:
3737
def gradleGitProperties = "datadog/trace/bootstrap/git/gradle-git.properties"
38-
def gitInfo = new EmbeddedGitInfoBuilder(gradleGitProperties).build(null)
38+
def gitInfo = new EmbeddedGitInfoBuilder([gradleGitProperties]).build(null)
3939

4040
then:
4141
gitInfo.repositoryURL == "[email protected]:DataDog/ciapp-test-resources.git"
@@ -50,4 +50,13 @@ class EmbeddedGitInfoBuilderTest extends Specification {
5050
gitInfo.commit.committer.email == "[email protected]"
5151
gitInfo.commit.committer.iso8601Date == "2023-03-22T14:43:21+0100"
5252
}
53+
54+
def "test embedded gitinfo has a lower priority than user supplied gitinfo"() {
55+
when:
56+
def embeddedGitInfoBuilder = new EmbeddedGitInfoBuilder()
57+
def userSuppliedGitInfoBuilder = new UserSuppliedGitInfoBuilder()
58+
59+
then:
60+
embeddedGitInfoBuilder.order() > userSuppliedGitInfoBuilder.order()
61+
}
5362
}

0 commit comments

Comments
 (0)