How to get Heroku app name/URL from inside the app

I'm working on a registration agent for http://www.dif.io to enable tracking of apps deployed on Heroku. I'm missing some pieces of information for the deployed app. The registration agent is a script (usually written in the app native language) which is designed to be executed after deployment (heroku run for example or automaticaly via some post deploy hook if any).

How do I get the application name, URL and some UUID identifier from inside the app, preferably from some ENV variables? I need it to be portable between languages.

I explored a sample Python application and all of the above info is missing. There are only couple more ENV variables related to Python. The dyno hostname however looks like an UUID.

I could use something like this but without the user/password requirements: https://addons.heroku.com/provider/resources/technical/reference/app-info

Please point me to the correct docs.


Solution 1:

The command app:info no longer seems to be a heroku command but just info will do the same thing so:

heroku info -s | grep web_url | cut -d= -f2

or to set the variable

heroku config:set HEROKU_URL=$(heroku info -s | grep web_url | cut -d= -f2)

Solution 2:

Dyno Metadata was introduced December 2015. It’s currently a labs feature which must be enabled first.

Dyno metadata gives the dyno easy access to information about the app and environment. Examples of available dyno metadata include details about the release, dyno size, application name as well as the unique identifier for the particular running dyne.

https://devcenter.heroku.com/articles/dyno-metadata

Solution 3:

There's a labs add-on that came out in Aug 2016 which puts all of these in your environment:

~ $ env
HEROKU_APP_ID:                   9daa2797-e49b-4624-932f-ec3f9688e3da
HEROKU_APP_NAME:                 example-app
HEROKU_DYNO_ID:                  1vac4117-c29f-4312-521e-ba4d8638c1ac
HEROKU_RELEASE_CREATED_AT:       2015-04-02T18:00:42Z
HEROKU_RELEASE_VERSION:          v42
HEROKU_SLUG_COMMIT:              2c3a0b24069af49b3de35b8e8c26765c1dba9ff0
HEROKU_SLUG_DESCRIPTION:         Deploy 2c3a0b2

https://devcenter.heroku.com/articles/dyno-metadata

Solution 4:

Dynos themselves don't have any information about the application name or URL they are running, as far as I can tell. The documentation on Dynos lists what local environment variables are set, but it's only has PORT and DYNO.

One workaround for that we use in hubot is to require the user to add a config like HEROKU_URL with the app hostname.

I've found that you can script most of this, by using heroku app:info with the -s flag for shell-friendly, with a little bit of grepping and cutting:

$ heroku apps:info -s  | grep web_url | cut -d= -f2
http://hubotio-campfire.herokuapp.com/

And to set HEROKU_URL from that:

$ heroku config:set HEROKU_URL=$(heroku apps:info -s  | grep web_url | cut -d= -f2)