Skip to content

docs(ts): use ctx.logger.info in v1 TypeScript examples#3794

Merged
gregfurman merged 2 commits into
hatchet-dev:mainfrom
ltsSmitty:docs/ts-v1-examples-ctx-logger
May 18, 2026
Merged

docs(ts): use ctx.logger.info in v1 TypeScript examples#3794
gregfurman merged 2 commits into
hatchet-dev:mainfrom
ltsSmitty:docs/ts-v1-examples-ctx-logger

Conversation

@ltsSmitty

@ltsSmitty ltsSmitty commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Description

Updates v1 TypeScript examples under sdks/typescript/src/v1/examples so task and workflow handlers log through ctx.logger.info instead of console.log, matching the SDK’s supported logging path and keeping run output visible in Hatchet’s logging pipeline.

I'm not sure if this was passed over (in what I assume was an upgrade from the non-versioned examples to v1), or if it was intentional; but seeing last month's celebration posts of new logging capabilities, I thought it was worth updating the examples to show it. In my new experience using Hatchet, my LLM which had access to the docs was able to set up logging using the provided ctx.logger without any issue, but I'd like for the examples to be clearer on what I assume is best practice.

Where handlers did not already take context, the second parameter ctx was added (e.g. webhook tasks, rate-limit examples, the non-durable task in the durable workflow example). Middleware before hooks and abort-signal examples now use the same logger on the provided context. Driver scripts (run.ts, event.ts, e2e helpers, agents, etc.) were left unchanged because they do not receive task context.

Type of change

  • Documentation change (pure documentation change)

@vercel

vercel Bot commented Apr 30, 2026

Copy link
Copy Markdown

@ltsSmitty is attempting to deploy a commit to the Hatchet Team on Vercel.

A member of the Team first needs to authorize it.

@ltsSmitty ltsSmitty marked this pull request as ready for review April 30, 2026 20:28
@promptless-for-oss

Copy link
Copy Markdown

Promptless prepared a documentation update related to this change.

Triggered by this PR

Updated documentation to reflect the ctx.logger pattern instead of the deprecated ctx.log() method. Changes include updates to the logging guide, middleware documentation, and added comprehensive logger property documentation to the TypeScript Context reference.

3 files changed:

  • frontend/docs/pages/v1/logging.mdx
  • frontend/docs/pages/v1/middleware.mdx
  • frontend/docs/pages/reference/typescript/Context.mdx

Review: Update TypeScript logger documentation

retries: 1,
fn: async (_input, ctx) => {
console.log('retrying bulk replay test task', ctx.retryCount());
ctx.logger.info('retrying bulk replay test task', ctx.retryCount());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ctx.logger interface expects these extra args to be in JSON form. See https://docs.hatchet.run/v1/logging#using-the-contextlog-method

Where the log events being sent to the engine would fail with

[WARN/Dispatcher] Could not put log: /EventsService/PutLog INVALID_ARGUMENT: Invalid metadata JSON: json: cannot unmarshal number into Go value of type map[string]interface {}

Instead, you'd need to interpolate this variable into the log message beforehand:

    ctx.logger.info(`retrying bulk replay test task ${ctx.retryCount()}`);

Or pass in the extra params in JSON form (which I'm incidentally unsure how to actually see these extra kwargs in the dashboard 🤷):

    ctx.logger.info('retrying bulk replay test task', {"retryCount": ctx.retryCount()});

@ltsSmitty

Copy link
Copy Markdown
Contributor Author

Great catch, sloppy of me to miss that. I'll address that.

On further digging, it looks like the metadata passed to the BYO structured logger isn't being passed to the LogLines, which explains your difficultly finding the kwargs. I'll submit that as a separate issue/PR.

image

@gregfurman gregfurman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :shipit: Thanks for addressing my comments and opening that extra issue!

@gregfurman gregfurman merged commit 4b6735e into hatchet-dev:main May 18, 2026
14 of 17 checks passed
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