Add Implementation of the open-tracing interceptor using gRPC interceptor.#14
Add Implementation of the open-tracing interceptor using gRPC interceptor.#14zhyon404 wants to merge 13 commits into
Conversation
|
Could we remove the existing interceptor code? I don't think we'd want two implementations. |
|
We could, of course this will loss backward compatible, but I agree that only one implementation is better. Do you want me to do this? |
f6d6696 to
b4bdc7c
Compare
|
Yes, we can bump the major version to indicate it's not backward compatible. |
|
Thank you so much for this! |
|
basically done. not writing much test though |
| command: | | ||
| . venv/bin/activate | ||
| python setup.py test | ||
| python3 setup.py test |
There was a problem hiding this comment.
Do we really need to run Python 3 here?
There was a problem hiding this comment.
I tried, using python works now.
|
|
||
| See the below code for basic usage or [examples/trivial](examples/trivial) for a | ||
| complete example. | ||
| using official grpc interceptor |
There was a problem hiding this comment.
I think we could leave the original line ("See the below code...") and also mention this new note at the end of the paragraph ;)
| tracer_interceptor = client_interceptor.OpenTracingClientInterceptor(tracer) | ||
| channel = # the grpc.Channel you created to invoke RPCs | ||
| channel = intercept_channel(channel, interceptor) | ||
| channel = grpc.intercept_channel(channel, tracer_interceptor) |
|
|
||
| On the server-side, the `context` argument passed into your service methods | ||
| packages the gRPC span created on the server-side. | ||
| from grpc_opentracing import scope |
There was a problem hiding this comment.
I have mixed feelings about this, as this will probably get discarded anyway in favor of the OT 2.0 API (ScopeManager)...
There was a problem hiding this comment.
I looked into current OT ScopeManager when I wrote this, and thinking it not meet the need. If we can use OT 2.0 API (ScopeManager) would be great.
| author='LightStep', | ||
| license='', | ||
| install_requires=['opentracing>=1.2.2', 'grpcio>=1.1.3', 'six>=1.10'], | ||
| install_requires=['opentracing>=1.2.2', 'grpcio>=1.8.1', 'six>=1.10'], |
There was a problem hiding this comment.
Interceptors exists within grpc exactly since 1.8.1?
There was a problem hiding this comment.
I checked it's 1.8.0. And changed the requirement.
| def test_constructor_default(self): | ||
| interceptor = client_interceptor.OpenTracingClientInterceptor(Tracer(), True) | ||
| self.assertIsNotNone(interceptor._tracer) | ||
| self.assertTrue(interceptor._log_payloads) |
There was a problem hiding this comment.
Think there are other ways to test more into detail the new code?
If you don't have more time slots to spend on this, adding a TODO list for the tests or adding a note somewhere related to this would help ;)
| from grpc_opentracing import open_tracing_client_interceptor | ||
| from grpc_opentracing.grpcext import intercept_channel | ||
| import grpc | ||
| from grpc_opentracing.grpc_interceptor import client_interceptor |
There was a problem hiding this comment.
Trying to stay as compatible as before, I'd suggest exposing this new client_interceptor with the same name we had for the old one, i.e.
# __init__.py
from grpc_interceptor import client_interceptor as open_tracing_ client_interceptor # old name, kept even if as deprecated
from grpc_interceptor import client_interceptor # the actual name of the new objectThere was a problem hiding this comment.
Oh, and the same would go for server_interceptor ;)
|
Hey @zhyon404 thanks for crafting all these changes! Definitely nice to finally use the official interceptor layer ;) I left a few comments for you - let me know your thoughts. If you are busy with other stuff let me know, so I can help with this. (And sorry for the delayed feedback!) |
|
Hey @carlosalberto, I added some changes according to your advice, I'm kind busy in next week, so it would be great if can help. |
|
@zhyon404 @carlosalberto Any plans to push this PR over the line? Is there anything I can do to help? |
|
Is there anything in here that is not ok? This will make the code and unit tests for interceptor servers so much easier :D |
| scope.set_active_span(current_span) | ||
| scope.end_span() |
There was a problem hiding this comment.
this doesn't quite work they way it might be expected. I believe you need to pass the original span from before when you create a new one at https://github.com/opentracing-contrib/python-grpc/pull/14/files#diff-4ecafa65ccad14bb230575320502f261R57
The reason for this is that otherwise if there are further gRPC calls issued by the calling code after this point before it explicitly creates a new span each of these calls will appear as though the previous gRPC was it's parent.
e.g.
- start tracer span
|
\--- client grpc call 1
|--- server grpc function 1
| \--- ... other tracing calls in server
\--- client grpc call 2
|--- server grpc function 2
| \--- ... other tracing calls in server
\--- client grpc call 3
\--- server grpc function 3
\--- ... other tracing calls in server
instead of
- start tracer span
|
|--- client grpc call 1
| \--- server grpc function 1
| \--- ... other tracing calls in server
|--- client grpc call 2
| \--- server grpc function 2
| \--- ... other tracing calls in server
\--- client grpc call 3
\--- server grpc function 3
\--- ... other tracing calls in server
So the function should take two arguments def _callback(self, current_span, original_span): and then do current_span.finish() followed by scope.set_active_span(original_span). Since you want to finish the current span, but when exiting the grpc interceptor back to the program code the active span should be set back to what it was before the interceptor was called.
No description provided.