middleware

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractTraceContext

func ExtractTraceContext(r *http.Request) (traceID, spanID string)

ExtractTraceContext extracts trace context from HTTP request headers. Returns the trace ID and span ID if present.

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats a duration for display.

func InjectTraceHeaders

func InjectTraceHeaders(ctx context.Context, req *http.Request)

InjectTraceHeaders adds trace context headers to an HTTP request. This can be used for distributed tracing across services.

func RequestMetadata

func RequestMetadata(r *http.Request) map[string]any

RequestMetadata extracts common metadata from an HTTP request.

func ResponseMetadata

func ResponseMetadata(resp *http.Response, duration time.Duration) map[string]any

ResponseMetadata creates metadata from an HTTP response.

func StatusCodeCategory

func StatusCodeCategory(code int) string

StatusCodeCategory returns a category string for the status code.

func TracingHTTPClient

func TracingHTTPClient(spanName string) *http.Client

TracingHTTPClient returns an http.Client with tracing enabled.

func TracingMiddleware

func TracingMiddleware(client *opik.Client, traceName string) func(http.Handler) http.Handler

TracingMiddleware wraps an http.Handler to automatically create spans for incoming requests.

Types

type TracingRoundTripper

type TracingRoundTripper struct {
	// contains filtered or unexported fields
}

TracingRoundTripper wraps an http.RoundTripper to automatically create spans for outgoing requests.

func NewTracingRoundTripper

func NewTracingRoundTripper(transport http.RoundTripper, spanName string) *TracingRoundTripper

NewTracingRoundTripper creates a new TracingRoundTripper. If transport is nil, http.DefaultTransport is used.

func (*TracingRoundTripper) RoundTrip

func (t *TracingRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

Jump to

Keyboard shortcuts

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