otel-supabase-edge-style
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOTel Supabase Edge Style
OTel Supabase Edge 风格
Hosted Supabase Edge Functions do not support the normal native OTel SDK
lifecycle today. Use a tiny provider-neutral shim that looks like OTel and can
be deleted later if native support lands.
Good reusable API names:
ts
tracer.startActiveSpan("edge.chat", async (span) => { ... });
span.setAttributes({ "tenant.id": tenantId });
span.setStatus({ code: SpanStatusCode.ERROR });
meter.createCounter("llm.tokens.input").add(tokens, attrs);
histogram.record(durationMs, attrs);Bad reusable API names:
ts
sendSuperlogSpan(...);
recordCounter(...);
trackSuperlogEvent(...);Keep the endpoint and ingest key inline in one setup area near the top of the
function. Do not read them from env — the ingest key is project-scoped +
write-only and Edge runtimes are flaky about env propagation anyway.
ts
const SUPERLOG_ENDPOINT = "https://intake.superlog.sh";
const SUPERLOG_KEY = "superlog_live_…"; // set by superlog-onboard skill on pairing目前托管版Supabase Edge Functions不支持常规的原生OTel SDK生命周期。可以使用一个轻量级、与供应商无关的类OTel适配层,待原生支持落地后即可移除。
推荐的可复用API命名:
ts
tracer.startActiveSpan("edge.chat", async (span) => { ... });
span.setAttributes({ "tenant.id": tenantId });
span.setStatus({ code: SpanStatusCode.ERROR });
meter.createCounter("llm.tokens.input").add(tokens, attrs);
histogram.record(durationMs, attrs);不推荐的可复用API命名:
ts
sendSuperlogSpan(...);
recordCounter(...);
trackSuperlogEvent(...);将端点和接入密钥集中配置在函数顶部的初始化区域。不要从环境变量中读取——接入密钥是项目级别的且仅可写入,而且Edge运行时在环境变量传播方面存在不稳定问题。
ts
const SUPERLOG_ENDPOINT = "https://intake.superlog.sh";
const SUPERLOG_KEY = "superlog_live_…"; // set by superlog-onboard skill on pairingSignals
信号类型
- Traces: span around the function operation and each critical provider call.
- Logs: concise structured OTLP log records for critical outcomes.
- Metrics: tenant-tagged counters/histograms for critical operations.
- LLM calls: capture /
llm.tokens.inputonly when provider instrumentation is unavailable; tag explicit token counters with tenant, provider, model, use case, call site, and outcome. Do not calculate LLM cost in edge function code; Superlog estimates it centrally from provider/model/token data.llm.tokens.output
Use or the runtime's equivalent when available so
OTLP fetches can finish after the response is returned.
EdgeRuntime.waitUntil(...)- 追踪(Traces):为函数操作及每个关键供应商调用创建span。
- 日志(Logs):为关键结果生成简洁的结构化OTLP日志记录。
- 指标(Metrics):为关键操作添加租户标签的计数器/直方图。
- LLM调用:仅当供应商工具不可用时,才捕获/
llm.tokens.input;为明确的令牌计数器添加租户、供应商、模型、使用场景、调用位置及结果标签。不要在边缘函数代码中计算LLM成本;Superlog会基于供应商/模型/令牌数据集中估算成本。llm.tokens.output
如果可用,请使用或运行时的等效方法,确保OTLP请求在返回响应后仍能完成。
EdgeRuntime.waitUntil(...)