Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

heroku

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?

like image 434
ex-nerd Avatar asked Jul 13 '12 06:07

ex-nerd


People also ask

How do I check my Heroku dyno?

You can view the amount of free dyno hours remaining by using the CLI. You can do this by running heroku ps on one of your free apps. Alternatively, you can also view this on Dashboard's billing page, which is refreshed daily to display the updated amount.

How many dynos can you have on Heroku?

By default, applications are limited to 100 total dynos across all process types. Additionally, a single process type that uses performance dynos can't be scaled to more than 10 dynos. Submit a request to raise this limit for your application.

What is a dyno unit Heroku?

The containers used at Heroku are called “dynos.” Dynos are isolated, virtualized Linux containers that are designed to execute code based on a user-specified command. Your app can scale to any specified number of dynos based on its resource demands.

How long does a Heroku Dyno last?

Starting today, Heroku accounts have an account-based pool of free dyno hours for use on free apps. This replaces the 18 hours a day limit on free apps, allowing a free app to run 24/7 if needed. New accounts receive 550 free dyno hours and you can verify your identity with a credit card for an additional 450 hours.


2 Answers

Recently that issue has been addressed by Heroku team.

The Dyno Manager adds DYNO environment variables that holds identifier of your dyno e.g. web.1, web.2, foo.1 etc. However, the variable is still experimental and subject to change or removal.

I needed that value (actually instance index like 1, 2 etc) to initialize flake id generator at instance startup and this variable was working perfectly fine for me.

You can read more about the variables on Local environment variables.

like image 111
Tom Avatar answered Sep 19 '22 08:09

Tom


The foreman package which heroku local uses seems to have changed the ENV variable name again (heroku/7.54.0). You can now get the worker name via $FOREMAN_WORKER_NAME when running locally. It has the same value $DYNO will have when running on Heroku (web.1, web.2, etc)

like image 36
Jacob Bijani Avatar answered Sep 21 '22 08:09

Jacob Bijani