Overview
Context helper functions allow you to extract metadata (trace IDs, span IDs, request IDs, user IDs) from Go contexts. These functions return empty strings if the metadata is not present in the context.Functions
GetTraceID
Extracts the trace ID from the context.ctx- The context to extract from
- The trace ID if set, or empty string
context.go:106-129
GetSpanID
Extracts the span ID from the context.ctx- The context to extract from
- The span ID if set, or empty string
context.go:131-147
GetRequestID
Extracts the request ID from the context.ctx- The context to extract from
- The request ID if set, or empty string
context.go:149-165
GetUserID
Extracts the user ID from the context.ctx- The context to extract from
- The user ID if set, or empty string
context.go:167-183
ExtractFieldsFromContext
Extracts all structured fields from the context.ctx- The context to extract from
- A slice of
Fieldstructs containing the extracted context values
trace_id, span_id, request_id, and user_id from the context and returns them as Field structs. This is used internally by LogCtx to automatically include context information in log entries.
Example:
context.go:185-221