Skip to content

Ship the injector bootstrap script (sitecustomize.py) in the distro wheel#34

Merged
mmanciop merged 1 commit into
mainfrom
sitecustomize
Jul 23, 2026
Merged

Ship the injector bootstrap script (sitecustomize.py) in the distro wheel#34
mmanciop merged 1 commit into
mainfrom
sitecustomize

Conversation

@mmanciop

@mmanciop mmanciop commented Jul 23, 2026

Copy link
Copy Markdown
Member

Closes #32.

Moves the sitecustomize.py that the OpenTelemetry injector triggers via PYTHONPATH from the dash0-operator repository (in its dash0hq/dash0-operator#1248 form, already adapted to this distribution) into the dash0-opentelemetry-distro wheel, at dash0/opentelemetry/injector/sitecustomize.py. This follows up on dash0hq/dash0-operator#1248 (comment): the script is now versioned, tested, and released together with the tree it bootstraps.

Deployment contract

Consumers building an injectable tree (such as the operator's instrumentation image):

  1. pip install --target <dir> dash0-opentelemetry-distro
  2. copy the script from its packaged location to <dir>/sitecustomize.py
  3. generate <dir>/all-dependencies.txt (one PEP 508 requirement per line) for the dependency-conflict check

The script stays valid Python 2.7+ so it can self-deactivate gracefully on interpreters the distribution does not support (the injector touches every Python process); it is excluded from ruff for that reason.

Deliberate deviations from the operator's copy

  • PYTHONPATH is split on os.pathsep (previously ,) in _self_deactivate, so self-deactivation also removes the injected site for child processes when PYTHONPATH has multiple entries.
  • The double-instrumentation check is derived from the injected tree instead of a hardcoded package list: the tree at the script's site is exactly the pinned dependency closure of this package's pyproject.toml (CI enforces this), so the script enumerates the opentelemetry-*/dash0-* distributions installed there and flags overlap with the application's sites. opentelemetry-api and opentelemetry-semantic-conventions are excluded — applications legitimately use the API layer for manual instrumentation (preserving dash0hq/dash0-operator@ea847dcc) — and version conflicts with them are still caught by the all-dependencies.txt check.

Version bump

The distro version bumps to 0.2.0

…heel

Move the sitecustomize.py that the OpenTelemetry injector triggers via
PYTHONPATH from the dash0-operator repository into the
dash0-opentelemetry-distro wheel, at
dash0/opentelemetry/injector/sitecustomize.py. Consumers building an
injectable tree (pip install --target <dir>) copy it from its packaged
location to <dir>/sitecustomize.py, so the script is versioned and
tested together with the tree it bootstraps.

Two deliberate deviations from the operator's copy:

- Split PYTHONPATH on os.pathsep (previously ","), so self-deactivation
  also removes the injected site when PYTHONPATH has multiple entries.
- Derive the double-instrumentation check from the OpenTelemetry
  packages actually installed in the injected tree (the pinned
  dependency closure of this package), instead of a hardcoded list.
  API-layer packages (opentelemetry-api, -semantic-conventions) are
  excluded: applications legitimately use them for manual
  instrumentation; version conflicts with them are still caught by the
  all-dependencies.txt check.

The script stays valid Python 2.7+ so it can self-deactivate gracefully
on interpreters the distribution does not support; it is excluded from
ruff for that reason.
@mmanciop
mmanciop requested a review from ocelotl July 23, 2026 08:38
mmanciop added a commit to dash0hq/dash0-operator that referenced this pull request Jul 23, 2026
…distribution

Follows dash0hq/opentelemetry-python-distribution#34: the injector bootstrap
script and its unit tests now live inside the dash0-opentelemetry-distro wheel.
The instrumentation image copies the packaged file to <target>/sitecustomize.py
after pip install, per the distribution's deployment contract. Drops the local
copy of the script, its unit tests, the make target and the CI job that ran
them.
@mmanciop
mmanciop enabled auto-merge (squash) July 23, 2026 12:39
@mmanciop
mmanciop merged commit 947854e into main Jul 23, 2026
9 checks passed
@mmanciop
mmanciop deleted the sitecustomize branch July 23, 2026 13:46
@mmanciop mmanciop mentioned this pull request Jul 23, 2026
mmanciop added a commit that referenced this pull request Jul 23, 2026
Fold the pending chloggen entry into the 0.2.0 - 2026-07-23 changelog
section. The version bump to 0.2.0 already landed with #34; uv.lock is
already current.
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.

Incorporate the sitecustomize from the operator

2 participants