Blyp Docs

Cloudflare Workers

Workers use a separate API from the Node/Bun server adapters.

import { initWorkersLogger, createWorkersLogger } from "blyp-js/workers";

initWorkersLogger({
  env: { service: "my-worker" },
  customProps: (request) => ({
    requestId: request.headers.get("x-request-id"),
  }),
});

export default {
  async fetch(request: Request): Promise<Response> {
    const log = createWorkersLogger(request);

    log.set({ action: "handle_request" });
    log.info("worker started");

    const response = Response.json({ ok: true });
    log.emit({ response });

    return response;
  },
};

Differences from the Node/Bun adapters

  • no file logging
  • no blyp.config.json
  • no automatic client log ingestion
  • console-based output only
  • request logs are emitted manually through emit()

Error emission

const log = createWorkersLogger(request);

try {
  // handler work
} catch (error) {
  log.emit({ error });
  throw error;
}

emit() returns the first emitted HttpRequestLog record and does not emit twice for the same request logger.

Relevant types

import type {
  WorkersLoggerConfig,
  WorkersEmitOptions,
  WorkersRequestLogger,
} from "blyp-js/workers";

On this page

No Headings