| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
@deeployed-peer-dev review |
Sorry, something went wrong.
|
Walkthrough
The PR migrates the customize‑enhance plugin to the new V2 instrumentation API, adds support for returnedObj expressions, and updates the test suite to validate the new behavior. A test class is moved into the core util package to match the relocated implementation. The plugin definitions and interceptors now use V2 interfaces, evaluate return values, and tag/log spans accordingly. The customize‑scenario tests are updated to exercise these changes, including new spans derived from returned values. Changes
sequenceDiagram
participant C as CustomizeController
participant S as TestService1
participant I as CustomizeInstanceInterceptor
participant T as SpanDataHolder
participant L as Logger
C->>S: retString("str0")
S->>I: beforeMethod()
I->>T: createSpan()
S-->>I: return "str0"
I->>T: evaluateReturnExpression("str0")
I->>T: addTag("returnValue", "str0")
I->>T: addLog("returnValue", "str0")
I->>T: finishSpan()
I->>L: logSpan()
The diagram illustrates the flow from the controller invoking a service method, the interceptor capturing the call, evaluating the returned object to enrich the span with tags and logs, and finally completing the span. Uplevel your code reviews with Deeployed Peer! |
Sorry, something went wrong.
There was a problem hiding this comment.
Sorry, something went wrong.
| Map<String, String> spanTags = tags == null ? Collections.EMPTY_MAP : new HashMap<String, String>(tags.size()); | ||
| Map<String, String> spanLogs = logs == null ? Collections.EMPTY_MAP : new HashMap<String, String>(logs.size()); | ||
|
|
There was a problem hiding this comment.
The code uses Collections.EMPTY_MAP for spanTags and spanLogs when tags or logs are null.
Collections.EMPTY_MAP is a raw, immutable map. Later, spanTags.clear() and spanLogs.clear() are called (lines 93‑94), which will throw an UnsupportedOperationException when the maps are immutable.
Replace the immutable maps with mutable ones.
| Map<String, String> spanTags = tags == null ? Collections.EMPTY_MAP : new HashMap<String, String>(tags.size()); | |
| Map<String, String> spanLogs = logs == null ? Collections.EMPTY_MAP : new HashMap<String, String>(logs.size()); | |
| Map<String, String> spanTags = tags == null ? new HashMap<>() : new HashMap<>(tags.size()); | |
| Map<String, String> spanLogs = logs == null ? new HashMap<>() : new HashMap<>(logs.size()); |
Sorry, something went wrong.
There was a problem hiding this comment.
TP
Sorry, something went wrong.
| spanTags.clear(); | ||
| spanLogs.clear(); |
There was a problem hiding this comment.
spanTags.clear(); and spanLogs.clear(); assume the maps are mutable.
After the change above, these calls are safe; otherwise, they would throw an exception.
Sorry, something went wrong.
There was a problem hiding this comment.
TP
Sorry, something went wrong.
| void handleMethodException(Throwable t) { | ||
| ContextManager.activeSpan().log(t); | ||
| } |
There was a problem hiding this comment.
handleMethodException logs the exception without checking if a span is active.
If no span is active, ContextManager.activeSpan() will return null, causing a NullPointerException.
Add a guard to ensure a span is active before logging.
| void handleMethodException(Throwable t) { | |
| ContextManager.activeSpan().log(t); | |
| } | |
| if (ContextManager.isActive()) { | |
| ContextManager.activeSpan().log(t); | |
| } |
Sorry, something went wrong.
There was a problem hiding this comment.
BP
Sorry, something went wrong.
| @Override | ||
| public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, | ||
| Class<?>[] argumentsTypes, Throwable t) { | ||
| Class<?>[] argumentsTypes, Throwable t, MethodInvocationContext context) { | ||
| super.handleMethodException(t); | ||
| } |
There was a problem hiding this comment.
There's a missing MethodInvocationContext argument in the call to super.handleMethodException(t). It should forward the context as well.
| @Override | |
| public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, | |
| Class<?>[] argumentsTypes, Throwable t) { | |
| Class<?>[] argumentsTypes, Throwable t, MethodInvocationContext context) { | |
| super.handleMethodException(t); | |
| } | |
| super.handleMethodException(t, context); |
Sorry, something went wrong.
There was a problem hiding this comment.
FP_Hallucination
Sorry, something went wrong.
|
3 FN |
Sorry, something went wrong.
|
gpt-oss-20b |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
Implemented support for returnedObj expressions in the customize‑enhance plugin and migrated the plugin to use the new V2 instrumentation API. Added new test cases, documentation updates, and configuration examples for return‑value based tags and logs.
File‑by‑file changes
CHANGES.md
apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/util/CustomizeExpressionTest.java
apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/define/CustomizeInstanceInstrumentation.java
apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/define/CustomizeStaticInstrumentation.java
apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/interceptor/BaseInterceptorMethods.java
apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/interceptor/CustomizeInstanceInterceptor.java
apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/interceptor/CustomizeStaticInterceptor.java
docs/en/setup/service-agent/java-agent/Customize-enhance-trace.md
test/plugin/scenarios/customize-scenario/bin/startup.sh
test/plugin/scenarios/customize-scenario/config/customize_enhance.xml
test/plugin/scenarios/customize-scenario/config/expectedData.yaml
test/plugin/scenarios/customize-scenario/src/main/java/test/apache/skywalking/apm/testcase/customize/controller/CustomizeController.java
test/plugin/scenarios/customize-scenario/src/main/java/test/apache/skywalking/apm/testcase/customize/service/TestService1.java
Result
The plugin now correctly parses returnedObj expressions, evaluates them against the method return value, and attaches the resulting values as tags or logs on the generated span. All tests pass with the new functionality.