Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App Engine Instance ID

Is it possible to get info on what instance you're running on? I want to output just a simple identifier for which instance the code is currently running on for logging purposes.

like image 698
Eurig Jones Avatar asked Nov 15 '25 17:11

Eurig Jones


2 Answers

Since there is no language tag, and seeing your profile history, I assume you are using GAE/J?

In that case, the instance ID information is embedded in one of the environment attributes that you could get via ApiProxy.getCurrentEnvironment() method. You could then extract the instance id from the resulting map using key BackendService.INSTANCE_ID_ENV_ATTRIBUTE.

Even though the key is stored in BackendService, this approach will also work for frontend instances. So in summary, the following code would fetch the instance ID for you:

String tInstanceId = ApiProxy.getCurrentEnvironment()
                             .getAttributes()
                             .get( BackendService.INSTANCE_ID_ENV_ATTRIBUTE )
                             .toString();

Please keep in mind that this approach is quite undocumented by Google, and might subject to change without warning in the future. But since your use case is only for logging, I think it would be sufficient for now.

like image 141
Ibrahim Arief Avatar answered Nov 17 '25 07:11

Ibrahim Arief


With the advent of Modules, you can get the current instance id in a more elegant way:

ModulesServiceFactory.getModulesService().getCurrentInstanceId()

like image 21
Su Zhang Avatar answered Nov 17 '25 08:11

Su Zhang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!