LoongSuite .pth site bootstrap for OpenTelemetry auto-instrumentation (opt-in via env)
Project description
loongsuite-site-bootstrap
在不修改业务代码、不改用 loongsuite-instrument 启动命令的前提下,通过 site-packages 中的 .pth 行在解释器早期触发一次 import,从而在进程内执行与 opentelemetry-instrument(sitecustomize → initialize())等价的 OpenTelemetry 自动注入逻辑。
与 loongsuite-bootstrap 的职责不同:本包只负责启动早期注入,不会安装任何 Instrumentation 包。可与 loongsuite-bootstrap 配合使用(推荐),也可按需自行 pip install 所需的 opentelemetry-instrumentation-* / loongsuite-instrumentation-*。
安装
pip install loongsuite-site-bootstrap
随后请安装 Instrumentation 与 Exporter。推荐用 loongsuite-bootstrap 安装:
loongsuite-bootstrap -a install --latest
# 或仅安装当前环境已存在依赖对应的埋点
loongsuite-bootstrap -a install --latest --auto-detect
也可以手动安装,例如:
pip install opentelemetry-exporter-otlp loongsuite-instrumentation-langchain
配置优先级
- 进程环境变量(导出、容器 env、启动参数等):已存在的键不会被
bootstrap-config.json覆盖。 ~/.loongsuite/bootstrap-config.json:仅在LOONGSUITE_PYTHON_SITE_BOOTSTRAP实际处于开启状态时才会读取;对文件中出现的键,仅当环境中尚未设置时写入os.environ(便于默认带上 OTLP、exporter 等,子进程可继承)。若环境中已显式设置该开关且为“关闭”含义,则不读 JSON、也不做自动注入。
JSON 根节点须为对象;键必须为字符串。值的类型会转成字符串再写入环境变量:bool → true / false,int / float → 十进制字符串,str → 原样,null 跳过,其它类型 → 紧凑 JSON 字符串。
示例 ~/.loongsuite/bootstrap-config.json:
{
"LOONGSUITE_PYTHON_SITE_BOOTSTRAP": "True",
"OTEL_SERVICE_NAME": "my-app",
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:4317"
}
若文件不存在、无法读取或 JSON 无效,则跳过文件(无效时可能打出一条 logging 告警);不影响 Python 正常启动。
启用方式
默认不执行任何 OTel 逻辑(避免影响环境中所有 Python 进程)。可在 bootstrap-config.json 或环境变量 中开启后,本包在进程启动早期执行自动注入:
export LOONGSUITE_PYTHON_SITE_BOOTSTRAP=True
True 字符串视为开启(不区分大小写,如 true / TRUE);其它任何取值(含空字符串等)均视为关闭。
启用时会(若尚未设置)默认:
OTEL_PYTHON_DISTRO=loongsuiteOTEL_PYTHON_CONFIGURATOR=loongsuite
从而使用 loongsuite-distro 中的 LoongSuiteDistro / LoongSuiteConfigurator(与 loongsuite-instrument + OTEL_PYTHON_DISTRO=loongsuite 一致)。上述两项仍使用 setdefault,在 JSON 补齐之后执行;若环境或 JSON 已为同名变量赋值,则保持已有取值。
行为说明
- 安装后 wheel 会在
site-packages根目录释放loongsuite-site-bootstrap.pth,其中含一行import loongsuite_site_bootstrap,依赖 CPythonsite对.pth中import行的标准行为。 - 不使用
python -S(禁用site)时才会生效。 - 作用范围是当前 Python 环境内所有启用了本 bootstrap 的进程,不仅是某一应用入口。
- 在
LOONGSUITE_PYTHON_SITE_BOOTSTRAP已开启且initialize()成功结束后,会向 stdout 打印一行英文:loongsuite-site-bootstrap: started successfully (OpenTelemetry auto-instrumentation initialized).(本包自带一个仅绑定在loongsuite_site_bootstraplogger 上的StreamHandler,不依赖应用是否已配置logging。)
卸载
pip uninstall loongsuite-site-bootstrap
卸载后 .pth 会随包移除;若曾手动复制 .pth,需自行清理。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file loongsuite_site_bootstrap-0.5.0-py3-none-any.whl.
File metadata
- Download URL: loongsuite_site_bootstrap-0.5.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7493ed5206cbbde37d22f1162c7630b1d98c792cb1975b9b7fe3c4a104db656c
|
|
| MD5 |
561e5930ffa4478265a5a6f5fb2bb75c
|
|
| BLAKE2b-256 |
e1b56408e94b790610f018b35da5641b935c17b6e2db3111596c3852de0cc903
|