问题
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
回答1:
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
and GAE_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.
回答2:
According to the current documentation the environment variables GAE_SERVICE
and GAE_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
来源:https://stackoverflow.com/questions/39728297/appengine-service-name-and-version-in-the-gae-flexible-env-from-my-code-at-runti