Skip to content

Commit

Permalink
gcp/observability: Cleanup resources allocated if start errors (#5960)
Browse files Browse the repository at this point in the history
  • Loading branch information
zasweq committed Jan 23, 2023
1 parent bc9728f commit 7bf6a58
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions gcp/observability/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,29 @@ func Start(ctx context.Context) error {
}

// Set the project ID if it isn't configured manually.
if err := ensureProjectIDInObservabilityConfig(ctx, config); err != nil {
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 {
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 startLogging(ctx, config)
return nil
}

// End is the clean-up API for gRPC Observability plugin. It is expected to be
Expand Down

0 comments on commit 7bf6a58

Please sign in to comment.