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
Draft
Conversation
…ALLOC_ENABLED env var Co-Authored-By: bot_apk <apk@cognition.ai>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
…c imports) Co-Authored-By: bot_apk <apk@cognition.ai>
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.
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 theCDK_TRACEMALLOC_ENABLEDenvironment variable.When set to a truthy value (
1,true,yes),tracemalloc.start()is called lazily on first metric emission and thecdk.memory.python_heap_bytesgauge is emitted alongside existing container memory metrics. When unset (the default), the function is a no-op returningNone— no tracing overhead, no metric emitted.Files changed:
airbyte_cdk/metrics/memory.py— adds_is_tracemalloc_enabled()andget_python_heap_bytes()airbyte_cdk/metrics/__init__.py— imports new function, addsMETRIC_MEMORY_PYTHON_HEAP_BYTESconstant, emits the gauge inemit_memory_metrics()unit_tests/metrics/test_memory.py— 7 new tests covering enabled/disabled/case-insensitive env var behaviorunit_tests/metrics/test_metrics_client.py— 2 new tests verifying MetricsClient emits/skips the heap metricResolves https://github.com/airbytehq/airbyte-internal-issues/issues/15952:
Review & Testing Checklist for Human
CDK_TRACEMALLOC_ENABLEDfollows the team's naming conventions for CDK env vars (vs. e.g.AIRBYTE_CDK_TRACEMALLOC_ENABLED).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.RuntimeErrorpath: Theexcept RuntimeErrorbranch inget_python_heap_bytes()(whentracemalloc.start()fails) has no dedicated test. Assess if this gap matters.devin/1772669295-add-memory-metrics-module(PR feat: add memory & resource metrics to Python CDK via DogStatsD (Tier 1) #931), notmain. 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:
CDK_TRACEMALLOC_ENABLED=true, and run a short connector sync — verifycdk.memory.python_heap_bytesappears in DogStatsD output.Notes
Updates since last revision
import sysfor macOSru_maxrsshandling; this branch addsimport tracemalloc; both are now present).