Skip to content

Instantly share code, notes, and snippets.

@kjin
Created January 9, 2019 17:30
Show Gist options
  • Save kjin/385a0691b555d84e6afcae22fc118022 to your computer and use it in GitHub Desktop.
Save kjin/385a0691b555d84e6afcae22fc118022 to your computer and use it in GitHub Desktop.
// Client for https://github.com/grpc/grpc-go/blob/master/examples/helloworld/greeter_server/main.go.
// 'helloworld.proto' is https://github.com/grpc/grpc-go/blob/master/examples/helloworld/helloworld/helloworld.proto.
const tracer = require('@google-cloud/trace-agent').start({ bufferSize: 1, samplingRate: 0 });
const grpc = require('grpc');
const bluebird = require('bluebird');
const protoFile = __dirname + '/helloworld.proto';
const proto = grpc.load(protoFile).helloworld;
const makeSingleClientCall = (port, value) => {
const client = new proto.Greeter(`localhost:${port}`, grpc.credentials.createInsecure());
return bluebird.promisify(client.sayHello.bind(client))({ name: value }).timeout(10000);
};
async function main() {
await tracer.runInRootSpan({ name: 'outer' }, async (span) => {
console.log(span.getTraceContext());
const res = await makeSingleClientCall(8080, 'hi');
span.endSpan();
console.log(res);
});
}
main().catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment