Loading...
Loading...
Python OpenTelemetry style: module-scope tracers/meters, decorators for bounded work, error spans, logs, and no wrappers.
npx skill4agent add superloglabs/skills otel-python-stylefrom opentelemetry import metrics, trace
from opentelemetry.trace import Status, StatusCode
tracer = trace.get_tracer("mugline.voice")
meter = metrics.get_meter("mugline.voice")
greetings = meter.create_counter("voice.greetings.delivered", unit="1")tracer.start_as_current_span(...)@tracer.start_as_current_span("do_work")
def do_work():
print("doing some work...")trace.get_current_span()@tracer.start_as_current_span("voice.deliver_initial_greeting")
async def _deliver_initial_greeting(*, tenant_id: str, user_id: str) -> None:
span = trace.get_current_span()
span.set_attributes({
"tenant.id": tenant_id,
"user.id": user_id,
"voice.use_case": "initial_greeting",
})with tracer.start_as_current_span("order.validate") as span:
span.set_attribute("tenant.id", tenant_id)
validate_order(order)tracer.start_span(...); span.end()try:
result = await client.messages.create(...)
except Exception as exc:
span = trace.get_current_span()
span.record_exception(exc)
span.set_status(Status(StatusCode.ERROR))
logger.exception("llm mug copy failed", extra={"tenant_id": tenant_id})
raiseset_logger_provider(logger_provider)opentelemetry._logsLoggingInstrumentor().instrument(...)logging.basicConfigSUPERLOG_ENDPOINT = "https://intake.superlog.sh"
SUPERLOG_KEY = "superlog_live_…" # set by superlog-onboard skill on pairing
def init_observability() -> None:
exporter = OTLPSpanExporter(
endpoint=f"{SUPERLOG_ENDPOINT}/v1/traces",
headers={"authorization": f"Bearer {SUPERLOG_KEY}"},
)
..._INITIALIZEDllm.tokens.inputllm.tokens.outputunit="tokens"llm.cost_usd