MCPcopy
hub / github.com/grpc/grpc-go / Start

Function Start

gcp/observability/observability.go:48–81  ·  view source on GitHub ↗

Start is the opt-in API for gRPC Observability plugin. This function should be invoked in the main function, and before creating any gRPC clients or servers, otherwise, they might not be instrumented. At high-level, this module does the following: - it loads observability config from environment; -

(ctx context.Context)

Source from the content-addressed store, hash-verified

46// Note: this method should only be invoked once.
47// Note: handle the error
48func Start(ctx context.Context) error {
49 config, err := parseObservabilityConfig()
50 if err != nil {
51 return err
52 }
53 if config == nil {
54 return fmt.Errorf("no ObservabilityConfig found")
55 }
56
57 // Set the project ID if it isn't configured manually.
58 if err = ensureProjectIDInObservabilityConfig(ctx, config); err != nil {
59 return err
60 }
61
62 // Cleanup any created resources this function created in case this function
63 // errors.
64 defer func() {
65 if err != nil {
66 End()
67 }
68 }()
69
70 // Enabling tracing and metrics via OpenCensus
71 if err = startOpenCensus(config); err != nil {
72 return fmt.Errorf("failed to instrument OpenCensus: %v", err)
73 }
74
75 if err = startLogging(ctx, config); err != nil {
76 return fmt.Errorf("failed to start logging: %v", err)
77 }
78
79 // Logging is controlled by the config at methods level.
80 return nil
81}
82
83// End is the clean-up API for gRPC Observability plugin. It is expected to be
84// invoked in the main function of the application. The suggested usage is

Callers 13

mainFunction · 0.92
mainFunction · 0.92
mainFunction · 0.92
mainFunction · 0.92
TestJSONEnvVarSetMethod · 0.85
TestNoEnvSetMethod · 0.85

Calls 6

parseObservabilityConfigFunction · 0.85
startOpenCensusFunction · 0.85
startLoggingFunction · 0.85
EndFunction · 0.70
ErrorfMethod · 0.65