Overview
What this demonstrates:- Handling pyenv-managed Python binaries
- Custom binary path configuration
- SSL capture from non-standard Python installations
oisp-cookbook/edge-cases/pyenv-python
The Challenge
Problem: pyenv installs Python in user home directories (~/.pyenv/versions/...) with bundled OpenSSL, making automatic detection difficult.
Solution: Explicitly configure OISP Sensor to monitor pyenv binaries.
Prerequisites
- Linux with eBPF support (kernel 5.8+)
- pyenv installed
- Python installed via pyenv
- OpenAI API key
Running the Example
With Docker Compose (Recommended)
- Container installs pyenv and Python 3.11
- OISP Sensor starts with custom binary path
- Python script makes OpenAI API call
- Events captured and validated
Without Docker
1. Find your pyenv Python binary:Expected Output
Application Output
Events Captured
ai.request event:
Configuration
Option 1: Command Line
Option 2: Config File
/etc/oisp/config.toml:
How It Works
Standard Python vs pyenv Python
Standard installation:OISP Sensor Attachment
When you specify--binary-path:
- Binary discovery - Sensor locates the pyenv Python binary
- Symbol resolution - Finds OpenSSL symbols (_ssl.so module)
- eBPF attachment - Attaches uprobes to Python’s SSL module
- SSL capture - Intercepts TLS traffic from pyenv Python
Verification
Check sensor logs to verify attachment:Architecture Diagram
Code Walkthrough
app.py:
- Process start -
python3 app.pystarts - SSL module load - Python loads _ssl.so (bundled OpenSSL)
- SSL handshake - TLS connection to api.openai.com
- Request - JSON payload with messages
- Response - Streamed completion
- Event export - ai.request + ai.response events
Validation
The cookbook includes automated validation:- ✅ Events file exists
- ✅ Contains ai.request event
- ✅ Contains ai.response event
- ✅ Process name is “python” or “python3”
- ✅ Provider is “OpenAI”
- ✅ Binary path contains “.pyenv”
Troubleshooting
No events captured
1. Verify binary path:Wrong Python version
If you have multiple pyenv versions, ensure you’re monitoring the active one:SSL module not found
Verify Python was built with SSL support:Wildcard pattern not working
The wildcard pattern (~/.pyenv/versions/*/bin/python*) may not expand correctly. Use explicit path instead:
Common pyenv Scenarios
Global Python version
Project-specific Python version
Virtual environments
pyenv virtual environments still use the base Python binary:Related Examples
- NVM Node.js - Similar issue with NVM-managed Node.js
- Python + OpenAI Simple - Standard Python installation
- Linux Troubleshooting - NVM/pyenv troubleshooting
Production Recommendations
For development:- Use explicit binary path in config
- Monitor all pyenv versions with wildcard
- Use system Python (not pyenv) for better detectability
- If pyenv required, pin version and use explicit path
- Add binary path to systemd service config
Multiple Python Versions
If your environment uses multiple Python versions:Performance Considerations
Impact of monitoring multiple binaries:- Each binary path adds one eBPF uprobe attachment
- Minimal overhead per attachment (less than 1% CPU)
- Safe to monitor 5-10 Python versions simultaneously
- Monitor only active versions in production
- Use wildcard for development environments
Next Steps
- Linux Platform Guide - Full Linux documentation
- Configuration - Config file reference
- All Cookbooks - Browse all examples