lumina-sdk.
init_lumina(config)
Initialize the Lumina client and return aLumina instance. Also stores the instance as a module-level singleton accessible via get_lumina().
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
config | dict | No | Configuration overrides (merged with env vars) |
config["endpoint"] | str | No | OTLP endpoint URL |
config["service_name"] | str | No | Service identifier |
config["api_key"] | str | No | Bearer token for authentication |
config["environment"] | str | No | "live" or "test" |
config["enabled"] | bool | No | Enable/disable tracing |
Lumina
Example:
get_lumina()
Retrieve the current module-level singleton (set by the lastinit_lumina() call).
Returns: Lumina | None
Example:
lumina.trace_llm(fn, *, name, system, prompt, metadata, tags)
Trace an LLM call with automatic attribute extraction. Handles both OpenAI and Anthropic response shapes. Works with both sync and async callables — pass either a regular function or a coroutine function. Parameters:| Parameter | Type | Required | Description |
|---|---|---|---|
fn | Callable[[], T] | Yes | Callable returning an LLM response |
name | str | No | Span name (default: "llm.request") |
system | str | No | Provider name: "openai", "anthropic", etc. |
prompt | str | No | Input prompt text |
metadata | dict | No | Custom key-value attributes |
tags | list[str] | No | Tags for filtering |
T (sync) or Coroutine[T] (async)
Automatically extracted from response:
- Model name (
gen_ai.response.model) - Prompt and completion tokens (
gen_ai.usage.*) - Response text (
gen_ai.completion) - Cost in USD (
lumina.cost_usd)
lumina.trace(name, fn, *, metadata, tags)
Create a span for any block of code. Use this to create parent spans for hierarchical (multi-span) traces. Works with both sync and async callables. Parameters:| Parameter | Type | Required | Description |
|---|---|---|---|
name | str | Yes | Span name |
fn | Callable[[Span], T] | Yes | Callable receiving the active span |
metadata | dict | No | Custom key-value attributes |
tags | list[str] | No | Tags for filtering |
T (sync) or Coroutine[T] (async)
Example:
lumina.flush()
Flush all buffered spans to the collector immediately. Returns:Coroutine[None] (must be awaited)
lumina.shutdown()
Flush all buffered spans and shut down the SDK. Returns:Coroutine[None] (must be awaited)
Span API
Thespan object passed to trace() callbacks is a standard OpenTelemetry Span.
span.set_attribute(key, value)
Add an attribute to the span.