-
Notifications
You must be signed in to change notification settings - Fork 579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add gRPC Filter #2572
Add gRPC Filter #2572
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2572 +/- ##
=======================================
+ Coverage 74.3% 74.4% +0.1%
=======================================
Files 144 145 +1
Lines 6569 6681 +112
=======================================
+ Hits 4883 4973 +90
- Misses 1543 1561 +18
- Partials 143 147 +4
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm otherwise
// * handler grpc.UnaryHandler | grpc.StreamHandler (UnaryServer, StreamServer) | ||
// * req, reply, srv interface{} (UnaryClient, UnaryServer, StreamClient) | ||
// * cc *grpc.ClientConn. | ||
type InterceptorInfo struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels a bit strange to make this and NewXInterceptorInfo functions public, as we don't expect users to ever need to use or call them. Would it be better to leave filters in the otelgrpc package? It also eliminates the filters.Filter
stutter for naming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I totally agree! This is because I created filters
package to follow the package structure in otelhttp
. (It has otelhttp.filters
) I moved around the NewXXXInterceptors and InterceptorInfo back and forth among otelgrpc
, otelgrpc/internal
and otelgrpc/filters
to eliminate unnecessary public members, but I gave up and settled down to the current state. If it's totally ok to move everything under otelgrpc
and otelgrpc/internal
directories, then I'm happy to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put the filter implementations in a separate package because most often they'll be referred to by users and filters.MethodPrefix()
makes more sense to me than otelhttp.MethodPrefix()
, doubly so for the meta-filters. otelhttp.Any()
is less indicative of behavior than filters.Any()
.
As for exporting the interceptor info struct, I think it might be worthwhile to do so as without it users cannot implement their own filters. That would also necessitate exporting its fields. I think I'm fine with not exporting it for now, but if there's a way to ensure this isn't a one-way door and we can change our minds later that would be great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think:
filters.MethodPrefix
feels better thanotelgrpc.MethodPrefix
filters.Any
feels better thanotelgrpc.Any
(orotelgrpc.FilterAny
)otelgrpc.Filter
feels better thanfilters.Filter
otelgrpc.InterceptorInfo
feels better thanfilters.InterceptorInfo
To get that, we would need to make InterceptorInfo (and its fields) public, but could keep NewXInterceptorInfo private, which I'm OK with. Would that work @Aneurysm9?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comment, @Aneurysm9. For now, I moved everything under otelgrpc
based on David's comment, but I'm happy to move those back to subsidiary filters
package. Let me know what I should do.
@dashpole thanks for the comment. @Aneurysm9 does it make sense to you to have everything for filter under |
@dashpole I moved everything under |
instrumentation/google.golang.org/grpc/otelgrpc/interceptorinfo.go
Outdated
Show resolved
Hide resolved
@dashpole Thank you David for the review and approval! To maintainers: should I change anything else? |
@MrAlias thank you for arranging this PR as the milestone. Could you help accelerate the review? I'm ready to change the code but I can't without the review from @Aneurysm9 but I have no idea how I can get help but for waiting. |
instrumentation/google.golang.org/grpc/otelgrpc/interceptorinfo.go
Outdated
Show resolved
Hide resolved
@Aneurysm9 could you reply to this comment so that I can move forward to the acceptable change? |
Apologies for the delay, I was on vacation.
Not necessarily. There could be a third package that contains It might also be possible to, as @dashpole suggested, use |
@Aneurysm9 I appreciate your comment. I hope you had a great vacation.
The reason Also per declaring Given, does it sound good to expose the fields of |
@Aneurysm9 I moved all filters under |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, and thanks for your patience, @ymotongpoo! Just a few nits.
instrumentation/google.golang.org/grpc/otelgrpc/interceptorinfo.go
Outdated
Show resolved
Hide resolved
instrumentation/google.golang.org/grpc/otelgrpc/interceptorinfo.go
Outdated
Show resolved
Hide resolved
…o.go Co-authored-by: David Ashpole <[email protected]>
…o.go Co-authored-by: David Ashpole <[email protected]>
@Aneurysm9 Kindly ping because it's been a week since your last comment and I updated the code regarding it. |
Open Telemetry in Go for grpc is unusable without this PR for our organization. |
@Aneurysm9 @MadVikingGod @MrAlias hi, all maintainers, let me know how I can proceed from here. It's been two weeks since @Aneurysm9's last comment and I'm totally stalling. For interface simplicity, if we don't think about abstraction for future, we can simply use method name as common input for Of course, if we are to use type InterceptorInfo struct {
Ctx context.Context
Method string
UnaryServerInfo *grpc.UnaryServerInfo
StreamServerInfo *grpc.StreamServerInfo
Typ InterceptorType
} Another option is just to keep method name and context when we instantiate type InterceptorInfo struct {
Ctx context.Context
// Method should be either of the followings:
// - method passed to unary/stream client interceptor function
// - info.FullMethodName, where info is Unary/StreamServerInfo passed to server interceptor function
Method string
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposed a function name change. Otherwise LGTM. Implement the change now or as a follow-on PR (or tell me I'm crazy and bring receipts :) )
instrumentation/google.golang.org/grpc/otelgrpc/filters/filters.go
Outdated
Show resolved
Hide resolved
@Aneurysm9 Thank you for the approval! Yes, I'm happy to create a follow-up PR for better implementation :) |
After the discussion in #2571 and looking up the whole discussion in #512, I changed the direction just to focus on solving the issue #355 and other possible demand to filter the request to trace.
Most of the implementation are from #512. I tried to follow the package structure to match
otelhttp.Filter
but because of the difference betweenhttp.Request
and the objects passed to four types of interceptors, some clumsy structs/functions remain to the surface.