@grand-board/otel-cloudflare - v8.4.0
    Preparing search index...

    Function withHTTPWorkflow

    • Mixin to add HTTP endpoints and automatic tracing to a Cloudflare Workflow class

      This mixin wraps the workflow's run method with:

      • OpenTelemetry tracing for all workflow steps
      • Trace context propagation across pause/resume cycles
      • Automatic OTLP flush on completion

      It also adds a static fetch method for HTTP access:

      • POST / - Start a new workflow instance
      • GET / - Health check
      • GET /status/:id - Get workflow instance status

      Type Parameters

      Parameters

      Returns T & HTTPWorkflowClass<Env, Params>

      import { WorkflowEntrypoint } from "cloudflare:workers";
      import { withHTTPWorkflow } from "@grand-board/otel-cloudflare";

      class MyWorkflowBase extends WorkflowEntrypoint<Env, MyParams> {
      async run(event: WorkflowEvent<MyParams>, step: WorkflowStep) {
      const data = await step.do("fetch-data", async () => {
      return await fetchData();
      });
      return { success: true, data };
      }
      }

      // Apply the mixin
      export const MyWorkflow = withHTTPWorkflow(MyWorkflowBase);

      // Worker fetch handler:
      export default {
      async fetch(request, env, ctx) {
      return MyWorkflow.fetch(request, env.MY_WORKFLOW);
      }
      }