How do I get the AppEngine service name and version in the GAE flexible env from my Java code at runtime in the Java 8/Jetty runtime?
I need the service and version to populate the ServiceContext info in the stackdriver error reporting on GCP. https://cloud.google.com/error-reporting/docs/formatting-error-messages
I am the Stackdriver Error Reporting product manager.
To answer your question: While I cannot find a clear documentation page for it. It seems that the environment variables
GAE_MODULE_NAME
andGAE_MODULE_VERSION
contain the data you are looking for.However, we recently changed how errors are processed on App Engine flexible environment: service name and version are now extracted automatically are not needed in the log entry payload. The
serviceContext
field is now optional on GAE Flex.The formatting error messages page should be updated in the following days to reflect this change.
According to the current documentation the environment variables
GAE_SERVICE
andGAE_VERSION
should be used.It is also possible to get the instance ID with the
GAE_INSTANCE
environment variable.https://cloud.google.com/appengine/docs/flexible/java/migrating#modules