Observability

Turn on spans and metrics with the tracing feature, pick your own backend, and know that no label ever carries a subject or resource id.

Every crate has an optional tracing feature, off by default. It adds spans through tracing and metrics through the metrics facade. You pick the backend: Prometheus, OpenTelemetry or your own recorder.

Cargo.toml
strig = { version = "0.10", features = ["tracing"] }
strig-server = { version = "0.10", features = ["tracing"] }

The features chain: strig-sync/tracing turns on strig/tracing; strig-postgres/tracing and strig-redis/tracing turn on strig-sync/tracing; strig-server/tracing turns on strig/tracing.

What it costs#

With the feature off, nothing is compiled in. With it on and no subscriber or recorder installed, a decision costs about 110 ns more:

decide/simpleTime
Before the feature existed517 ns
Feature off518 ns
Feature on, nothing installed630 ns

The bigger operations are within noise. The core still does no IO and still compiles to WebAssembly with and without the feature; there, the decision latency histogram is not recorded, because std::time::Instant is not available on wasm32-unknown-unknown. The JavaScript binding is not instrumented.

Export over OpenTelemetry#

crates/strig-server/examples/otlp.rs exports spans and metrics over OTLP/HTTP with tracing-opentelemetry and metrics-exporter-opentelemetry:

Terminal
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 \
  cargo run -p strig-server --features tracing --example otlp

Point the endpoint at your collector. Decision and query spans are debug; the rest are info, so set the filter to see them. Events (a dropped audit record, a lost LISTEN connection, a breaker changing phase) go out at warn or info.

No personal data#

A metric label is one of: operation, permission (only a permission the catalog knows; anything else is unknown), effect, reason kind, invariant name, step, outcome, status, change kind, transport name, route, error code, breaker phase. Never a subject id, a resource id, an attribute or a request body. Spans carry the same fields.

Tests in each crate run a scenario with recognizable ids and fail if one shows up in a label or a span. An invariant you write labels the metric with the name you gave it, so keep that name a constant.

A decision made by a custom invariant or override while governance judges a change belongs to that change. Only the outermost operation on a thread feeds the metrics, so strig_decisions_total counts what your application asked for. Spans nest either way.

Metrics#

MetricTypeLabels
strig_decisions_totalcounteroperation (decide, explain), effect, reason, permission
strig_decision_duration_secondshistogramoperation
strig_query_duration_secondshistogramoperation (list, who_can, who_can_on)
strig_mutations_totalcounteroutcome (applied, refused)
strig_mutation_violations_totalcounterinvariant
strig_approvals_totalcounterstep (propose, approve, reject, expire), outcome
strig_audit_writes_totalcounterstatus (written, pending, dropped, refused)
strig_audit_pendinggaugenone. Depth of the retry queue.
strig_audit_write_failures_totalcounternone
strig_audit_dropped_totalcounternone
strig_sync_changes_totalcounterkind, direction (published, received)
strig_sync_publish_errors_totalcountertransport
strig_sync_sessions_open / strig_sync_sessions_opened_totalgauge / counternone
strig_sync_resyncs_totalcounterreason (reconnect, lagged, notice)
strig_sync_transport_reconnects_totalcountertransport
strig_sync_transport_failures_totalcountertransport, stage (subscribe, stream)
strig_server_requests_totalcounterroute, status
strig_server_request_duration_secondshistogramroute
strig_server_errors_totalcountercode
strig_client_calls_totalcounterroute, outcome
strig_client_call_duration_secondshistogramroute
strig_client_breaker_transitions_totalcounterto (closed, half_open, open)
strig_client_breaker_stategaugenone. 0 closed, 1 half open, 2 open.

Two worth an alert: strig_audit_pending growing means the audit sink is failing and records are queuing, and strig_client_breaker_state at 2 means a client has stopped calling a decision server that keeps failing.

Spans#

SpanWhereFields
strig.decisiondecide, check, explainoperation, permission, effect, reason
strig.querylist, who_can, who_can_onoperation, permission, kind
strig.governance.applyGovernance::apply and GovernanceAtoutcome
strig.approvalpropose, approve, reject, expire_duestep, outcome
strig.audit.writeeach audit record sent to the sinkmode
strig.sync.publish, strig.sync.relay, strig.sync.sessionhub publish, transport relay, one client sessiontransport on publish
strig.postgres.publish, strig.postgres.subscribe, strig.postgres.store.load, strig.postgres.store.reload, strig.postgres.store.commit_mutation, strig.redis.publish, strig.redis.subscribethe transportsnone
strig.server.request, strig.client.callthe decision server and its clientroute, status or outcome