grpc/grpc-go · error
failed to instrument OpenCensus: %v
Error message
failed to instrument OpenCensus: %v
What it means
A wrapper returned by Start() when startOpenCensus(config) fails. The inner error (interpolated via %v) is usually one of: Stackdriver exporter creation failure, view registration failure, or exporter type-assertion failure. Because Start() defers End() on error, partial resources are cleaned up, but no telemetry instrumentation is applied to subsequently created clients/servers.
Source
Thrown at gcp/observability/observability.go:72
return fmt.Errorf("no ObservabilityConfig found")
}
// Set the project ID if it isn't configured manually.
if err = ensureProjectIDInObservabilityConfig(ctx, config); err != nil {
return err
}
// Cleanup any created resources this function created in case this function
// errors.
defer func() {
if err != nil {
End()
}
}()
// Enabling tracing and metrics via OpenCensus
if err = startOpenCensus(config); err != nil {
return fmt.Errorf("failed to instrument OpenCensus: %v", err)
}
if err = startLogging(ctx, config); err != nil {
return fmt.Errorf("failed to start logging: %v", err)
}
// Logging is controlled by the config at methods level.
return nil
}
// End is the clean-up API for gRPC Observability plugin. It is expected to be
// invoked in the main function of the application. The suggested usage is
// "defer observability.End()". This function also flushes data to upstream, and
// cleanup resources.
//
// Note: this method should only be invoked once.
func End() {
stopLogging()View on GitHub (pinned to 03255a9237)
Solutions
- Inspect the wrapped error string after the colon; it identifies the underlying cause (project ID, auth, duplicate view registration).
- Ensure Application Default Credentials are available: run `gcloud auth application-default login` or set GOOGLE_APPLICATION_CREDENTIALS.
- Confirm config.ProjectID is valid and the account has monitoring/trace write scopes.
- Call Start() exactly once per process; do not re-invoke after End().
Example fix
// before
if err := observability.Start(ctx); err != nil {
log.Fatal(err) // "failed to instrument OpenCensus: ..."
}
// after
if err := observability.Start(ctx); err != nil {
log.Fatalf("observability disabled, continuing without telemetry: %v", err)
}
// and ensure ADC is present: gcloud auth application-default login Defensive patterns
Strategy: try-catch
Try / catch
if err := observability.Start(ctx); err != nil {
if strings.Contains(err.Error(), "failed to instrument OpenCensus") {
log.Printf("running without tracing/metrics: %v", err)
} else {
return err
}
} Prevention
- Always pair Start() with defer observability.End() so partial resources are cleaned up on failure.
- Ensure Application Default Credentials are present before Start() in any environment enabling trace/metrics.
- Call Start() exactly once per process; guard with sync.Once.
When it happens
Trigger: Invoking Start() with a config that enables cloud_trace or cloud_monitoring but whose ProjectID cannot be resolved, or whose Stackdriver exporter cannot authenticate. Also when default views have already been registered by a prior Start() call in the same process.
Common situations: Running on a machine without Application Default Credentials (no GOOGLE_APPLICATION_CREDENTIALS and no metadata server); specifying a non-existent GCP project ID; calling Start() twice (e.g. in a test binary and in the app).
Related errors
- failed to start logging: %v
- unable to create CloudLogging exporter: %v
- no ObservabilityConfig found
- failed to create Stackdriver exporter: %v
- invalid method string: %v, err: %v
AI-assisted analysis of grpc/grpc-go@03255a9237 (2026-08-07).
Data as JSON: /api/errors/b8c114056a7e1aeb.
Report an issue: GitHub.