Is there a way to determine programmatically the name of service that code is running in on Google App Engine? The only solution I have is to use the http request object in the servlet and inspect the url that was requested and extract it from that. But I would prefer something more globally accessible throughout the service.
Asked
Active
Viewed 82 times
1
-
Possible duplicate of [AppEngine service name and version in the GAE flexible env from my code at runtime in Java/Jetty?](https://stackoverflow.com/questions/39728297/appengine-service-name-and-version-in-the-gae-flexible-env-from-my-code-at-runti) – arudzinska Apr 16 '18 at 08:11
-
I updated my question title to include "Standard Environment" as the link you provided is for the Flexible Environment. – Johann Apr 16 '18 at 08:57
1 Answers
0
You can use the method getModuleId()
in Api Proxy.
So, a Servlet example:
import com.google.apphosting.api.ApiProxy;
import java.io.IOException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class HelloServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/plain");
ApiProxy.Environment env = ApiProxy.getCurrentEnvironment();
resp.getWriter().print("Service: ");
resp.getWriter().println(env.getModuleId());
}
}
This will print the name of the Service (Services were previously called Modules, that's why this method is named like that)

Mangu
- 3,160
- 2
- 25
- 42