feat: Add Programmatic Configuration Support for Tracing Decorators #495
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.
Add Programmatic Configuration Support for Tracing Decorators
🚀 Overview
This PR adds the ability to programmatically configure API keys and pipeline IDs for Openlayer tracing decorators, providing an alternative to environment variables for more flexible runtime configuration.
🎯 Problem
Previously, users could only configure tracing through environment variables:
This approach had limitations:
✨ Solution
Added a new
configure()
function that allows programmatic configuration with a clear precedence chain:🔧 New
configure()
Function📋 Configuration Precedence
@trace(inference_pipeline_id="specific")
)configure()
function🎨 Key Features
✅ Flexible Configuration Options
✅ Runtime Configuration Changes
✅ Testing Support
🛠 Technical Implementation
Enhanced Client Initialization
_get_client()
to use configured values with fallback to environment variablesPipeline ID Precedence Chain
_handle_trace_completion()
to implement proper precedence logicPublic API Integration
configure
to public exports insrc/openlayer/lib/__init__.py
📝 Usage Examples
Multi-Environment Application
Dynamic Configuration
None - This is a purely additive change that maintains full backward compatibility with existing environment variable usage.
🧪 Testing
Test Coverage
python -m pytest tests/test_tracer_configuration.py -v # ============================================ 9 passed in 7.78s ============================================
📁 Files Changed
src/openlayer/lib/tracing/tracer.py
- Addedconfigure()
function and enhanced client initializationsrc/openlayer/lib/__init__.py
- Exportedconfigure
to public APIexamples/tracing/programmatic_configuration.py
- Comprehensive usage examplestests/test_tracer_configuration.py
- Full test suite covering all scenarios🎉 Benefits
📖 Documentation
Added comprehensive examples in
examples/tracing/programmatic_configuration.py
demonstrating:All functions include detailed docstrings with usage examples and parameter descriptions.