Skip to content

Commit af6c884

Browse files
authored
feat: extend logger with potential cluster attribute (#168)
1 parent 4c826cb commit af6c884

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

controller/lifecycle/lifecycle.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
ctrl "sigs.k8s.io/controller-runtime"
1717
"sigs.k8s.io/controller-runtime/pkg/client"
1818
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
19+
mccontext "sigs.k8s.io/multicluster-runtime/pkg/context"
1920

2021
"github.com/platform-mesh/golang-commons/controller/lifecycle/api"
2122
"github.com/platform-mesh/golang-commons/controller/lifecycle/runtimeobject"
@@ -34,6 +35,10 @@ func Reconcile(ctx context.Context, nName types.NamespacedName, instance runtime
3435
reconcileId := uuid.New().String()
3536

3637
log := l.Log().MustChildLoggerWithAttributes("name", nName.Name, "namespace", nName.Namespace, "reconcile_id", reconcileId)
38+
cluster, ok := mccontext.ClusterFrom(ctx)
39+
if ok {
40+
log = log.MustChildLoggerWithAttributes("cluster", cluster)
41+
}
3742
sentryTags := sentry.Tags{"namespace": nName.Namespace, "name": nName.Name}
3843

3944
ctx = logger.SetLoggerInContext(ctx, log)

0 commit comments

Comments
 (0)