Skip to content

spanforge.config — Global configuration

Module: spanforge.config

spanforge.config provides the global configuration singleton, the configure() entry point, and environment-variable interpolation utilities.


Quick example

from spanforge import configure
from spanforge.config import get_config

configure(
    preset="production",
    exporter="otlp",
    endpoint="http://collector:4318",
)
cfg = get_config()
print(cfg.exporter)  # "otlp"

API

SpanForgeConfig

Mutable dataclass holding all SDK configuration fields. Key fields:

FieldDefaultEnv varDescription
exporter"console"SPANFORGE_EXPORTERBackend: console, jsonl, otlp, webhook, datadog, grafana_loki
endpointNoneSPANFORGE_ENDPOINTExporter destination (file path or URL)
org_idNoneSPANFORGE_ORG_IDOrganisation identifier
service_name"unknown-service"SPANFORGE_SERVICE_NAMEHuman-readable service name
env"production"SPANFORGE_ENVDeployment environment tag
service_version"0.0.0"SPANFORGE_SERVICE_VERSIONSemVer string
signing_keyNoneSPANFORGE_SIGNING_KEYBase64-encoded HMAC key
sample_rate1.0SPANFORGE_SAMPLE_RATEFraction of traces to emit (0.0–1.0)
on_export_error"warn"SPANFORGE_ON_EXPORT_ERROR"warn" / "raise" / "drop"
enable_trace_storeFalseSPANFORGE_ENABLE_TRACE_STOREIn-process ring buffer
no_egressFalseSPANFORGE_NO_EGRESSBlock all network exporters
compliance_samplingTrueSPANFORGE_COMPLIANCE_SAMPLINGAlways-record compliance events
consent_enforcementFalseSPANFORGE_CONSENT_ENFORCEMENTT.R.U.S.T. consent checks
hitl_enabledFalseSPANFORGE_HITL_ENABLEDHuman-in-the-loop review queue

See the source docstring for the full list of fields.


configure(**kwargs)

def configure(**kwargs: Any) -> None: ...

Mutate the global SpanForgeConfig singleton. Accepts any field name as a keyword argument. Unknown keys raise ValueError.

Presets: Pass preset="<name>" to apply a sensible defaults bundle before other kwargs:

PresetExporterSample rateNotes
developmentconsole1.0Trace store on, private endpoints allowed
testingconsole1.0on_export_error="raise"
stagingconsole0.5Always-sample errors
productionotlp0.1Batch 512, flush 5 s
otel_passthroughotel_bridge1.0Compliance sampling on

get_config()

def get_config() -> SpanForgeConfig: ...

Return the live configuration singleton. Modifications to the returned object affect all subsequent SDK operations.


interpolate_env()

Added in: 2.0.3

def interpolate_env(data: Any) -> Any: ...

Recursively replace ${VAR} and ${VAR:default} patterns in data.

Walks strings, dicts (values only), and lists depth-first. Non-string leaves are returned unchanged.

PatternBehaviour
${FOO}Replaced with os.environ["FOO"]; left as-is if unset.
${FOO:bar}Replaced with os.environ["FOO"] when set, "bar" otherwise.

Example:

import os
from spanforge.config import interpolate_env

os.environ["MODEL"] = "gpt-4o"
result = interpolate_env({
    "model": "${MODEL}",
    "endpoint": "${ENDPOINT:https://api.openai.com/v1}",
})
# {"model": "gpt-4o", "endpoint": "https://api.openai.com/v1"}

Note: Dict keys are not interpolated — only values.