Documentation
¶
Index ¶
- Constants
- func CopyDefault(src context.Context, timeout ...time.Duration) context.Context
- func GetTraceID(ctx context.Context) string
- func WithExistingOrNewTraceID(ctx context.Context) context.Context
- func WithTraceID(ctx context.Context, traceID string) context.Context
- func WithTraceIDLogger(ctx context.Context) context.Context
- type ContextCopier
- type LoggerContextKey
- type RequestContextKey
- type TraceIDContextKey
Constants ¶
const ( LoggerKey LoggerContextKey = "logger" TraceIDKey TraceIDContextKey = "traceId" TraceIDHeader string = "X-Trace-Id" RequestSettingsKey RequestContextKey = "requestSettings" )
Variables ¶
This section is empty.
Functions ¶
func CopyDefault ¶ added in v0.29.3
CopyDefault creates a new context by copying the values added by simba by default, such as trace ID and logger. If a timeout is provided, the returned context will automatically cancel after the specified duration.
func GetTraceID ¶ added in v0.27.5
GetTraceID retrieves the trace ID from the context. If no trace ID is present, it returns an empty string.
func WithExistingOrNewTraceID ¶ added in v0.27.5
WithExistingOrNewTraceID returns a context with a trace ID. If the context already has a trace ID, it is reused.
func WithTraceID ¶ added in v0.27.5
WithTraceID returns a context with the provided trace ID.
Types ¶
type ContextCopier ¶ added in v0.29.3
type ContextCopier struct {
// contains filtered or unexported fields
}
ContextCopier builds a new context by copying selected values from a source context.
func NewContextCopier ¶ added in v0.29.3
func NewContextCopier(src context.Context) *ContextCopier
NewContextCopier creates a new context copier starting with a background context.
func (*ContextCopier) Build ¶ added in v0.29.3
func (c *ContextCopier) Build() context.Context
Build finalizes the context copying and returns the new context. If a timeout was set, returns a context with deadline that will automatically cancel after the timeout.
func (*ContextCopier) WithLogger ¶ added in v0.29.3
func (c *ContextCopier) WithLogger() *ContextCopier
WithLogger copies the logger from the source context.
func (*ContextCopier) WithTimeout ¶ added in v0.29.4
func (c *ContextCopier) WithTimeout(timeout time.Duration) *ContextCopier
WithTimeout sets a timeout for the context.
func (*ContextCopier) WithTraceID ¶ added in v0.29.3
func (c *ContextCopier) WithTraceID() *ContextCopier
WithTraceID copies the trace ID from the source context.
func (*ContextCopier) WithValue ¶ added in v0.29.3
func (c *ContextCopier) WithValue(key any) *ContextCopier
WithValue copies a specific value from the source context if it exists.
type LoggerContextKey ¶
type LoggerContextKey string
type RequestContextKey ¶
type RequestContextKey string
type TraceIDContextKey ¶ added in v0.27.2
type TraceIDContextKey string