middleware

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GRPCClientHandler

func GRPCClientHandler(opts ...otelgrpc.Option) stats.Handler

GRPCClientHandler returns a gRPC stats handler for client-side instrumentation. The newer otelgrpc API uses stats handlers instead of interceptors.

Example:

conn, err := grpc.NewClient("localhost:50051",
	grpc.WithStatsHandler(middleware.GRPCClientHandler()),
)

func GRPCServerHandler

func GRPCServerHandler(opts ...otelgrpc.Option) stats.Handler

GRPCServerHandler returns a gRPC stats handler for server-side instrumentation. The newer otelgrpc API uses stats handlers instead of interceptors.

Example:

server := grpc.NewServer(
	grpc.StatsHandler(middleware.GRPCServerHandler()),
)

func GinMiddleware

func GinMiddleware(serviceName string) gin.HandlerFunc

GinMiddleware returns a Gin middleware that traces requests. It creates spans for each HTTP request and records standard HTTP attributes.

Example:

r := gin.Default()
r.Use(middleware.GinMiddleware("my-service"))
r.GET("/users/:id", handleGetUser)

func HTTPMiddleware

func HTTPMiddleware(serviceName string) func(http.Handler) http.Handler

HTTPMiddleware returns an HTTP middleware that traces requests. It uses OpenTelemetry's otelhttp package for standard HTTP instrumentation.

Example:

mux := http.NewServeMux()
mux.HandleFunc("/users", handleUsers)

handler := middleware.HTTPMiddleware("my-service")(mux)
http.ListenAndServe(":8080", handler)

func HTTPMiddlewareWithOptions

func HTTPMiddlewareWithOptions(serviceName string, opts ...otelhttp.Option) func(http.Handler) http.Handler

HTTPMiddlewareWithOptions returns an HTTP middleware with custom options. This allows for more advanced configuration of the HTTP instrumentation.

Example:

handler := middleware.HTTPMiddlewareWithOptions("my-service",
	otelhttp.WithSpanNameFormatter(func(operation string, r *http.Request) string {
		return fmt.Sprintf("%s %s", r.Method, r.URL.Path)
	}),
)(mux)

Types

This section is empty.

Jump to

Keyboard shortcuts

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