Skip to content

Commit 0bc2e91

Browse files
authored
Merge pull request #288 from getappmap/feat/disable-value-tostring-config
feat: add config parameter to disable custom stringification
2 parents 6d1d9f8 + 2b7ff80 commit 0bc2e91

File tree

8 files changed

+91
-12
lines changed

8 files changed

+91
-12
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ jobs:
4141

4242
- name: Run Tests
4343
shell: bash
44+
env:
45+
GITHUB_TOKEN: ${{ github.token }}
4446
run: |
4547
set -e
4648
bin/disable-gradle-daemon

agent/src/main/java/com/appland/appmap/config/Properties.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class Properties {
3434
public static final Integer PatternThreshold =
3535
resolveProperty("appmap.config.patternThreshold", 10);
3636

37+
public static final Boolean DisableValue = resolveProperty("appmap.event.disableValue", false);
3738
public static final Integer MaxValueSize = resolveProperty("appmap.event.valueSize", 1024);
3839

3940
public static final String[] Records = resolveProperty("appmap.record", new String[0]);

agent/src/main/java/com/appland/appmap/output/v1/Value.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,23 @@ public <T> T get() {
115115
*/
116116
public Value freeze() {
117117
if (this.value != null) {
118-
try {
119-
this.value = this.value.toString();
120-
121-
if (Properties.MaxValueSize > 0 && this.value != null) {
122-
this.value = StringUtils.abbreviate((String) this.value, "...", Properties.MaxValueSize);
118+
if (Properties.DisableValue) {
119+
this.value = "< disabled >";
120+
} else {
121+
try {
122+
this.value = this.value.toString();
123+
124+
if (Properties.MaxValueSize > 0 && this.value != null) {
125+
this.value = StringUtils.abbreviate((String) this.value, "...", Properties.MaxValueSize);
126+
}
127+
} catch (Throwable e) {
128+
Logger.println("failed to resolve value of " + this.classType);
129+
Logger.println(e.getMessage());
130+
// it's possible our value object has been partially cleaned up and
131+
// calls toString on a null object or the operation is otherwise
132+
// unsupported
133+
this.value = "< invalid >";
123134
}
124-
} catch (Throwable e) {
125-
Logger.println("failed to resolve value of " + this.classType);
126-
Logger.println(e.getMessage());
127-
// it's possible our value object has been partially cleaned up and
128-
// calls toString on a null object or the operation is otherwise
129-
// unsupported
130-
this.value = "< invalid >";
131135
}
132136
}
133137
return this;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.appland.appmap.test.fixture;
2+
3+
public class Example {
4+
@Override
5+
public String toString() {
6+
return "an Example";
7+
}
8+
9+
public Example doSomething(Example other) {
10+
return other;
11+
}
12+
13+
}

agent/test/event/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.class
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.io.IOException;
2+
import java.io.OutputStreamWriter;
3+
4+
import com.appland.appmap.record.Recorder;
5+
import com.appland.appmap.record.Recording;
6+
7+
import com.appland.appmap.test.fixture.Example;
8+
9+
public class DisabledValue {
10+
11+
public static void main(String[] argv) {
12+
final Recording recording = Recorder.getInstance().record(() -> {
13+
new Example().doSomething(new Example());
14+
});
15+
16+
try {
17+
recording.readFully(true, new OutputStreamWriter(System.out));
18+
} catch (IOException e) {
19+
e.printStackTrace();
20+
}
21+
22+
}
23+
}

agent/test/event/appmap.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: test-event
2+
packages:
3+
- path: com.appland.appmap.test.fixture

agent/test/event/event.bats

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bats
2+
3+
load '../../build/bats/bats-support/load'
4+
load '../../build/bats/bats-assert/load'
5+
load '../helper'
6+
7+
sep="$JAVA_PATH_SEPARATOR"
8+
AGENT_JAR="$(find_agent_jar)"
9+
wd=$(getcwd)
10+
test_cp="${wd}/test/event${sep}${wd}/build/classes/java/test"
11+
java_cmd="java -javaagent:'${AGENT_JAR}' -cp '${test_cp}'"
12+
13+
setup() {
14+
javac -cp "${AGENT_JAR}${sep}${test_cp}" test/event/*.java
15+
16+
cd test/event
17+
_configure_logging
18+
}
19+
20+
@test "disabled value" {
21+
local cmd="${java_cmd} -Dappmap.event.disableValue=true DisabledValue"
22+
[[ $BATS_VERBOSE_RUN == 1 ]] && echo "cmd: $cmd" >&3
23+
24+
local output
25+
output=$(eval "$cmd")
26+
27+
echo "$output" | jq -e '.events[0] | select(.event=="call"
28+
and .parameters[0].value == "< disabled >"
29+
and .receiver.value == "< disabled >")'
30+
echo "$output" | jq -e '.events[1] | select(.event=="return"
31+
and .return_value.value == "< disabled >")'
32+
}

0 commit comments

Comments
 (0)