Skip to content

feat: add opt-in tracemalloc Python heap metrics (AI-Triage PR)#933

Draft
devin-ai-integration[bot] wants to merge 2 commits intodevin/1772669295-add-memory-metrics-modulefrom
devin/1772744091-add-tracemalloc-opt-in
Draft

feat: add opt-in tracemalloc Python heap metrics (AI-Triage PR)#933
devin-ai-integration[bot] wants to merge 2 commits intodevin/1772669295-add-memory-metrics-modulefrom
devin/1772744091-add-tracemalloc-opt-in

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Mar 5, 2026

This PR targets the following PR:


feat: add opt-in tracemalloc Python heap metrics (AI-Triage PR)

Summary

Re-introduces get_python_heap_bytes() (removed from this branch in commit c8b0197 due to reviewer concerns about unconditional overhead) as an opt-in feature gated behind the CDK_TRACEMALLOC_ENABLED environment variable.

When set to a truthy value (1, true, yes), tracemalloc.start() is called lazily on first metric emission and the cdk.memory.python_heap_bytes gauge is emitted alongside existing container memory metrics. When unset (the default), the function is a no-op returning None — no tracing overhead, no metric emitted.

Files changed:

  • airbyte_cdk/metrics/memory.py — adds _is_tracemalloc_enabled() and get_python_heap_bytes()
  • airbyte_cdk/metrics/__init__.py — imports new function, adds METRIC_MEMORY_PYTHON_HEAP_BYTES constant, emits the gauge in emit_memory_metrics()
  • unit_tests/metrics/test_memory.py — 7 new tests covering enabled/disabled/case-insensitive env var behavior
  • unit_tests/metrics/test_metrics_client.py — 2 new tests verifying MetricsClient emits/skips the heap metric

Resolves https://github.com/airbytehq/airbyte-internal-issues/issues/15952:

Review & Testing Checklist for Human

  • Env var naming: Confirm CDK_TRACEMALLOC_ENABLED follows the team's naming conventions for CDK env vars (vs. e.g. AIRBYTE_CDK_TRACEMALLOC_ENABLED).
  • Top-level import tracemalloc: The stdlib module is imported at module level per Python coding standards, even though the original (removed) implementation used a lazy inline import. Verify this is acceptable — the import itself is cheap but it does load the module unconditionally.
  • No test for RuntimeError path: The except RuntimeError branch in get_python_heap_bytes() (when tracemalloc.start() fails) has no dedicated test. Assess if this gap matters.
  • Base branch: This PR targets devin/1772669295-add-memory-metrics-module (PR feat: add memory & resource metrics to Python CDK via DogStatsD (Tier 1) #931), not main. Ensure it is rebased/merged correctly after feat: add memory & resource metrics to Python CDK via DogStatsD (Tier 1) #931 lands.

Suggested manual test plan:

  1. Check out this branch, set CDK_TRACEMALLOC_ENABLED=true, and run a short connector sync — verify cdk.memory.python_heap_bytes appears in DogStatsD output.
  2. Unset the env var and repeat — verify no tracemalloc overhead and no heap metric emitted.

Notes

Updates since last revision

  • Resolved merge conflict with base branch (base added import sys for macOS ru_maxrss handling; this branch adds import tracemalloc; both are now present).

…ALLOC_ENABLED env var

Co-Authored-By: bot_apk <apk@cognition.ai>
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

…c imports)

Co-Authored-By: bot_apk <apk@cognition.ai>
@github-actions
Copy link

github-actions bot commented Mar 5, 2026

PyTest Results (Fast)

3 911 tests  +9   3 899 ✅ +9   6m 14s ⏱️ -31s
    1 suites ±0      12 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit a58279d. ± Comparison against base commit b208bd0.

@github-actions
Copy link

github-actions bot commented Mar 5, 2026

PyTest Results (Full)

3 914 tests  +9   3 902 ✅ +9   11m 29s ⏱️ +15s
    1 suites ±0      12 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit a58279d. ± Comparison against base commit b208bd0.

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.

0 participants