Skip to content

Latest commit

 

History

History

spring-cloud-gcp-trace-sample

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Spring Framework on Google Cloud Trace Starter Example

This sample application demonstrates using the Spring Framework on Google Cloud Trace Starter in your code.

You can read about the Spring Boot Starter for Stackdriver Trace in more detail at the Spring Framework on Google Cloud Reference Document Stackdriver Trace section.

Similar content is also available in the Distributed tracing with Micrometer codelab.

Setup & Configuration

open btn

  1. Create a Google Cloud Project

  2. Create a service account with Trace Append permission. Furnish a new JSON key and then set the credentials using the GOOGLE_APPLICATION_CREDENTIALS environment variable or using Spring Framework on Google Cloud Starter Core properties.

    Alternatively, if you have the Google Cloud SDK installed and initialized and are logged in with application default credentials, you can skip this step since Spring Framework on Google Cloud will auto-discover those settings for you.

  3. Enable the Stackdriver Trace API

  4. Go to the Google Cloud Console Pub/Sub topics page and create a topic called traceTopic.

    Still in the same page, locate the newly created topic, click the button with the three vertical dots at the end of the topic’s line and click "New subscription". Create a new subscription called traceSubscription with all default parameters.

  5. Run $ mvn clean install from the root directory of the project.

Run the Example

Run the following command in the same directory as this sample (spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample):

$ mvn spring-boot:run

Browse to http://localhost:8080 or use the Web Preview button in Cloud Shell to preview the app on port 8080. This will trigger the ExampleController.work() method, which in turn will call other services, and also a remote RESTful call to ExampleController.meet() method.

To see the traces, navigate to Stackdriver Trace console’s Trace List view. You should see the trace information in detail. Additionally, if you logged in with the Google Cloud SDK or have the GOOGLE_CLOUD_PROJECT environment variable set to your Google Cloud project ID, you can also click the View link in front of the DetailsLog to view the log entries related to that trace ID.

Note that the trace transmission delay default value is 10 seconds, so it can take a little while for the traces to show up in the Trace List page. You can shorten this delay using the spring.cloud.gcp.trace.scheduled-delay-seconds property.

Deploy to App Engine Standard Environment

If you have Cloud SDK installed, Maven App Engine Plug-in can be used to deploy the application to App Engine Standard environment:

$ mvn clean package appengine:deploy -Dapp.deploy.projectId=$PROJECT_ID -Dapp.deploy.version=$VERSION