Commit 9fc139d4 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Ensure runtime environment values are exposed through the Go runtime InitModule context.

parent 6813b577
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -4,6 +4,9 @@ All notable changes to this project are documented below.
The format is based on [keep a changelog](http://keepachangelog.com) and this project uses [semantic versioning](http://semver.org).

## [Unreleased]
### Added
- Ensure runtime environment values are exposed through the Go runtime InitModule context.

### Changed
- Log more error information when InitModule hooks from Go runtime plugins return errors.

+4 −1
Original line number Diff line number Diff line
@@ -1790,6 +1790,9 @@ func NewRuntimeProviderGo(logger, startupLogger *zap.Logger, db *sql.DB, config
		matchLock: matchLock,
	}

	// The baseline context that will be passed to all InitModule calls.
	ctx := NewRuntimeGoContext(context.Background(), env, RuntimeExecutionModeRunOnce, nil, 0, "", "", "", "", "")

	modulePaths := make([]string, 0)
	for _, path := range paths {
		if strings.ToLower(filepath.Ext(path)) != ".so" {
@@ -1821,7 +1824,7 @@ func NewRuntimeProviderGo(logger, startupLogger *zap.Logger, db *sql.DB, config
		}

		// Run the initialisation.
		if err = fn(context.Background(), stdLogger, db, nk, initializer); err != nil {
		if err = fn(ctx, stdLogger, db, nk, initializer); err != nil {
			startupLogger.Fatal("Error returned by InitModule function in Go module", zap.String("name", name), zap.Error(err))
			return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, errors.New("error returned by InitModule function in Go module")
		}
+4 −1
Original line number Diff line number Diff line
@@ -22,7 +22,10 @@ import (
func NewRuntimeGoContext(ctx context.Context, env map[string]string, mode RuntimeExecutionMode, queryParams map[string][]string, sessionExpiry int64, userID, username, sessionID, clientIP, clientPort string) context.Context {
	ctx = context.WithValue(ctx, runtime.RUNTIME_CTX_ENV, env)
	ctx = context.WithValue(ctx, runtime.RUNTIME_CTX_MODE, mode.String())

	if queryParams != nil {
		ctx = context.WithValue(ctx, runtime.RUNTIME_CTX_QUERY_PARAMS, queryParams)
	}

	if userID != "" {
		ctx = context.WithValue(ctx, runtime.RUNTIME_CTX_USER_ID, userID)