traceid

package
v0.3.2-rc0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 3 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 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)

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