fix(agent-observability): degrade gracefully when opentelemetry is missing - #29
Merged
Merged
Conversation
…ssing core/agentlens/runtime.py imported opentelemetry at module scope with no guard, so any environment without the (optional) opentelemetry package crashed every agent-observability hook phase at import time, before the existing try/except-based error handling in main()/runtime.main() could ever run. Fresh installs typically hit this because run_hook.sh falls back to system python3 when the project .venv lacks zhiyanllm, and system python3 rarely has opentelemetry installed. Wrap the import in try/except, consistent with how the rest of the agentlens package already treats opentelemetry/zhiyanllm as optional (bootstrap.load_runtime, tracing.generate_turn_carrier). The two call sites for _otel_trace are only reached once bootstrap.ensure_initialized has confirmed the runtime is available, so this is a no-op on the happy path. Regenerated the .cursor/.claude Classic host bundles via scripts/build-classic-hosts.py --write to keep them in sync with the .codebuddy source. Fixes #17 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
10 of 14 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
core/agentlens/runtime.pyimportedopentelemetryat module scope with no guard, so any environment without the (optional)opentelemetrypackage crashed every agent-observability hook phase (SessionStart/UserPromptSubmit/PreToolUse/PostToolUse/Stop) at import time — before the existing try/except error handling inmain()/runtime.main()ever got a chance to run.run_hook.shfalls back to systempython3whenever the project.venvlackszhiyanllm, and systempython3typically doesn't haveopentelemetryinstalled — matching the traceback reported in [Bug]: ⚠ Hook SessionStart [warning] #17.try/except, consistent with how the rest ofagentlensalready treatsopentelemetry/zhiyanllmas optional (bootstrap.load_runtime,tracing.generate_turn_carrier). The two call sites for_otel_traceare only reached oncebootstrap.ensure_initializedhas confirmed the runtime is available, so this is a no-op on the happy path..cursor/.claudeClassic host bundles viascripts/build-classic-hosts.py --writeso all three editions stay in sync with the.codebuddysource.This supersedes #28, which was opened from a stale branch that also carried unrelated, already-superseded commits and conflicted with
main. This branch is based directly on currentmainand only touches the 3 files above.Fixes #17
Test plan
opentelemetryinstalled.pytest tests/— 123 passed; the 6 pre-existing failures (test_cls_sink.py,test_collector.py) reproduce identically on the pre-fix code, confirming they're unrelated environment-dependent baseline failures, not regressions.python3 scripts/build-classic-hosts.py --check— Classic bundles match generator.bash scripts/validate.sh— passed (6/6).bash scripts/smoke-install.sh— passed.bash scripts/scan-secrets.sh— blocked; the bundled helper only supports Linux x86_64 and this was run on macOS.🤖 Generated with Claude Code