Documentation
¶
Overview ¶
Package correlation provides transport-neutral correlation, request, and causation identifiers. Identifiers are diagnostic metadata only; they are never authentication, authorization, tenancy, replay, or idempotency proof.
Index ¶
- Constants
- Variables
- func Disclose(label, value string, policy DisclosurePolicy) (string, error)
- func WithValues(ctx context.Context, values Values) context.Context
- type Carrier
- type CausationID
- type Codec
- type CodecOptions
- type CorrelationID
- type Deterministic
- type DeterministicOptions
- type DisclosureMode
- type DisclosurePolicy
- type ExternalID
- type ExternalIDOptions
- type Factory
- type FactoryOptions
- type Generator
- type GeneratorFunc
- type InboundPolicy
- type Policy
- type Propagator
- type RequestID
- type Values
Examples ¶
Constants ¶
const ( // DefaultCorrelationField is the transport-neutral correlation key. DefaultCorrelationField = "correlation_id" // DefaultRequestField is the transport-neutral request key. DefaultRequestField = "request_id" // DefaultCausationField is the transport-neutral causation key. DefaultCausationField = "causation_id" )
Variables ¶
var ( // ErrInvalidCarrier reports malformed, unbounded, or unsupported metadata. ErrInvalidCarrier = errors.New("correlation: invalid carrier") // ErrConflictingCarrier reports more than one distinct value for a field. ErrConflictingCarrier = errors.New("correlation: conflicting carrier values") // ErrCarrierOverwrite reports injection into an already populated field. ErrCarrierOverwrite = errors.New("correlation: carrier overwrite") )
var ( // ErrInvalidFactory reports invalid factory configuration. ErrInvalidFactory = errors.New("correlation: invalid factory") // ErrGeneration reports a generator failure or invalid generated value. ErrGeneration = errors.New("correlation: generation failed") )
var ErrInvalidDerivation = errors.New("correlation: invalid deterministic derivation")
ErrInvalidDerivation reports unsafe deterministic derivation input or configuration.
var ErrInvalidDisclosure = errors.New("correlation: invalid disclosure policy")
ErrInvalidDisclosure reports unsafe disclosure configuration.
var ErrInvalidExternalID = errors.New("correlation: invalid external identifier")
ErrInvalidExternalID reports invalid external identifier metadata.
var ErrInvalidID = errors.New("correlation: invalid identifier")
ErrInvalidID reports an identifier that violates its validation policy.
var ErrInvalidPropagator = errors.New("correlation: invalid propagator")
ErrInvalidPropagator reports missing explicit propagation dependencies.
Functions ¶
Types ¶
type Carrier ¶
Carrier is an explicit transport metadata boundary. Values must return a copy or immutable view. Set replaces one field with exactly one value.
type CausationID ¶
type CausationID string
CausationID identifies the immediate parent request, message, or event.
func MustCausationID ¶
func MustCausationID(value string, policy Policy) CausationID
MustCausationID is ParseCausationID for static configuration and tests.
func ParseCausationID ¶
func ParseCausationID(value string, policy Policy) (CausationID, error)
ParseCausationID validates and returns a causation identifier.
func (CausationID) String ¶
func (id CausationID) String() string
type Codec ¶
type Codec struct {
// contains filtered or unexported fields
}
Codec injects and extracts typed values without assigning trust.
func NewCodec ¶
func NewCodec(options CodecOptions) (*Codec, error)
NewCodec validates and copies carrier configuration.
type CodecOptions ¶
type CodecOptions struct {
Policy Policy
CorrelationField string
RequestField string
CausationField string
}
CodecOptions configure immutable carrier field names and validation.
type CorrelationID ¶
type CorrelationID string
CorrelationID groups work in one logical interaction or workflow.
func MustCorrelationID ¶
func MustCorrelationID(value string, policy Policy) CorrelationID
MustCorrelationID is ParseCorrelationID for static configuration and tests.
func ParseCorrelationID ¶
func ParseCorrelationID(value string, policy Policy) (CorrelationID, error)
ParseCorrelationID validates and returns a correlation identifier.
func (CorrelationID) String ¶
func (id CorrelationID) String() string
type Deterministic ¶
type Deterministic struct {
// contains filtered or unexported fields
}
Deterministic derives linkable IDs for an explicitly stable workflow. It is never selected by Factory defaults and should be keyed for private inputs.
func NewDeterministic ¶
func NewDeterministic(options DeterministicOptions) (*Deterministic, error)
NewDeterministic validates and copies deterministic strategy configuration.
func (*Deterministic) Derive ¶
func (strategy *Deterministic) Derive(input []byte) (CorrelationID, error)
Derive hashes input with length-delimited, versioned domain separation.
type DeterministicOptions ¶
DeterministicOptions configure an explicitly opted-in stable strategy.
type DisclosureMode ¶
type DisclosureMode uint8
DisclosureMode controls identifier disclosure to logs and telemetry.
const ( // RedactDisclosure is the safe default and emits only a marker. RedactDisclosure DisclosureMode = iota // HashDisclosure emits a keyed, domain-separated stable token. HashDisclosure // ExposeDisclosure emits validated raw identifier text. ExposeDisclosure )
type DisclosurePolicy ¶
type DisclosurePolicy struct {
Mode DisclosureMode
Key []byte
}
DisclosurePolicy must explicitly opt into linkable or raw output.
type ExternalID ¶
type ExternalID struct {
// contains filtered or unexported fields
}
ExternalID is an optional typed external identifier with explicit source and trust metadata. It is not implicitly promoted to any correlation ID.
func NewExternalID ¶
func NewExternalID(options ExternalIDOptions) (ExternalID, error)
NewExternalID validates and copies external metadata.
func (ExternalID) Kind ¶
func (external ExternalID) Kind() string
Kind returns the external identifier's declared semantic kind.
func (ExternalID) Source ¶
func (external ExternalID) Source() string
Source returns the declared transport or system source.
func (ExternalID) Trusted ¶
func (external ExternalID) Trusted() bool
Trusted reports the caller's explicit trust decision.
func (ExternalID) Value ¶
func (external ExternalID) Value() string
Value returns the validated external identifier text.
type ExternalIDOptions ¶
ExternalIDOptions require the caller to state type, source, and trust.
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
Factory creates fresh hop identifiers without global mutable state.
func NewFactory ¶
func NewFactory(options FactoryOptions) (*Factory, error)
NewFactory constructs a factory. The default generator uses crypto/rand.
func (*Factory) Accept ¶
func (factory *Factory) Accept(inbound Values, policy InboundPolicy) (Values, error)
Accept starts a receiving hop. No inbound value is used unless its exact semantic trust is enabled.
func (*Factory) Next ¶
Next preserves correlation, creates a request ID, and makes the prior request the immediate cause.
Example ¶
generator := &sequenceGenerator{values: []string{"child-request"}}
factory, _ := correlation.NewFactory(correlation.FactoryOptions{Generator: generator})
parent := correlation.Values{
CorrelationID: correlation.MustCorrelationID("workflow", correlation.Policy{}),
RequestID: correlation.MustRequestID("parent-request", correlation.Policy{}),
}
child, _ := factory.Next(parent)
fmt.Println(child.CorrelationID, child.RequestID, child.CausationID)
Output: workflow child-request parent-request
type FactoryOptions ¶
FactoryOptions configure an immutable Factory.
type Generator ¶
Generator supplies canonical random identifier text. It is structurally compatible with identifier.Generator[string] from identifier.
type GeneratorFunc ¶
GeneratorFunc adapts a function to Generator.
func (GeneratorFunc) New ¶
func (function GeneratorFunc) New() (string, error)
New calls the wrapped function.
type InboundPolicy ¶
InboundPolicy explicitly identifies which inbound semantics cross a trust boundary. Request IDs are never preserved because each hop gets a new one.
type Policy ¶
type Policy struct {
MaxLength int
}
Policy bounds and validates an identifier. The zero value accepts the canonical ASCII alphabet [A-Za-z0-9_-] up to 128 bytes.
type Propagator ¶
type Propagator struct {
// contains filtered or unexported fields
}
Propagator explicitly composes hop generation with a transport codec.
func NewPropagator ¶
func NewPropagator(factory *Factory, codec *Codec) (*Propagator, error)
NewPropagator rejects ambient or incomplete propagation configuration.
func (*Propagator) Receive ¶
func (propagator *Propagator) Receive(carrier Carrier, policy InboundPolicy) (Values, error)
Receive extracts untrusted metadata and applies an explicit trust policy while creating a fresh delivery-attempt request ID.
type RequestID ¶
type RequestID string
RequestID identifies one transport request or delivery attempt.
func MustRequestID ¶
MustRequestID is ParseRequestID for static configuration and tests.
func ParseRequestID ¶
ParseRequestID validates and returns a request identifier.
type Values ¶
type Values struct {
CorrelationID CorrelationID
RequestID RequestID
CausationID CausationID
}
Values carries the three deliberately distinct identifier semantics.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package httpcorrelation explicitly propagates correlation metadata over HTTP.
|
Package httpcorrelation explicitly propagates correlation metadata over HTTP. |
|
requestidbridge
Package requestidbridge integrates explicitly with request ID middleware such as http-middleware/requestid without importing hidden context keys.
|
Package requestidbridge integrates explicitly with request ID middleware such as http-middleware/requestid without importing hidden context keys. |
|
Package jsonrpc propagates correlation through an explicit JSON-RPC metadata object.
|
Package jsonrpc propagates correlation through an explicit JSON-RPC metadata object. |
|
Package log provides bounded slog attributes compatible with log's standard log/slog composition API.
|
Package log provides bounded slog attributes compatible with log's standard log/slog composition API. |
|
Package queue propagates correlation metadata through backend-neutral queue metadata maps.
|
Package queue propagates correlation metadata through backend-neutral queue metadata maps. |
|
Package schedule provides explicit correlation lifecycle helpers for scheduled work.
|
Package schedule provides explicit correlation lifecycle helpers for scheduled work. |
|
Package telemetry links correlation metadata to OpenTelemetry without treating correlation IDs as trace or span IDs.
|
Package telemetry links correlation metadata to OpenTelemetry without treating correlation IDs as trace or span IDs. |
|
Package webhook provides an explicit webhook-named HTTP correlation adapter.
|
Package webhook provides an explicit webhook-named HTTP correlation adapter. |