一键导入
otel-python-style
Python OpenTelemetry style: module-scope tracers/meters, decorators for bounded work, error spans, logs, and no wrappers.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Python OpenTelemetry style: module-scope tracers/meters, decorators for bounded work, error spans, logs, and no wrappers.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
FastAPI OpenTelemetry style: native FastAPIInstrumentor, centralized observability init, Python decorators, OTLP logs, and LLM cost metrics.
Next.js/Vercel OpenTelemetry style: instrumentation.ts, @vercel/otel bootstrap, native @opentelemetry/api call sites, env docs, and no raw NodeSDK replacement.
General OpenTelemetry onboarding style for Superlog managed agents: native APIs, signal quality, env vars, LLM metrics, and smoke checks.
Supabase Edge Function observability style: tiny provider-neutral OTel-shaped shim, OTLP export config, traces/logs/metrics, and LLM cost metrics.
Onboard a project to Superlog by installing OpenTelemetry traces, logs, and metrics across every app and service in the repo. Triggers on requests like "install Superlog", "set up Superlog", "add Superlog telemetry", "onboard this repo to Superlog", "instrument with OpenTelemetry for Superlog".
Expo / React Native OpenTelemetry style: bootstrap guards, init ordering, public env vars, mobile-compatible exporters, and product action spans.
| name | otel-python-style |
| description | Python OpenTelemetry style: module-scope tracers/meters, decorators for bounded work, error spans, logs, and no wrappers. |
Acquire OTel objects at module scope.
from 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")
Prefer decorators for functions with clear boundaries.
@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",
})
Use a context manager when a decorator does not fit.
with tracer.start_as_current_span("order.validate") as span:
span.set_attribute("tenant.id", tenant_id)
validate_order(order)
Do not use detached tracer.start_span(...); span.end() for bounded work.
Record exceptions on the active span.
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})
raise
If logs are claimed as OTLP-forwarded, configure both:
set_logger_provider(logger_provider) from opentelemetry._logsLoggingInstrumentor().instrument(...)Preserve existing logging.basicConfig, console/file handlers, and log levels.
If the runtime needs OTLP auth headers, check OTEL_EXPORTER_OTLP_HEADERS during
initialization. When it is absent, log one clear warning and return without
installing exporters.
def init_observability() -> bool:
if not os.getenv("OTEL_EXPORTER_OTLP_HEADERS"):
logging.getLogger(__name__).warning(
"otel disabled; OTEL_EXPORTER_OTLP_HEADERS is not set"
)
return False
...
return True
Add a small _INITIALIZED guard only when the app can realistically call this
function more than once.
Counters:
llm.tokens.inputllm.tokens.outputUse semantic units when the SDK supports them: token counters use
unit="tokens". Do not add app-side llm.cost_usd pricing metrics for normal
LLM calls; Superlog estimates cost centrally from provider/model/token data.
Histograms:
Avoid raw high-cardinality values in metric attributes. Prefer tenant/org/project, operation/use case, provider/model, and outcome dimensions over user-level metric tags.