Dataclass for SDK configuration.
from botanu.sdk.config import BotanuConfig| Field | Type | Default | Description |
|---|---|---|---|
service_name |
str |
"unknown_service" |
Service name (from OTEL_SERVICE_NAME) |
service_version |
str |
None |
Service version (from OTEL_SERVICE_VERSION) |
service_namespace |
str |
None |
Service namespace (from OTEL_SERVICE_NAMESPACE) |
deployment_environment |
str |
"production" |
Environment (from OTEL_DEPLOYMENT_ENVIRONMENT or BOTANU_ENVIRONMENT) |
auto_detect_resources |
bool |
True |
Auto-detect cloud resources |
otlp_endpoint |
str |
"http://localhost:4318/v1/traces" |
OTLP endpoint |
otlp_headers |
dict |
None |
Custom headers for OTLP exporter |
max_export_batch_size |
int |
512 |
Max spans per batch |
max_queue_size |
int |
2048 |
Max spans in queue |
schedule_delay_millis |
int |
5000 |
Delay between batch exports |
trace_sample_rate |
float |
1.0 |
Sampling rate (1.0 = 100%) |
propagation_mode |
str |
"lean" |
"lean" or "full" |
auto_instrument_packages |
list |
[...] |
Packages to auto-instrument |
config = BotanuConfig(
service_name="my-service",
deployment_environment="production",
otlp_endpoint="http://collector:4318/v1/traces",
)Load configuration from a YAML file.
@classmethod
def from_yaml(cls, path: Optional[str] = None) -> BotanuConfigParameters:
path: Path to YAML config file
Raises:
FileNotFoundError: If config file doesn't existValueError: If YAML is malformedImportError: If PyYAML is not installed
Example:
config = BotanuConfig.from_yaml("config/botanu.yaml")Load config from file if exists, otherwise use environment variables.
@classmethod
def from_file_or_env(cls, path: Optional[str] = None) -> BotanuConfigSearch order:
- Explicit
pathargument BOTANU_CONFIG_FILEenvironment variable./botanu.yaml./botanu.yml./config/botanu.yaml./config/botanu.yml- Falls back to environment-only config
Example:
# Auto-discovers config file
config = BotanuConfig.from_file_or_env()
# Explicit path
config = BotanuConfig.from_file_or_env("my-config.yaml")Export configuration as dictionary.
def to_dict(self) -> Dict[str, Any]Example:
config = BotanuConfig(service_name="my-service")
print(config.to_dict())
# {
# "service": {"name": "my-service", ...},
# "otlp": {"endpoint": "...", ...},
# ...
# }service:
name: string # Service name
version: string # Service version
namespace: string # Service namespace
environment: string # Deployment environment
resource:
auto_detect: boolean # Auto-detect cloud resources
otlp:
endpoint: string # OTLP endpoint URL
headers: # Custom headers
header-name: value
export:
batch_size: integer # Max spans per batch
queue_size: integer # Max spans in queue
delay_ms: integer # Delay between exports
sampling:
rate: float # Sampling rate (0.0-1.0)
propagation:
mode: string # "lean" or "full"
auto_instrument_packages: # List of packages to instrument
- package_nameservice:
name: ${OTEL_SERVICE_NAME:-default-service}
environment: ${ENVIRONMENT}
otlp:
endpoint: ${COLLECTOR_URL:-http://localhost:4318}/v1/traces
headers:
Authorization: Bearer ${API_TOKEN}Syntax:
${VAR_NAME}- Required variable${VAR_NAME:-default}- Variable with default value
Bootstrap function to initialize the SDK.
from botanu import enable
enable(
service_name: Optional[str] = None,
otlp_endpoint: Optional[str] = None,
config: Optional[BotanuConfig] = None,
auto_instrument: bool = True,
auto_instrument_packages: Optional[List[str]] = None,
propagation_mode: Optional[str] = None,
**kwargs: Any,
) -> None| Parameter | Type | Default | Description |
|---|---|---|---|
service_name |
str |
From env | Service name |
otlp_endpoint |
str |
From env | OTLP endpoint URL |
config |
BotanuConfig |
None |
Pre-built configuration |
auto_instrument |
bool |
True |
Enable auto-instrumentation |
auto_instrument_packages |
list |
None |
Override default packages |
propagation_mode |
str |
None |
"lean" or "full" |
**kwargs |
Any |
{} |
Additional config fields |
- Creates/merges
BotanuConfig - Configures
TracerProviderwithRunContextEnricher - Sets up OTLP exporter (if SDK extras installed)
- Enables auto-instrumentation (if requested)
- Configures W3C Baggage propagation
from botanu import enable
enable(service_name="my-service")from botanu import enable
from botanu.sdk.config import BotanuConfig
config = BotanuConfig.from_yaml("config/botanu.yaml")
enable(config=config)enable(
service_name="my-service",
otlp_endpoint="http://collector:4318/v1/traces",
auto_instrument_packages=["fastapi", "openai_v2"],
propagation_mode="full",
)Disable the SDK and clean up resources.
from botanu import disable
disable() -> None- Flushes pending spans
- Shuts down span processors
- Disables instrumentation
Check if the SDK is currently enabled.
from botanu import is_enabled
is_enabled() -> boolif not is_enabled():
enable(service_name="my-service")| Variable | Description | Default |
|---|---|---|
OTEL_SERVICE_NAME |
Service name | "unknown_service" |
OTEL_SERVICE_VERSION |
Service version | None |
OTEL_SERVICE_NAMESPACE |
Service namespace | None |
OTEL_DEPLOYMENT_ENVIRONMENT |
Deployment environment | "production" |
OTEL_EXPORTER_OTLP_ENDPOINT |
OTLP base endpoint | "http://localhost:4318" |
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT |
OTLP traces endpoint (full URL) | None |
OTEL_EXPORTER_OTLP_HEADERS |
OTLP headers (key=value pairs) | None |
| Variable | Description | Default |
|---|---|---|
BOTANU_ENVIRONMENT |
Fallback for environment | "production" |
BOTANU_PROPAGATION_MODE |
"lean" or "full" |
"lean" |
BOTANU_TRACE_SAMPLE_RATE |
Sampling rate (0.0-1.0) | "1.0" |
BOTANU_AUTO_DETECT_RESOURCES |
Auto-detect cloud resources | "true" |
BOTANU_CONFIG_FILE |
Path to YAML config file | None |
Model for run metadata.
from botanu.models.run_context import RunContextCreate a new run context.
@classmethod
def create(
cls,
use_case: str,
workflow: Optional[str] = None,
workflow_version: Optional[str] = None,
environment: Optional[str] = None,
tenant_id: Optional[str] = None,
parent_run_id: Optional[str] = None,
deadline_seconds: Optional[float] = None,
) -> RunContextCreate a retry context from an original run.
@classmethod
def create_retry(cls, original: RunContext) -> RunContextReconstruct context from baggage dictionary.
@classmethod
def from_baggage(cls, baggage: Dict[str, str]) -> Optional[RunContext]Serialize to baggage format.
def to_baggage_dict(self, lean_mode: bool = True) -> Dict[str, str]Serialize to span attributes.
def to_span_attributes(self) -> Dict[str, Any]Context manager to set this as the current run.
def as_current(self) -> ContextManagerMark the run as complete.
def complete(
self,
status: RunStatus,
error_class: Optional[str] = None,
) -> None| Field | Type | Description |
|---|---|---|
run_id |
str |
Unique UUIDv7 identifier |
root_run_id |
str |
Root run ID (same as run_id for first attempt) |
use_case |
str |
Business use case name |
workflow |
str |
Workflow/function name |
workflow_version |
str |
Version hash |
environment |
str |
Deployment environment |
tenant_id |
str |
Tenant identifier |
parent_run_id |
str |
Parent run ID |
attempt |
int |
Attempt number |
start_time |
datetime |
Run start time |
outcome |
RunOutcome |
Recorded outcome |
Enum for run status.
from botanu.models.run_context import RunStatus
class RunStatus(Enum):
SUCCESS = "success"
FAILURE = "failure"
PARTIAL = "partial"- Configuration Guide - Configuration how-to
- Architecture - SDK design
- Existing OTel Setup - Integration patterns