Skip to content

Latest commit

 

History

History
91 lines (72 loc) · 5.25 KB

README.md

File metadata and controls

91 lines (72 loc) · 5.25 KB

Spring Boot with OpenCensus Sample

Setup Credentials

  1. Create a Google Cloud Platform 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 GCP 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 the sample will auto-discover those settings for you.
  3. Enable the Stackdriver Trace API

Setup Bigtable

Follow the instructions in the user documentation to create a Google Cloud Platform project and Cloud Bigtable instance if necessary. You'll need to reference your project id and instance id to run the application.

Make sure the right values are set in the spring_sample_backend/config/application.properties

  • spring.opencensus.sample.backend.bigtable.enabled=true
  • spring.opencensus.sample.backend.bigtable.projectId=YOUR_PROJECT_ID
  • spring.opencensus.sample.backend.bigtable.instanceId=YOUR_INSTANCE_ID

Setup CloudStorage

Follow the instructions in the getting started to setup Cloud Storage and create a Google Cloud Platform project if necessary. You'll need to reference your project id to run the application.

Make sure the right values are set in the spring_sample_backend/config/application.properties

  • spring.opencensus.sample.backend.cloudstorage.enabled=true
  • spring.opencensus.sample.backend.cloudstorage.projectId=YOUR_PROJECT_ID

Setup Datastore

Follow the instructions in the getting started to setup Datastore and create a Google Cloud Platform project if necessary. You'll need to reference your project id to run the application.

Make sure the right values are set in the spring_sample_backend/config/application.properties

  • spring.opencensus.sample.backend.datastore.enabled=true
  • spring.opencensus.sample.backend.datastore.projectId=YOUR_PROJECT_ID

Run the Example

Setup the

$ mvn -pl :spring-sample-backend spring-boot:run -Dspring.config.location=spring_sample_backend/config/
$ mvn -pl :spring-sample-frontend spring-boot:run -Dspring.config.location=spring_sample_frontend/config/
  • Go to http://localhost:8081/ to check that the Frontend is up.
  • Go to http://localhost:8081/init if this is the first time you are using the Sample. (e.g. creates Bigtable table).
  • Go to http://localhost:8081/work this can be called multiple times to generate traces.
  • Go to http://localhost:8081/cleanup when you are done using the Sample. (e.g. deletes Bigtable table)

To see the traces, navigate to Stackdriver Trace console's Trace List view.

Details about Implementation

The Frontend simply redirects incoming requests /init,/work and /cleanup to the Backend via HTTP requests /backend_init,/backend_work and /backend_cleanup.

The Backend supports multiple types of workers including Bigtable, Datastore and Cloud Storage. For every incoming request calls the corresponding action on the registered workers.

The current implementation uses Sleuth and GCP Spring Trace to generate traces for HTTP calls and propagate the TraceContext via Thread Local variables in-process. For calls to GCP services (Bigtable, Datastore, Cloud Storage) which are instrumented using OpenCensus an extra module is required to translate the Brave TraceContext into OpenCensus Span (see here).

Caveat

  1. The current design does not work properly if calls are going from libraries instrumented with OpenCensus to libraries instrumented with Sleuth (e.g. http calls) but this should not be the case in this example where only GCP client libraries are instrumented with OpenCensus.