Skip to content

Commit

Permalink
Fix e2e test issue in tracing
Browse files Browse the repository at this point in the history
Signed-off-by: Aiden Dai <[email protected]>
  • Loading branch information
daixba committed Jul 18, 2023
1 parent c03f75f commit 3ea3c6b
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -525,23 +525,27 @@ private JsonStringBuilder(final JacksonEvent event) {
this.event = event;
}


public String toJsonString() {
private JsonNode getBaseNode() {
// Get root node.
JsonNode baseNode;
if (getRootKey() != null && !getRootKey().isEmpty() && event.containsKey(getRootKey())) {
baseNode = event.getNode(getRootKey());
} else {
baseNode = event.getJsonNode();
return event.getNode(getRootKey());
}

return event.getJsonNode();
}


public String toJsonString() {

String jsonString;
if (getIncludeKeys() != null && !getIncludeKeys().isEmpty()) {
jsonString = searchAndFilter(baseNode, "", getIncludeKeys(), RETAIN_ALL);
jsonString = searchAndFilter(getBaseNode(), "", getIncludeKeys(), RETAIN_ALL);
} else if (getExcludeKeys() != null && !getExcludeKeys().isEmpty()) {
jsonString = searchAndFilter(baseNode, "", getExcludeKeys(), EXCLUDE_ALL);
jsonString = searchAndFilter(getBaseNode(), "", getExcludeKeys(), EXCLUDE_ALL);
} else {
jsonString = baseNode.toString();
// Some successors have its own implementation of toJsonString, such as JacksonSpan.
// In such case, the root key will be ignored.
// TODO: Need to check if such behaviour is expected.
jsonString = event.toJsonString();
}

final String tagsKey = getTagsKey();
Expand All @@ -562,7 +566,7 @@ public String toJsonString() {
* @param filterAction Either to include (RETAIN_ALL or true) or to exclude (EXCLUDE_ALL or false)
* @return a json string with filtered keys
*/
private String searchAndFilter(JsonNode node, String path, final List<String> filterKeys, boolean filterAction) {
String searchAndFilter(JsonNode node, String path, final List<String> filterKeys, boolean filterAction) {

if (node.isArray()) { // for array node.
StringJoiner sj = new StringJoiner(",", "[", "]");
Expand Down

0 comments on commit 3ea3c6b

Please sign in to comment.