Observability & Logging - sgajbi/portfolio-analytics-system GitHub Wiki
The Portfolio Analytics System includes robust observability capabilities to ensure that every event, API call, and calculation can be traced end-to-end.
Recent enhancements provide:
- Correlation ID propagation across all services.
- Standardized logging for consistent debugging.
-
Database-level traceability via
processed_events
.
<svc-shortname>:<uuid>
Example:
- Ingestion →
ING:550e8400-e29b-41d4-a716-446655440000
- Cost Calculator →
COST:550e8400-e29b-41d4-a716-446655440000
(inherited from Ingestion)
- Ingestion →
ING
- Persistence →
PST
- Cost Calculator →
COST
- Cashflow Calculator →
CFLOW
- Position Calculator →
POS
- Valuation Calculator →
VAL
- Performance Calculator →
PERF
- API Service →
QRY
- Generated in Ingestion Service if missing.
- Passed through Kafka message headers to downstream services.
- Logged in all services.
- Included in API responses as
X-Correlation-ID
.
All logs follow the same structure:
<Timestamp> [<LogLevel>] [corr_id=<CorrelationID>] <ServiceName> - <Message>
Example:
2025-08-01 12:34:56 [INFO] [corr_id=VAL:123e4567-e89b-12d3-a456-426614174000] ValuationCalculator - Valuation updated for Portfolio 1001, AAPL
- Shared logger in
portfolio_common.logging_utils
- Injects
correlation_id
fromcontextvars
- Applied in all services
-
Stores
(event_id, service_name, correlation_id, processed_at)
-
Used to:
- Prevent duplicate processing (idempotency)
- Trace processing of a specific event across services
Example query:
SELECT *
FROM processed_events
WHERE correlation_id = 'ING:550e8400-e29b-41d4-a716-446655440000';
-
Identify correlation ID from API response or log.
-
Search Splunk/ELK:
corr_id=ING:550e8400-e29b-41d4-a716-446655440000
-
Query
processed_events
to see processing status. -
Identify the last processed service for further investigation.
-
Integration tests confirm correlation ID:
- Is generated if missing.
- Is propagated to all downstream services.
-
Log format is validated in service startup tests.