Skip to content

Added PostHog telementry#254

Merged
klemen1999 merged 13 commits into
mainfrom
feat/telementry
Jul 14, 2026
Merged

Added PostHog telementry#254
klemen1999 merged 13 commits into
mainfrom
feat/telementry

Conversation

@klemen1999

@klemen1999 klemen1999 commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Purpose

  • Adds end-to-end telemetry for modelconverter convert, split into three events:

  • Introduces a dedicated telemetry helper module in modelconverter/utils/telemetry.py:

    • defines PostHog-backed defaults via luxonis_ml.telemetry
    • generates/persists a per-run MODELCONVERTER_CONVERSION_RUN_ID
    • builds normalized event payloads for command/configuration/result
    • buckets counts and memory usage to avoid sending raw high-cardinality values
    • classifies failures into user_interrupt, config_error, upload_error, conversion_error, or generic runtime failure
  • Wires telemetry across Docker boundaries:

    • docker_exec() now forwards telemetry-related environment variables into the compose config in modelconverter/utils/docker_utils.py
    • launcher() skips duplicate outer event capture when already running inside Docker, so one conversion run keeps one shared run id and cleaner telemetry in modelconverter/__main__.py
  • Refactors target version lookup into a standalone helper in modelconverter/utils/target_versions.py, then re-exports it through modelconverter/utils/__init__.py.

  • Updates dependency requirements in requirements.txt:

    • bumps luxonis-ml from >=0.8.5 to ~=0.9.0
    • adds the telemetry extra
    • switches nn-archive extra naming to nn_archive
  • Disables telemetry in CI by setting LUXONIS_TELEMETRY_ENABLED: "false" across workflow files under .github/workflows, which keeps tests/publish jobs from emitting telemetry.

  • Adds focused telemetry tests in tests/test_utils/test_telemetry.py:

    • conversion summary generation
    • config-source detection
    • result-property bucketing
    • Docker env propagation
    • telemetry default initialization
  • Example of the new event shape:

{
    "flow_name": "modelconverter_conversion_lifecycle",
    "conversion_run_id": "...",
    "flow_step": "result_recorded",
    "target": "rvc4",
    "config_source": "direct_model_input",
    "result": "success",
    "duration_ms": 1234,
    "uploaded_output": True,
    "peak_ram_usage_bucket": "1g_4g",
}

NOTES:

  • This currently depends on Added generic Telemetry module luxonis-ml#437. Before merge we need to adjust the requirements.txt accordingly
  • To test out telementry use --dev flag so docker image gets rebuilt and actually uses the telementry luxonis-ml branch

Specification

None / not applicable

Dependencies & Potential Impact

None / not applicable

Deployment Plan

None / not applicable

Testing & Validation

None / not applicable

AI Usage

Assisted-by: AGENT_NAME:MODEL_VERSION [TOOL1] [TOOL2]

Submitted code was reviewed by a human: YES/NO

The author is taking the responsibility for the contribution: YES/NO

Summary by CodeRabbit

  • New Features
    • Added enhanced conversion telemetry and detailed run/result reporting, including duration, peak RAM, artifact/output counts, and improved exit-code handling.
    • Extended Docker build images to include git where needed.
  • Bug Fixes
    • Disabled Luxonis telemetry for CI workflows to keep automated runs consistent.
  • Tests
    • Added unit tests covering telemetry utilities and compose environment injection.
  • Chores
    • Updated luxonis-ml to use the repository version with telemetry extras.

@klemen1999 klemen1999 requested a review from a team as a code owner June 30, 2026 14:10
@klemen1999 klemen1999 requested review from conorsim, kozlov721 and tersekmatija and removed request for a team June 30, 2026 14:10
@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

An error occurred during the review process. Please try again later.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/telementry

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@klemen1999

klemen1999 commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator Author

NOTE: Changes to requirements.txt, RVC2 Dockerfile and RVC3 Dockerfile are temporary just for the tests to pass. They should be reverted once related luxonis-ml branch gets merged and released

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
modelconverter/__main__.py (1)

185-223: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Preserve the original main_stage input for telemetry.

Line 223 reports main_stage_provided=True after Line 185 fills main_stage from config defaults, so telemetry can’t distinguish user-provided input from resolved config state.

Proposed fix
-        main_stage = main_stage or _main_stage
+        main_stage_provided = main_stage is not None
+        main_stage = main_stage or _main_stage
@@
-                main_stage_provided=main_stage is not None,
+                main_stage_provided=main_stage_provided,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@modelconverter/__main__.py` around lines 185 - 223, The telemetry flag for
main stage input is using the resolved `main_stage` value instead of the
original caller input, so it cannot tell whether the user actually supplied a
main stage. In `__main__.py`, preserve the initial `main_stage` argument before
it is defaulted from `_main_stage`, and pass that original value into
`build_conversion_summary` for `main_stage_provided` so `build_flow_properties`
reflects user input accurately.
🧹 Nitpick comments (3)
docker/rvc2/Dockerfile (1)

110-119: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Avoid shipping git in the final runtime image.

git is only needed for the later pip install -r ... steps that resolve VCS requirements. Installing it in its own layer keeps it in the published image permanently, which adds avoidable tool surface and image weight. Move the install into the same RUN as the pip installs and purge it before that layer commits.

Proposed change
-RUN <<EOF
-
-    set -e
-
-    apt-get update
-    apt-get install -y --no-install-recommends git
-    rm -rf /var/lib/apt/lists/*
-
-EOF
-
 ...
 RUN <<EOF
 
     set -e
 
-    pip install --upgrade pip  --no-cache-dir
+    apt-get update
+    apt-get install -y --no-install-recommends git
+    pip install --upgrade pip --no-cache-dir
     pip install -r requirements.txt --no-cache-dir
     pip install -r requirements-rvc2.txt --no-cache-dir
     pip install openvino==2022.3.0 openvino-dev==2022.3.0 --no-cache-dir
+    apt-get purge -y --auto-remove git
+    rm -rf /var/lib/apt/lists/*
 
 EOF
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docker/rvc2/Dockerfile` around lines 110 - 119, The standalone apt-get
install of git in the Dockerfile is leaving git baked into the final runtime
image. Move the git installation into the same RUN block that performs the later
pip install steps so it is only present while resolving VCS requirements, then
remove git before that layer completes; use the existing Dockerfile RUN sequence
around the pip install logic to keep the final image free of git.
docker/rvc3/Dockerfile (1)

66-75: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Avoid keeping git in the shipped RVC3 image.

This looks build-time-only as well: git is needed for the following VCS-backed pip install calls, not for steady-state runtime. Installing it in a separate layer leaves unnecessary tooling in the final image. Fold the install into the pip layer and purge it before the layer finishes.

Proposed change
-RUN <<EOF
-
-    set -e
-
-    apt-get update
-    apt-get install -y --no-install-recommends git
-    rm -rf /var/lib/apt/lists/*
-
-EOF
-
 ...
 RUN <<EOF
 
     set -e
 
-    pip install --upgrade pip  --no-cache-dir
+    apt-get update
+    apt-get install -y --no-install-recommends git
+    pip install --upgrade pip --no-cache-dir
     pip install -r requirements.txt --no-cache-dir
     pip install -r requirements-rvc3.txt --no-cache-dir
     pip install openvino==2022.3.0 openvino-dev==2022.3.0 --no-cache-dir
+    apt-get purge -y --auto-remove git
+    rm -rf /var/lib/apt/lists/*
 
 EOF
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docker/rvc3/Dockerfile` around lines 66 - 75, The Dockerfile currently
installs git in a standalone layer, which leaves build-only tooling in the final
RVC3 image. Move the git install into the same layer that runs the VCS-backed
pip installs, using the existing pip build step as the place to temporarily
install git, and remove/purge it before that layer completes. Keep the change
localized to the Dockerfile build flow around the pip install commands so git is
not present in the shipped image.
modelconverter/utils/telemetry.py (1)

352-356: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Minor inconsistency: RVC3 branch skips _drop_none.

Unlike the RVC2/RVC4/Hailo branches, this dict is returned raw, so any None (e.g. compress_to_fp16) leaks into the payload. Wrap it in _drop_none for consistency.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@modelconverter/utils/telemetry.py` around lines 352 - 356, The RVC3Config
branch in telemetry serialization returns a raw dict, unlike the RVC2/RVC4/Hailo
paths, so None values such as compress_to_fp16 can leak into the payload. Update
the RVC3 handling in the telemetry helper to pass the returned dict through
_drop_none, keeping behavior consistent with the other branches in the same
function.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@modelconverter/__main__.py`:
- Line 182: Result telemetry is being skipped for pre-conversion failures
because path validation happens before the try/finally path in __main__.py and
the RESULT_EVENT gate later ignores config/setup errors. Move the path
normalization/validation logic into the main try flow around the conversion
entrypoint, and update the RESULT_EVENT payload assembly to use fallback values
when conversion_start or conversion_summary is missing so failures still emit a
result event. Use the existing conversion_summary, conversion_start, and
phase="configuration" handling to keep the telemetry shape consistent.
- Around line 241-243: The archive name extraction in the archive-handling block
is truncating dotted names at the first period, so stable names like
my.model.nn_archive become my. Update the logic in the code that sets
archive_name near is_nn_archive(original_path) to remove only the archive suffix
from Path(original_path).name instead of splitting on the first dot, preserving
any dots that are part of the base name.
- Around line 805-839: The launcher path in __main__.py leaves the conversion
run ID set in os.environ after calling get_conversion_run_id(), which can leak
into later in-process launches. Update the try/finally flow around
run_in_configured_environment() to restore or clear the environment state after
the command finishes, using the existing conversion_run_id/get_conversion_run_id
and command_telemetry capture block as the reference point.

In `@modelconverter/utils/telemetry.py`:
- Around line 235-254: `command_result_from_exception` and
`command_failure_reason_from_exception` are misclassifying `SystemExit(0)` from
the launcher path as a failure. Update the exception handling in
`modelconverter/utils/telemetry.py` so `SystemExit` with code 0 (and still
None/130) is treated like success: return "success" from
`command_result_from_exception` and `None` from
`command_failure_reason_from_exception`. Keep the existing
`KeyboardInterrupt`/interrupt behavior unchanged and make sure
`command_result_from_exception` and `command_failure_reason_from_exception` stay
consistent for the `COMMAND_EVENT` telemetry.

In `@requirements.txt`:
- Around line 2-3: The luxonis-ml dependency is currently pinned to a mutable
Git branch ref, which makes installs non-reproducible. Update the requirements
entry to use an immutable commit SHA for the
git+https://github.com/luxonis/luxonis-ml.git reference, or revert the
luxonis-ml[data,nn_archive,s3,gcs,telemetry] specifier back to the published
~=0.9.0 release once the telemetry changes are included. Make sure the final
dependency string in requirements.txt points to a fixed revision rather than
feat/telemetry.

In `@tests/test_utils/test_telemetry.py`:
- Around line 182-185: The telemetry environment-reset test is still inheriting
LUXONIS_TELEMETRY_ENABLED from the workflow, so it is not testing the true
default path. In the test setup that clears LUXONIS_TELEMETRY_BACKEND,
LUXONIS_TELEMETRY_API_KEY, LUXONIS_TELEMETRY_ENDPOINT, and
LUXONIS_TELEMETRY_DEBUG, also clear LUXONIS_TELEMETRY_ENABLED with the same
monkeypatch.delenv pattern so the test exercises the intended default
configuration.

---

Outside diff comments:
In `@modelconverter/__main__.py`:
- Around line 185-223: The telemetry flag for main stage input is using the
resolved `main_stage` value instead of the original caller input, so it cannot
tell whether the user actually supplied a main stage. In `__main__.py`, preserve
the initial `main_stage` argument before it is defaulted from `_main_stage`, and
pass that original value into `build_conversion_summary` for
`main_stage_provided` so `build_flow_properties` reflects user input accurately.

---

Nitpick comments:
In `@docker/rvc2/Dockerfile`:
- Around line 110-119: The standalone apt-get install of git in the Dockerfile
is leaving git baked into the final runtime image. Move the git installation
into the same RUN block that performs the later pip install steps so it is only
present while resolving VCS requirements, then remove git before that layer
completes; use the existing Dockerfile RUN sequence around the pip install logic
to keep the final image free of git.

In `@docker/rvc3/Dockerfile`:
- Around line 66-75: The Dockerfile currently installs git in a standalone
layer, which leaves build-only tooling in the final RVC3 image. Move the git
install into the same layer that runs the VCS-backed pip installs, using the
existing pip build step as the place to temporarily install git, and
remove/purge it before that layer completes. Keep the change localized to the
Dockerfile build flow around the pip install commands so git is not present in
the shipped image.

In `@modelconverter/utils/telemetry.py`:
- Around line 352-356: The RVC3Config branch in telemetry serialization returns
a raw dict, unlike the RVC2/RVC4/Hailo paths, so None values such as
compress_to_fp16 can leak into the payload. Update the RVC3 handling in the
telemetry helper to pass the returned dict through _drop_none, keeping behavior
consistent with the other branches in the same function.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: edc78f15-3703-4ef6-8764-6f6408fdadb5

📥 Commits

Reviewing files that changed from the base of the PR and between bc75dc4 and 226c335.

📒 Files selected for processing (24)
  • .github/workflows/actions_autoupdate.yaml
  • .github/workflows/bom-test.yaml
  • .github/workflows/hailo_publish.yaml
  • .github/workflows/hailo_test.yaml
  • .github/workflows/modelconverter_test.yaml
  • .github/workflows/publish.yaml
  • .github/workflows/python-publish.yml
  • .github/workflows/rvc2_publish.yaml
  • .github/workflows/rvc2_test.yaml
  • .github/workflows/rvc3_publish.yaml
  • .github/workflows/rvc3_test.yaml
  • .github/workflows/rvc4_publish.yaml
  • .github/workflows/rvc4_test.yaml
  • .github/workflows/semgrep.yaml
  • .github/workflows/unittests.yaml
  • docker/rvc2/Dockerfile
  • docker/rvc3/Dockerfile
  • modelconverter/__main__.py
  • modelconverter/utils/__init__.py
  • modelconverter/utils/docker_utils.py
  • modelconverter/utils/target_versions.py
  • modelconverter/utils/telemetry.py
  • requirements.txt
  • tests/test_utils/test_telemetry.py

Comment thread modelconverter/__main__.py Outdated
Comment thread modelconverter/__main__.py Outdated
Comment thread modelconverter/__main__.py Outdated
Comment thread modelconverter/utils/telemetry.py
Comment thread requirements.txt Outdated
Comment thread tests/test_utils/test_telemetry.py

@kozlov721 kozlov721 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@klemen1999 klemen1999 merged commit 55f65fb into main Jul 14, 2026
10 checks passed
@klemen1999 klemen1999 deleted the feat/telementry branch July 14, 2026 09:08
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.

2 participants