Get WorkerID from within a activity

How do I access the worker ID information from within an activity ? I can see it in the logs while logging it using activity.GetLogger() , but I need to access it from within the activity code.

What is the use case for this?

Each activity execution can end up on any of your activity workers (hosts) and api (Activity info) does not expose the worker identity currently.
If you need this for debugging, you can see the identity of the worker that ran last retry of activity in the ActivityTaskStarted event in event history. If the activity is currently retrying you can use DescribeWorkflowExecution api to get “pending activity info” which would also give you current activity retry count, last failure message, last heartbeat details if activity is heartbeating and should include last worker identity

So, this activity has to dynamically determine if that particular worker machine has enough resources (storage) to be able to continue the work. For that I am storing/ updating the storage information of each worker in a separate DB. This activity will query the DB and determine if that worker has enough unreserved storage left, then only it will continue, else reject. For this storing and querying purpose of each worker’s unreserved storage information I need to access the unique WorkerID for each worker machine.

It is not only for debugging purpose , I need to access it programmatically , I have explained my use case here Get WorkerID from within a activity - #4 by dddd

Think you should set your max concurrent activity executor slots per worker such that it can support
max concurrent activity executions that it can handle given its resources.
If a worker is currently processing max number of concurrent activities you configure, for example:

worker.New(ctx, taskQueue, worker.Options{
MaxConcurrentActivityExecutionSize: X,
})

if its currently processing X activities concurrently it would stop polling for activity tasks until at least one activity completes.
we are working on some updates with worker auto-tuning so in future a worker would be able to adjust this config based on cpu/memory automatically.

if you must have this information for this use case maybe set this worker id as an env var and then can get it in your activity code, currently its not possible via api, but I think the approach to limit activity concurrency via config is probably better and then scale on number of activity workers

It will be impossible to predict accurately what MaxConcurrentActivityExecutionSize could be as in my usecase the storage requirement for each activity execution will vary widely, so I cannot rely on just MaxConcurrentActivityExecutionSize. I was already considering this env variable option as there is no other direct way to do this with temporal, I guess I will just go with this option.