ctxkeys

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 1 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CellIDFrom

func CellIDFrom(ctx context.Context) (string, bool)

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

func ContractAttrsFrom(ctx context.Context) (any, bool)

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

func ContractIDFrom(ctx context.Context) (string, bool)

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

func JourneyIDFrom(ctx context.Context) (string, bool)

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

func SliceIDFrom(ctx context.Context) (string, bool)

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

func WithCellID(ctx context.Context, id string) context.Context

WithCellID returns a new context carrying the given cell ID.

func WithContractAttrs

func WithContractAttrs(ctx context.Context, attrs any) context.Context

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

func WithContractID(ctx context.Context, id string) context.Context

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

func WithJourneyID(ctx context.Context, id string) context.Context

WithJourneyID returns a new context carrying the given journey ID.

func WithSliceID

func WithSliceID(ctx context.Context, id string) context.Context

WithSliceID returns a new context carrying the given slice ID.

Types

This section is empty.

Jump to

Keyboard shortcuts

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