OpenCensus エクスポータを設定する

Cloud Monitoring エクスポータを設定するためのサンプル。



// Enable OpenCensus exporters to export metrics
// to Stackdriver Monitoring.
// Exporters use Application Default Credentials to authenticate.
// See
// for more details.
exporter, err := stackdriver.NewExporter(stackdriver.Options{})
if err != nil {
// Flush must be called before main() exits to ensure metrics are recorded.
defer exporter.Flush()

if err := exporter.StartMetricsExporter(); err != nil {
	log.Fatalf("Error starting metric exporter: %v", err)
defer exporter.StopMetricsExporter()