Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Add a hello world example for grpc integration#99

Merged
liyanhui1228 merged 3 commits intocensus-instrumentation:masterfrom
liyanhui1228:grpc_example
Dec 15, 2017
Merged

Add a hello world example for grpc integration#99
liyanhui1228 merged 3 commits intocensus-instrumentation:masterfrom
liyanhui1228:grpc_example

Conversation

@liyanhui1228
Copy link
Copy Markdown
Contributor

For #3.

@liyanhui1228 liyanhui1228 requested a review from duggelz December 15, 2017 19:37


if __name__ == '__main__':
run()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style-wise, I would call this main rather than run.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check that the response is what we expect.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... but you can do this later.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

@duggelz duggelz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good with minor comments.

@liyanhui1228 liyanhui1228 merged commit 8059f54 into census-instrumentation:master Dec 15, 2017
@liyanhui1228 liyanhui1228 deleted the grpc_example branch December 15, 2017 23:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants