correlation

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package correlation carries the request-scoped identifiers that every signal is joined on: the request ID and the tenant (observability-reliability.md §3.1).

It lives in core/shared rather than in the observability adapter because both ends need it and they are not allowed to know each other: the REST middleware writes the values, the logger and the metrics read them, and presentation must not import infrastructure (project-structure.md §2).

Only identifiers belong here. The actor and the permissions have their own typed wrapper; a context value is not a place to keep an authorisation decision (ADR-0005).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIClientFrom

func APIClientFrom(ctx context.Context) string

APIClientFrom returns the client, or the empty string for a request no app is behind.

func ComponentFrom

func ComponentFrom(ctx context.Context) string

ComponentFrom returns the component, or the empty string where nothing named one.

func ContextWithAPIClient

func ContextWithAPIClient(ctx context.Context, clientID string) context.Context

ContextWithAPIClient carries the OAuth client a request acts under (identity.md §15.3): an identifier of a registered app, which is what "audited with the client as a first-class actor attribute" means. An identifier like the other two, never content - which is why it belongs here.

func ContextWithComponent

func ContextWithComponent(ctx context.Context, component string) context.Context

ContextWithComponent carries which part of the system a line came from: `rest`, `worker.runner`, `worker.scheduler`, and so on (observability-reliability.md §3.1).

It is not the same as `role`, and the difference is why it exists. The role is the *process* and one process may serve several (ADR-0014), so a line from a combined deployment reads `role=api,worker` and says nothing about which loop wrote it. The component is the loop, and it is set once where each one starts rather than at every call site - a field a caller has to remember is a field that is missing from exactly the line being read at three in the morning.

A name, never a workspace or a person: it belongs here for the same reason the other three do.

func ContextWithRequestID

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

ContextWithRequestID carries the request ID through the call chain. It is what a user quotes in a support request: the one handle that connects a response to a log entry (api-guidelines.md §6).

func ContextWithTenant

func ContextWithTenant(ctx context.Context, tenantID string) context.Context

ContextWithTenant carries the tenant for the signals. tenant_id is a mandatory log field (§3.1) and the one metric label an operator may switch on (§3.2) - an identifier of an installation, not user content.

This is for observability only. The tenant boundary itself is enforced by the transaction wrapper against the database (ADR-0010), never by reading this value.

func RequestIDFrom

func RequestIDFrom(ctx context.Context) string

RequestIDFrom returns the request ID, or the empty string outside a request.

func TenantFrom

func TenantFrom(ctx context.Context) string

TenantFrom returns the tenant, or the empty string outside a tenant scope.

Types

This section is empty.

Jump to

Keyboard shortcuts

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