Skip to content

Commit

Permalink
adding a test case for MigrateWebMvcTagsToObservationConvention for t…
Browse files Browse the repository at this point in the history
…he case where the iterable passed to `Tags.and(...)` is *not* an identifier, and partially fixing it, BUT this commit still has a strange test failure with cyclically duplicating http request/response variables
  • Loading branch information
nmck257 committed Oct 16, 2024
1 parent cea3ccf commit 8b037de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private Statement refactorTagsUsage(ExecutionContext ctx, org.openrewrite.java.t
}
return getMultiKeyValueStatement(ctx, coords, args, returnIdentifier);
} else if (TAGS_AND_TAG_ITERABLE.matches(init) || TAGS_OF_TAG_ITERABLE.matches(init)) {
J.Identifier iterable = (J.Identifier) init.getArguments().get(0);
Expression iterable = init.getArguments().get(0);
String template = "for (Tag tag : #{any()}) {\n" +
" #{any()}.and(KeyValue.of(tag.getKey(), tag.getValue()));\n" +
"}\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,13 @@ public Iterable<Tag> getTags(HttpServletRequest request, HttpServletResponse res
tags = tags.and("a", "b", "c", "d");
tags = Tags.and(Tag.of("a", "b"), staticTag);
tags = tags.and(staticTags);
tags = tags.and(methodTags());
return tags;
}
private Tags methodTags() {
return staticTags;
}
}
""",
"""
Expand Down Expand Up @@ -219,8 +224,15 @@ public KeyValues getHighCardinalityKeyValues(ServerRequestObservationContext con
for (Tag tag : staticTags) {
values.and(KeyValue.of(tag.getKey(), tag.getValue()));
}
for (Tag tag : methodTags()) {
values.and(KeyValue.of(tag.getKey(), tag.getValue()));
}
return values;
}
private Tags methodTags() {
return staticTags;
}
}
"""
)
Expand Down

0 comments on commit 8b037de

Please sign in to comment.