Spring Cloud GCP Logging Starter Example
This sample application demonstrates using the Spring Cloud GCP Logging Starter to store and group logs by trace ID, with the Google Stackdriver Logging API.
Setup & Configuration
Running the Example
Run the sample application from Maven:
$ mvn spring-boot:run
Then, issue a request containing the
x-cloud-trace-context header to the
localhost:8080/log endpoint and verify that a label appears in Stackdriver:
$ curl --header "x-cloud-trace-context: [Some-Trace-ID]" localhost:8080/log
To see the logged lines, navigate to the Logging section of the Cloud Console.
Global resource and look under the
spring.log channel to see the logged text.
If your application is deployed to Google App Engine (GAE) or Google Kubernetes Engine (GKE), you will instead find the logs under the deployment’s resource in the Stackdriver UI under the
You can further narrow down the log by request by using the following filtering text that takes advantage of the trace ID label in each logged line.
For example, if deployed to App Engine (by using
mvn appengine:deploy in this sample) you can use the following to filter by the trace ID:
resource.type="gae_app" logName="projects/[Your-Project-ID]/logs/spring.log" labels."appengine.googleapis.com/trace_id"="[Trace-ID-Of-Request]"
Expand the log entry labels and note that
appengine.googleapis.com/trace_id label is set to the same value for both log messages.
The trace ID header
x-cloud-trace-context is set automatically when deployed to App Engine.
When running on GAE or GKE, also remember to remove the