Install and configure Sentry SDK for Python #1315
Draft
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.
On this branch, I installed and configured the Sentry SDK for error tracking and performance monitoring in the Runtime API application.
Details
Dependencies
sentry-sdk[fastapi] >= 2.0.0, < 3.0.0to production dependencies with FastAPI integrationConfiguration (all in
nmdc_runtime/config.py)SENTRY_DSN: DSN string (default: empty)SENTRY_ENVIRONMENT: environment name (default: "unknown")IS_SENTRY_ENABLED: boolean flag (default: False)SENTRY_TRACES_SAMPLE_RATE: transaction sampling (default: 0.1)SENTRY_PROFILES_SAMPLE_RATE: profiling sampling (default: 0.1)Initialization
Sentry initializes in
nmdc_runtime/api/main.pyonly when bothIS_SENTRY_ENABLED=trueandSENTRY_DSNis non-empty. Sample rates default to 10% for production safety.Error Handling
Added
get_float_from_env()helper with validation that raisesValueErrorwith actionable messages on invalid input.Example Configuration
Related issue(s)
Resolves the Sentry SDK installation task. Coordination with @eecavanna needed to generate production DSN.
Related subsystem(s)
docsdirectory)Testing
I tested these changes by creating comprehensive unit tests in
tests/test_config.pycovering all configuration variables, default values, environment variable parsing, and error handling. Manual testing verified configuration loading and Sentry initialization logic. CodeQL security scan passed with 0 alerts.Documentation
docsdirectory)Updated
.env.examplewith all Sentry configuration variables including descriptions and usage guidance.Maintainability
study_id: str)# TODOor# FIXMEblackto format all the Python files I created/modifiedOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.