Skip to content

Commit 9d9b1df

Browse files
authored
Merge branch 'master' into gyuheon0h/jvm-ldpreload-reset
2 parents f3795eb + ca975c2 commit 9d9b1df

4 files changed

Lines changed: 82 additions & 13 deletions

File tree

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/probe/LogProbe.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,6 @@ private void processCaptureExpressions(CapturedContext context, LogStatus logSta
730730
captureExpression.getName(), Object.class.getTypeName(), null));
731731
} else {
732732
if (captureExpression.capture != null) {
733-
Value.toCapturedSnapshot(captureExpression.getName(), result);
734733
context.addCaptureExpression(
735734
Value.toCapturedSnapshot(
736735
captureExpression.getName(),
@@ -740,8 +739,20 @@ private void processCaptureExpressions(CapturedContext context, LogStatus logSta
740739
captureExpression.capture.maxLength,
741740
captureExpression.capture.maxFieldCount));
742741
} else {
743-
context.addCaptureExpression(
744-
Value.toCapturedSnapshot(captureExpression.getName(), result));
742+
// inherit from probe capture field because no specific capture
743+
if (capture != null) {
744+
context.addCaptureExpression(
745+
Value.toCapturedSnapshot(
746+
captureExpression.getName(),
747+
result,
748+
capture.maxReferenceDepth,
749+
capture.maxCollectionSize,
750+
capture.maxLength,
751+
capture.maxFieldCount));
752+
} else {
753+
context.addCaptureExpression(
754+
Value.toCapturedSnapshot(captureExpression.getName(), result));
755+
}
745756
}
746757
}
747758
} catch (EvaluationException ex) {

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/agent/CapturedSnapshotTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,6 +3028,47 @@ public void captureExpressionsWithCaptureLimits() throws IOException, URISyntaxE
30283028
assertEquals("depth", fldValue.getNotCapturedReason());
30293029
}
30303030

3031+
@Test
3032+
public void captureExpressionsWithInheritedCaptureLimits()
3033+
throws IOException, URISyntaxException {
3034+
final String CLASS_NAME = "CapturedSnapshot08";
3035+
LogProbe probe =
3036+
createProbeBuilder(PROBE_ID, CLASS_NAME, "doit", null)
3037+
.evaluateAt(MethodLocation.EXIT)
3038+
.captureSnapshot(false)
3039+
.capture(new LogProbe.Capture(1, 10, 3, 1))
3040+
.captureExpressions(
3041+
Arrays.asList(
3042+
new LogProbe.CaptureExpression(
3043+
"typed_fld_fld_msg",
3044+
new ValueScript(
3045+
DSL.getMember(
3046+
DSL.getMember(DSL.getMember(DSL.ref("typed"), "fld"), "fld"),
3047+
"msg"),
3048+
"typed.fld.fld.msg"),
3049+
null),
3050+
new LogProbe.CaptureExpression(
3051+
"typed", new ValueScript(DSL.ref("typed"), "typed"), null)))
3052+
.build();
3053+
TestSnapshotListener listener = installProbes(probe);
3054+
Class<?> testClass = compileAndLoadClass(CLASS_NAME);
3055+
int result = Reflect.onClass(testClass).call("main", "1").get();
3056+
assertEquals(3, result);
3057+
Snapshot snapshot = assertOneSnapshot(listener);
3058+
CapturedContext.CapturedValue msgValue =
3059+
deserializeCapturedValue(
3060+
snapshot.getCaptures().getReturn().getCaptureExpressions().get("typed_fld_fld_msg"));
3061+
assertEquals("hel", msgValue.getValue());
3062+
assertEquals("truncated", msgValue.getNotCapturedReason());
3063+
CapturedContext.CapturedValue typedValue =
3064+
deserializeCapturedValue(
3065+
snapshot.getCaptures().getReturn().getCaptureExpressions().get("typed"));
3066+
Map<String, CapturedContext.CapturedValue> fields =
3067+
(Map<String, CapturedContext.CapturedValue>) typedValue.getValue();
3068+
CapturedContext.CapturedValue fldValue = fields.get("fld");
3069+
assertEquals("depth", fldValue.getNotCapturedReason());
3070+
}
3071+
30313072
@Test
30323073
public void methodParametersAttribute() throws Exception {
30333074
final String CLASS_NAME = "CapturedSnapshot01";

dd-trace-core/src/main/java/datadog/trace/core/tagprocessor/PayloadTagsProcessor.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,40 +212,40 @@ public boolean visitPrimitive(PathCursor path) {
212212

213213
private boolean notRedacted(PathCursor path) {
214214
if (redactionRules.findMatching(path) != null) {
215-
collectedTags.put(path.toString(tagPrefix), REDACTED);
215+
collectedTags.set(path.toString(tagPrefix), REDACTED);
216216
return false;
217217
}
218218
return true;
219219
}
220220

221221
@Override
222222
public void booleanValue(PathCursor path, boolean value) {
223-
collectedTags.put(path.toString(tagPrefix), value);
223+
collectedTags.set(path.toString(tagPrefix), value);
224224
}
225225

226226
@Override
227227
public void stringValue(PathCursor path, String value) {
228-
collectedTags.put(path.toString(tagPrefix), value);
228+
collectedTags.set(path.toString(tagPrefix), value);
229229
}
230230

231231
@Override
232232
public void intValue(PathCursor path, int value) {
233-
collectedTags.put(path.toString(tagPrefix), value);
233+
collectedTags.set(path.toString(tagPrefix), value);
234234
}
235235

236236
@Override
237237
public void longValue(PathCursor path, long value) {
238-
collectedTags.put(path.toString(tagPrefix), value);
238+
collectedTags.set(path.toString(tagPrefix), value);
239239
}
240240

241241
@Override
242242
public void doubleValue(PathCursor path, double value) {
243-
collectedTags.put(path.toString(tagPrefix), value);
243+
collectedTags.set(path.toString(tagPrefix), value);
244244
}
245245

246246
@Override
247247
public void nullValue(PathCursor path) {
248-
collectedTags.put(path.toString(tagPrefix), null);
248+
collectedTags.set(path.toString(tagPrefix), null);
249249
}
250250

251251
@Override
@@ -257,7 +257,7 @@ public boolean keepCollectingTags() {
257257
if (collectedTags.size() < maxTags) {
258258
return true;
259259
}
260-
collectedTags.put(DD_PAYLOAD_TAGS_INCOMPLETE, true);
260+
collectedTags.set(DD_PAYLOAD_TAGS_INCOMPLETE, true);
261261
return false;
262262
}
263263

dd-trace-core/src/main/java/datadog/trace/core/tagprocessor/RemoteHostnameAdder.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,32 @@
99
public final class RemoteHostnameAdder extends TagsPostProcessor {
1010
private final Supplier<String> hostnameSupplier;
1111

12+
private TagMap.Entry cachedHostEntry = null;
13+
1214
public RemoteHostnameAdder(Supplier<String> hostnameSupplier) {
1315
this.hostnameSupplier = hostnameSupplier;
1416
}
1517

1618
@Override
1719
public void processTags(
1820
TagMap unsafeTags, DDSpanContext spanContext, AppendableSpanLinks spanLinks) {
19-
if (spanContext.getSpanId() == spanContext.getRootSpanId()) {
20-
unsafeTags.put(DDTags.TRACER_HOST, hostnameSupplier.get());
21+
if (spanContext.getSpanId() != spanContext.getRootSpanId()) {
22+
return;
23+
}
24+
25+
String hostname = hostnameSupplier.get();
26+
if (hostname == null) {
27+
return;
2128
}
29+
30+
TagMap.Entry cachedHostEntry = this.cachedHostEntry;
31+
if (cachedHostEntry != null && hostname.equals(cachedHostEntry.objectValue())) {
32+
unsafeTags.set(cachedHostEntry);
33+
return;
34+
}
35+
36+
TagMap.Entry newEntry = TagMap.Entry.create(DDTags.TRACER_HOST, hostname);
37+
unsafeTags.set(newEntry);
38+
this.cachedHostEntry = newEntry;
2239
}
2340
}

0 commit comments

Comments
 (0)