Documentation
¶
Overview ¶
Package ctxkeys provides typed context keys for Cell-model identifiers (cell, slice, journey, contract) propagated through context.Context.
Generic observability and networking keys (request, trace, span, correlation, real IP) live in github.com/ghbvf/gocell/pkg/ctxkeys. Cell-model keys belong here because they encode GoCell architectural concepts rather than generic cross-service conventions.
Index ¶
- func CellIDFrom(ctx context.Context) (string, bool)
- func ContractAttrsFrom(ctx context.Context) (any, bool)
- func ContractIDFrom(ctx context.Context) (string, bool)
- func JourneyIDFrom(ctx context.Context) (string, bool)
- func SliceIDFrom(ctx context.Context) (string, bool)
- func WithCellID(ctx context.Context, id string) context.Context
- func WithContractAttrs(ctx context.Context, attrs any) context.Context
- func WithContractID(ctx context.Context, id string) context.Context
- func WithJourneyID(ctx context.Context, id string) context.Context
- func WithSliceID(ctx context.Context, id string) context.Context
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CellIDFrom ¶
CellIDFrom extracts the cell ID from ctx. The boolean reports whether the key was present; it can be true with an empty value, so callers that treat "" as invalid must check both ok and v != "".
func ContractAttrsFrom ¶
ContractAttrsFrom extracts the contract attribute slice from ctx as an any. Callers type-assert to []wrapper.Attr. Reports false when the key is absent.
func ContractIDFrom ¶
ContractIDFrom extracts the contract ID from ctx. The boolean reports whether the key was present; callers that treat "" as invalid must check both ok and v != "".
func JourneyIDFrom ¶
JourneyIDFrom extracts the journey ID from ctx. The boolean reports whether the key was present; it can be true with an empty value, so callers that treat "" as invalid must check both ok and v != "".
func SliceIDFrom ¶
SliceIDFrom extracts the slice ID from ctx. The boolean reports whether the key was present; it can be true with an empty value, so callers that treat "" as invalid must check both ok and v != "".
func WithCellID ¶
WithCellID returns a new context carrying the given cell ID.
func WithContractAttrs ¶
WithContractAttrs returns a new context carrying a pre-built slice of contract-derived span attributes (gocell.contract.id / kind / transport + http.method/route or messaging.system/destination).
wrapper.HTTPHandler writes the slice at the moment a request enters the contract-bound handler chain. The outer HTTP Tracing middleware reads it after next.ServeHTTP returns and late-binds the attributes onto the single request-owned span — achieving "one request → one span" on contract-bound routes without the inner wrapper creating a duplicate span.
The slice is passed as any so kernel/ctxkeys stays free of any wrapper type dependency. Consumers type-assert to their known type ([]kernel/wrapper.Attr).
func WithContractID ¶
WithContractID returns a new context carrying the given contract ID. The contract id is set by wrapper.HTTPHandler / WrapConsumer at the moment a request / event is accepted for processing, so downstream middleware, handlers, and event consumers can tag logs and metrics with the same identifier that the span carries in the gocell.contract.id attribute.
func WithJourneyID ¶
WithJourneyID returns a new context carrying the given journey ID.
Types ¶
This section is empty.