Skip to content

Commit dcfb15b

Browse files
committed
add enableTracing flag
1 parent f955a09 commit dcfb15b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
infrav1exp "sigs.k8s.io/cluster-api-provider-gcp/exp/api/v1beta1"
4141
expcontrollers "sigs.k8s.io/cluster-api-provider-gcp/exp/controllers"
4242
"sigs.k8s.io/cluster-api-provider-gcp/feature"
43+
ot "sigs.k8s.io/cluster-api-provider-gcp/pkg/otel"
4344
"sigs.k8s.io/cluster-api-provider-gcp/util/reconciler"
4445
"sigs.k8s.io/cluster-api-provider-gcp/version"
4546
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -84,6 +85,7 @@ var (
8485
leaderElectionLeaseDuration time.Duration
8586
leaderElectionRenewDeadline time.Duration
8687
leaderElectionRetryPeriod time.Duration
88+
enableTracing bool
8789
)
8890

8991
func main() {
@@ -147,6 +149,13 @@ func main() {
147149
// Setup the context that's going to be used in controllers and for the manager.
148150
ctx := ctrl.SetupSignalHandler()
149151

152+
if enableTracing {
153+
if err := ot.RegisterTracing(ctx, setupLog); err != nil {
154+
setupLog.Error(err, "unable to set up tracing")
155+
os.Exit(1)
156+
}
157+
}
158+
150159
if setupErr := setupReconcilers(ctx, mgr); setupErr != nil {
151160
setupLog.Error(err, "unable to setup reconcilers")
152161
os.Exit(1)
@@ -366,5 +375,11 @@ func initFlags(fs *pflag.FlagSet) {
366375
"The maximum duration a reconcile loop can run (e.g. 90m)",
367376
)
368377

378+
fs.BoolVar(&enableTracing,
379+
"enable-tracing",
380+
false,
381+
"Enable collecting and sending traces to opentelemetry-collector service",
382+
)
383+
369384
feature.MutableGates.AddFlag(fs)
370385
}

0 commit comments

Comments
 (0)