Skip to content

Commit

Permalink
update more example to use StartMetricsExporter (census-instrumentati…
Browse files Browse the repository at this point in the history
…on#710)

* update more example to use StartMetricsExporter
- remove StopMetricsExporter from non-main func.

* update options.
  • Loading branch information
rghetia authored and songy23 committed Aug 30, 2019
1 parent 1f35aa5 commit 96323f4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
13 changes: 11 additions & 2 deletions content/exporters/supported-exporters/Go/Stackdriver.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,17 @@ func main() {
ProjectID: "demo-project-id",
// MetricPrefix helps uniquely identify your metrics.
MetricPrefix: "demo-prefix",
// ReportingInterval sets the frequency of reporting metrics
// to stackdriver backend.
ReportingInterval: 60 * time.Second,
})
if err != nil {
log.Fatalf("Failed to create the Stackdriver exporter: %v", err)
}
// It is imperative to invoke flush before your main function exits
defer sd.Flush()

// Start metric exporter
// Start the metrics exporter
sd.StartMetricsExporter()
defer sd.StopMetricsExporter()
}
Expand All @@ -98,6 +101,9 @@ func main() {
ProjectID: "demo-project-id",
// MetricPrefix helps uniquely identify your metrics.
MetricPrefix: "demo-prefix",
// ReportingInterval sets the frequency of reporting metrics
// to stackdriver backend.
ReportingInterval: 60 * time.Second,
})
if err != nil {
log.Fatalf("Failed to create the Stackdriver exporter: %v", err)
Expand Down Expand Up @@ -127,14 +133,17 @@ func main() {
ProjectID: "demo-project-id",
// MetricPrefix helps uniquely identify your metrics.
MetricPrefix: "demo-prefix",
// ReportingInterval sets the frequency of reporting metrics
// to stackdriver backend.
ReportingInterval: 60 * time.Second,
})
if err != nil {
log.Fatalf("Failed to create the Stackdriver exporter: %v", err)
}
// It is imperative to invoke flush before your main function exits
defer sd.Flush()

// Start metric exporter
// Start the metrics exporter
sd.StartMetricsExporter()
defer sd.StopMetricsExporter()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ func main() {
// Register the exporter as a trace exporter
trace.RegisterExporter(sd)

// Register the exporter as a metrics exporter
view.RegisterExporter(sd)
// Start the metrics exporter
sd.StartMetricsExporter()
defer sd.StopMetricsExporter()

// For demo purposes, always sample
trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func main() {
// Enable tracing
trace.RegisterExporter(se)

// Start metrics collection
// Start the metrics exporter
se.StartMetricsExporter()
defer se.StopMetricsExporter()

Expand Down
6 changes: 2 additions & 4 deletions content/integrations/memcached/Go.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,8 @@ func enableOpenCensusTracingAndMetrics() (func(), error) {
// Register as a tracing exporter.
trace.RegisterExporter(sd)

// Register as a metrics exporter.
view.RegisterExporter(sd)

view.SetReportingPeriod(60 * time.Second)
// Start metrics exporter.
sd.StartMetricsExporter()

// Most importantly register all the views for GoMemcache.
if err := view.Register(memcache.AllViews...); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion content/integrations/mongodb/go_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ func main() {
if err != nil {
log.Fatalf("Failed to create Stackdriver exporter: %v", err)
}
view.RegisterExporter(sde)
sde.StartMetricsExporter()
defer sde.StopMetricsExporter()
trace.RegisterExporter(sde)
if err := mongowrapper.RegisterAllViews(); err != nil {
log.Fatalf("Failed to register all views: %v\n", err)
Expand Down
3 changes: 0 additions & 3 deletions content/integrations/redis/Go/gomodule_redigo.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ func enableOpenCensus() (func(), error) {
return nil, err
}
sd.StartMetricsExporter()
defer sd.StopMetricsExporter()

return sd.Flush, nil
}
Expand Down Expand Up @@ -249,7 +248,6 @@ func enableOpenCensus() (func(), error) {
return nil, err
}
sd.StartMetricsExporter()
defer sd.StopMetricsExporter()

return sd.Flush, nil
}
Expand Down Expand Up @@ -436,7 +434,6 @@ func enableOpenCensus() (func(), error) {
return nil, err
}
sd.StartMetricsExporter()
defer sd.StopMetricsExporter()

// Enable tracing
trace.RegisterExporter(sd)
Expand Down

0 comments on commit 96323f4

Please sign in to comment.