trace

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 2 Imported by: 0

README

trace

Trace provides usecase for generating trace id, commonly used for tracing your request throughout its lifecycle.

How to Use

trace.New creates new random trace string.

Context

Use NewContext to inject your trace to context.

ctx := trace.NewContext(context.Background(), "your-trace-id")

Use TraceFromContext to extract your trace from context

trace := trace.TraceFromContext(ctx)
fmt.Println(trace)
// your-trace-id

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() string

New creates new random string using ksuid

func NewContext

func NewContext(parentCtx context.Context, trace string) context.Context

NewContext create new context that is injected with trace

func TraceFromContext

func TraceFromContext(ctx context.Context) string

TraceFromContext extract trace from context

Types

type TraceContextKeyType

type TraceContextKeyType string
const (
	// TraceContextKey is a custom context key for trace
	TraceContextKey TraceContextKeyType = "trace.context.key"
)

Jump to

Keyboard shortcuts

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