traceid

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2025 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromTraceId

func FromTraceId(ctx context.Context) string

FromTraceId returns a trace id from the given context if one is present. Returns the empty string if a trace id cannot be found.

func GetTraceId

func GetTraceId(c *gin.Context) string

GetTraceId get trace id from gin.Context.

func InjectNewFromTraceId added in v0.3.4

func InjectNewFromTraceId(ctx, newCtx context.Context) context.Context

func NextTraceId added in v0.3.4

func NextTraceId() string

NextTraceId next returns the trace id, which use ulid.

func TraceId

func TraceId(opts ...Option) gin.HandlerFunc

TraceId is a middleware that injects a trace id into the context of each request. if it is empty, set to write head

  • traceIdHeader is the name of the HTTP Header which contains the trace id. Exported so that it can be changed by developers. (default "X-Trace-Id")
  • nextTraceID generates the next trace id.(default NewSequence function use utilities/sequence)

func WithTraceId added in v0.3.4

func WithTraceId(ctx context.Context, traceId string) context.Context

Types

type Config

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

Config defines the config for TraceId middleware

type Option

type Option func(*Config)

Option TraceId option

func WithNextTraceId

func WithNextTraceId(f func() string) Option

WithNextTraceId optional next trace id function (default NewSequence function use utilities/sequence)

func WithTraceIdHeader

func WithTraceIdHeader(s string) Option

WithTraceIdHeader optional request id header (default "X-Trace-Id")

Jump to

Keyboard shortcuts

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