docs(ts): use ctx.logger.info in v1 TypeScript examples#3794
Conversation
|
@ltsSmitty is attempting to deploy a commit to the Hatchet Team on Vercel. A member of the Team first needs to authorize it. |
|
Promptless prepared a documentation update related to this change. Triggered by this PR Updated documentation to reflect the 3 files changed:
|
| 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()); |
There was a problem hiding this comment.
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()});
Description
Updates v1 TypeScript examples under
sdks/typescript/src/v1/examplesso task and workflow handlers log throughctx.logger.infoinstead ofconsole.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
ctxwas added (e.g. webhook tasks, rate-limit examples, the non-durable task in the durable workflow example). Middlewarebeforehooks 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