Repository navigation
Issue 11 observability - #31
Open
jaineel132 wants to merge 4 commits into
Open
jaineel132 wants to merge 4 commits into
jaineel132 wants to merge 4 commits into
Conversation
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.
Summary
Adds observability to Mnema through a Prometheus
/metricsendpoint and opt-in structured JSON logging. Instrumentation is implemented in the service layer, ensuring coverage across MCP tools, the SDK, CLI, and REST API.Related issue
Closes #11
Changes
pyproject.tomlAdded a new
[observability]extra:prometheus-client>=0.21python-json-logger>=3.2config.pyAdded the
MNEMA_LOG_FORMATconfiguration field with:textas the default formatjsonas the optional structured logging formatdiagnostics.pyAdded a Prometheus metric registry containing:
mnema_memories_totalcounter with anoperationlabelmnema_embed_latency_secondshistogrammnema_backend_latency_secondshistogrammnema_memory_countgaugeUses a private
CollectorRegistryto prevent duplicate-timeseries errors when Mnema modules are reloaded during tests.Added
_NoOpMetricfallbacks when the observability extra is not installed.Added JSON formatter support in
configure_logging().Falls back to text logging when
python-json-loggeris unavailable and prints an installation hint tostderr.Added the shared
metrics_payload()helper.service.pyInstrumented:
rememberrecallsearchupdateforgetforget_scopestatsAdded embedding and backend latency measurements.
Added operation counters and memory-count gauge updates.
Added structured
logger.info()calls.api/app.pyGET /metricsendpoint to the REST API.501with an installation hint when the Prometheus dependency is unavailable.server.pyGET /metricsendpoint to the MCP streamable-HTTP transport usingFastMCP.custom_route.tests/test_observability.pyAdded 10 tests covering:
501behavior whenprometheus_clientis unavailableDocumentation and repository configuration
UnreleasedinCHANGELOG.md.MNEMA_LOG_FORMATto the configuration table inREADME.md.opencode.jsonto.gitignore.Checklist
ruff check .is cleanpytestpasses with the relevant extras installedNotes for reviewer
Optional dependency discipline is preserved: importing
mnemadoes not require the new observability dependencies. Metrics use_NoOpMetricfallbacks whenprometheus-clientis unavailable, andMNEMA_LOG_FORMAT=jsonfalls back to text logging whenpython-json-loggeris unavailable. Both cases provide an installation hint throughstderr.Metrics use a module-owned private
CollectorRegistry, preventingprometheus_client's duplicate-timeseries errors when Mnema modules are reloaded during tests.The
/metricsendpoint is available on both HTTP surfaces:mnema serveFastMCP.custom_routeThe stdio transport has no HTTP endpoint, so
mnema serveis the scrape path for stdio-based deployments.The
python-json-logger>=3.2requirement uses thepythonjsonlogger.jsonimport path, avoiding the deprecatedjsonloggermodule warning introduced in version 4.x.mypyintroduces no new errors compared with the baseline. Pre-existing errors incli.pyandserver.pyremain unchanged and were verified againstmain.Four backend-matrix skips are pre-existing because optional backend dependencies are not installed locally. The full suite passes with
[dev,observability]andfastapiinstalled.