The telemetryflow-gen CLI tool helps you quickly set up TelemetryFlow SDK integration in your Python projects.
The generator is installed automatically with the SDK:
pip install telemetryflow-python-sdkVerify installation:
telemetryflow-gen --versiongraph TB
A[telemetryflow-gen] --> B[init]
A --> C[example]
A --> D[version]
B --> E[Creates .env.telemetryflow]
B --> F[Creates example script]
C --> G[--type basic]
C --> H[--type http-server]
D --> I[Shows version info]
| Command | Description |
|---|---|
init |
Initialize TelemetryFlow in your project |
example |
Generate example code |
version |
Show version information |
Initialize TelemetryFlow SDK integration in your project.
telemetryflow-gen init [options]| Option | Short | Default | Description |
|---|---|---|---|
--output |
-o |
. |
Output directory |
--force |
-f |
false |
Overwrite existing files |
| File | Description |
|---|---|
.env.telemetryflow |
Environment configuration template |
telemetryflow_example.py |
Basic usage example |
# Initialize in current directory
telemetryflow-gen init
# Initialize in specific directory
telemetryflow-gen init -o ./src
# Force overwrite existing files
telemetryflow-gen init --force# .env.telemetryflow
# Required: API Key credentials
TELEMETRYFLOW_API_KEY_ID=tfk_your_key_id
TELEMETRYFLOW_API_KEY_SECRET=tfs_your_key_secret
# Required: Service configuration
TELEMETRYFLOW_SERVICE_NAME=my-service
TELEMETRYFLOW_SERVICE_VERSION=1.0.0
# Optional: Endpoint (default: api.telemetryflow.id:4317)
TELEMETRYFLOW_ENDPOINT=api.telemetryflow.id:4317
# Optional: Environment (default: production)
TELEMETRYFLOW_ENVIRONMENT=development
# Optional: Service namespace
TELEMETRYFLOW_SERVICE_NAMESPACE=telemetryflow# telemetryflow_example.py
from telemetryflow import TelemetryFlowBuilder
from telemetryflow.application.commands import SpanKind
def main():
client = TelemetryFlowBuilder().with_auto_configuration().build()
client.initialize()
try:
# Record metrics
client.increment_counter("app.requests.total")
client.record_gauge("app.active_connections", 42)
# Emit logs
client.log_info("Application started")
# Create traces
with client.span("process_request", SpanKind.SERVER) as span_id:
client.add_span_event(span_id, "checkpoint_reached")
finally:
client.shutdown()
if __name__ == "__main__":
main()Generate example code for different use cases.
telemetryflow-gen example [options]| Option | Short | Default | Description |
|---|---|---|---|
--type |
-t |
basic |
Example type |
--output |
-o |
. |
Output directory |
--force |
-f |
false |
Overwrite existing files |
| Type | Description | Output File |
|---|---|---|
basic |
Basic SDK usage | basic_example.py |
http-server |
HTTP server with instrumentation | http_server_example.py |
# Generate basic example
telemetryflow-gen example
# Generate HTTP server example
telemetryflow-gen example --type http-server
# Generate to specific directory
telemetryflow-gen example -t http-server -o ./examplesThe basic example demonstrates:
- Client initialization and shutdown
- Recording metrics (counter, gauge, histogram)
- Emitting logs (info, warn, error, debug)
- Creating trace spans with events
- Nested spans using context manager
- Getting SDK status
The HTTP server example demonstrates:
- Full request instrumentation
- Automatic span creation for requests
- Request duration histogram
- Request counter metrics
- Error counting and logging
- Nested spans for database/cache operations
- Multiple endpoints with different behaviors
Display version information.
telemetryflow-gen versionTelemetryFlow Python SDK v1.1.1
Git Commit: abc1234
Git Branch: main
Build Time: 2024-12-30T00:00:00Z
Python: 3.12.11
Platform: darwin/arm64
sequenceDiagram
participant Dev as Developer
participant Gen as telemetryflow-gen
participant FS as File System
Dev->>Gen: telemetryflow-gen init
Gen->>Gen: Display banner
Gen->>FS: Create .env.telemetryflow
Gen->>FS: Create telemetryflow_example.py
Gen-->>Dev: Initialization complete
Dev->>Dev: Edit .env.telemetryflow
Dev->>Dev: Set API credentials
Dev->>Gen: telemetryflow-gen example -t http-server
Gen->>FS: Create http_server_example.py
Gen-->>Dev: Example generated
Dev->>Dev: Run example
Note over Dev: source .env.telemetryflow
Note over Dev: python http_server_example.py
cd your-project
telemetryflow-gen initEdit .env.telemetryflow with your credentials:
TELEMETRYFLOW_API_KEY_ID=tfk_your_actual_key
TELEMETRYFLOW_API_KEY_SECRET=tfs_your_actual_secret
TELEMETRYFLOW_SERVICE_NAME=your-service-nameOption A: Source the file:
source .env.telemetryflowOption B: Use python-dotenv:
from dotenv import load_dotenv
load_dotenv('.env.telemetryflow')from telemetryflow import TelemetryFlowBuilder
# In your application startup
client = TelemetryFlowBuilder().with_auto_configuration().build()
client.initialize()
# In your application shutdown
client.shutdown()Keep different configurations for each environment:
.env.telemetryflow.development
.env.telemetryflow.staging
.env.telemetryflow.production
Add to .gitignore:
.env.telemetryflow
.env.telemetryflow.*
*.localOrganize services by namespace:
TELEMETRYFLOW_SERVICE_NAMESPACE=platform
TELEMETRYFLOW_SERVICE_NAME=api-gatewayTrack deployments with versions:
TELEMETRYFLOW_SERVICE_VERSION=1.2.3command not found: telemetryflow-gen
Solution: Reinstall the SDK or check your PATH:
pip install --force-reinstall telemetryflow-python-sdk
# or
python -m telemetryflow.cli.generator initPermissionError: [Errno 13] Permission denied
Solution: Check directory permissions or use sudo (not recommended):
chmod 755 ./output-directory
telemetryflow-gen init -o ./output-directoryError: .env.telemetryflow already exists. Use --force to overwrite.
Solution: Use the --force flag or backup existing files:
mv .env.telemetryflow .env.telemetryflow.backup
telemetryflow-gen initdef main(argv: list[str] | None = None) -> int:
"""Main entry point for the CLI."""
...| Code | Description |
|---|---|
| 0 | Success |
| 1 | Error (file exists, invalid option, etc.) |