middleware

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2025 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Description: This file is used to collect metrics for the service.

Index

Constants

View Source
const (
	TraceIDHeader     = "X-Trace-Id"
	TraceParentHeader = "traceparent"
	GinTraceIDKey     = "trace_id"
)
View Source
const (
	// Called, generally means that the current service is invoked by another service
	Callee = "callee"
)

Variables

View Source
var (
	// if data type is counter, otlp will add a _total suffix to the metric name,
	// so we use updowncounter to avoid this suffix
	RequestCount    api.Float64UpDownCounter
	ErrRequestCount api.Float64UpDownCounter
	RequestTime     api.Float64Histogram
)

Functions

func FromContext

func FromContext(ctx context.Context) (string, bool)

FromContext retrieves trace ID from context

func GetTraceID

func GetTraceID(c *gin.Context) (string, bool)

GetTraceID retrieves trace ID from gin context

func GetTracer

func GetTracer() oteltrace.Tracer

GetTracer returns the tracer for the application

func InitTracer

func InitTracer(ctx context.Context, cfg *config.Trace) (*sdktrace.TracerProvider, error)

func Meter

func Meter() api.Meter

Meter returns the metrics meter used for custom metrics.

func MetricsMiddleware

func MetricsMiddleware(cfg *config.Metrics) func(c *gin.Context)

MetricsMiddleware is a middleware that collects metrics

func SetTracer

func SetTracer(name string)

SetTracer sets the tracer for the application

func TraceFilter

func TraceFilter(cfg *config.Trace) func(c *gin.Context) bool

TraceFilter returns a function that filters traces based on the configuration

func TraceID

func TraceID() gin.HandlerFunc

TraceID returns a middleware that handles trace ID propagation

Types

This section is empty.

Jump to

Keyboard shortcuts

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