Skip to content

Commit a956837

Browse files
authored
Merge branch 'master' into andrea.marziali/jms-npe
2 parents 6e2ddb1 + bcbd429 commit a956837

File tree

4 files changed

+350
-11
lines changed

4 files changed

+350
-11
lines changed

dd-java-agent/instrumentation/jsp-2.3/src/main/java/datadog/trace/instrumentation/jsp/JSPDecorator.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
66
import datadog.trace.bootstrap.instrumentation.decorator.BaseDecorator;
77
import java.net.URI;
8-
import java.net.URISyntaxException;
98
import javax.servlet.RequestDispatcher;
109
import javax.servlet.http.HttpServletRequest;
11-
import javax.servlet.jsp.HttpJspPage;
1210
import org.apache.jasper.JspCompilationContext;
13-
import org.slf4j.LoggerFactory;
1411

1512
public class JSPDecorator extends BaseDecorator {
1613
public static final CharSequence JSP_COMPILE = UTF8BytesString.create("jsp.compile");
@@ -68,11 +65,14 @@ public void onRender(final AgentSpan span, final HttpServletRequest req) {
6865
// HttpServletRequest#getRequestURL(),
6966
// normalizing the URL should remove those symbols for readability and consistency
7067
try {
71-
span.setTag(
72-
"jsp.requestURL", (new URI(req.getRequestURL().toString())).normalize().toString());
73-
} catch (final URISyntaxException uriSE) {
74-
LoggerFactory.getLogger(HttpJspPage.class)
75-
.debug("Failed to get and normalize request URL: {}", uriSE.getMessage());
68+
// note: getRequestURL is supposed to always be nonnull - however servlet wrapping can happen
69+
// and we never know if ever this can happen
70+
final StringBuffer requestURL = req.getRequestURL();
71+
if (requestURL != null && requestURL.length() > 0) {
72+
span.setTag("jsp.requestURL", (new URI(requestURL.toString())).normalize().toString());
73+
}
74+
} catch (final Throwable ignored) {
75+
// logging here will be too verbose
7676
}
7777
}
7878
}

dd-java-agent/instrumentation/spring/spring-messaging-4.0/src/main/java/datadog/trace/instrumentation/springmessaging/SpringMessageExtractAdapter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.Map;
1111
import java.util.function.Function;
1212
import org.springframework.messaging.Message;
13+
import org.springframework.messaging.MessageHeaders;
1314

1415
public final class SpringMessageExtractAdapter
1516
implements AgentPropagation.ContextVisitor<Message<?>> {
@@ -33,7 +34,12 @@ public String apply(String key) {
3334

3435
@Override
3536
public void forEachKey(Message<?> carrier, AgentPropagation.KeyClassifier classifier) {
36-
for (Map.Entry<String, ?> header : carrier.getHeaders().entrySet()) {
37+
final MessageHeaders messageHeaders = carrier.getHeaders();
38+
if (messageHeaders == null || messageHeaders.isEmpty()) {
39+
return;
40+
}
41+
42+
for (Map.Entry<String, ?> header : messageHeaders.entrySet()) {
3743
Object headerValue = header.getValue();
3844
if ("_datadog".equals(header.getKey())) {
3945
if (headerValue instanceof String) {

remote-config/remote-config-core/src/main/java/datadog/remoteconfig/state/ProductState.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ public boolean apply(
5858
errors = null;
5959

6060
List<ParsedConfigKey> configBeenUsedByProduct = new ArrayList<>();
61+
List<ParsedConfigKey> changedKeys = new ArrayList<>();
6162
boolean changesDetected = false;
6263

64+
// Step 1: Detect all changes
6365
for (ParsedConfigKey configKey : relevantKeys) {
6466
try {
6567
RemoteConfigResponse.Targets.ConfigTarget target =
@@ -68,14 +70,28 @@ public boolean apply(
6870

6971
if (isTargetChanged(configKey, target)) {
7072
changesDetected = true;
71-
byte[] content = getTargetFileContent(fleetResponse, configKey);
72-
callListenerApplyTarget(fleetResponse, hinter, configKey, content);
73+
changedKeys.add(configKey);
7374
}
7475
} catch (ReportableException e) {
7576
recordError(e);
7677
}
7778
}
7879

80+
// Step 2: For products other than ASM_DD, apply changes immediately
81+
if (product != Product.ASM_DD) {
82+
for (ParsedConfigKey configKey : changedKeys) {
83+
try {
84+
byte[] content = getTargetFileContent(fleetResponse, configKey);
85+
callListenerApplyTarget(fleetResponse, hinter, configKey, content);
86+
} catch (ReportableException e) {
87+
recordError(e);
88+
}
89+
}
90+
}
91+
92+
// Step 3: Remove obsolete configurations (for all products)
93+
// For ASM_DD, this is critical: removes MUST happen before applies to prevent
94+
// duplicate rule warnings from the ddwaf rule parser and causing memory spikes.
7995
List<ParsedConfigKey> keysToRemove =
8096
cachedTargetFiles.keySet().stream()
8197
.filter(configKey -> !configBeenUsedByProduct.contains(configKey))
@@ -86,6 +102,22 @@ public boolean apply(
86102
callListenerRemoveTarget(hinter, configKey);
87103
}
88104

105+
// Step 4: For ASM_DD, apply changes AFTER removes
106+
// TODO: This is a temporary solution. The proper fix requires better synchronization
107+
// between remove and add/update operations. This should be discussed
108+
// with the guild to determine the best long-term design approach.
109+
if (product == Product.ASM_DD) {
110+
for (ParsedConfigKey configKey : changedKeys) {
111+
try {
112+
byte[] content = getTargetFileContent(fleetResponse, configKey);
113+
callListenerApplyTarget(fleetResponse, hinter, configKey, content);
114+
} catch (ReportableException e) {
115+
recordError(e);
116+
}
117+
}
118+
}
119+
120+
// Step 5: Commit if there were changes
89121
if (changesDetected) {
90122
try {
91123
callListenerCommit(hinter);

0 commit comments

Comments
 (0)