ronantakizawa/codereview-bench huggingface dataset:
Repository: traefik/traefik
File: pkg/plugins/wasip.go (Go)

Code before:
//go:build !windows

package plugins

import (
	"context"
	"fmt"
	"os"

	"github.com/stealthrocket/wasi-go/imports"
	wazergo_wasip1 "github.com/stealthrocket/wasi-go/imports/wasi_snapshot_preview1"
	"github.com/stealthrocket/wazergo"
	"github.com/tetratelabs/wazero"
	wazero_wasip1 "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
)

type ContextApplier func(ctx context.Context) context.Context

func Instantiate(ctx context.Context, runtime wazero.Runtime, mod wazero.CompiledModule, settings Settings) (ContextApplier, error) {
	extension := imports.DetectSocketsExtension(mod)
	if extension != nil {
		hostModule := wazergo_wasip1.NewHostModule(*extension)

		builder := imports.NewBuilder().WithSocketsExtension("auto", mod)

		envs := []string{}
		for _, env := range settings.Envs {
			envs = append(envs, fmt.Sprintf("%s=%s", env, os.Getenv(env)))
		}
		if len(envs) > 0 {
			builder.WithEnv(envs...)
		}

		if len(settings.Mounts) > 0 {
			builder.WithDirs(settings.Mounts...)
		}

		ctx, sys, err := builder.Instantiate(ctx, runtime)
		if err != nil {
			return nil, err
		}

		inst, err := wazergo.Instantiate(ctx, runtime, hostModule, wazergo_wasip1.WithWASI(sys))
		if err != nil {
			return nil, err
		}


Review comment (suggestion):
```suggestion
		hostModule := wazergo_wasip1.NewHostModule(*socketsExtension)
```

Code after:
//go:build !windows

package plugins

import (
	"context"
	"fmt"
	"os"

	"github.com/stealthrocket/wasi-go/imports"
	wazergo_wasip1 "github.com/stealthrocket/wasi-go/imports/wasi_snapshot_preview1"
	"github.com/stealthrocket/wazergo"
	"github.com/tetratelabs/wazero"
	wazero_wasip1 "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
)

type ContextApplier func(ctx context.Context) context.Context

// InstantiateHost instantiates the Host module according to the guest requirements (for now only SocketExtensions).
func InstantiateHost(ctx context.Context, runtime wazero.Runtime, mod wazero.CompiledModule, settings Settings) (ContextApplier, error) {
	if extension := imports.DetectSocketsExtension(mod); extension != nil {
		envs := []string{}
		for _, env := range settings.Envs {
			envs = append(envs, fmt.Sprintf("%s=%s", env, os.Getenv(env)))
		}

		builder := imports.NewBuilder().WithSocketsExtension("auto", mod)
		if len(envs) > 0 {
			builder.WithEnv(envs...)
		}

		if len(settings.Mounts) > 0 {
			builder.WithDirs(settings.Mounts...)
		}

		ctx, sys, err := builder.Instantiate(ctx, runtime)
		if err != nil {
			return nil, err
		}

		inst, err := wazergo.Instantiate(ctx, runtime, wazergo_wasip1.NewHostModule(*extension), wazergo_wasip1.WithWASI(sys))
		if err != nil {
			return nil, fmt.Errorf("wazergo instantiation: %w", err)
		}

		return func(ctx context.Context) context.Context {
			return wazergo.WithModuleInstance(ctx, inst)
Repository: traefik/traefik
File: pkg/plugins/wasip.go (Go)

Code before:
		if len(envs) > 0 {
			builder.WithEnv(envs...)
		}

		if len(settings.Mounts) > 0 {
			builder.WithDirs(settings.Mounts...)
		}

		ctx, sys, err := builder.Instantiate(ctx, runtime)
		if err != nil {
			return nil, err
		}

		inst, err := wazergo.Instantiate(ctx, runtime, hostModule, wazergo_wasip1.WithWASI(sys))
		if err != nil {
			return nil, err
		}

		return func(ctx context.Context) context.Context {
			return wazergo.WithModuleInstance(ctx, inst)
		}, nil
	}

	_, err := wazero_wasip1.Instantiate(ctx, runtime)
	if err != nil {
		return nil, err
	}
	return func(ctx context.Context) context.Context {
		return ctx
	}, nil
}


Review comment (suggestion):
```suggestion
		return nil, err
```
```suggestion
		return nil, fmt.Errorf("wazero instantiation: %w", err)
```

Code after:
		}

		if len(settings.Mounts) > 0 {
			builder.WithDirs(settings.Mounts...)
		}

		ctx, sys, err := builder.Instantiate(ctx, runtime)
		if err != nil {
			return nil, err
		}

		inst, err := wazergo.Instantiate(ctx, runtime, wazergo_wasip1.NewHostModule(*extension), wazergo_wasip1.WithWASI(sys))
		if err != nil {
			return nil, fmt.Errorf("wazergo instantiation: %w", err)
		}

		return func(ctx context.Context) context.Context {
			return wazergo.WithModuleInstance(ctx, inst)
		}, nil
	}

	_, err := wazero_wasip1.Instantiate(ctx, runtime)
	if err != nil {
		return nil, fmt.Errorf("wazero instantiation: %w", err)
	}

	return func(ctx context.Context) context.Context {
		return ctx
	}, nil
}
Repository: traefik/traefik
File: pkg/plugins/wasip.go (Go)

Code before:
	extension := imports.DetectSocketsExtension(mod)
	if extension != nil {
		hostModule := wazergo_wasip1.NewHostModule(*extension)

		builder := imports.NewBuilder().WithSocketsExtension("auto", mod)

		envs := []string{}
		for _, env := range settings.Envs {
			envs = append(envs, fmt.Sprintf("%s=%s", env, os.Getenv(env)))
		}
		if len(envs) > 0 {
			builder.WithEnv(envs...)
		}

		if len(settings.Mounts) > 0 {
			builder.WithDirs(settings.Mounts...)
		}

		ctx, sys, err := builder.Instantiate(ctx, runtime)
		if err != nil {
			return nil, err
		}

		inst, err := wazergo.Instantiate(ctx, runtime, hostModule, wazergo_wasip1.WithWASI(sys))
		if err != nil {
			return nil, err
		}

		return func(ctx context.Context) context.Context {
			return wazergo.WithModuleInstance(ctx, inst)
		}, nil
	}

	_, err := wazero_wasip1.Instantiate(ctx, runtime)
	if err != nil {
		return nil, err
	}
	return func(ctx context.Context) context.Context {
		return ctx
	}, nil
}


Review comment (suggestion):
```suggestion
			return nil, fmt.Errorf("wazergo instantiation: %w", err)
```

Code after:
func InstantiateHost(ctx context.Context, runtime wazero.Runtime, mod wazero.CompiledModule, settings Settings) (ContextApplier, error) {
	if extension := imports.DetectSocketsExtension(mod); extension != nil {
		envs := []string{}
		for _, env := range settings.Envs {
			envs = append(envs, fmt.Sprintf("%s=%s", env, os.Getenv(env)))
		}

		builder := imports.NewBuilder().WithSocketsExtension("auto", mod)
		if len(envs) > 0 {
			builder.WithEnv(envs...)
		}

		if len(settings.Mounts) > 0 {
			builder.WithDirs(settings.Mounts...)
		}

		ctx, sys, err := builder.Instantiate(ctx, runtime)
		if err != nil {
			return nil, err
		}

		inst, err := wazergo.Instantiate(ctx, runtime, wazergo_wasip1.NewHostModule(*extension), wazergo_wasip1.WithWASI(sys))
		if err != nil {
			return nil, fmt.Errorf("wazergo instantiation: %w", err)
		}

		return func(ctx context.Context) context.Context {
			return wazergo.WithModuleInstance(ctx, inst)
		}, nil
	}

	_, err := wazero_wasip1.Instantiate(ctx, runtime)
	if err != nil {
		return nil, fmt.Errorf("wazero instantiation: %w", err)
	}

	return func(ctx context.Context) context.Context {
		return ctx
	}, nil
}
Repository: traefik/traefik
File: pkg/plugins/middlewarewasm.go (Go)

Code before:
		handler.ModuleConfig(config),
		handler.Logger(logs.NewWasmLogger(logger)),
	}

	i := cfg.Interface()
	if i != nil {
		config, ok := i.(map[string]interface{})
		if !ok {
			return nil, nil, fmt.Errorf("could not type assert config: %T", i)
		}

		data, err := json.Marshal(config)
		if err != nil {
			return nil, nil, fmt.Errorf("marshaling config: %w", err)
		}

		opts = append(opts, handler.GuestConfig(data))
	}

	opts = append(opts, handler.Runtime(func(ctx context.Context) (wazero.Runtime, error) {
		return rt, nil
	}))

	mw, err := wasm.NewMiddleware(applyCtx(ctx), code, opts...)
	if err != nil {
		return nil, nil, err
	}

	return mw.NewHandler(ctx, next), applyCtx, nil
}

// WasmMiddleware is an HTTP handler plugin wrapper.
type WasmMiddleware struct {
	middlewareName string
	config         reflect.Value
	builder        wasmMiddlewareBuilder
}

// NewHandler creates a new HTTP handler.
func (m WasmMiddleware) NewHandler(ctx context.Context, next http.Handler) (http.Handler, error) {
	return m.builder.newHandler(ctx, next, m.config, m.middlewareName)
}


Review comment (suggestion):
```suggestion
		return nil, nil, fmt.Errorf("creating middleware: %w", err)
```

Code after:
		handler.ModuleConfig(config),
		handler.Logger(logs.NewWasmLogger(logger)),
	}

	i := cfg.Interface()
	if i != nil {
		config, ok := i.(map[string]interface{})
		if !ok {
			return nil, nil, fmt.Errorf("could not type assert config: %T", i)
		}

		data, err := json.Marshal(config)
		if err != nil {
			return nil, nil, fmt.Errorf("marshaling config: %w", err)
		}

		opts = append(opts, handler.GuestConfig(data))
	}

	opts = append(opts, handler.Runtime(func(ctx context.Context) (wazero.Runtime, error) {
		return rt, nil
	}))

	mw, err := wasm.NewMiddleware(applyCtx(ctx), code, opts...)
	if err != nil {
		return nil, nil, fmt.Errorf("creating middleware: %w", err)
	}

	return mw.NewHandler(ctx, next), applyCtx, nil
}

// WasmMiddleware is an HTTP handler plugin wrapper.
type WasmMiddleware struct {
	middlewareName string
	config         reflect.Value
	builder        wasmMiddlewareBuilder
}

// NewHandler creates a new HTTP handler.
func (m WasmMiddleware) NewHandler(ctx context.Context, next http.Handler) (http.Handler, error) {
	return m.builder.newHandler(ctx, next, m.config, m.middlewareName)
}
Repository: traefik/traefik
File: pkg/provider/nomad/nomad.go (Go)

Code before:
						Index: uint64(t.UnixNano()),
					}
				}
			}
		}()

		return serviceEventsChan, nil
	}

	return p.client.EventStream().Stream(ctx,
		map[api.Topic][]string{
			api.TopicService: {"*"},
		},
		0,
		&api.QueryOptions{
			Namespace: p.namespace,
		},
	)
}

func (p *Provider) loadConfiguration(ctx context.Context) (*dynamic.Configuration, error) {
	var items []item
	var err error
	if p.AllowEmptyServices {
		items, err = p.getNomadServiceDataWithEmptyServices(ctx)
		if err != nil {
			return nil, err
		}
	} else {
		items, err = p.getNomadServiceData(ctx)
		if err != nil {
			return nil, err
		}
	}

	return p.buildConfig(ctx, items), nil
}

func (p *Provider) getNomadServiceData(ctx context.Context) ([]item, error) {
	// first, get list of service stubs
	opts := &api.QueryOptions{AllowStale: p.Stale}
	opts = opts.WithContext(ctx)

	stubs, _, err := p.client.Services().List(opts)
	if err != nil {
		return nil, err
	}

	var items []item

	for _, stub := range stubs {

Review comment (suggestion):
```suggestion
func (p *Provider) pollOrWatch(ctx context.Context) (<-chan *api.Events, error) {
	if p.Watch {
		return p.client.EventStream().Stream(ctx,
			map[api.Topic][]string{
				api.TopicService: {"*"},
			},
			0,
			&api.QueryOptions{
				Namespace: p.namespace,
			},
		)
	}

	serviceEventsChan := make(chan *api.Events, 1)

	go func() {
		ticker := time.NewTicker(time.Duration(p.RefreshInterval))
		defer ticker.Stop()

		for {
			select {
			case <-ctx.Done():
				return
			case t := <-ticker.C:
				serviceEventsChan <- &api.Events{
					Index: uint64(t.UnixNano()),
				}
			}
		}
	}()

	return serviceEventsChan, nil
}
```

Code after:
			&api.QueryOptions{
				Namespace: p.namespace,
			},
		)
	}

	serviceEventsChan := make(chan *api.Events, 1)

	go func() {
		ticker := time.NewTicker(time.Duration(p.RefreshInterval))
		defer ticker.Stop()

		for {
			select {
			case <-ctx.Done():
				return
			case t := <-ticker.C:
				serviceEventsChan <- &api.Events{
					Index: uint64(t.UnixNano()),
				}
			}
		}
	}()

	return serviceEventsChan, nil
}

func (p *Provider) loadConfiguration(ctx context.Context) (*dynamic.Configuration, error) {
	var items []item
	var err error
	if p.AllowEmptyServices {
		items, err = p.getNomadServiceDataWithEmptyServices(ctx)
		if err != nil {
			return nil, err
		}
	} else {
		items, err = p.getNomadServiceData(ctx)
		if err != nil {
			return nil, err
		}
	}

	return p.buildConfig(ctx, items), nil
}

func (p *Provider) updateLastConfiguration(conf *dynamic.Configuration) (bool, error) {
	confHash, err := hashstructure.Hash(conf, nil)
	if err != nil {
		return false, fmt.Errorf("hashing the configuration: %w", err)
	}
Repository: traefik/traefik
File: pkg/server/server_entrypoint_tcp_http3.go (Go)

Code before:
type http3server struct {
	*http3.Server

	http3conn net.PacketConn

	lock   sync.RWMutex
	getter func(info *tls.ClientHelloInfo) (*tls.Config, error)
}

func newHTTP3Server(ctx context.Context, name string, config *static.EntryPoint, httpsServer *httpServer) (*http3server, error) {
	var conn net.PacketConn
	var err error

	if config.HTTP3 == nil {
		return nil, nil
	}

	if config.HTTP3.AdvertisedPort < 0 {
		return nil, errors.New("advertised port must be greater than or equal to zero")
	}

	// if we have predefined connections from socket activation
	if socketActivation.isEnabled() {
		conn, err = socketActivation.getConn(name)
		if err != nil {
			log.Ctx(ctx).Warn().Str("name", name).Msgf("Unable to use socket activation for entrypoint: %v", err)
		}
	}

	if conn == nil {
		listenConfig := newListenConfig(config)
		conn, err = listenConfig.ListenPacket(ctx, "udp", config.GetAddress())
		if err != nil {
			return nil, fmt.Errorf("starting listener: %w", err)
		}
	}

	h3 := &http3server{
		http3conn: conn,
		getter: func(info *tls.ClientHelloInfo) (*tls.Config, error) {
			return nil, errors.New("no tls config")
		},
	}

	h3.Server = &http3.Server{
		Addr:      config.GetAddress(),
		Port:      config.HTTP3.AdvertisedPort,
		Handler:   httpsServer.Server.(*http.Server).Handler,
		TLSConfig: &tls.Config{GetConfigForClient: h3.getGetConfigForClient},
		QUICConfig: &quic.Config{
			Allow0RTT: false,

Review comment (suggestion):
```suggestion
			log.Ctx(ctx).Warn().Err(err).Str("name", name).Msg("Unable to use socket activation for entrypoint")
```

Code after:
type http3server struct {
	*http3.Server

	http3conn net.PacketConn

	lock   sync.RWMutex
	getter func(info *tls.ClientHelloInfo) (*tls.Config, error)
}

func newHTTP3Server(ctx context.Context, name string, config *static.EntryPoint, httpsServer *httpServer) (*http3server, error) {
	var conn net.PacketConn
	var err error

	if config.HTTP3 == nil {
		return nil, nil
	}

	if config.HTTP3.AdvertisedPort < 0 {
		return nil, errors.New("advertised port must be greater than or equal to zero")
	}

	// if we have predefined connections from socket activation
	if socketActivation.isEnabled() {
		conn, err = socketActivation.getConn(name)
		if err != nil {
			log.Ctx(ctx).Warn().Err(err).Str("name", name).Msg("Unable to use socket activation for entrypoint")
		}
	}

	if conn == nil {
		listenConfig := newListenConfig(config)
		conn, err = listenConfig.ListenPacket(ctx, "udp", config.GetAddress())
		if err != nil {
			return nil, fmt.Errorf("starting listener: %w", err)
		}
	}

	h3 := &http3server{
		http3conn: conn,
		getter: func(info *tls.ClientHelloInfo) (*tls.Config, error) {
			return nil, errors.New("no tls config")
		},
	}

	h3.Server = &http3.Server{
		Addr:      config.GetAddress(),
		Port:      config.HTTP3.AdvertisedPort,
		Handler:   httpsServer.Server.(*http.Server).Handler,
		TLSConfig: &tls.Config{GetConfigForClient: h3.getGetConfigForClient},
		QUICConfig: &quic.Config{
			Allow0RTT: false,
Repository: traefik/traefik
File: pkg/middlewares/accesslog/logger_test.go (Go)

Code before:
				},
			},
		},
	}

	for _, test := range testCases {
		t.Run(test.desc, func(t *testing.T) {
			logFile, err := os.CreateTemp(t.TempDir(), "*.log")
			require.NoError(t, err)

			config := &types.AccessLog{
				FilePath: logFile.Name(),
				Format:   CommonFormat,
				Fields:   &test.accessLogFields,
			}

			logger, err := NewHandler(config)
			require.NoError(t, err)
			t.Cleanup(func() {
				err := logger.Close()
				require.NoError(t, err)
			})

			if config.FilePath != "" {
				_, err = os.Stat(config.FilePath)
				require.NoError(t, err)
			}

			req := &http.Request{
				Header: map[string][]string{},
				URL: &url.URL{
					Path: testPath,
				},
			}

			for _, s := range expectedValues {
				req.Header.Add(test.header, s)
			}

			chain := alice.New()
			chain = chain.Append(capture.Wrap)
			chain = chain.Append(WrapHandler(logger))
			handler, err := chain.Then(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
				rw.WriteHeader(http.StatusOK)
			}))
			require.NoError(t, err)
			handler.ServeHTTP(httptest.NewRecorder(), req)

			logData, err := os.ReadFile(logFile.Name())
			require.NoError(t, err)


Review comment (suggestion):
```suggestion
				require.NoErrorf(t, err, "logger should create %s", config.FilePath)
```

Code after:
				},
			},
		},
	}

	for _, test := range testCases {
		t.Run(test.desc, func(t *testing.T) {
			logFile, err := os.CreateTemp(t.TempDir(), "*.log")
			require.NoError(t, err)

			config := &types.AccessLog{
				FilePath: logFile.Name(),
				Format:   CommonFormat,
				Fields:   &test.accessLogFields,
			}

			logger, err := NewHandler(config)
			require.NoError(t, err)
			t.Cleanup(func() {
				err := logger.Close()
				require.NoError(t, err)
			})

			if config.FilePath != "" {
				_, err = os.Stat(config.FilePath)
				require.NoErrorf(t, err, "logger should create %s", config.FilePath)
			}

			req := &http.Request{
				Header: map[string][]string{},
				URL: &url.URL{
					Path: testPath,
				},
			}

			for _, s := range expectedValues {
				req.Header.Add(test.header, s)
			}

			chain := alice.New()
			chain = chain.Append(capture.Wrap)
			chain = chain.Append(WrapHandler(logger))
			handler, err := chain.Then(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
				rw.WriteHeader(http.StatusOK)
			}))
			require.NoError(t, err)
			handler.ServeHTTP(httptest.NewRecorder(), req)

			logData, err := os.ReadFile(logFile.Name())
			require.NoError(t, err)
Repository: traefik/traefik
File: pkg/middlewares/accesslog/logger_test.go (Go)

Code before:
	file, err := os.CreateTemp("", "testlogger")
	require.NoError(t, err, "failed to create temp file")

	original := os.Stdout
	os.Stdout = file

	restoreStdout = func() {
		os.Stdout = original
		_ = os.RemoveAll(file.Name())
	}

	return file, restoreStdout
}

func doLoggingTLSOpt(t *testing.T, config *types.AccessLog, enableTLS bool) {
	t.Helper()
	logger, err := NewHandler(config)
	require.NoError(t, err)
	t.Cleanup(func() {
		err := logger.Close()
		require.NoError(t, err)
	})

	if config.FilePath != "" {
		_, err = os.Stat(config.FilePath)
		require.NoError(t, err)
	}

	req := &http.Request{
		Header: map[string][]string{
			"User-Agent": {testUserAgent},
			"Referer":    {testReferer},
		},
		Proto:      testProto,
		Host:       testHostname,
		Method:     testMethod,
		RemoteAddr: fmt.Sprintf("%s:%d", testHostname, testPort),
		URL: &url.URL{
			User: url.UserPassword(testUsername, ""),
			Path: testPath,
		},
		Body: io.NopCloser(bytes.NewReader([]byte("bar"))),
	}
	if enableTLS {
		req.TLS = &tls.ConnectionState{
			Version:     tls.VersionTLS13,
			CipherSuite: tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
		}
	}

	chain := alice.New()

Review comment (suggestion):
```suggestion
		require.NoErrorf(t, err, "logger should create %s", config.FilePath)
```

Code after:
	file, err := os.CreateTemp("", "testlogger")
	require.NoError(t, err, "failed to create temp file")

	original := os.Stdout
	os.Stdout = file

	restoreStdout = func() {
		os.Stdout = original
		_ = os.RemoveAll(file.Name())
	}

	return file, restoreStdout
}

func doLoggingTLSOpt(t *testing.T, config *types.AccessLog, enableTLS bool) {
	t.Helper()
	logger, err := NewHandler(config)
	require.NoError(t, err)
	t.Cleanup(func() {
		err := logger.Close()
		require.NoError(t, err)
	})

	if config.FilePath != "" {
		_, err = os.Stat(config.FilePath)
		require.NoErrorf(t, err, "logger should create %s", config.FilePath)
	}

	req := &http.Request{
		Header: map[string][]string{
			"User-Agent": {testUserAgent},
			"Referer":    {testReferer},
		},
		Proto:      testProto,
		Host:       testHostname,
		Method:     testMethod,
		RemoteAddr: fmt.Sprintf("%s:%d", testHostname, testPort),
		URL: &url.URL{
			User: url.UserPassword(testUsername, ""),
			Path: testPath,
		},
		Body: io.NopCloser(bytes.NewReader([]byte("bar"))),
	}
	if enableTLS {
		req.TLS = &tls.ConnectionState{
			Version:     tls.VersionTLS13,
			CipherSuite: tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
		}
	}

	chain := alice.New()
Repository: traefik/traefik
File: pkg/middlewares/ipwhitelist/ip_whitelist.go (Go)

Code before:
	}

	logger.Debugf("Setting up IPWhiteLister with sourceRange: %s", config.SourceRange)

	return &ipWhiteLister{
		strategy:    strategy,
		whiteLister: checker,
		next:        next,
		name:        name,
	}, nil
}

func (wl *ipWhiteLister) GetTracingInformation() (string, ext.SpanKindEnum) {
	return wl.name, tracing.SpanKindNoneEnum
}

func (wl *ipWhiteLister) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
	ctx := middlewares.GetLoggerCtx(req.Context(), wl.name, typeName)
	logger := log.FromContext(ctx)

	clientIP := wl.strategy.GetIP(req)
	err := wl.whiteLister.IsAuthorized(clientIP)
	if err != nil {
		msg := fmt.Sprintf("Rejecting IP %s: %v", clientIP, err)
		logger.Debug(msg)
		tracing.SetErrorWithEvent(req, msg) //nolint: govet
		reject(ctx, rw)
		return
	}
	logger.Debugf("Accepting IP %s", clientIP)

	wl.next.ServeHTTP(rw, req)
}

func reject(ctx context.Context, rw http.ResponseWriter) {
	statusCode := http.StatusForbidden

	rw.WriteHeader(statusCode)
	_, err := rw.Write([]byte(http.StatusText(statusCode)))
	if err != nil {
		log.FromContext(ctx).Error(err)
	}
}


Review comment (suggestion):
```suggestion
		tracing.SetErrorWithEvent(req, msg)
```

Code after:
	}

	logger.Debugf("Setting up IPWhiteLister with sourceRange: %s", config.SourceRange)

	return &ipWhiteLister{
		strategy:    strategy,
		whiteLister: checker,
		next:        next,
		name:        name,
	}, nil
}

func (wl *ipWhiteLister) GetTracingInformation() (string, ext.SpanKindEnum) {
	return wl.name, tracing.SpanKindNoneEnum
}

func (wl *ipWhiteLister) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
	ctx := middlewares.GetLoggerCtx(req.Context(), wl.name, typeName)
	logger := log.FromContext(ctx)

	clientIP := wl.strategy.GetIP(req)
	err := wl.whiteLister.IsAuthorized(clientIP)
	if err != nil {
		logger.Debugf("Rejecting IP %s: %v", clientIP, err)
		tracing.SetErrorWithEvent(req, "Rejecting IP %s: %v", clientIP, err)
		reject(ctx, rw)
		return
	}
	logger.Debugf("Accepting IP %s", clientIP)

	wl.next.ServeHTTP(rw, req)
}

func reject(ctx context.Context, rw http.ResponseWriter) {
	statusCode := http.StatusForbidden

	rw.WriteHeader(statusCode)
	_, err := rw.Write([]byte(http.StatusText(statusCode)))
	if err != nil {
		log.FromContext(ctx).Error(err)
	}
}