From ca8f57eff83d970647d2679b12e18c65604bdb7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Garc=C3=ADa=20Crespo?= Date: Wed, 4 Sep 2024 08:05:52 +0000 Subject: [PATCH 1/2] Log from activity interceptor --- temporal/log.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/temporal/log.go b/temporal/log.go index 61b8332..ff96cc9 100644 --- a/temporal/log.go +++ b/temporal/log.go @@ -74,6 +74,9 @@ var loggerContextKey = contextKey{} func (a *activityInboundInterceptor) ExecuteActivity(ctx context.Context, in *temporalsdk_interceptor.ExecuteActivityInput) (interface{}, error) { ctx = context.WithValue(ctx, loggerContextKey, a.logger) + + a.logger.V(1).Info("Executing activity.") + return a.Next.ExecuteActivity(ctx, in) } From 8317f2d5c261dbdb8625b809070578d9180e2d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Garc=C3=ADa=20Crespo?= Date: Wed, 4 Sep 2024 08:08:43 +0000 Subject: [PATCH 2/2] Define activity context logger values once --- temporal/log.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/temporal/log.go b/temporal/log.go index ff96cc9..7b95c1b 100644 --- a/temporal/log.go +++ b/temporal/log.go @@ -73,9 +73,15 @@ type contextKey struct{} var loggerContextKey = contextKey{} func (a *activityInboundInterceptor) ExecuteActivity(ctx context.Context, in *temporalsdk_interceptor.ExecuteActivityInput) (interface{}, error) { - ctx = context.WithValue(ctx, loggerContextKey, a.logger) + info := temporalsdk_activity.GetInfo(ctx) + logger := a.logger.WithValues( + "ActivityID", info.ActivityID, + "ActivityType", info.ActivityType.Name, + ) + + ctx = context.WithValue(ctx, loggerContextKey, logger) - a.logger.V(1).Info("Executing activity.") + logger.V(1).Info("Executing activity.") return a.Next.ExecuteActivity(ctx, in) } @@ -86,12 +92,5 @@ func GetLogger(ctx context.Context) logr.Logger { return logr.Discard() } - logger := v.(logr.Logger) - - info := temporalsdk_activity.GetInfo(ctx) - - return logger.WithValues( - "ActivityID", info.ActivityID, - "ActivityType", info.ActivityType.Name, - ) + return v.(logr.Logger) }