Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 6, 2025

On this branch, I installed and configured the Sentry SDK for error tracking and performance monitoring in the Runtime API application.

Details

Dependencies

  • Added sentry-sdk[fastapi] >= 2.0.0, < 3.0.0 to production dependencies with FastAPI integration

Configuration (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.py only when both IS_SENTRY_ENABLED=true and SENTRY_DSN is non-empty. Sample rates default to 10% for production safety.

Error Handling
Added get_float_from_env() helper with validation that raises ValueError with actionable messages on invalid input.

Example Configuration

# Enable Sentry in production
SENTRY_DSN=https://...@sentry.io/123456
SENTRY_ENVIRONMENT=production
IS_SENTRY_ENABLED=true
SENTRY_TRACES_SAMPLE_RATE=0.1  # 10% sampling

Related issue(s)

Resolves the Sentry SDK installation task. Coordination with @eecavanna needed to generate production DSN.

Related subsystem(s)

  • Runtime API (except the Minter)
  • Minter
  • Dagster
  • Project documentation (in the docs directory)
  • Translators (metadata ingest pipelines)
  • MongoDB migrations
  • Other

Testing

  • I tested these changes (explain below)
  • I did not test these changes

I tested these changes by creating comprehensive unit tests in tests/test_config.py covering 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

  • I have not checked for relevant documentation yet (e.g. in the docs directory)
  • I have updated all relevant documentation so it will remain accurate
  • Other (explain below)

Updated .env.example with all Sentry configuration variables including descriptions and usage guidance.

Maintainability

  • Every Python function I defined includes a docstring (test functions are exempt from this)
  • Every Python function parameter I introduced includes a type hint (e.g. study_id: str)
  • All "to do" or "fix me" Python comments I added begin with either # TODO or # FIXME
  • I used black to format all the Python files I created/modified
  • The PR title is in the imperative mood (e.g. "Do X") and not the declarative mood (e.g. "Does X" or "Did X")
Original prompt

This section details on the original issue you should resolve

<issue_title>Install and configure Sentry SDK for Python</issue_title>
<issue_description>- [ ] Install the Sentry SDK for Python (list it as a production dependency in pyproject.toml).

  • Define a config variable (named SENTRY_DSN) that can store the Sentry DSN. Give it a default value of "" (empty string). Add a corresponding environment variable to the example .env file.
  • Define a config variable (named SENTRY_ENVIRONMENT) that can store the Sentry environment name. Give it a default value of "unknown" (string). Add a corresponding environment variable to the example .env file.
  • Define a config variable (named IS_SENTRY_ENABLED) that is a boolean flag whose default value is False (boolean). Add a corresponding environment variable to the example .env file. This environment variable can be used to control whether Sentry is enabled or not, regardless of the values of the other two environment variables.
  • Initialize the Sentry SDK within the Runtime API application (not Dagster).
  • Work with team member @eecavanna to generate a Sentry DSN.</issue_description>

<agent_instructions>Implement as much of this as you can in a Pull Request branch. When you have gone as far as you can, tell me what work remains. I will do the remaining work.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@ssarrafan No update for 2 weeks. Removing from sprint.

💡 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.

Copilot AI and others added 5 commits November 6, 2025 03:48
- Added sentry-sdk[fastapi] to pyproject.toml dependencies
- Added SENTRY_DSN, SENTRY_ENVIRONMENT, and IS_SENTRY_ENABLED config variables
- Updated .env.example with Sentry configuration variables
- Initialized Sentry SDK in Runtime API application (main.py)
- Added comprehensive tests for Sentry configuration

Co-authored-by: eecavanna <134325062+eecavanna@users.noreply.github.com>
- Added version constraint to sentry-sdk dependency (>= 2.0.0, < 3.0.0)
- Made sample rates configurable via environment variables
- Changed default sample rates from 100% to 10% to avoid performance impact
- Moved importlib import to top of test file
- Added tests for new sample rate configuration variables

Co-authored-by: eecavanna <134325062+eecavanna@users.noreply.github.com>
- Added get_float_from_env helper function with validation
- Provides helpful error messages for invalid float values
- Added comprehensive tests for the new helper function
- Updated sample rate config to use the helper function

Co-authored-by: eecavanna <134325062+eecavanna@users.noreply.github.com>
- Changed error message from "number between 0.0 and 1.0" to "numeric value"
- This makes the helper function more reusable and accurate

Co-authored-by: eecavanna <134325062+eecavanna@users.noreply.github.com>
Copilot AI changed the title [WIP] Install and configure Sentry SDK for Python Install and configure Sentry SDK for Python Nov 6, 2025
Copilot AI requested a review from eecavanna November 6, 2025 04:02
Copilot finished work on behalf of eecavanna November 6, 2025 04:02
@eecavanna
Copy link
Collaborator

I'll take over from here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Install and configure Sentry SDK for Python

2 participants