- Add actual scenario definition example to qualify.md - Add stateful test API example to qualify.md - Fix observe.md sampling section to show explicit config and rates - Build: clean | Tests: 849 pass, 0 fail
4.4 KiB
Observe Mode
Runtime visibility and drift detection without blocking by default.
Observe extends the invariant framework from Invariant-Driven Automated Testing (Malhado Ribeiro, 2021) to production environments: contracts run continuously against live traffic to detect behavioral drift without affecting requests.
What Observe Does
apophis observe validates your runtime observe configuration:
- Checks that observe mode is allowed in the current environment
- Validates reporting sink setup (logs, metrics, traces)
- Confirms non-blocking semantics
- Reports what would be observed and why it is safe
When to Use It
- Staging: Validate observe config before promoting to production
- Production: Monitor contract drift without affecting requests
- Platform teams: Centralized visibility across services
Safety Boundaries
Observe mode is non-blocking by default:
- Non-blocking by default: Contract violations are logged, not thrown
- No request failures in non-blocking mode: Violations are reported instead of thrown
- Explicit opt-in for blocking: Requires
allowBlocking: truein environment policy - Production gating: Blocking behavior is blocked in production by default
Sink Configuration
Observe mode requires a reporting sink. Configure it in your environment policy:
environments: {
staging: {
name: 'staging',
allowVerify: true,
allowObserve: true,
allowQualify: false,
allowChaos: false,
allowBlocking: false,
requireSink: true
}
}
APOPHIS supports these sink types:
- Logs: Structured logging of contract violations
- Metrics: Counter and histogram metrics for violation rates
- Traces: Distributed tracing integration for violation context
Sampling
Control observation overhead with sampling:
profiles: {
'staging-observe': {
name: 'staging-observe',
mode: 'observe',
preset: 'platform-observe',
routes: []
}
}
The platform-observe preset enables sampling. Configure the rate explicitly:
profiles: {
'staging-observe': {
mode: 'observe',
preset: 'platform-observe',
routes: [],
sampling: 1.0 // 100% of requests observed
}
}
Staging vs Production
| Environment | Blocking | Sampling | Sink Required |
|---|---|---|---|
| Staging | No (default) | 100% | Yes |
| Production | No (default) | 100% | Yes |
Default is 1.0 (100%). Configure lower rates for production explicitly:
profiles: {
'prod-observe': {
mode: 'observe',
preset: 'platform-observe',
routes: [],
sampling: 0.1 // 10% of requests observed
}
}
--check-config Flag
Validate config without activating observe mode:
apophis observe --profile staging-observe --check-config
This is useful in CI to ensure observe config is valid before deployment.
Exit Codes
| Code | Meaning |
|---|---|
| 0 | Observe config is valid and safe |
| 2 | Safety violation or invalid config |
Config Example
// apophis.config.js
export default {
mode: 'observe',
profile: 'staging-observe',
profiles: {
'staging-observe': {
name: 'staging-observe',
mode: 'observe',
preset: 'platform-observe',
routes: []
}
},
presets: {
'platform-observe': {
name: 'platform-observe',
depth: 'standard',
timeout: 10000,
parallel: true,
chaos: false,
observe: true
}
},
environments: {
staging: {
name: 'staging',
allowVerify: true,
allowObserve: true,
allowQualify: false,
allowChaos: false,
allowBlocking: false,
requireSink: true
},
production: {
name: 'production',
allowVerify: true,
allowObserve: true,
allowQualify: false,
allowChaos: false,
allowBlocking: false,
requireSink: true
}
}
};
Sink Endpoint Configuration
Configure the reporting sink endpoint in your observe config:
observe: {
sink: {
endpoint: 'http://collector.internal:4318'
}
}
Monorepo Validation
For monorepos, use apophis doctor --workspace to validate observe configuration across all workspace packages. observe itself does not support --workspace; use doctor to check config in each package.
Mode Mismatch
Profiles configured for verify mode will be rejected by apophis observe. Only profiles with mode: 'observe' are valid.