You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Star2 (2)You must be signed in to star a repository
About
Enterprise-grade Python SDK for TelemetryFlow - the observability platform that provides unified metrics, logs, and traces collection following OpenTelemetry standards.
Enterprise-grade Python SDK for TelemetryFlow - the observability platform that provides unified metrics, logs, and traces collection following OpenTelemetry standards.
Features
Feature
Description
100% OTLP Compliant
Full OpenTelemetry Protocol support
DDD Architecture
Domain-Driven Design with clean layers
CQRS Pattern
Command Query Responsibility Segregation
Three Signals
Metrics, Logs, and Traces
Multiple Protocols
gRPC (default) and HTTP
Type Safety
Full type hints with mypy support
Framework Integrations
Flask, FastAPI middleware
CLI Generator
Project scaffolding tool
Architecture
graph TB
subgraph "Interface Layer"
A[TelemetryFlowClient]
B[TelemetryFlowBuilder]
end
subgraph "Application Layer"
C[Commands]
D[Queries]
end
subgraph "Domain Layer"
E[TelemetryConfig]
F[Credentials]
end
subgraph "Infrastructure Layer"
G[CommandHandler]
H[OTLPExporterFactory]
I[OpenTelemetry SDK]
end
A --> C
B --> E
C --> G
G --> H
H --> I
E --> F
style A fill:#4CAF50
style E fill:#2196F3
style G fill:#FF9800
Loading
Installation
pip install telemetryflow-python-sdk
With optional dependencies:
# HTTP framework support (Flask, FastAPI)
pip install telemetryflow-python-sdk[http]
# gRPC support
pip install telemetryflow-python-sdk[grpc]
# Development tools
pip install telemetryflow-python-sdk[dev]
# All extras
pip install telemetryflow-python-sdk[dev,http,grpc]
from telemetryflow import TelemetryFlowBuilder
from telemetryflow.application.commands import SpanKind
def main():
# Create client from environment variables
client = TelemetryFlowBuilder().with_auto_configuration().build()
# Initialize the SDK
client.initialize()
try:
# Record metrics
client.increment_counter("http.requests.total", attributes={"method": "GET"})
client.record_gauge("app.connections.active", 42)
client.record_histogram("http.request.duration", 0.125, unit="s")
# Emit logs
client.log_info("Request processed", {"user_id": "123"})
client.log_error("Database connection failed", {"db": "users"})
# Create traces
with client.span("process_request", SpanKind.SERVER) as span_id:
client.add_span_event(span_id, "validation_complete")
with client.span("database_query", SpanKind.CLIENT) as db_span:
client.add_span_event(db_span, "query_executed", {"rows": 10})
finally:
# Always shutdown to flush pending data
client.shutdown()
if __name__ == "__main__":
main()
3. Using Context Manager
from telemetryflow import TelemetryFlowBuilder
# Client auto-initializes and shuts down
with TelemetryFlowBuilder().with_auto_configuration().build() as client:
client.increment_counter("app.started")
client.log_info("Application running")
# Initialize in current directory
telemetryflow-gen init
# Generate example code
telemetryflow-gen example --type basic
telemetryflow-gen example --type http-server
# Show version
telemetryflow-gen version
Data Flow
sequenceDiagram
participant App as Application
participant SDK as TelemetryFlow SDK
participant OTEL as OpenTelemetry
participant TF as TelemetryFlow Backend
App->>SDK: client.increment_counter()
SDK->>SDK: Create Command
SDK->>OTEL: Record Metric
Note over OTEL: Batch & Export
OTEL->>TF: OTLP Export (gRPC/HTTP)
TF-->>OTEL: Ack
# Run tests
make test
# Run with coverage
make test-coverage
# Lint code
make lint
# Format code
make format
# Type check
make typecheck
# Run all checks
make check
# Build package
make build
Testing
# All tests
pytest
# Unit tests only
pytest tests/unit/ -v
# Integration tests
pytest tests/integration/ -v -m integration
# With coverage
pytest --cov=telemetryflow --cov-report=html
Testing Strategy
Layer
Target Coverage
Focus
Domain
90%+
Value objects, validation
Application
85%+
Commands, queries
Infrastructure
80%+
Handlers, exporters
Client
85%+
Public API
Best Practices
1. Initialize Once
# Good: Single initialization at startup
client = TelemetryFlowBuilder().with_auto_configuration().build()
client.initialize()
# Bad: Creating client per request
for request in requests:
client = TelemetryFlowBuilder()... # Don't do this!
2. Use Context Managers
# Good: Automatic cleanup
with client.span("operation") as span_id:
# work...
# Avoid: Manual management (error-prone)
span_id = client.start_span("operation")
# if exception, span may not end
client.end_span(span_id)
Enterprise-grade Python SDK for TelemetryFlow - the observability platform that provides unified metrics, logs, and traces collection following OpenTelemetry standards.