Documentation
¶
Index ¶
- func GRPCClientHandler(opts ...otelgrpc.Option) stats.Handler
- func GRPCServerHandler(opts ...otelgrpc.Option) stats.Handler
- func GinMiddleware(serviceName string) gin.HandlerFunc
- func HTTPMiddleware(serviceName string) func(http.Handler) http.Handler
- func HTTPMiddlewareWithOptions(serviceName string, opts ...otelhttp.Option) func(http.Handler) http.Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GRPCClientHandler ¶
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 ¶
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 ¶
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.