Intelligent Deferred Head Sampling for OpenTelemetry with policy-driven governance
Project description
Clarvynn OpenTelemetry Adapters
Policy-based governance for OpenTelemetry telemetry.
What is Clarvynn?
Clarvynn provides Deferred Head Sampling for OpenTelemetry. It acts as a Control Plane that enforces Purposeful Observability, ensuring you capture high-fidelity signal without the high-volume noise.
Result: Keep 100% of critical signals (errors, slow requests) while sampling out the noise that distracts your team and bloats your storage. This strategic reduction saves 60-80% on ingestion and indexing costs, reallocating budget back to engineering capacity.
Language Support
| Language | Status | Adapter |
|---|---|---|
| Python | Production Ready | adapters/opentelemetry-python/ |
| Java | Planned | - |
| Node.js | Planned | - |
| Go | Planned | - |
Quick Start (Python)
1. Install
pip install clarvynn
2. Create Policy
# policy.yaml
sampling:
base_rate: 0.01 # 1% of routine traffic
conditions:
- name: errors
when: "status_code >= 400"
- name: slow_requests
when: "duration_ms > 1000"
3. Run
export CLARVYNN_ENABLED=true
export CLARVYNN_POLICY_PATH=policy.yaml
opentelemetry-instrument python app.py
That's it. Clarvynn is now intelligently sampling your telemetry.
Key Features
- Deferred Head Sampling - Decisions made after request completion
- Policy-driven - Simple YAML configuration
- Minimal overhead - < 50µs per span evaluation
- Drop-in - Works with existing OTEL instrumentation
- Distributed tracing - W3C TraceContext Level 2 support
- Signal Improvement - High-Fidelity Signal, Low-Volume Noise
- Log correlation - Logs automatically follow trace sampling
How It Works
Traditional sampling makes decisions before execution:
HEAD-BASED: [Sample?] → Execute → [Don't know if it failed!]
- Might drop errors
Clarvynn uses Deferred Head Sampling to decide after execution:
DEFERRED HEAD: Execute → [Error? Slow?] → [Sample!]
- Never miss critical signals
Example:
# Your policy
conditions:
- name: errors
when: "status_code >= 500"
# What happens:
Request → Execute → Status: 500 → Exported (error captured)
Request → Execute → Status: 200 → 1% chance (base_rate)
Documentation
Getting Started:
- Quick Start - 5-minute tutorial
- Python Adapter - Python-specific docs
Python Adapter Docs:
- Configuration - Python config reference
- Frameworks - Flask, Django, FastAPI
- How It Works - Python architecture
Shared Documentation:
- CPL Reference - Policy language (all languages)
- W3C TraceContext Level 2 - Distributed tracing
- Architecture - System design
- Adapter Development - Building new adapters
Architecture
clarvynn/
├── core/ # Shared CPL engine (all languages)
│ ├── cpl_engine/ # Policy evaluation logic
│ ├── policies/ # Example policies
│ └── specs/ # Language-agnostic specs
│
└── adapters/ # Language-specific adapters
├── opentelemetry-python/ # Production ready
├── opentelemetry-java/ # Planned
├── opentelemetry-nodejs/ # Planned
└── opentelemetry-go/ # Planned
Design Philosophy:
core/= Language-agnostic policy engine and specificationsadapters/= Language-specific OpenTelemetry integrations
Each adapter uses the same CPL policy format, ensuring consistent behavior across languages.
Non-Blocking Architecture (Python)
Clarvynn operates as a Lightweight Adapter that ensures minimal impact on application performance by using a fully non-blocking export pipeline:
Request Ends
↓
ClarvynnSpanProcessor (Sync, ~2µs)
├─ 1. Evaluate CPL Policy (Keep/Drop)
└─ 2. Inject TraceState (W3C Level 2)
↓
BatchExporterAdapter (Async Queue)
↓
Background Thread (Async)
↓
OTLPSpanExporter (Network I/O)
This architecture ensures that governance decisions happen synchronously (to decide before queuing), but network I/O happens asynchronously (to avoid blocking the application).
Example: Multi-Service Deployment
Deploy the same policy across all services:
# policy.yaml (use everywhere)
sampling:
base_rate: 0.01
conditions:
- name: errors
when: "status_code >= 400"
- name: slow_requests
when: "duration_ms > 1000"
What happens:
API Gateway (Python):
└─ Error (500) → Exported + marked critical
Auth Service (Java): # Coming Soon
└─ Sees critical trace → Exported
Database Service (Go): # Coming Soon
└─ Sees critical trace → Exported
Result: Complete trace captured end-to-end
Testing
Clarvynn has comprehensive test coverage (336 tests, 100% pass rate):
# Install test dependencies
pip install -r requirements-dev.txt
# Run all tests
pytest
# Run with coverage
pytest --cov=core --cov=clarvynn --cov-report=html
See tests/README.md for detailed testing guide.
Compatibility
| Component | Supported Versions |
|---|---|
| Python | 3.9, 3.10, 3.11, 3.12, 3.13 |
| OpenTelemetry SDK | 1.25.0 - 1.39.0 (tested) |
| OpenTelemetry API | 1.25.0 - 1.39.0 |
Compatibility is verified with automated testing. See scripts/test_otel_compatibility.py.
Contributing
We welcome contributions! See CONTRIBUTING.md.
Adding a new language adapter? See Adapter Development Guide.
License
Apache 2.0 - See LICENSE
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clarvynn-0.3.1.tar.gz.
File metadata
- Download URL: clarvynn-0.3.1.tar.gz
- Upload date:
- Size: 62.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0443ca64837ca3e40e882fcbe4a47ad367ca1a71bd388b5beaf0d2e2090ac901
|
|
| MD5 |
7c32dd470df9dbbd1b14cddd873cf0fa
|
|
| BLAKE2b-256 |
41808125e772825485a8abafd4c14b1f29946247a9aa1a634d1f0ca9a26a871f
|
Provenance
The following attestation bundles were made for clarvynn-0.3.1.tar.gz:
Publisher:
publish.yml on Clarvynn/Clarvynn
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clarvynn-0.3.1.tar.gz -
Subject digest:
0443ca64837ca3e40e882fcbe4a47ad367ca1a71bd388b5beaf0d2e2090ac901 - Sigstore transparency entry: 779858985
- Sigstore integration time:
-
Permalink:
Clarvynn/Clarvynn@70f9daf8bc7176d670cd1336cc83ad1c3df328a8 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/Clarvynn
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@70f9daf8bc7176d670cd1336cc83ad1c3df328a8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file clarvynn-0.3.1-py3-none-any.whl.
File metadata
- Download URL: clarvynn-0.3.1-py3-none-any.whl
- Upload date:
- Size: 61.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0adc03470612866dd664733a66bb3a1eb0ceb78a38b9343e1184fcebe7092634
|
|
| MD5 |
c9f5586c3e9a5f4f54fb631f00ca708b
|
|
| BLAKE2b-256 |
1da897f542dba2c611f12a34296051820e0beee6884e7773f0b6b6c75442ba68
|
Provenance
The following attestation bundles were made for clarvynn-0.3.1-py3-none-any.whl:
Publisher:
publish.yml on Clarvynn/Clarvynn
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clarvynn-0.3.1-py3-none-any.whl -
Subject digest:
0adc03470612866dd664733a66bb3a1eb0ceb78a38b9343e1184fcebe7092634 - Sigstore transparency entry: 779858986
- Sigstore integration time:
-
Permalink:
Clarvynn/Clarvynn@70f9daf8bc7176d670cd1336cc83ad1c3df328a8 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/Clarvynn
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@70f9daf8bc7176d670cd1336cc83ad1c3df328a8 -
Trigger Event:
release
-
Statement type: