configmiddleware

package module
v1.58.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2026 License: Apache-2.0 Imports: 6 Imported by: 2

README

OpenTelemetry Collector Middleware Configuration

This package implements a configuration struct for referring to middleware extensions.

Overview

The configmiddleware package defines a Config type that allows components to configure middleware extensions, typically as an ordered list. This support is built in for push-based receivers configured through confighttp and configgrpc, as for example in the OTLP receiver:

receivers:
  otlp:
    protocols:
      http:
        middlewares:
          - id: limitermiddleware

Methods

The package provides four key methods to retrieve appropriate middleware handlers:

  1. GetHTTPClientRoundTripper: Obtains a function to wrap an HTTP client with a middleware extension via a http.RoundTripper.

  2. GetHTTPServerHandler: Obtains a function to wrap an HTTP server with a middleware extension via a http.Handler.

  3. GetGRPCClientOptions: Obtains a []grpc.DialOption that configure a middleware extension for gRPC clients.

  4. GetGRPCServerOptions: Obtains a []grpc.ServerOption that configure a middleware extension for gRPC servers.

These functions are typically called during Start() by a component, passing the component.Host extensions. An error is returned if the named extension cannot be found.

Documentation

Overview

Package configmiddleware implements a configuration struct to name middleware extensions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ID specifies the name of the extension to use.
	ID component.ID `mapstructure:"id,omitempty"`
	// contains filtered or unexported fields
}

Middleware defines the extension ID for a middleware component.

func (Config) GetGRPCClientOptions

func (m Config) GetGRPCClientOptions(ctx context.Context, extensions map[component.ID]component.Component) ([]grpc.DialOption, error)

GetGRPCClientOptions attempts to select the appropriate extensionmiddleware.GRPCClient from the map of extensions, and returns the gRPC dial options. If a middleware is not found, an error is returned. This should only be used by gRPC clients.

func (Config) GetGRPCServerOptions

func (m Config) GetGRPCServerOptions(ctx context.Context, extensions map[component.ID]component.Component) ([]grpc.ServerOption, error)

GetGRPCServerOptions attempts to select the appropriate extensionmiddleware.GRPCServer from the map of extensions, and returns the gRPC server options. If a middleware is not found, an error is returned. This should only be used by gRPC servers.

func (Config) GetHTTPClientRoundTripper

func (m Config) GetHTTPClientRoundTripper(ctx context.Context, extensions map[component.ID]component.Component) (extensionmiddleware.WrapHTTPRoundTripperFunc, error)

GetHTTPClientRoundTripper attempts to select the appropriate extensionmiddleware.HTTPClient from the map of extensions, and returns the HTTP client wrapper function. If a middleware is not found, an error is returned. This should only be used by HTTP clients.

func (Config) GetHTTPServerHandler

func (m Config) GetHTTPServerHandler(ctx context.Context, extensions map[component.ID]component.Component) (extensionmiddleware.WrapHTTPHandlerFunc, error)

GetHTTPServerHandler attempts to select the appropriate extensionmiddleware.HTTPServer from the map of extensions, and returns the http.Handler wrapper function. If a middleware is not found, an error is returned. This should only be used by HTTP servers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL