Skip to main content

Low-level Rust-backed Python module for CodeTracer recording (PyO3)

Project description

Codetracer Python Recorder

codetracer-python-recorder is the Rust-backed recorder module that powers Python tracing inside Codetracer. The PyO3 extension exposes a small Python façade so packaged environments (desktop bundles, uv run, virtualenvs) can start and stop recording without shipping an additional interpreter.

Installation

codetracer-python-recorder publishes binary wheels for CPython 3.12 and 3.13 on Linux (manylinux2014 x86_64/aarch64), macOS 11+ universal2 (arm64 + x86_64), and Windows 10+ (win_amd64). Install the package into the interpreter you plan to trace:

python -m pip install codetracer-python-recorder

Source distributions are available for audit and custom builds; maturin and a Rust toolchain are required when building from source.

Command-line entry point

The wheel installs a console script named codetracer-python-recorder and the package can also be invoked with python -m codetracer_python_recorder. Both forms share the same arguments:

python -m codetracer_python_recorder \
  --trace-dir ./trace-out \
  --format json \
  --activation-path app/main.py \
  --trace-filter config/trace-filter.toml \
  app/main.py --arg=value
  • --trace-dir (default: ./trace-out) – directory that will receive trace.json, trace_metadata.json, and trace_paths.json.
  • --format – trace serialisation format (binary or json). Use json for integration with the DB backend importer.
  • --activation-path – optional gate that postpones tracing until the interpreter executes this file (defaults to the target script).
  • --trace-filter – path to a filter file. Provide multiple times or use :: separators within a single argument to build a chain. When present, the recorder prepends the project default .codetracer/trace-filter.toml (if found near the target script) so later entries override the defaults. The CODETRACER_TRACE_FILTER environment variable accepts the same ::-separated syntax when using the auto-start hook.

All additional arguments are forwarded to the target script unchanged. The CLI reuses whichever interpreter launches it so wrappers such as uv run, pipx, or activated virtual environments behave identically to python script.py.

Trace filter configuration

  • Filter files are TOML with [meta], [scope], and [[scope.rules]] tables. Rules evaluate in declaration order and can tweak both execution (exec) and value decisions (value_default).
  • Supported selector domains: pkg, file, obj for scopes; local, global, arg, ret, attr for value policies. Match types default to glob and also accept regex or literal (e.g. local:regex:^(metric|masked)_\w+$).
  • Default discovery: .codetracer/trace-filter.toml next to the traced script. Chain additional files via CLI (--trace-filter path_a --trace-filter path_b), environment variable (CODETRACER_TRACE_FILTER=path_a::path_b), or Python helpers (trace(..., trace_filter=[path_a, path_b])). Later entries override earlier ones when selectors overlap.
  • A built-in builtin-default filter is always prepended. It skips CPython standard-library frames (e.g. asyncio, threading, importlib) while re-enabling third-party packages under site-packages (except helpers such as _virtualenv.py), and redacts common secrets (password, token, API keys, etc.) across locals/globals/args/returns/attributes. Project filters can loosen or tighten these defaults as required.
  • Runtime metadata captures the active chain under trace_metadata.json -> trace_filter, including per-kind redaction and drop counters. See docs/onboarding/trace-filters.md for the full DSL reference and examples.

Example snippet:

[meta]
name = "local-redaction"
version = 1

[scope]
default_exec = "trace"
default_value_action = "allow"

[[scope.rules]]
selector = "pkg:my_app.services.*"
value_default = "redact"
[[scope.rules.value_patterns]]
selector = "local:glob:public_*"
action = "allow"
[[scope.rules.value_patterns]]
selector = 'local:regex:^(metric|masked)_\w+$'
action = "allow"
[[scope.rules.value_patterns]]
selector = "arg:literal:debug_payload"
action = "drop"

Trace naming semantics

  • Module-level activations no longer appear as the ambiguous <module> label. When the recorder sees co_qualname == "<module>", it first reuses the frame's __name__, then falls back to trace-filter hints, sys.path roots, and package markers so scripts report <__main__> while real modules keep their dotted names (e.g., <my_pkg.mod> or <boto3.session>).
  • The globals-derived naming flow ships enabled by default; disable it temporarily with --no-module-name-from-globals, codetracer.configure_policy(module_name_from_globals=False), or CODETRACER_MODULE_NAME_FROM_GLOBALS=0 if you need to compare against the legacy resolver.
  • The angle-bracket convention remains for module entries so downstream tooling can distinguish top-level activations at a glance.
  • Traces will still emit <module> for synthetic filenames (<stdin>, <string>), frozen/importlib bootstrap frames, or exotic loaders that omit filenames entirely. This preserves previous behaviour when no reliable name exists.

Packaging expectations

Desktop installers add the wheel to PYTHONPATH before invoking the user’s interpreter. When embedding the recorder elsewhere, ensure the wheel (or its extracted site-packages directory) is discoverable on sys.path and run the CLI with the interpreter you want to trace.

The CLI writes recorder metadata into trace_metadata.json describing the wheel version, target script, and diff preference so downstream tooling can make decisions without re-running the trace.

Development benchmarks

  • Rust microbench: cargo bench --bench trace_filter --no-default-features exercises baseline, glob-heavy, and regex-heavy selector chains.
  • Python smoke benchmark: pytest codetracer-python-recorder/tests/python/perf/test_trace_filter_perf.py -q when the environment variable CODETRACER_TRACE_FILTER_PERF=1 is set.
  • Run both together with just bench. The helper seeds a virtualenv, runs Criterion, then executes the Python smoke test while writing target/perf/trace_filter_py.json (per-scenario durations plus redaction/drop statistics).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codetracer_python_recorder-0.3.0.tar.gz (144.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

codetracer_python_recorder-0.3.0-cp313-cp313-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.13Windows x86-64

codetracer_python_recorder-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

codetracer_python_recorder-0.3.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

codetracer_python_recorder-0.3.0-cp313-cp313-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

codetracer_python_recorder-0.3.0-cp313-cp313-macosx_10_12_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

codetracer_python_recorder-0.3.0-cp312-cp312-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.12Windows x86-64

codetracer_python_recorder-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

codetracer_python_recorder-0.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

codetracer_python_recorder-0.3.0-cp312-cp312-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

codetracer_python_recorder-0.3.0-cp312-cp312-macosx_10_12_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

Details for the file codetracer_python_recorder-0.3.0.tar.gz.

File metadata

File hashes

Hashes for codetracer_python_recorder-0.3.0.tar.gz
Algorithm Hash digest
SHA256 7c4b418ae872611b2b22ad9e2d016f72735b89f1af3a371a5721f85691cd8609
MD5 ad472404ecad5b0fd58789d238fb52e9
BLAKE2b-256 c839bf4d30e5958d5d3235aa4489756fc30faf2f1c38cf75b2e5efb6c323c47c

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetracer_python_recorder-0.3.0.tar.gz:

Publisher: recorder-release.yml on metacraft-labs/codetracer-python-recorder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codetracer_python_recorder-0.3.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for codetracer_python_recorder-0.3.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2982f5ca1bee72f9ef2a8d71dbb73c6cd323b623a71ee8c8541a4cbf34649701
MD5 13a7bd2146b8b9515b012a5e932aac3a
BLAKE2b-256 36738ecd1a9919c62387f1b3551e4be9bcf7431a4493bb0222c9d4bc38beb4c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetracer_python_recorder-0.3.0-cp313-cp313-win_amd64.whl:

Publisher: recorder-release.yml on metacraft-labs/codetracer-python-recorder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codetracer_python_recorder-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for codetracer_python_recorder-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d2b1a5981b0986b41e8b1c93705a9c69ea2eb4a139ee6a8f7678f21217de3cc5
MD5 ac2da649770cd8b4f19399f53a6dd4e1
BLAKE2b-256 ffd2b2ea40a03e3dbf9c3715ef3d36d27b0ce358bd8ffb687be3911d0c85748b

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetracer_python_recorder-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: recorder-release.yml on metacraft-labs/codetracer-python-recorder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codetracer_python_recorder-0.3.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for codetracer_python_recorder-0.3.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cabf6c23f76f55b57bf64f4213284be43d0ba6bb37600221a897e5a776184d01
MD5 1fef6685f07ed3aa09c975fc3b42f350
BLAKE2b-256 a21551d712756e0e4645ab8606de27f4687e271797349d1e2565098a3fa9cfd7

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetracer_python_recorder-0.3.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: recorder-release.yml on metacraft-labs/codetracer-python-recorder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codetracer_python_recorder-0.3.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for codetracer_python_recorder-0.3.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ec7461be7272da9c75ed1019e32461e0734712705974be86df54932ca320dd06
MD5 d4d04b188fc27877ac799571ef94ad68
BLAKE2b-256 1670a31be0a3fca5d4e62c2e870365bf0872bc5ff5b7b98ff67c5b7361d3482f

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetracer_python_recorder-0.3.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: recorder-release.yml on metacraft-labs/codetracer-python-recorder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codetracer_python_recorder-0.3.0-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for codetracer_python_recorder-0.3.0-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5c46e3d24e3ae08d28c4c0dba52e4e445c09cf2b57930145966bd737a25c4158
MD5 a979378bf9eb39fd03ae87da9eded80e
BLAKE2b-256 1756859e6e054db493e6fe327b849fd37f17d91f0dbd2f53bab5367504d5004c

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetracer_python_recorder-0.3.0-cp313-cp313-macosx_10_12_x86_64.whl:

Publisher: recorder-release.yml on metacraft-labs/codetracer-python-recorder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codetracer_python_recorder-0.3.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for codetracer_python_recorder-0.3.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7013ab23d341a10808e602aab805462939648a9adfb2b21f5779daf8b7e783f9
MD5 8e79858086b154fbee2cabcaf5e39090
BLAKE2b-256 053faaa5082b2944027122e11acffc75cded5a4727d868d556329029f59c9041

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetracer_python_recorder-0.3.0-cp312-cp312-win_amd64.whl:

Publisher: recorder-release.yml on metacraft-labs/codetracer-python-recorder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codetracer_python_recorder-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for codetracer_python_recorder-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 50214c54da67c1ffd418cc9c12b50c31d248da5bfda8e4f9609f17ed524ed298
MD5 83daf0c6eef5e04ec0b9541e9dedbff0
BLAKE2b-256 d8ae319b3760057bc698520ee95d5f12b1c39f37f532cf90e846d6bf63deb346

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetracer_python_recorder-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: recorder-release.yml on metacraft-labs/codetracer-python-recorder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codetracer_python_recorder-0.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for codetracer_python_recorder-0.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 34fa9d045cf02cc418f948206fe0752fea6931a89b5c20baafcfcda4a859c2c1
MD5 c699d514c1ca548554f7f16ed3a7ca17
BLAKE2b-256 b6694d0e2dd2e7fd8c18a126a0c8b9cbc5352dc1a3b7327ceb442bab86676b71

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetracer_python_recorder-0.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: recorder-release.yml on metacraft-labs/codetracer-python-recorder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codetracer_python_recorder-0.3.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for codetracer_python_recorder-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 263d05a6a58b04d941135d86c895918d6df7ececf8782876154f334b3ba2d9eb
MD5 aa36a8702199f222895fdb9629735393
BLAKE2b-256 3b24b374190a70475cc6da22ddd01ebe01305043e4e728dfc6a3af43fc198f32

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetracer_python_recorder-0.3.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: recorder-release.yml on metacraft-labs/codetracer-python-recorder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codetracer_python_recorder-0.3.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for codetracer_python_recorder-0.3.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d0cc6760a336a40f2a990b01e33cbaf633203fccb1e46951d9b62d1a15b2bcca
MD5 f455e0e26e93bc207b19ee75bbd7430e
BLAKE2b-256 6759fcfe3834a3870771727892f1d5786988179169562c1bcf2b3a9955603a43

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetracer_python_recorder-0.3.0-cp312-cp312-macosx_10_12_x86_64.whl:

Publisher: recorder-release.yml on metacraft-labs/codetracer-python-recorder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page