Telemetry utilities and shared components for Pharia projects
Project description
Pharia Telemetry
A clean, minimal OpenTelemetry foundation library for Pharia services providing observability, tracing, and context propagation utilities.
๐ฏ What is pharia-telemetry?
pharia-telemetry provides a simple, focused foundation for observability in Pharia services:
- Context Propagation: User and session context flows automatically across all service calls
- Structured Logging: Logs automatically include trace IDs and user context
- OpenTelemetry Setup: Minimal, high-level setup for distributed tracing
- Standardized Constants: Clean, namespaced constants for consistent telemetry
Key Principle: pharia-telemetry handles the foundation with minimal API surface, you add framework-specific auto-instrumentation.
๐ฆ Installation
Requires Python 3.10+.
# Basic installation
pip install pharia-telemetry
# With structlog support (for structured logging)
pip install pharia-telemetry[structlog]
Install from GitHub (pinned to commit)
For services that depend on a specific commit from the GitHub repo, use a direct VCS reference:
# HTTPS (recommended)
pip install "pharia-telemetry @ git+https://github.com/aleph-alpha/pharia-telemetry.git@<commit-sha>"
# SSH (if you have SSH keys configured)
pip install "pharia-telemetry @ git+ssh://git@github.com/aleph-alpha/pharia-telemetry.git@<commit-sha>"
# With optional extras
pip install "pharia-telemetry[structlog] @ git+https://github.com/aleph-alpha/pharia-telemetry.git@<commit-sha>"
In requirements files (PEP 508):
pharia-telemetry @ git+https://github.com/aleph-alpha/pharia-telemetry.git@<commit-sha>
pharia-telemetry[structlog] @ git+https://github.com/aleph-alpha/pharia-telemetry.git@<commit-sha>
๐ 30-Second Setup
from pharia_telemetry import setup_telemetry, constants, set_baggage_item
# 1. One-line setup
setup_telemetry("my-service", service_version="1.0.0")
# 2. Set context that flows everywhere
set_baggage_item(constants.Baggage.USER_ID, "user-123")
# 3. Add framework instrumentation (optional)
# FastAPIInstrumentor.instrument_app(app) # for FastAPI
# SQLAlchemyInstrumentor().instrument() # for databases
Result: Your service now has distributed tracing with user context flowing through all operations!
๐ฏ Clean API Design
pharia-telemetry features a clean, focused API designed for ease of use:
from pharia_telemetry import (
# Core setup (essential)
setup_telemetry, # One-function setup
# GenAI instrumentation (most users)
create_chat_span, # Smart sync/async chat spans
create_embeddings_span, # Smart sync/async embeddings spans
create_tool_execution_span,# Smart sync/async tool spans
set_genai_span_usage, # Token usage tracking
set_genai_span_response, # Response metadata
# Context propagation (advanced)
set_baggage_item, # Set context for propagation
get_baggage_item, # Get propagated context
# Logging integration (optional)
create_context_injector, # Custom logging integration
)
๐ Documentation Guide
Choose your path based on what you need:
๐ New to pharia-telemetry?
Start here โ Getting Started Guide
- Basic setup and first examples
- Understanding the concepts
- Your first instrumented service
๐ Want automatic instrumentation?
Go to โ Auto-Instrumentation Guide
- Available instrumentation packages
- FastAPI, SQLAlchemy, HTTPX setup
- When auto-instrumentation works (and when it doesn't)
๐ ๏ธ Need manual control?
See โ Manual Instrumentation Guide
- SSE streaming issues and solutions
- HTTP/2 compatibility problems
- Custom span management
- Performance optimization
๐งณ Working with context propagation?
Read โ Baggage & Context Guide
- User and session context
- Cross-service correlation
- Standardized baggage keys
- Custom context patterns
๐ Setting up logging?
Check โ Structured Logging Guide
- Automatic trace correlation
- Log configuration patterns
- Integration with structlog
๐ค Building GenAI applications?
Visit โ GenAI Spans Guide
- OpenTelemetry semantic conventions for AI
- Automatic span attributes for models
- Token usage tracking
- Agent and tool instrumentation
โ๏ธ Need advanced configuration?
Visit โ Configuration Guide
- Environment variables
- OTLP exporter setup
- Custom resource attributes
- Production deployment
๐๏ธ Building integrations?
Browse โ Integration Examples
- Complete FastAPI service
- Microservice communication
- Background task processing
- Real-world patterns
๐ Having issues?
Try โ Troubleshooting Guide
- Common problems and solutions
- Debug techniques
- Performance considerations
๐ Core Features
- ๐ฌ OpenTelemetry Integration: Minimal setup utilities for distributed tracing
- ๐งณ Baggage Management: Context propagation across service boundaries
- ๐ Structured Logging: Automatic trace correlation for log records
- ๐ค Smart GenAI Spans: Auto-detecting sync/async convenience functions for AI operations
- ๐ง Production Ready: Graceful degradation when OpenTelemetry is unavailable
- ๐ Pharia Standards: Standardized constants and conventions across all services
- ๐ฏ Focused API: Clean, intuitive functions for common use cases
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Your Application + Auto โ
โ Instrumentation โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ pharia-telemetry Foundation โ
โ (Propagators, Baggage, Logging) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ OpenTelemetry SDK โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ OTLP Exporters & Backend โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Quick Examples
Context Propagation
from pharia_telemetry import constants, set_baggage_item
# Set once, flows everywhere
set_baggage_item(constants.Baggage.USER_ID, "user-123")
set_baggage_item(constants.Baggage.SESSION_ID, "session-456")
Structured Logging
import structlog
from pharia_telemetry import add_context_to_logs
# Easy integration with any logging framework
injector = add_context_to_logs("structlog")
structlog.configure(processors=[
injector, # Adds trace_id + baggage automatically
structlog.processors.JSONRenderer(),
])
GenAI Operations
from pharia_telemetry import create_chat_span, create_embeddings_span
from pharia_telemetry.sem_conv.gen_ai import GenAI
# Smart convenience functions that auto-detect sync/async context
with create_chat_span(
model="llama-3.1-8B",
agent_id=GenAI.Values.PhariaAgentId.QA_CHAT,
conversation_id="conv-123"
) as span:
# Works in both sync and async contexts
pass
# Also works seamlessly in async contexts
async with create_embeddings_span(model="text-embedding-3-small") as span:
# Automatic context detection
pass
Clean Constants Structure
from pharia_telemetry import constants
# Namespaced and organized
user_id = constants.Baggage.USER_ID # "app.user.id"
qa_chat = constants.Baggage.Values.UserIntent.QA_CHAT # "pharia_qa_chat"
# GenAI constants in separate module
model = constants.GenAI.REQUEST_MODEL # "gen_ai.request.model"
chat_op = constants.GenAI.Values.OperationName.CHAT # "chat"
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
๐ Support
- ๐ง Email: conrad.poepke@aleph-alpha.com
- ๐ Issues: GitHub Issues
Project details
Release history Release notifications | RSS feed
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 pharia_telemetry-0.1.dev1.tar.gz.
File metadata
- Download URL: pharia_telemetry-0.1.dev1.tar.gz
- Upload date:
- Size: 77.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 |
c3217510ebe65c7367572bca2199c37f284765f74afdb14e43fcf90e6a2eba0a
|
|
| MD5 |
3719a234dbadcd242692a550f75dd95e
|
|
| BLAKE2b-256 |
d2bf6c677fbdad2d80a7db95c1ef49763986f7a98f7b97375495e839b61a9caa
|
Provenance
The following attestation bundles were made for pharia_telemetry-0.1.dev1.tar.gz:
Publisher:
release-please.yml on Aleph-Alpha/pharia-telemetry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pharia_telemetry-0.1.dev1.tar.gz -
Subject digest:
c3217510ebe65c7367572bca2199c37f284765f74afdb14e43fcf90e6a2eba0a - Sigstore transparency entry: 498414628
- Sigstore integration time:
-
Permalink:
Aleph-Alpha/pharia-telemetry@f3887973cdc8175644845af0f5bbf18c435fb426 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Aleph-Alpha
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-please.yml@f3887973cdc8175644845af0f5bbf18c435fb426 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pharia_telemetry-0.1.dev1-py3-none-any.whl.
File metadata
- Download URL: pharia_telemetry-0.1.dev1-py3-none-any.whl
- Upload date:
- Size: 27.7 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 |
cd979a3b6ef4694fe5154a443242f772458ac430bb2113dc46e93573feb57d12
|
|
| MD5 |
995edcd45601d94785c9f0c926ba65ee
|
|
| BLAKE2b-256 |
2b6f61572aedb7790b98962a3b6ba7e43e0f85c506886b8152b41aa6ddf55a95
|
Provenance
The following attestation bundles were made for pharia_telemetry-0.1.dev1-py3-none-any.whl:
Publisher:
release-please.yml on Aleph-Alpha/pharia-telemetry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pharia_telemetry-0.1.dev1-py3-none-any.whl -
Subject digest:
cd979a3b6ef4694fe5154a443242f772458ac430bb2113dc46e93573feb57d12 - Sigstore transparency entry: 498414633
- Sigstore integration time:
-
Permalink:
Aleph-Alpha/pharia-telemetry@f3887973cdc8175644845af0f5bbf18c435fb426 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Aleph-Alpha
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-please.yml@f3887973cdc8175644845af0f5bbf18c435fb426 -
Trigger Event:
push
-
Statement type: