telemetry

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ScopeName is the instrumentation scope name.
	ScopeName = "github.com/rakunlabs/ada/middleware/telemetry"
)

Variables

This section is empty.

Functions

func MetricAttributes

func MetricAttributes(r *http.Request, statusCode int, additionalAttributes []attribute.KeyValue) []attribute.KeyValue

func Middleware

func Middleware(opts ...Option) func(next http.Handler) http.Handler

Middleware is an echo middleware to add metrics to rec for each HTTP request. If recorder config is nil, the middleware will use a recorder with default configuration.

func NewServerTotalRequests

func NewServerTotalRequests(meter metric.Meter) (metric.Int64Counter, error)

func RequestTraceAttrs

func RequestTraceAttrs(req *http.Request) []attribute.KeyValue

func ResponseTraceAttrs

func ResponseTraceAttrs(resp ResponseTelemetry) []attribute.KeyValue

func Version

func Version() string

Version is the current release version of the ada telemetry instrumentation.

Types

type BodyWrapper

type BodyWrapper struct {
	io.ReadCloser
	// contains filtered or unexported fields
}

BodyWrapper wraps a http.Request.Body (an io.ReadCloser) to track the number of bytes read and the last error.

func NewBodyWrapper

func NewBodyWrapper(body io.ReadCloser) *BodyWrapper

NewBodyWrapper creates a new BodyWrapper.

The onRead attribute is a callback that will be called every time the data is read, with the number of bytes being read.

func (*BodyWrapper) BytesRead

func (w *BodyWrapper) BytesRead() int64

BytesRead returns the number of bytes read up to this point.

func (*BodyWrapper) Close

func (w *BodyWrapper) Close() error

Close closes the io.ReadCloser.

func (*BodyWrapper) Read

func (w *BodyWrapper) Read(b []byte) (int, error)

Read reads the data from the io.ReadCloser, and stores the number of bytes read and the error.

type Filter

type Filter func(*http.Request) bool

Filter is a predicate used to determine whether a given http.request should be traced. A Filter must return true if the request should be traced.

type HTTPMeter

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

HTTPMeter is a recorder of HTTP metrics for prometheus. Use NewHTTPMeter to initialize it.

func NewHTTPMeter

func NewHTTPMeter(meter metric.Meter) HTTPMeter

func (*HTTPMeter) Record

func (m *HTTPMeter) Record(ctx context.Context, data MetricData)

type MetricData

type MetricData struct {
	ResponseSize         int64
	RequestSize          int64
	AdditionalAttributes []attribute.KeyValue
	ElapsedTime          float64
	StatusCode           int
	Request              *http.Request
}

type Option

type Option func(*config)

func WithMeterProvider

func WithMeterProvider(provider metric.MeterProvider) Option

WithMeterProvider specifies a meter provider to use for creating a metric. If none is specified, the global provider is used.

func WithMetricAttributesFn

func WithMetricAttributesFn(fn func(*http.Request) []attribute.KeyValue) Option

WithMetricAttributesFn allows customizing the attributes added to metrics.

func WithPropagators

func WithPropagators(propagators propagation.TextMapPropagator) Option

WithPropagators specifies propagators to use for extracting information from the HTTP requests. If none are specified, global ones will be used.

func WithPublicEndpoint

func WithPublicEndpoint() Option

WithPublicEndpoint configures the Handler to link the span with an incoming span context. If this option is not provided, then the association is a child association instead of a link.

func WithPublicEndpointFn

func WithPublicEndpointFn(fn func(*http.Request) bool) Option

WithPublicEndpointFn runs with every request, and allows conditionally configuring the Handler to link the span with an incoming span context. If this option is not provided or returns false, then the association is a child association instead of a link. Note: WithPublicEndpoint takes precedence over WithPublicEndpointFn.

func WithSpanNameFormatter

func WithSpanNameFormatter(formatter func(routeName string, r *http.Request) string) Option

WithSpanNameFormatter specifies a span name formatter to use for creating span names.

func WithTracerProvider

func WithTracerProvider(provider trace.TracerProvider) Option

WithTracerProvider specifies a tracer provider to use for creating spans. If none is specified, the global provider is used.

type ResponseTelemetry

type ResponseTelemetry struct {
	StatusCode int
	ReadBytes  int64
	WriteBytes int64
}

Jump to

Keyboard shortcuts

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