@heystack/otel 0.3.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -157,6 +157,9 @@ As belt-and-suspenders the exporter also drops any span whose HTTP target points
157
157
 
158
158
  ## Migration / versioning
159
159
 
160
+ - **`0.3.5`** — **type-constraint fix (Workers).** A Worker whose `queue` consumer is typed with a concrete message body — `queue(batch: MessageBatch<MyJob>, …)`, the normal case — failed to compile against `instrument()` in 0.3.4 (`TS2345`: `MessageBatch<unknown>` not assignable to `MessageBatch<MyJob>`). The `WorkerHandler` constraint declared its entrypoints as arrow properties, whose parameters are checked **contravariantly** under `strictFunctionTypes`, so a narrowed handler wasn't assignable. 0.3.5 declares them with **method syntax** (bivariant parameters) and widens the batch to `MessageBatch<any>`, mirroring Cloudflare's own `ExportedHandler` — a typed-queue Worker now type-checks with a bare `instrument(handler, cfg)`. Runtime behaviour unchanged. Also adds a **consumer type-check gate** (`pnpm consumer-typecheck`, run in `check` and `prepublishOnly`) that compiles a fully-typed Worker against the built `dist` through the public `exports` map and asserts `satisfies ExportedHandler<Env>` — the regression that escaped in 0.3.3/0.3.4 now fails the build before publish.
161
+ - **`0.3.4`** — **type-inference fix (Workers).** Restores `instrument()`'s ability to infer the handler's concrete `Env` type. In 0.3.3 the signature was `instrument<E = unknown, H extends WorkerHandler<E>>`, so `E` defaulted to `unknown` and was never recovered from the handler — under `strictFunctionTypes` a Worker typed `fetch(req, env: Env, ctx)` then failed to compile (`TS2345: 'Env' is not assignable to 'unknown'`) unless the caller passed `instrument<Env>(...)` explicitly. 0.3.4 infers `E` from the handler argument (`instrument<H extends WorkerHandler<any>>(...): Instrumented<EnvOf<H>, H>`), so a bare `instrument(handler, cfg)` type-checks again. Runtime behaviour is unchanged; no `0.3.3` consumer needs the explicit type arg after upgrading.
162
+ - **`0.3.3`** — `/next` uses bare, exports-mapped dynamic imports so the OpenNext (Cloudflare Pages) build resolves the workers entry correctly (fixes a build break). Workers/Node paths unchanged.
160
163
  - **`0.3.2`** — runtime-correctness fixes:
161
164
  - **ContextManager registered (CRITICAL).** 0.3.1's `suppressTracing` was a no-op because no ContextManager was registered, so the exporter's ingest POST could still be re-traced into a feedback loop. 0.3.2 registers an `AsyncLocalStorageContextManager` (Node + workerd under `nodejs_compat`; sync stack-manager fallback otherwise) so suppression works — and as a bonus you get cross-`await` span parenting + per-request context isolation. **Workers now require `nodejs_compat`.** New dependency: `@opentelemetry/context-async-hooks`.
162
165
  - **Hostname-accurate self-span filter** (no sibling-domain false positives; `host:port` now matched; more host-only attrs covered).
package/dist/workers.d.ts CHANGED
@@ -197,9 +197,9 @@ export declare function __resetWarnings(): void;
197
197
  * a Worker never drops a handler Cloudflare requires for deploy.
198
198
  */
199
199
  interface WorkerHandler<E> {
200
- fetch?: (req: Request, env: E, ctx: ExecutionContext) => Promise<Response> | Response;
201
- queue?: (batch: MessageBatch, env: E, ctx: ExecutionContext) => Promise<void> | void;
202
- scheduled?: (controller: ScheduledController, env: E, ctx: ExecutionContext) => Promise<void> | void;
200
+ fetch?(req: Request, env: E, ctx: ExecutionContext): Promise<Response> | Response;
201
+ queue?(batch: MessageBatch<any>, env: E, ctx: ExecutionContext): Promise<void> | void;
202
+ scheduled?(controller: ScheduledController, env: E, ctx: ExecutionContext): Promise<void> | void;
203
203
  [key: string]: unknown;
204
204
  }
205
205
  /**
@@ -253,5 +253,20 @@ type Instrumented<E, H> = Omit<H, "fetch" | "queue" | "scheduled"> & (H extends
253
253
  } ? {
254
254
  scheduled: (controller: ScheduledController, env: E, ctx: ExecutionContext) => Promise<void>;
255
255
  } : unknown);
256
- export declare function instrument<E = unknown, H extends WorkerHandler<E> = WorkerHandler<E>>(handler: H, config: WorkersConfig): Instrumented<E, H>;
256
+ /**
257
+ * Recover a handler's concrete env type from whichever traced entrypoint it
258
+ * declares (`fetch`, else `queue`, else `scheduled`). This lets `instrument()`
259
+ * infer the env from the handler argument itself rather than requiring the
260
+ * caller to pass it explicitly — a Worker typed `fetch(req, env: Env, ctx)`
261
+ * type-checks with a bare `instrument(handler, cfg)` call. Falls back to
262
+ * `unknown` for a handler with no recognised entrypoint.
263
+ */
264
+ type EnvOf<H> = H extends {
265
+ fetch: (req: Request, env: infer E, ctx: ExecutionContext) => unknown;
266
+ } ? E : H extends {
267
+ queue: (batch: MessageBatch, env: infer E, ctx: ExecutionContext) => unknown;
268
+ } ? E : H extends {
269
+ scheduled: (controller: ScheduledController, env: infer E, ctx: ExecutionContext) => unknown;
270
+ } ? E : unknown;
271
+ export declare function instrument<H extends WorkerHandler<any>>(handler: H, config: WorkersConfig): Instrumented<EnvOf<H>, H>;
257
272
  export type { Span };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heystack/otel",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "Runtime-aware OpenTelemetry tracing that exports to Heystack (Node, Next.js, Workers).",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -19,8 +19,9 @@
19
19
  "test": "vitest run",
20
20
  "typecheck": "tsc --noEmit",
21
21
  "validate": "node scripts/validate-entries.mjs",
22
- "check": "pnpm typecheck && pnpm build && pnpm validate && pnpm test",
23
- "prepublishOnly": "pnpm build && pnpm validate"
22
+ "consumer-typecheck": "node scripts/consumer-typecheck.mjs",
23
+ "check": "pnpm typecheck && pnpm build && pnpm validate && pnpm consumer-typecheck && pnpm test",
24
+ "prepublishOnly": "pnpm build && pnpm validate && pnpm consumer-typecheck"
24
25
  },
25
26
  "dependencies": {
26
27
  "@opentelemetry/api": "^1.9.0",