Esta página foi traduzida pela API Cloud Translation.
Switch to English

Configurar um exportador do OpenCensus

Amostras para configurar o exportador do Cloud Monitoring

Amostra de código

Go

// Enable OpenCensus exporters to export metrics
// to Stackdriver Monitoring.
// Exporters use Application Default Credentials to authenticate.
// See https://developers.google.com/identity/protocols/application-default-credentials
// for more details.
exporter, err := stackdriver.NewExporter(stackdriver.Options{})
if err != nil {
	log.Fatal(err)
}
// 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()