forked from cleveragents/cleveragents-core
a6242c1e38
Implements comprehensive observability infrastructure per issue #940: - Add PrometheusRegistry with counters/histograms/gauges for all 14 operational metric keys; supports /metrics HTTP endpoint (server mode) and file-based export (local mode) - Add AuditBridge event subscriber that automatically writes security-relevant domain events to audit.jsonl with structured AuditRecord schema (timestamp, event_type, actor, action, resource, outcome, metadata, correlation_id, plan_id, session_id) - Add configure_structlog() for JSON or text log output with inject_correlation_id processor for log correlation across plan executions - Add observability config fields to Settings: metrics_prometheus_port, metrics_file_path, audit_jsonl_path, log_format - Add prometheus-client>=0.20.0 to project dependencies - Add 61 Behave BDD scenarios covering metrics registry, audit bridge routing, structured log output, and settings integration ISSUES CLOSED: #940
82 lines
3.4 KiB
Gherkin
82 lines
3.4 KiB
Gherkin
Feature: JSON Structlog Configuration
|
|
As a platform operator
|
|
I want configurable structured logging with JSON output and correlation IDs
|
|
So that I can parse and correlate log records across plan executions
|
|
|
|
# --- configure_structlog ---
|
|
|
|
Scenario: configure_structlog can be called with json format
|
|
When I call configure_structlog with log_format "json"
|
|
Then no exception should be raised from configure_structlog
|
|
|
|
Scenario: configure_structlog can be called with text format
|
|
When I call configure_structlog with log_format "text"
|
|
Then no exception should be raised from configure_structlog
|
|
|
|
Scenario: configure_structlog can be called with INFO log level
|
|
When I call configure_structlog with log_level "INFO"
|
|
Then no exception should be raised from configure_structlog
|
|
|
|
Scenario: configure_structlog can be called with DEBUG log level
|
|
When I call configure_structlog with log_level "DEBUG"
|
|
Then no exception should be raised from configure_structlog
|
|
|
|
# --- Correlation ID context variable ---
|
|
|
|
Scenario: set_correlation_id stores a value retrievable by get_correlation_id
|
|
When I set the correlation ID to "CORR-ABC-123"
|
|
Then get_correlation_id should return "CORR-ABC-123"
|
|
|
|
Scenario: get_correlation_id returns None when not set
|
|
Given the correlation ID is cleared
|
|
Then get_correlation_id should return None
|
|
|
|
Scenario: set_correlation_id can be updated
|
|
When I set the correlation ID to "CORR-FIRST"
|
|
And I set the correlation ID to "CORR-SECOND"
|
|
Then get_correlation_id should return "CORR-SECOND"
|
|
|
|
Scenario: set_correlation_id can be cleared with None
|
|
When I set the correlation ID to "CORR-TO-CLEAR"
|
|
And I set the correlation ID to None
|
|
Then get_correlation_id should return None
|
|
|
|
# --- inject_correlation_id processor ---
|
|
|
|
Scenario: inject_correlation_id adds correlation_id to event dict when set
|
|
Given the correlation ID is set to "PROC-CORR-001"
|
|
When I run the inject_correlation_id processor on an empty event dict
|
|
Then the event dict should contain key "correlation_id" with value "PROC-CORR-001"
|
|
|
|
Scenario: inject_correlation_id does not overwrite existing correlation_id
|
|
Given the correlation ID is set to "PROC-CORR-002"
|
|
When I run the inject_correlation_id processor on an event dict with correlation_id "EXISTING"
|
|
Then the event dict should contain key "correlation_id" with value "EXISTING"
|
|
|
|
Scenario: inject_correlation_id does nothing when correlation ID is None
|
|
Given the correlation ID is cleared
|
|
When I run the inject_correlation_id processor on an empty event dict
|
|
Then the event dict should not contain key "correlation_id"
|
|
|
|
# --- Settings integration ---
|
|
|
|
Scenario: Settings has log_format field defaulting to text
|
|
When I create default settings for structlog
|
|
Then settings.log_format should equal "text"
|
|
|
|
Scenario: Settings log_format can be set to json
|
|
When I create settings with log_format "json"
|
|
Then settings.log_format should equal "json"
|
|
|
|
Scenario: Settings has metrics_prometheus_port field
|
|
When I create default settings for structlog
|
|
Then settings.metrics_prometheus_port should be an integer
|
|
|
|
Scenario: Settings has audit_jsonl_path field
|
|
When I create default settings for structlog
|
|
Then settings.audit_jsonl_path should be a string
|
|
|
|
Scenario: Settings has metrics_file_path field
|
|
When I create default settings for structlog
|
|
Then settings.metrics_file_path should be a string
|