Add a hello world example for grpc integration#99
Add a hello world example for grpc integration#99liyanhui1228 merged 3 commits intocensus-instrumentation:masterfrom
Conversation
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| run() |
There was a problem hiding this comment.
Style-wise, I would call this main rather than run.
| channel = grpc.intercept_channel(channel, tracer_interceptor) | ||
| stub = hello_world_pb2_grpc.HelloWorldStub(channel) | ||
| response = stub.SayHello(hello_world_pb2.HelloRequest(name='you')) | ||
| print("Message received: " + response.message) |
There was a problem hiding this comment.
We should check that the response is what we expect.
There was a problem hiding this comment.
Yeah similar as above, will check that in the system test.
| from opencensus.trace.exporters import stackdriver_exporter | ||
| from opencensus.trace.ext.grpc import client_interceptor | ||
|
|
||
| HOST_PORT = 'localhost:50051' |
There was a problem hiding this comment.
You might look into the 'portpicker' package on PyPI for picking unused ports instead of hardcoding. Hardcoding can run into problems when you're running tests on CI machines and can have collisions which lead to hard-to-debug failures.
There was a problem hiding this comment.
Good suggestion! This is just an example and will not be running on CI. I'll do that when I added the system test for grpc integration.
There was a problem hiding this comment.
You're right, for a sample app, hard-coding ports is probably the right thing to, because it's simpler for the person trying to learn from the code.
For #3.