[INFRA 6] Add observability layer for API and scan worker#167
Merged
Vishnu2707 merged 1 commit intoJul 8, 2026
Merged
Conversation
2b12cff to
d7307dd
Compare
…ics, readiness probe Implements issue openshield-org#159 (INFRA 6). - api/observability.py: shared module with JSON logging (python-json-logger), optional Sentry init (only when SENTRY_DSN set), request-ID middleware, Prometheus metrics, and the /metrics endpoint. - api/app.py: wire observability middleware first; split /health (liveness, no DB) from /ready (DB connectivity → 200/503); echo X-Request-ID; include request_id in JSON error responses and auth failures; /ready + /metrics public. - api/models/finding.py: add DatabaseManager.ping() for the readiness probe. - scanner/worker.py: shared JSON logging, conditional Sentry, scan_id as a structured log field, scan success/failure counters, scan duration, queue depth. - scanner/engine.py: increment per-rule error counter when a rule raises. - scanner/nvd_client.py, api/services/ai_provider.py: record external-call latency. - requirements.txt: add prometheus-client, python-json-logger, sentry-sdk. - tests/test_observability.py: probes, /metrics, request IDs, auth request_id, conditional Sentry, worker metrics. No metric is labelled with request_id, scan_id, subscription_id, resource_id, error_message or user input.
d7307dd to
5e4906f
Compare
Vishnu2707
approved these changes
Jul 8, 2026
Vishnu2707
left a comment
Member
There was a problem hiding this comment.
exactly what we needed at this stage, logging, metrics and health probes all done right. approving!
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Implements the observability layer requested in #159.
Adds:
X-Request-ID(client-supplied ID echoed; generated UUID when absent)request_idincluded in auth-failure and error responsesscan_id/metricsendpoint/healthfor liveness only (no DB dependency)/readyfor database readiness (200 {"status": "ready"};503 {"status": "not_ready", "error": "database_unreachable"}when the DB is unreachable)SENTRY_DSN(no-op when unset)Prometheus metrics are intentionally kept low-cardinality: no
request_id,scan_id,subscription_id,resource_id, error text, or user input is used as a label./readyand/metricsare treated as always-public probe/scrape endpoints and are exempt from the JWT middleware.Scope control
This PR does not change:
/api/scoreTesting
This branch has been rebased onto the latest
dev.pytest tests/ -v --tb=short:118 passed2 skipped1 failedThe single failure is pre-existing and environmental —
test_ai_hallucination_guard::test_vector_store_purityfails becausechromadbis not installed in the local environment. It is unrelated to this change and reproduces on a cleandevcheckout.pytest tests/test_observability.py -v:10 passed(all new observability tests).Lint gate (enforced by CI):
ruff check .— passes.ruff format --check .— passes; all files formatted.Closes #159