temporalio / sdk-typescript

Temporal TypeScript SDK
Other
519 stars 102 forks source link

[Feature Request] Get workflow info / activity context in PayloadCodec #849

Open klesniewski opened 2 years ago

klesniewski commented 2 years ago

Is your feature request related to a problem? Please describe.

We have a codec that makes calls to an external service. As such, for various reasons encoding/decoding could fail. This will be retried and hopefully eventually works. However, we would like to see that failure in workflow/activity execution logs. This means we would like to attach for example workflowId to our logs, so that when we search for logs of particular workflow, we get to see these log messages.

Unfortunately, I didn't find a way to get this information in codecs. I could only make it work when decoding (but not encoding) for an activity, as then (and only then) Context.current() works.

We have this working in Go SDK through context-aware data converters, but I didn't find a way to make it work in TypeScript SDK.

Describe the solution you'd like

A way to access the activity/workflow execution metadata, so it can be added to logs. Information like:

Additional context

TS SDK version: 1.0.1

bergundy commented 2 years ago

As a temporary solution, you can pass that context in the payload metadata from a PayloadConverter and read it (and delete it) in your PayloadCodec.

I hope we can get to this issue soon.

mjameswh commented 1 year ago

There's somewhat of a chicken-or-egg problem here. WorkflowInfo and ActivityContext both contains some fields that needs decoding/encoding. It would not makes sense therefore to make these objects directly accessible to the PayloadCodec.

Providing trimmed down context object, specific to PayloadCodec would however be reasonable. It may also be useful to include request headers there. And a logger.

pzerelles commented 4 months ago

As a temporary solution, you can pass that context in the payload metadata from a PayloadConverter and read it (and delete it) in your PayloadCodec.

I hope we can get to this issue soon.

How exactly is this possible with the Typescript SDK?

pzerelles commented 4 months ago

There's somewhat of a chicken-or-egg problem here. WorkflowInfo and ActivityContext both contains some fields that needs decoding/encoding. It would not makes sense therefore to make these objects directly accessible to the PayloadCodec.

Providing trimmed down context object, specific to PayloadCodec would however be reasonable. It may also be useful to include request headers there. And a logger.

Is there a plan when this will be available? I need to pass tenant specific context from a workflow to a PayloadCodec.

jroof88 commented 1 month ago

👋 Hi just checking in here...is this something that is being considered? I'd love to have this in the Go SDK and be able to use workflow.Context in my PayloadCodec