Skip to content

Conversation

@chris-olszewski
Copy link
Member

@chris-olszewski chris-olszewski commented Jan 7, 2026

What was changed

Introduce a new workflow-imports module in the interceptors package the just rexports what is needed by the workflow interceptors. In the package itself these exports are just stubs that throw if they are used.

When bundling the workflow bundle we use NormalModuleReplacementPlugin to swap out this module with one that actually re-exports from @temporalio/workflow.

Why?

A follow up to #1812 overdue to avoid lazy module loading while keeping @temporalio/workflow as an optional dependency.

Checklist

  1. Closes N/A

  2. How was this tested:
    The OTEL tests continue to pass with spans getting created.

Made a quick test project to show it is okay to not have @temporal/workflow and use the interceptors package up until you attempt to use a Workflow interceptor.

{
  "dependencies": {
    "@temporalio/common": "^1.14.0",
    "@temporalio/interceptors-opentelemetry": "file:/Users/olszewski/tmp/otel_lazy_fix/packages/interceptors-opentelemetry"
  },
  "scripts": {
    "test": "node index.js"
  },
  "type": "module"
}
import { OpenTelemetryWorkflowClientInterceptor, OpenTelemetryInboundInterceptor, OpenTelemetryActivityOutboundInterceptor } from '@temporalio/interceptors-opentelemetry';

try {
  console.log('making client interceptor')
  new OpenTelemetryWorkflowClientInterceptor();
} catch (e) {
  console.error(e);
}
try {
  console.log('making inbound interceptor')
  new OpenTelemetryInboundInterceptor().execute({ headers: {} }, async () => { });
} catch (e) {
  console.error(e);
}
try {
  console.log('making activity outbound')
  new OpenTelemetryActivityOutboundInterceptor();
} catch (e) {
  console.error(e);
}

Result:

> node index.js

making client interceptor
making inbound interceptor
making activity outbound
/Users/olszewski/tmp/my-otel-test/node_modules/.pnpm/@temporalio+interceptors-opentelemetry@file+..+otel_lazy_fix+packages+interceptors-open_4ed1001953f3d7991853514bfcd75c4a/node_modules/@temporalio/interceptors-opentelemetry/lib/workflow/workflow-imports.js:18
    throw new common_1.IllegalStateError('Workflow uninitialized');
          ^

IllegalStateError: Workflow uninitialized
    at getActivator (/Users/olszewski/tmp/my-otel-test/node_modules/.pnpm/@temporalio+interceptors-opentelemetry@file+..+otel_lazy_fix+packages+interceptors-open_4ed1001953f3d7991853514bfcd75c4a/node_modules/@temporalio/interceptors-opentelemetry/lib/workflow/workflow-imports.js:18:11)
    at OpenTelemetryInboundInterceptor.execute (/Users/olszewski/tmp/my-otel-test/node_modules/.pnpm/@temporalio+interceptors-opentelemetry@file+..+otel_lazy_fix+packages+interceptors-open_4ed1001953f3d7991853514bfcd75c4a/node_modules/@temporalio/interceptors-opentelemetry/lib/workflow/index.js:67:50)
    at file:///Users/olszewski/tmp/my-otel-test/index.js:11:41
    at ModuleJob.run (node:internal/modules/esm/module_job:345:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:651:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)
  1. Any docs updates needed?
    N/A

@chris-olszewski chris-olszewski marked this pull request as ready for review January 7, 2026 21:28
@chris-olszewski chris-olszewski requested a review from a team as a code owner January 7, 2026 21:28
@chris-olszewski chris-olszewski force-pushed the olszewski/chore_avoid_lazy_load branch from 170899c to 3787c84 Compare January 8, 2026 14:58
@chris-olszewski chris-olszewski force-pushed the olszewski/chore_avoid_lazy_load branch from 52cb059 to 8aae3a1 Compare January 8, 2026 19:21
@chris-olszewski chris-olszewski merged commit 31ad5c0 into main Jan 8, 2026
22 of 27 checks passed
@chris-olszewski chris-olszewski deleted the olszewski/chore_avoid_lazy_load branch January 8, 2026 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants