Set up an OpenCensus exporter

Samples for setting up the Cloud Monitoring exporter.

Code sample


// 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()

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser