Skip to content

[BUG] OpenTelemetry instrumentation fails on AgentCore Runtime due to hardcoded local Python path in shebang (macOS) #487

@Texas-Tim

Description

@Texas-Tim

ReSubmitting since I'm not allowed to reopen Issue #474 Bug still exists, the workaround is quite simple, but would like to see this fixed.

When deploying a LangGraph agent with aws-opentelemetry-distro on macOS, the opentelemetry-instrument script in the packaged dependencies contains a hardcoded shebang pointing to the local venv path. This causes the agent to fail with "Runtime initialization time exceeded" because the path doesn't exist on the AgentCore runtime.

To Reproduce
On macOS, set up a project with a virtual environment:

mkdir my-agent && cd my-agent
python3 -m venv .venv
source .venv/bin/activate
pip install bedrock-agentcore-starter-toolkit
Create requirements.txt with OpenTelemetry:
langchain>=1.2.10
langchain-aws>=1.3.1
langgraph>=1.0.10
bedrock-agentcore>=1.4.3
aws-opentelemetry-distro>=0.10.0
Create a basic agent (agent.py) and deploy:
agentcore configure -e agent.py -n my_agent -r us-east-1 --non-interactive
agentcore launch
Invoke the agent:
agentcore invoke '{"prompt": "Hello"}'
Error: Runtime initialization time exceeded. Please make sure that initialization completes in 30s.

CloudWatch logs show:
/var/task/bin/opentelemetry-instrument: line 2: /Users/username/path/to/project/.venv/bin/python3: No such file or directory
Root cause
Inspecting the packaged dependencies.zip, the bin/opentelemetry-instrument script contains:

#!/bin/sh
'''exec' '/Users/username/path/to/project/.venv/bin/python3' "$0" "$@"' '''
This hardcoded local path doesn't exist on the AgentCore runtime.

Expected behavior
Scripts should use portable shebangs like #!/usr/bin/env python3 that work on any system.

Environment
OS: macOS (darwin)
Python: 3.13
bedrock-agentcore-starter-toolkit: 0.3.x
aws-opentelemetry-distro: 0.10.0+
Deployment type: direct_code_deploy
Workaround
After deployment fails, manually fix the shebangs in the cached dependencies.zip:

Extract .bedrock_agentcore/<agent_name>/dependencies.zip
Replace hardcoded shebangs in bin/* scripts with #!/usr/bin/env python3
Re-zip and run agentcore launch again

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions