refactor initTrace -> initTracing()

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
Ahmet Alp Balkan 2018-07-13 10:47:42 -07:00
parent 5a32ddf0ff
commit d01f525453
2 changed files with 15 additions and 11 deletions

View file

@ -88,15 +88,7 @@ var catalog = []*pb.Product{
func main() { func main() {
flag.Parse() flag.Parse()
exporter, err := stackdriver.NewExporter(stackdriver.Options{}) initTracing()
if err != nil {
log.Printf("failed to initialize stackdriver exporter: %+v", err)
log.Println("skipping uploading traces to stackdriver")
} else {
trace.RegisterExporter(exporter)
trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})
log.Println("registered stackdriver")
}
log.Printf("starting grpc server at :%d", *port) log.Printf("starting grpc server at :%d", *port)
run(*port) run(*port)
@ -114,6 +106,18 @@ func run(port int) string {
return l.Addr().String() return l.Addr().String()
} }
func initTracing() {
exporter, err := stackdriver.NewExporter(stackdriver.Options{})
if err != nil {
log.Printf("failed to initialize stackdriver exporter: %+v", err)
log.Println("skipping uploading traces to stackdriver")
} else {
trace.RegisterExporter(exporter)
trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})
log.Println("registered stackdriver")
}
}
type productCatalog struct{} type productCatalog struct{}
func (p *productCatalog) ListProducts(context.Context, *pb.Empty) (*pb.ListProductsResponse, error) { func (p *productCatalog) ListProducts(context.Context, *pb.Empty) (*pb.ListProductsResponse, error) {

View file

@ -69,7 +69,7 @@ func main() {
} }
port = fmt.Sprintf(":%s", port) port = fmt.Sprintf(":%s", port)
initTrace() initTracing()
lis, err := net.Listen("tcp", port) lis, err := net.Listen("tcp", port)
if err != nil { if err != nil {
@ -86,7 +86,7 @@ func main() {
} }
} }
func initTrace() { func initTracing() {
exporter, err := stackdriver.NewExporter(stackdriver.Options{}) exporter, err := stackdriver.NewExporter(stackdriver.Options{})
if err != nil { if err != nil {
log.Printf("failed to initialize stackdriver exporter: %+v", err) log.Printf("failed to initialize stackdriver exporter: %+v", err)