Skip to content

Commit 65a8c19

Browse files
authored
Merge branch 'master' into andrea.marziali/rum-jboss-fix
2 parents 1b1a350 + 5aa25ba commit 65a8c19

15 files changed

Lines changed: 160 additions & 97 deletions

File tree

dd-java-agent/instrumentation/java-concurrent/java-concurrent-21/build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ tasks.named("check").configure {
4646

4747
dependencies {
4848
testImplementation project(':dd-java-agent:instrumentation:trace-annotation')
49-
50-
// Using Spock 2.4-M6 because it contains fix for deadlock when blocking in mock response generators.
51-
// See: https://github.com/spockframework/spock/pull/1910
52-
testImplementation libs.spock24.core
53-
testImplementation libs.spock24.junit4
5449
}
5550

5651
// Set all compile tasks to use JDK21 but let instrumentation code targets 1.8 compatibility

dd-java-agent/instrumentation/java-concurrent/java-concurrent-21/src/previewTest/groovy/StructuredConcurrencyTest.groovy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import static datadog.trace.agent.test.utils.TraceUtils.runnableUnderTrace
99
import static java.time.Instant.now
1010

1111
class StructuredConcurrencyTest extends AgentTestRunner {
12+
@Override
13+
boolean useStrictTraceWrites() {
14+
// TODO: Monitor in CI to validate fix effectiveness against freezes.
15+
return false
16+
}
17+
1218
/**
1319
* Tests the structured task scope with a single task.
1420
*/

dd-java-agent/instrumentation/lettuce-4/src/test/groovy/Lettuce4ClientTestBase.groovy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,10 @@ abstract class Lettuce4ClientTestBase extends VersionedNamingTestBase {
8383
redisClient.shutdown()
8484
redisServer.stop()
8585
}
86+
87+
@Override
88+
boolean useStrictTraceWrites() {
89+
// TODO: Monitor in CI to validate fix effectiveness against freezes.
90+
return false
91+
}
8692
}

dd-java-agent/instrumentation/vertx-redis-client-3.9/src/test/groovy/VertxRedisAPITestBase.groovy

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import datadog.trace.test.util.Flaky
2-
3-
import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
4-
52
import io.vertx.core.AsyncResult
63
import io.vertx.core.Handler
74
import io.vertx.redis.client.RedisAPI
85
import io.vertx.redis.client.Response
96
import spock.lang.AutoCleanup
107
import spock.lang.Shared
8+
import spock.util.concurrent.PollingConditions
119

1210
import java.util.concurrent.CountDownLatch
1311
import java.util.concurrent.TimeUnit
1412

13+
import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
14+
1515
abstract class VertxRedisAPITestBase extends VertxRedisTestBase {
1616

1717
@AutoCleanup(quiet = true)
@@ -154,21 +154,34 @@ class VertxRedisAPIRedisForkedTest extends VertxRedisAPITestBase {
154154
class VertxRedisAPIRedisConnectionForkedTest extends VertxRedisAPITestBase {
155155
@Override
156156
RedisAPI createRedis() {
157+
RedisAPI api = null
158+
159+
new PollingConditions(delay: 3, timeout: 15).eventually {
160+
(api = connect()) != null
161+
}
162+
163+
return api
164+
}
165+
166+
private RedisAPI connect() {
157167
def latch = new CountDownLatch(1)
158-
def ret
159-
redis.connect({ar ->
168+
RedisAPI api = null
169+
redis.connect({ ar ->
160170
try {
161-
if (!ar.succeeded()) {
171+
if (ar.succeeded()) {
172+
api = RedisAPI.api(ar.result())
173+
} else {
174+
println "Redis connection failed"
162175
ar.cause().printStackTrace(System.out)
163176
}
164-
ret = RedisAPI.api(ar.result())
165177
} catch (Throwable t) {
166178
t.printStackTrace(System.out)
167179
} finally {
168180
latch.countDown()
169181
}
170182
})
171183
latch.await(10, TimeUnit.SECONDS)
172-
return ret
184+
185+
return api
173186
}
174187
}

dd-java-agent/instrumentation/vertx-redis-client-3.9/src/test/groovy/VertxRedisTestBase.groovy

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
import org.testcontainers.utility.DockerImageName
2-
3-
import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
4-
import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
5-
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan
6-
71
import com.redis.testcontainers.RedisContainer
82
import datadog.trace.agent.test.asserts.ListWriterAssert
93
import datadog.trace.agent.test.asserts.TraceAssert
@@ -21,13 +15,18 @@ import io.vertx.redis.client.Redis
2115
import io.vertx.redis.client.Request
2216
import io.vertx.redis.client.Response
2317
import org.testcontainers.containers.wait.strategy.Wait
18+
import org.testcontainers.utility.DockerImageName
2419
import spock.lang.AutoCleanup
2520
import spock.lang.Shared
2621

2722
import java.util.concurrent.CountDownLatch
2823
import java.util.concurrent.TimeUnit
2924
import java.util.function.Function
3025

26+
import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
27+
import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
28+
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan
29+
3130
abstract class VertxRedisTestBase extends VersionedNamingTestBase {
3231

3332
@Shared
@@ -86,11 +85,12 @@ abstract class VertxRedisTestBase extends VersionedNamingTestBase {
8685
TEST_WRITER.start()
8786
}
8887

89-
public <T, R> R runWithHandler(final Handler<Handler<AsyncResult<T>>> redisCommand,
90-
final Function<T, R> resultFunction = null) {
88+
<T, R> R runWithHandler(final Handler<Handler<AsyncResult<T>>> redisCommand,
89+
final Function<T, R> resultFunction = null) {
9190
R result = null
9291
CountDownLatch latch = new CountDownLatch(1)
93-
redisCommand.handle({ ar ->
92+
redisCommand.handle({
93+
ar ->
9494
runUnderTrace("handler") {
9595
if (resultFunction) {
9696
result = resultFunction.apply(ar.result())
@@ -102,8 +102,8 @@ abstract class VertxRedisTestBase extends VersionedNamingTestBase {
102102
result
103103
}
104104

105-
public <T, R> R runWithParentAndHandler(final Handler<Handler<AsyncResult<T>>> redisCommand,
106-
final Function<T, R> resultFunction = null) {
105+
def <T, R> R runWithParentAndHandler(final Handler<Handler<AsyncResult<T>>> redisCommand,
106+
final Function<T, R> resultFunction = null) {
107107
R result = null
108108
def parentSpan = runUnderTrace("parent") {
109109
result = runWithHandler(redisCommand, resultFunction)
@@ -160,8 +160,4 @@ abstract class VertxRedisTestBase extends VersionedNamingTestBase {
160160
List<String> responseToStrings(Response r) {
161161
r.iterator().collect { it.toString() }
162162
}
163-
164-
public <T> T identity(T t) {
165-
return t
166-
}
167163
}

dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,7 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
11831183
}
11841184
}
11851185

1186+
@Flaky(value = "https://github.com/DataDog/dd-trace-java/issues/9396", suites = ["PekkoHttpServerInstrumentationAsyncHttp2Test"])
11861187
def "test exception"() {
11871188
setup:
11881189
def method = "GET"

dd-trace-core/src/main/java/datadog/trace/core/monitor/TracerHealthMetrics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ private static class Flush implements AgentTaskScheduler.Task<TracerHealthMetric
417417
private static final String[] UNSET_TAG = new String[] {"priority:unset"};
418418
private static final String[] SINGLE_SPAN_SAMPLER = new String[] {"sampler:single-span"};
419419

420-
private final long[] previousCounts = new long[43];
420+
private final long[] previousCounts = new long[50];
421421
private int countIndex;
422422

423423
@Override

internal-api/src/main/java/datadog/trace/api/ConfigOrigin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public enum ConfigOrigin {
1919
DD_CONFIG("dd_config"),
2020
/** set for cases where it is difficult/not possible to determine the source of a config. */
2121
UNKNOWN("unknown"),
22+
/** set when the config is calculated from multiple configs */
23+
CALCULATED("calculated"),
2224
/** set when the user has not set any configuration for the key (defaults to a value) */
2325
DEFAULT("default");
2426

internal-api/src/main/java/datadog/trace/bootstrap/config/provider/ConfigConverter.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ final class ConfigConverter {
2121

2222
private static final Logger log = LoggerFactory.getLogger(ConfigConverter.class);
2323

24+
/**
25+
* Custom exception for invalid boolean values to maintain backward compatibility. When caught in
26+
* ConfigProvider, boolean methods should return false instead of default value.
27+
*/
28+
static class InvalidBooleanValueException extends IllegalArgumentException {
29+
public InvalidBooleanValueException(String message) {
30+
super(message);
31+
}
32+
}
33+
2434
private static final ValueOfLookup LOOKUP = new ValueOfLookup();
2535

2636
/**
@@ -39,6 +49,8 @@ static <T> T valueOf(final String value, @Nonnull final Class<T> tClass) {
3949
return (T) LOOKUP.get(tClass).invoke(value);
4050
} catch (final NumberFormatException e) {
4151
throw e;
52+
} catch (final IllegalArgumentException e) {
53+
throw e;
4254
} catch (final Throwable e) {
4355
log.debug("Can't parse: ", e);
4456
throw new NumberFormatException(e.toString());
@@ -413,8 +425,15 @@ static BitSet parseIntegerRangeSet(@Nonnull String str, final String settingName
413425
public static Boolean booleanValueOf(String value) {
414426
if ("1".equals(value)) {
415427
return Boolean.TRUE;
428+
} else if ("0".equals(value)) {
429+
return Boolean.FALSE;
430+
} else if ("true".equalsIgnoreCase(value)) {
431+
return Boolean.TRUE;
432+
} else if ("false".equalsIgnoreCase(value)) {
433+
return Boolean.FALSE;
416434
} else {
417-
return Boolean.valueOf(value);
435+
// Throw custom exception for invalid boolean values to maintain backward compatibility
436+
throw new InvalidBooleanValueException("Invalid boolean value: " + value);
418437
}
419438
}
420439

internal-api/src/main/java/datadog/trace/bootstrap/config/provider/ConfigProvider.java

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,27 @@ public double getDouble(String key, double defaultValue) {
193193

194194
private <T> T get(String key, T defaultValue, Class<T> type, String... aliases) {
195195
for (ConfigProvider.Source source : sources) {
196+
String sourceValue = source.get(key, aliases);
196197
try {
197-
String sourceValue = source.get(key, aliases);
198198
T value = ConfigConverter.valueOf(sourceValue, type);
199199
if (value != null) {
200200
if (collectConfig) {
201201
ConfigCollector.get().put(key, sourceValue, source.origin());
202202
}
203203
return value;
204204
}
205-
} catch (NumberFormatException ex) {
206-
// continue
205+
} catch (ConfigConverter.InvalidBooleanValueException ex) {
206+
// For backward compatibility: invalid boolean values should return false, not default
207+
// Store the invalid sourceValue for telemetry, but return false for the application
208+
if (Boolean.class.equals(type)) {
209+
if (collectConfig) {
210+
ConfigCollector.get().put(key, sourceValue, source.origin());
211+
}
212+
return (T) Boolean.FALSE;
213+
}
214+
// For non-boolean types, continue to next source
215+
} catch (IllegalArgumentException ex) {
216+
// continue - covers both NumberFormatException and other IllegalArgumentException
207217
}
208218
}
209219
if (collectConfig) {
@@ -255,7 +265,12 @@ public Map<String, String> getMergedMap(String key, String... aliases) {
255265
String value = sources[i].get(key, aliases);
256266
Map<String, String> parsedMap = ConfigConverter.parseMap(value, key);
257267
if (!parsedMap.isEmpty()) {
258-
origin = sources[i].origin();
268+
if (origin != ConfigOrigin.DEFAULT) {
269+
// if we already have a non-default origin, the value is calculated from multiple sources
270+
origin = ConfigOrigin.CALCULATED;
271+
} else {
272+
origin = sources[i].origin();
273+
}
259274
}
260275
merged.putAll(parsedMap);
261276
}
@@ -277,7 +292,12 @@ public Map<String, String> getMergedTagsMap(String key, String... aliases) {
277292
Map<String, String> parsedMap =
278293
ConfigConverter.parseTraceTagsMap(value, ':', Arrays.asList(',', ' '));
279294
if (!parsedMap.isEmpty()) {
280-
origin = sources[i].origin();
295+
if (origin != ConfigOrigin.DEFAULT) {
296+
// if we already have a non-default origin, the value is calculated from multiple sources
297+
origin = ConfigOrigin.CALCULATED;
298+
} else {
299+
origin = sources[i].origin();
300+
}
281301
}
282302
merged.putAll(parsedMap);
283303
}
@@ -298,7 +318,12 @@ public Map<String, String> getOrderedMap(String key) {
298318
String value = sources[i].get(key);
299319
Map<String, String> parsedMap = ConfigConverter.parseOrderedMap(value, key);
300320
if (!parsedMap.isEmpty()) {
301-
origin = sources[i].origin();
321+
if (origin != ConfigOrigin.DEFAULT) {
322+
// if we already have a non-default origin, the value is calculated from multiple sources
323+
origin = ConfigOrigin.CALCULATED;
324+
} else {
325+
origin = sources[i].origin();
326+
}
302327
}
303328
merged.putAll(parsedMap);
304329
}
@@ -322,7 +347,13 @@ public Map<String, String> getMergedMapWithOptionalMappings(
322347
Map<String, String> parsedMap =
323348
ConfigConverter.parseMapWithOptionalMappings(value, key, defaultPrefix, lowercaseKeys);
324349
if (!parsedMap.isEmpty()) {
325-
origin = sources[i].origin();
350+
if (origin != ConfigOrigin.DEFAULT) {
351+
// if we already have a non-default origin, the value is calculated from multiple
352+
// sources
353+
origin = ConfigOrigin.CALCULATED;
354+
} else {
355+
origin = sources[i].origin();
356+
}
326357
}
327358
merged.putAll(parsedMap);
328359
}

0 commit comments

Comments
 (0)