Runtimes (TypeScript)
Use this page to run the SDK outside a long-lived Node process.
Edge runtimes and serverless
Section titled “Edge runtimes and serverless”One transport everywhere: OTLP protobuf over fetch, gzipped through CompressionStream when the runtime has it. On Cloudflare Workers, enable Node compatibility (the SDK uses AsyncLocalStorage for context):
compatibility_flags = ["nodejs_compat"]In serverless (Workers, Lambda, edge functions), flush explicitly. The beforeExit hook only fires when the event loop empties, never on a frozen or reused invocation:
import { flush } from "@cetra-ai/sdk";
export default { async fetch(request, env, ctx) { const response = handle(request); ctx.waitUntil(flush()); return response; },};Browser feedback
Section titled “Browser feedback”The @cetra-ai/sdk/browser subpath imports nothing from OpenTelemetry; it posts an end-user feedback score with a public key (pk-cetra-…) and never throws:
import { feedback } from "@cetra-ai/sdk/browser";
const { ok } = await feedback({ baseUrl: "https://cetra.example.org", publicKey: "pk-cetra-…", traceId, // 32 hex chars, from traceparent or your app value: 1,});Known limits
Section titled “Known limits”- Zero-argument functions and
undefined: no arguments record no input (Python records{}); anundefinedreturn records no output (Python recordsnull). Returnnullto record a JSONnull. - Integral floats: JavaScript has one number type, and OpenTelemetry JS encodes an integral number as an int attribute; Python writes a double for
1.0. The server reads both.bigintbecomes a decimal string in payloads. - Resource attributes: only
OTEL_SERVICE_NAMEis read (from the config’s env source);OTEL_RESOURCE_ATTRIBUTESis not (Python reads it). - Usage counts:
setUsagerecords only safe integers (Number.isSafeInteger); a larger value, a non-integer or a negative one is skipped with a debug line. Python’sset_usagerecords any non-negativeint, including values beyond 2^53. - Abandoned generators: a half-consumed generator is left unexported (TypeScript has no finalizer); Python’s garbage collector ends it with status ok.
- Cloudflare Workers need
nodejs_compat(above); flush throughctx.waitUntil(flush())before the invocation is frozen. - Serverless: call
await flush()(orshutdown()) at the end of each invocation; the SDK installs no signal handlers andbeforeExitdoes not fire onprocess.exit().