This method accepts config and exporter; the exporter argument is exposed to assist unit testing of the OpenCensus behavior.
(config *config)
| 122 | // This method accepts config and exporter; the exporter argument is exposed to |
| 123 | // assist unit testing of the OpenCensus behavior. |
| 124 | func startOpenCensus(config *config) error { |
| 125 | // If both tracing and metrics are disabled, there's no point inject default |
| 126 | // StatsHandler. |
| 127 | if config == nil || (config.CloudTrace == nil && config.CloudMonitoring == nil) { |
| 128 | return nil |
| 129 | } |
| 130 | |
| 131 | var err error |
| 132 | exporter, err = newExporter(config) |
| 133 | if err != nil { |
| 134 | return err |
| 135 | } |
| 136 | |
| 137 | var to opencensus.TraceOptions |
| 138 | if config.CloudTrace != nil { |
| 139 | to.TS = trace.ProbabilitySampler(config.CloudTrace.SamplingRate) |
| 140 | trace.RegisterExporter(exporter.(trace.Exporter)) |
| 141 | logger.Infof("Start collecting and exporting trace spans with global_trace_sampling_rate=%.2f", config.CloudTrace.SamplingRate) |
| 142 | } |
| 143 | |
| 144 | if config.CloudMonitoring != nil { |
| 145 | if err := view.Register(defaultViews...); err != nil { |
| 146 | return fmt.Errorf("failed to register observability views: %v", err) |
| 147 | } |
| 148 | view.SetReportingPeriod(defaultMetricsReportingInterval) |
| 149 | view.RegisterExporter(exporter.(view.Exporter)) |
| 150 | logger.Infof("Start collecting and exporting metrics") |
| 151 | } |
| 152 | |
| 153 | internal.AddGlobalServerOptions.(func(opt ...grpc.ServerOption))(opencensus.ServerOption(to)) |
| 154 | internal.AddGlobalDialOptions.(func(opt ...grpc.DialOption))(opencensus.DialOption(to)) |
| 155 | logger.Infof("Enabled OpenCensus StatsHandlers for clients and servers") |
| 156 | |
| 157 | return nil |
| 158 | } |
| 159 | |
| 160 | // stopOpenCensus flushes the exporter's and cleans up globals across all |
| 161 | // packages if exporter was created. |
no test coverage detected