Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NK-599 Enrich JS/Lua runtimes context. #1274

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
- Ensure matchmaker stats behave correctly if matchmaker becomes fully empty and idle.
- Correctly clear rank cache entries on account deletion.
- Only display owned purchases in the console account tab.
- Correctly infer X-Forwarded-For headers on Satori Authenticate calls in JS/Lua runtimes.

## [3.23.0] - 2024-07-27
### Added
Expand Down
22 changes: 22 additions & 0 deletions server/runtime_javascript.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type RuntimeJS struct {
nkInst goja.Value
jsLoggerInst goja.Value
env goja.Value
envMap map[string]string
vm *goja.Runtime
nakamaModule *runtimeJavascriptNakamaModule
callbacks *RuntimeJavascriptCallbacks
Expand Down Expand Up @@ -197,6 +198,8 @@ func (rp *RuntimeProviderJS) Rpc(ctx context.Context, id string, headers, queryP
rp.logger.Error("Could not instantiate js logger.", zap.Error(err))
return "", errors.New("Could not run Rpc function."), codes.Internal
}

ctx = NewRuntimeGoContext(ctx, r.node, r.version, r.envMap, RuntimeExecutionModeRPC, headers, queryParams, expiry, userID, username, vars, sessionID, clientIP, clientPort, lang)
r.SetContext(ctx)
retValue, err, code := r.InvokeFunction(RuntimeExecutionModeRPC, id, fn, jsLogger, headers, queryParams, userID, username, vars, expiry, sessionID, clientIP, clientPort, lang, payload)
r.SetContext(context.Background())
Expand Down Expand Up @@ -256,6 +259,8 @@ func (rp *RuntimeProviderJS) BeforeRt(ctx context.Context, id string, logger *za
logger.Error("Could not instantiate js logger.", zap.Error(err))
return nil, errors.New("Could not run runtime Before function.")
}

ctx = NewRuntimeGoContext(ctx, r.node, r.version, r.envMap, RuntimeExecutionModeBefore, nil, nil, expiry, userID, username, vars, sessionID, clientIP, clientPort, lang)
r.SetContext(ctx)
result, fnErr, _ := r.InvokeFunction(RuntimeExecutionModeBefore, id, fn, jsLogger, nil, nil, userID, username, vars, expiry, sessionID, clientIP, clientPort, lang, envelopeMap)
r.SetContext(context.Background())
Expand Down Expand Up @@ -340,6 +345,8 @@ func (rp *RuntimeProviderJS) AfterRt(ctx context.Context, id string, logger *zap
logger.Error("Could not instantiate js logger.", zap.Error(err))
return errors.New("Could not run runtime After function.")
}

ctx = NewRuntimeGoContext(ctx, r.node, r.version, r.envMap, RuntimeExecutionModeAfter, nil, nil, expiry, userID, username, vars, sessionID, clientIP, clientPort, lang)
r.SetContext(ctx)
_, fnErr, _ := r.InvokeFunction(RuntimeExecutionModeAfter, id, fn, jsLogger, nil, nil, userID, username, vars, expiry, sessionID, clientIP, clientPort, lang, outMap, inMap)
r.SetContext(context.Background())
Expand Down Expand Up @@ -405,6 +412,8 @@ func (rp *RuntimeProviderJS) BeforeReq(ctx context.Context, id string, logger *z
logger.Error("Could not instantiate js logger.", zap.Error(err))
return nil, errors.New("Could not run runtime Before function."), codes.Internal
}

ctx = NewRuntimeGoContext(ctx, r.node, r.version, r.envMap, RuntimeExecutionModeBefore, nil, nil, expiry, userID, username, vars, "", clientIP, clientPort, "")
r.SetContext(ctx)
result, fnErr, code := r.InvokeFunction(RuntimeExecutionModeBefore, id, fn, jsLogger, nil, nil, userID, username, vars, expiry, "", clientIP, clientPort, "", reqMap)
r.SetContext(context.Background())
Expand Down Expand Up @@ -508,6 +517,8 @@ func (rp *RuntimeProviderJS) AfterReq(ctx context.Context, id string, logger *za
logger.Error("Could not instantiate js logger.", zap.Error(err))
return errors.New("Could not run runtime After function.")
}

ctx = NewRuntimeGoContext(ctx, r.node, r.version, r.envMap, RuntimeExecutionModeAfter, nil, nil, expiry, userID, username, vars, "", clientIP, clientPort, "")
r.SetContext(ctx)
_, fnErr, _ := r.InvokeFunction(RuntimeExecutionModeAfter, id, fn, jsLogger, nil, nil, userID, username, vars, expiry, "", clientIP, clientPort, "", resMap, reqMap)
r.SetContext(context.Background())
Expand Down Expand Up @@ -1731,6 +1742,7 @@ func NewRuntimeProviderJS(ctx context.Context, logger, startupLogger *zap.Logger
vm: runtime,
nakamaModule: nakamaModule,
env: runtime.ToValue(config.GetRuntime().Environment),
envMap: config.GetRuntime().Environment,
callbacks: callbacks,
}
}
Expand Down Expand Up @@ -1872,6 +1884,7 @@ func (rp *RuntimeProviderJS) MatchmakerMatched(ctx context.Context, entries []*M
return "", false, errors.New("Could not run matchmaker matched hook.")
}

ctx = NewRuntimeGoContext(ctx, r.node, r.version, r.envMap, RuntimeExecutionModeMatchmaker, nil, nil, 0, "", "", nil, "", "", "", "")
r.SetContext(ctx)
retValue, err, _ := r.InvokeFunction(RuntimeExecutionModeMatchmaker, "matchmakerMatched", fn, jsLogger, nil, nil, "", "", nil, 0, "", "", "", "", r.vm.ToValue(entriesSlice))
r.SetContext(context.Background())
Expand Down Expand Up @@ -1963,6 +1976,7 @@ func (rp *RuntimeProviderJS) TournamentEnd(ctx context.Context, tournament *api.
return errors.New("Could not run tournament end hook.")
}

ctx = NewRuntimeGoContext(ctx, r.node, r.version, r.envMap, RuntimeExecutionModeTournamentEnd, nil, nil, 0, "", "", nil, "", "", "", "")
r.SetContext(ctx)
retValue, err, _ := r.InvokeFunction(RuntimeExecutionModeTournamentEnd, "tournamentEnd", fn, jsLogger, nil, nil, "", "", nil, 0, "", "", "", "", tournamentObj, r.vm.ToValue(end), r.vm.ToValue(reset))
r.SetContext(context.Background())
Expand Down Expand Up @@ -2039,6 +2053,7 @@ func (rp *RuntimeProviderJS) TournamentReset(ctx context.Context, tournament *ap
return errors.New("Could not run tournament reset hook.")
}

ctx = NewRuntimeGoContext(ctx, r.node, r.version, r.envMap, RuntimeExecutionModeTournamentReset, nil, nil, 0, "", "", nil, "", "", "", "")
r.SetContext(ctx)
retValue, err, _ := r.InvokeFunction(RuntimeExecutionModeTournamentReset, "tournamentReset", fn, jsLogger, nil, nil, "", "", nil, 0, "", "", "", "", tournamentObj, r.vm.ToValue(end), r.vm.ToValue(reset))
r.SetContext(context.Background())
Expand Down Expand Up @@ -2100,6 +2115,7 @@ func (rp *RuntimeProviderJS) LeaderboardReset(ctx context.Context, leaderboard *
return errors.New("Could not run leaderboard reset hook.")
}

ctx = NewRuntimeGoContext(ctx, r.node, r.version, r.envMap, RuntimeExecutionModeLeaderboardReset, nil, nil, 0, "", "", nil, "", "", "", "")
r.SetContext(ctx)
retValue, err, _ := r.InvokeFunction(RuntimeExecutionModeLeaderboardReset, "leaderboardReset", fn, jsLogger, nil, nil, "", "", nil, 0, "", "", "", "", leaderboardObj, r.vm.ToValue(reset))
r.SetContext(context.Background())
Expand Down Expand Up @@ -2141,6 +2157,7 @@ func (rp *RuntimeProviderJS) Shutdown(ctx context.Context) {
return
}

ctx = NewRuntimeGoContext(ctx, r.node, r.version, r.envMap, RuntimeExecutionModeShutdown, nil, nil, 0, "", "", nil, "", "", "", "")
r.SetContext(ctx)
_, err, _ = r.InvokeFunction(RuntimeExecutionModeShutdown, "shutdown", fn, jsLogger, nil, nil, "", "", nil, 0, "", "", "", "")
r.SetContext(context.Background())
Expand Down Expand Up @@ -2178,6 +2195,7 @@ func (rp *RuntimeProviderJS) PurchaseNotificationApple(ctx context.Context, purc
return errors.New("Could not run Purchase Notification Apple hook.")
}

ctx = NewRuntimeGoContext(ctx, r.node, r.version, r.envMap, RuntimeExecutionModePurchaseNotificationApple, nil, nil, 0, "", "", nil, "", "", "", "")
r.SetContext(ctx)
retValue, err, _ := r.InvokeFunction(RuntimeExecutionModePurchaseNotificationApple, "purchaseNotificationApple", fn, jsLogger, nil, nil, "", "", nil, 0, "", "", "", "", r.vm.ToValue(purchaseMap), r.vm.ToValue(providerPayload))
r.SetContext(context.Background())
Expand Down Expand Up @@ -2220,6 +2238,7 @@ func (rp *RuntimeProviderJS) SubscriptionNotificationApple(ctx context.Context,
return errors.New("Could not run Subscription Notification Apple hook.")
}

ctx = NewRuntimeGoContext(ctx, r.node, r.version, r.envMap, RuntimeExecutionModeSubscriptionNotificationApple, nil, nil, 0, "", "", nil, "", "", "", "")
r.SetContext(ctx)
retValue, err, _ := r.InvokeFunction(RuntimeExecutionModeSubscriptionNotificationApple, "subscriptionNotificationApple", fn, jsLogger, nil, nil, "", "", nil, 0, "", "", "", "", r.vm.ToValue(subscriptionMap), r.vm.ToValue(providerPayload))
r.SetContext(context.Background())
Expand Down Expand Up @@ -2262,6 +2281,7 @@ func (rp *RuntimeProviderJS) PurchaseNotificationGoogle(ctx context.Context, pur
return errors.New("Could not run Purchase Notification Google hook.")
}

ctx = NewRuntimeGoContext(ctx, r.node, r.version, r.envMap, RuntimeExecutionModePurchaseNotificationGoogle, nil, nil, 0, "", "", nil, "", "", "", "")
r.SetContext(ctx)
retValue, err, _ := r.InvokeFunction(RuntimeExecutionModePurchaseNotificationGoogle, "purchaseNotificationGoogle", fn, jsLogger, nil, nil, "", "", nil, 0, "", "", "", "", r.vm.ToValue(purchaseMap), r.vm.ToValue(providerPayload))
r.SetContext(context.Background())
Expand Down Expand Up @@ -2304,6 +2324,7 @@ func (rp *RuntimeProviderJS) SubscriptionNotificationGoogle(ctx context.Context,
return errors.New("Could not run Subscription Notification Google hook.")
}

ctx = NewRuntimeGoContext(ctx, r.node, r.version, r.envMap, RuntimeExecutionModeSubscriptionNotificationGoogle, nil, nil, 0, "", "", nil, "", "", "", "")
r.SetContext(ctx)
retValue, err, _ := r.InvokeFunction(RuntimeExecutionModeSubscriptionNotificationGoogle, "subscriptionNotificationGoogle", fn, jsLogger, nil, nil, "", "", nil, 0, "", "", "", "", r.vm.ToValue(subscriptionMap), r.vm.ToValue(providerPayload))
r.SetContext(context.Background())
Expand Down Expand Up @@ -2365,6 +2386,7 @@ func (rp *RuntimeProviderJS) StorageIndexFilter(ctx context.Context, indexName s
pointerizeSlices(valueMap)
objectMap["value"] = valueMap

ctx = NewRuntimeGoContext(ctx, r.node, r.version, r.envMap, RuntimeExecutionModeStorageIndexFilter, nil, nil, 0, "", "", nil, "", "", "", "")
r.SetContext(ctx)
retValue, err, _ := r.InvokeFunction(RuntimeExecutionModeStorageIndexFilter, "storageIndexFilter", fn, jsLogger, nil, nil, "", "", nil, 0, "", "", "", "", r.vm.ToValue(objectMap))
r.SetContext(context.Background())
Expand Down
18 changes: 18 additions & 0 deletions server/runtime_lua.go
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,7 @@ func NewRuntimeProviderLua(ctx context.Context, logger, startupLogger *zap.Logge
version: version,
vm: vm,
luaEnv: RuntimeLuaConvertMapString(vm, config.GetRuntime().Environment),
env: config.GetRuntime().Environment,
callbacks: callbacksGlobals,
}
return r
Expand Down Expand Up @@ -1353,6 +1354,7 @@ func (rp *RuntimeProviderLua) Rpc(ctx context.Context, id string, headers, query

// Set context value used for logging
vmCtx := context.WithValue(ctx, ctxLoggerFields{}, map[string]string{"rpc_id": id})
vmCtx = NewRuntimeGoContext(ctx, r.node, r.version, r.env, RuntimeExecutionModeRPC, headers, queryParams, expiry, userID, username, vars, sessionID, clientIP, clientPort, lang)
r.vm.SetContext(vmCtx)
result, fnErr, code, isCustomErr := r.InvokeFunction(RuntimeExecutionModeRPC, lf, headers, queryParams, userID, username, vars, expiry, sessionID, clientIP, clientPort, lang, payload)
r.vm.SetContext(context.Background())
Expand Down Expand Up @@ -1413,6 +1415,7 @@ func (rp *RuntimeProviderLua) BeforeRt(ctx context.Context, id string, logger *z

// Set context value used for logging
vmCtx := context.WithValue(ctx, ctxLoggerFields{}, map[string]string{"api_id": strings.TrimPrefix(id, RTAPI_PREFIX_LOWERCASE), "mode": RuntimeExecutionModeBefore.String()})
vmCtx = NewRuntimeGoContext(ctx, r.node, r.version, r.env, RuntimeExecutionModeBefore, nil, nil, expiry, userID, username, vars, sessionID, clientIP, clientPort, lang)
r.vm.SetContext(vmCtx)
result, fnErr, _, isCustomErr := r.InvokeFunction(RuntimeExecutionModeBefore, lf, nil, nil, userID, username, vars, expiry, sessionID, clientIP, clientPort, lang, envelopeMap)
r.vm.SetContext(context.Background())
Expand Down Expand Up @@ -1489,6 +1492,7 @@ func (rp *RuntimeProviderLua) AfterRt(ctx context.Context, id string, logger *za

// Set context value used for logging
vmCtx := context.WithValue(ctx, ctxLoggerFields{}, map[string]string{"api_id": strings.TrimPrefix(id, RTAPI_PREFIX_LOWERCASE), "mode": RuntimeExecutionModeAfter.String()})
vmCtx = NewRuntimeGoContext(ctx, r.node, r.version, r.env, RuntimeExecutionModeAfter, nil, nil, expiry, userID, username, vars, sessionID, clientIP, clientPort, lang)
r.vm.SetContext(vmCtx)
_, fnErr, _, isCustomErr := r.InvokeFunction(RuntimeExecutionModeAfter, lf, nil, nil, userID, username, vars, expiry, sessionID, clientIP, clientPort, lang, outMap, inMap)
r.vm.SetContext(context.Background())
Expand Down Expand Up @@ -1546,6 +1550,7 @@ func (rp *RuntimeProviderLua) BeforeReq(ctx context.Context, id string, logger *

// Set context value used for logging
vmCtx := context.WithValue(ctx, ctxLoggerFields{}, map[string]string{"api_id": strings.TrimPrefix(id, API_PREFIX_LOWERCASE), "mode": RuntimeExecutionModeBefore.String()})
vmCtx = NewRuntimeGoContext(ctx, r.node, r.version, r.env, RuntimeExecutionModeBefore, nil, nil, expiry, userID, username, vars, "", clientIP, clientPort, "")
r.vm.SetContext(vmCtx)
result, fnErr, code, isCustomErr := r.InvokeFunction(RuntimeExecutionModeBefore, lf, nil, nil, userID, username, vars, expiry, "", clientIP, clientPort, "", reqMap)
r.vm.SetContext(context.Background())
Expand Down Expand Up @@ -1641,6 +1646,7 @@ func (rp *RuntimeProviderLua) AfterReq(ctx context.Context, id string, logger *z

// Set context value used for logging
vmCtx := context.WithValue(ctx, ctxLoggerFields{}, map[string]string{"api_id": strings.TrimPrefix(id, API_PREFIX_LOWERCASE), "mode": RuntimeExecutionModeAfter.String()})
vmCtx = NewRuntimeGoContext(ctx, r.node, r.version, r.env, RuntimeExecutionModeAfter, nil, nil, expiry, userID, username, vars, "", clientIP, clientPort, "")
r.vm.SetContext(vmCtx)
_, fnErr, _, isCustomErr := r.InvokeFunction(RuntimeExecutionModeAfter, lf, nil, nil, userID, username, vars, expiry, "", clientIP, clientPort, "", resMap, reqMap)
r.vm.SetContext(context.Background())
Expand Down Expand Up @@ -1703,6 +1709,7 @@ func (rp *RuntimeProviderLua) MatchmakerMatched(ctx context.Context, entries []*

// Set context value used for logging
vmCtx := context.WithValue(ctx, ctxLoggerFields{}, map[string]string{"mode": RuntimeExecutionModeMatchmaker.String()})
vmCtx = NewRuntimeGoContext(ctx, r.node, r.version, r.env, RuntimeExecutionModeMatchmaker, nil, nil, 0, "", "", nil, "", "", "", "")
r.vm.SetContext(vmCtx)
retValue, err, _, _ := r.invokeFunction(r.vm, lf, luaCtx, entriesTable)
r.vm.SetContext(context.Background())
Expand Down Expand Up @@ -1793,6 +1800,7 @@ func (rp *RuntimeProviderLua) TournamentEnd(ctx context.Context, tournament *api

// Set context value used for logging
vmCtx := context.WithValue(ctx, ctxLoggerFields{}, map[string]string{"mode": RuntimeExecutionModeTournamentEnd.String()})
vmCtx = NewRuntimeGoContext(ctx, r.node, r.version, r.env, RuntimeExecutionModeTournamentEnd, nil, nil, 0, "", "", nil, "", "", "", "")
r.vm.SetContext(vmCtx)
retValue, err, _, _ := r.invokeFunction(r.vm, lf, luaCtx, tournamentTable, lua.LNumber(end), lua.LNumber(reset))
r.vm.SetContext(context.Background())
Expand Down Expand Up @@ -1864,6 +1872,7 @@ func (rp *RuntimeProviderLua) TournamentReset(ctx context.Context, tournament *a

// Set context value used for logging
vmCtx := context.WithValue(ctx, ctxLoggerFields{}, map[string]string{"mode": RuntimeExecutionModeTournamentReset.String()})
vmCtx = NewRuntimeGoContext(ctx, r.node, r.version, r.env, RuntimeExecutionModeTournamentReset, nil, nil, 0, "", "", nil, "", "", "", "")
r.vm.SetContext(vmCtx)
retValue, err, _, _ := r.invokeFunction(r.vm, lf, luaCtx, tournamentTable, lua.LNumber(end), lua.LNumber(reset))
r.vm.SetContext(context.Background())
Expand Down Expand Up @@ -1917,6 +1926,7 @@ func (rp *RuntimeProviderLua) LeaderboardReset(ctx context.Context, leaderboard

// Set context value used for logging
vmCtx := context.WithValue(ctx, ctxLoggerFields{}, map[string]string{"mode": RuntimeExecutionModeLeaderboardReset.String()})
vmCtx = NewRuntimeGoContext(ctx, r.node, r.version, r.env, RuntimeExecutionModeLeaderboardReset, nil, nil, 0, "", "", nil, "", "", "", "")
r.vm.SetContext(vmCtx)
retValue, err, _, _ := r.invokeFunction(r.vm, lf, luaCtx, leaderboardTable, lua.LNumber(reset))
r.vm.SetContext(context.Background())
Expand Down Expand Up @@ -1949,6 +1959,7 @@ func (rp *RuntimeProviderLua) Shutdown(ctx context.Context) {

// Set context value used for logging
vmCtx := context.WithValue(ctx, ctxLoggerFields{}, map[string]string{"mode": RuntimeExecutionModeShutdown.String()})
vmCtx = NewRuntimeGoContext(ctx, r.node, r.version, r.env, RuntimeExecutionModeShutdown, nil, nil, 0, "", "", nil, "", "", "", "")
r.vm.SetContext(vmCtx)
_, err, _, _ = r.invokeFunction(r.vm, lf, luaCtx)
r.vm.SetContext(context.Background())
Expand Down Expand Up @@ -1976,6 +1987,7 @@ func (rp *RuntimeProviderLua) PurchaseNotificationApple(ctx context.Context, pur

// Set context value used for logging
vmCtx := context.WithValue(ctx, ctxLoggerFields{}, map[string]string{"mode": RuntimeExecutionModePurchaseNotificationApple.String()})
vmCtx = NewRuntimeGoContext(ctx, r.node, r.version, r.env, RuntimeExecutionModePurchaseNotificationApple, nil, nil, 0, "", "", nil, "", "", "", "")
r.vm.SetContext(vmCtx)
retValue, err, _, _ := r.invokeFunction(r.vm, lf, luaCtx, purchaseTable, lua.LString(providerPayload))
r.vm.SetContext(context.Background())
Expand Down Expand Up @@ -2009,6 +2021,7 @@ func (rp *RuntimeProviderLua) SubscriptionNotificationApple(ctx context.Context,

// Set context value used for logging
vmCtx := context.WithValue(ctx, ctxLoggerFields{}, map[string]string{"mode": RuntimeExecutionModeSubscriptionNotificationApple.String()})
vmCtx = NewRuntimeGoContext(ctx, r.node, r.version, r.env, RuntimeExecutionModeSubscriptionNotificationApple, nil, nil, 0, "", "", nil, "", "", "", "")
r.vm.SetContext(vmCtx)
retValue, err, _, _ := r.invokeFunction(r.vm, lf, luaCtx, subscriptionTable, lua.LString(providerPayload))
r.vm.SetContext(context.Background())
Expand Down Expand Up @@ -2042,6 +2055,7 @@ func (rp *RuntimeProviderLua) PurchaseNotificationGoogle(ctx context.Context, pu

// Set context value used for logging
vmCtx := context.WithValue(ctx, ctxLoggerFields{}, map[string]string{"mode": RuntimeExecutionModePurchaseNotificationGoogle.String()})
vmCtx = NewRuntimeGoContext(ctx, r.node, r.version, r.env, RuntimeExecutionModePurchaseNotificationGoogle, nil, nil, 0, "", "", nil, "", "", "", "")
r.vm.SetContext(vmCtx)
retValue, err, _, _ := r.invokeFunction(r.vm, lf, luaCtx, purchaseTable, lua.LString(providerPayload))
r.vm.SetContext(context.Background())
Expand Down Expand Up @@ -2075,6 +2089,7 @@ func (rp *RuntimeProviderLua) SubscriptionNotificationGoogle(ctx context.Context

// Set context value used for logging
vmCtx := context.WithValue(ctx, ctxLoggerFields{}, map[string]string{"mode": RuntimeExecutionModeSubscriptionNotificationGoogle.String()})
vmCtx = NewRuntimeGoContext(ctx, r.node, r.version, r.env, RuntimeExecutionModeSubscriptionNotificationGoogle, nil, nil, 0, "", "", nil, "", "", "", "")
r.vm.SetContext(vmCtx)
retValue, err, _, _ := r.invokeFunction(r.vm, lf, luaCtx, subscriptionTable, lua.LString(providerPayload))
r.vm.SetContext(context.Background())
Expand Down Expand Up @@ -2131,6 +2146,7 @@ func (rp *RuntimeProviderLua) StorageIndexFilter(ctx context.Context, indexName

// Set context value used for logging
vmCtx := context.WithValue(ctx, ctxLoggerFields{}, map[string]string{"mode": RuntimeExecutionModeStorageIndexFilter.String()})
vmCtx = NewRuntimeGoContext(ctx, r.node, r.version, r.env, RuntimeExecutionModeStorageIndexFilter, nil, nil, 0, "", "", nil, "", "", "", "")
r.vm.SetContext(vmCtx)
retValue, err, _, _ := r.invokeFunction(r.vm, lf, luaCtx, writeTable)
r.vm.SetContext(context.Background())
Expand Down Expand Up @@ -2202,6 +2218,7 @@ type RuntimeLua struct {
version string
vm *lua.LState
luaEnv *lua.LTable
env map[string]string
callbacks *RuntimeLuaCallbacks
}

Expand Down Expand Up @@ -2522,6 +2539,7 @@ func newRuntimeLuaVM(logger *zap.Logger, db *sql.DB, protojsonMarshaler *protojs
version: version,
vm: vm,
luaEnv: RuntimeLuaConvertMapString(vm, config.GetRuntime().Environment),
env: config.GetRuntime().Environment,
callbacks: callbacks,
}

Expand Down
Loading