Search code examples
heroku

How to identify a heroku dyno number from within the app?


Is there a way to identify the heroku dyno name (e.g. web.1, web.2) from within the application? I'd like to be able to generate a unique request id (e.g. to track requests between web and worker dynos for consolidated logging of the entire request stack) and it seems to me that the dyno identifier would make a decent starting point.

If this can't be done, does anyone have a fallback recommendation?


Solution

  • I asked this question of Heroku support, and since there are others here who have asked similar questions to mine I figured I should share it. Heroku staff member JD replied with the following:

    No, it's not possible to see this information from inside the dyno. We've reviewed this feature request before and have chosen not to implement it, as this would introduce a Heroku-specific variable which we aim to avoid in our stack. As such, we don't have plans to implement this feature.

    You can generate / add to your environment a unique identifier (e.g. a UUID) on dyno boot to accomplish a similar result, and you can correlate this to your app's dynos by printing it to your logs at that time. If you ever need to find it later, you can check your logs for that line (of course, you'll need to drain your logs using Papertrail, Loggly, etc, or to your own server).

    Unfortunately for my scenario, a UUID is too long (if I wanted such a large piece of data, I would just use a UUID to track things in the first place). But it's still good to have an official answer.