Skip to main content

Automatic OpenTelemetry instrumentation for the legacy OpenHands V0 / CodeAct runtime.

What is covered

This package wraps the V0 python -m openhands.core.main execution path:

  • openhands.core.main.run_controller for the ENTRY span.

  • openhands.core.loop.run_agent_until_done for the AGENT span fallback.

  • AgentController.__init__ / AgentController.close for lifecycle-bound ENTRY and AGENT spans that survive python -m from-import binding.

  • AgentController._step for ReAct STEP spans.

  • Runtime.run_action for TOOL spans.

  • LLM.__init__ to bridge the current OpenHands context into LiteLLM calls.

Span tree

ENTRY  enter openhands
`-- AGENT invoke_agent codeact
    |-- STEP  react step [xN]
    |   |-- LLM   chat {model}
    |   `-- TOOL  execute_tool {tool_name}
    `-- STEP  react step [...]

python -m and from-import binding

When OpenHands V0 is launched via python -m openhands.core.main, Python executes main.py as __main__. Symbols imported with from ... import can be bound before module-level wrappers are installed, so patching openhands.core.main.run_controller is not enough by itself.

To keep ENTRY and AGENT spans reliable, this instrumentation primarily opens them from AgentController.__init__ and closes them from AgentController.close. The module-level wrappers remain as a fallback for programmatic invocations.

Cross-thread context bridge

OpenHands V0 may execute controller steps and runtime tool calls in worker threads with fresh asyncio loops. The instrumentation stores the active OTel context by session id and re-attaches it in STEP, TOOL, and LLM bridge wrappers so the trace remains:

ENTRY -> AGENT -> STEP -> (LLM / TOOL).

Semantic-convention I/O capture

STEP spans emit input.value / output.value alongside GenAI semantic attributes. ENTRY and AGENT spans use only GenAI-native attributes — they do not mirror OpenInference input.value / output.value. TOOL spans never set input.value / output.value; they always set gen_ai.tool.call.arguments (JSON object string, "{}" when empty) and gen_ai.tool.call.result.

  • ENTRY emits gen_ai.input.messages and gen_ai.output.messages using the ARMS parts-based message schema.

  • AGENT emits gen_ai.input.messages, gen_ai.output.messages, gen_ai.system_instructions, and gen_ai.tool.definitions.

  • STEP emits recent input history and the pending assistant/tool-call output for the ReAct round.

  • TOOL emits gen_ai.tool.name, gen_ai.tool.type, gen_ai.tool.call.id, gen_ai.tool.description, gen_ai.tool.call.arguments, and gen_ai.tool.call.result.

Usage

from opentelemetry.instrumentation.openhands import OpenHandsInstrumentor

OpenHandsInstrumentor().instrument()

Configuration

Environment variables:

  • OTEL_INSTRUMENTATION_OPENHANDS_ENABLED (default true)

  • OTEL_INSTRUMENTATION_OPENHANDS_OUTER_SPANS (default true)

  • OTEL_INSTRUMENTATION_OPENHANDS_AUTO_INSTRUMENT_LITELLM (default true)

I/O capture is always on and content is emitted in full.

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

File details

Details for the file loongsuite_instrumentation_openhands-0.8.0-py3-none-any.whl.

File metadata

File hashes

Hashes for loongsuite_instrumentation_openhands-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3963e51abe93cdb161e3ab2e394a1c41f6c2cd810b83e8c7f2050c6d5950f5f8
MD5 4ba91d61c52fc0ce8f217b437ab81e1d
BLAKE2b-256 3de8192f9d040750147b36b66c405d8b93be2e860544f6872f145bfac9eec527

See more details on using hashes here.

Release history Release notifications | RSS feed

0.9.0

1 file

This release

0.8.0 This release

1 file

0.7.0

1 file

0.6.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page