Last active
February 3, 2026 07:12
-
-
Save tedmax100/c944d33341d5ff1db96f19b2dbdc8c6f to your computer and use it in GitHub Desktop.
get_instruments.py
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
| """獲取並顯示 OpenTelemetry 自動埋點插件清單""" | |
| import json | |
| import sys | |
| from typing import List, Dict, Any | |
| def get_instrumentation_libraries(limit: int = None) -> List[Dict[str, Any]]: | |
| """ | |
| 獲取 OpenTelemetry 自動埋點插件清單 | |
| Args: | |
| limit: 限制返回的插件數量,None 表示不限制 | |
| Returns: | |
| 插件清單 | |
| """ | |
| try: | |
| from opentelemetry.instrumentation.bootstrap_gen import libraries | |
| except ImportError as e: | |
| print(f"錯誤:無法導入 OpenTelemetry 模組:{e}", file=sys.stderr) | |
| print("請執行:pip install opentelemetry-instrumentation", file=sys.stderr) | |
| sys.exit(1) | |
| if not libraries: | |
| print("警告:未找到任何插件", file=sys.stderr) | |
| return [] | |
| return libraries[:limit] if limit else libraries | |
| def display_libraries(libraries: List[Dict[str, Any]]) -> None: | |
| """ | |
| 顯示插件清單 | |
| Args: | |
| libraries: 插件清單 | |
| """ | |
| total = len(libraries) | |
| print(f"--- OTel 自動埋點插件清單 (共 {total} 筆) ---") | |
| print(json.dumps(libraries, indent=2, ensure_ascii=False)) | |
| print(f"\n總計:{total} 個插件") | |
| def main(): | |
| """主函數""" | |
| # 可以根據需要修改限制數量,None 表示顯示全部 | |
| limit = None # 改為 100 可以只顯示前 100 筆 | |
| libraries = get_instrumentation_libraries(limit) | |
| display_libraries(libraries) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment