Created
January 9, 2019 17:30
-
-
Save kjin/385a0691b555d84e6afcae22fc118022 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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