feat(injector): Add return-implements function join point#602
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
56aec54 to
ee796e1
Compare
|
PTAL @korECM |
17d27eb to
df69d0c
Compare
e37581f to
f054729
Compare
eliottness
left a comment
There was a problem hiding this comment.
Do you mind adding tests for generic interfaces and generic interface implementations ?
What do you exactly mean by generic interfaces? Could you give me an example? |
|
@kakkoyun I mean making sure the new join-point interact correctly with concrete types having a generic component and interfaces declared in the join-point being able to be generic. Concretely simply adding tests in internal/injector/testdata/injector/result-implements-join/config.yml would be enough for me |
01ea546 to
fd5e99c
Compare
5af6ebb to
afe939a
Compare
fd5e99c to
ff5b86b
Compare
cd7519c to
9721aaa
Compare
It was a good call! Handled as part of 9721aaa |
9721aaa to
f7476cf
Compare
RomainMuller
left a comment
There was a problem hiding this comment.
I think there are some issues with the current implementation of the "implies imported" heuristics.
ff5b86b to
81f002c
Compare
f7476cf to
bd35383
Compare
bd35383 to
cbef457
Compare
Adds a new FunctionOption, 'return-implements', to the function join point selector. This allows matching functions where at least one return value's type implements a specified interface. The implementation leverages type information passed via the AspectContext during join point matching. It utilizes helpers from the 'typed' package for resolving interface names and performing type implementation checks (`types.Implements`). The `packageMayMatch` and `fileMayMatch` hints for this option return `may.Unknown` to correctly handle Go's structural typing, ensuring that types implementing an interface without explicitly importing its package are still considered. A comprehensive test case (`testdata/injector/return-implements`) is included, covering various scenarios like explicit interface returns, concrete type implementations (including custom types), multiple return values, and non-matching cases. Signed-off-by: Kemal Akkoyun <[email protected]>
Signed-off-by: Kemal Akkoyun <[email protected]>
…n value interface matching This update adds the `finalResultImplements` FunctionOption, enabling the matching of functions where the final return value implements a specified interface. The implementation includes methods for determining package and file match types, as well as evaluating the final return value against the target interface. Additionally, the configuration YAML has been updated with test cases demonstrating the new functionality, including scenarios that illustrate the distinction between `result-implements` and `final-result-implements`. Signed-off-by: Kemal Akkoyun <[email protected]>
…in points This commit extends the result-implements and final-result-implements join points to properly handle generic types. Previously, functions returning generic types that implement interfaces (e.g., GenericBuffer[string] implementing io.Reader) were not being instrumented correctly. The fix ensures that the type checker properly resolves generic type instantiations, allowing the join points to correctly identify when generic types implement the specified interfaces. Signed-off-by: Kemal Akkoyun <[email protected]>
Signed-off-by: Kemal Akkoyun <[email protected]>
cbef457 to
cda266d
Compare
81f002c to
983120d
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #602 +/- ##
==========================================
- Coverage 70.14% 66.32% -3.83%
==========================================
Files 109 110 +1
Lines 7517 7682 +165
==========================================
- Hits 5273 5095 -178
- Misses 1718 2056 +338
- Partials 526 531 +5
🚀 New features to boost your workflow:
|
|
@kakkoyun However, after looking at the orchestrion.yml file, it seems that ResultOfType is still being used. This makes me think that while the join point support has been added, it's not actually capturing errors yet. Could you please confirm if my understanding is correct? |
|
Hey 👋 Yes, we haven't utilizing the new improvements yet. Feel free to test it out and contribute the changes in your mind. Otherwise, we are working on a related issue and we will handle it as part of that. cc @hannahkm |

Adds the return-implements: "" selector to the function join point. This allows matching functions where at least one return value implements the specified interface, respecting Go's structural typing.
Includes a test case (testdata/injector/return-implements) covering standard library and custom types.
--
Fixes #538
ref: #537
xref: DataDog/dd-trace-go#3168
xref: LANGPLAT-159