[MUSIC PLAYING]
RAY TSANG: In this video, you'll learn
how to quickly adopt Google Cloud platform
services with Springboard framework using Spring Cloud
GCP.
GCP engineers have been working closely with the Spring teams
to produce idiomatic integrations
for many of our GCP services.
Let's see how you can use Cloud Spanner,
add distributed tracing to Cloud Trace,
send logs to Cloud Logging with a Spring Boot application.
First, create a new application using Spring Initializer
at start.spring.io.
In the bottom, you can add dependencies
to add capabilities to your application at GCP support.
Generate the application and open it in your favorite IDE.
You can use Spring Data with Cloud Spanner,
so you can take advantage of Spring Data features,
such as object relational mapping, crowd repository,
inventing, and auditing.
First, add the Spring Cloud GCP Cloud Spanner starter.
Create a POJO for object relational mapping.
Annotate the POJO with Cloud Spanner
annotations to configure a table mapping and primary keys.
Rather than creating your own data access object,
you can use Spring Data's repository
to automatically generate and implement cloud operations
to Cloud Spanner.
In application.properties, configure the Cloud Spanner
instance ID and database ID to connect to.
You can then use the repository for basic cloud operations.
But you can also enhance the repository
with additional finder methods or custom queries.
Spring Data will automatically infer the query
from the name of the method, or use a query
that you provide, using the query annotation.
Finally, rather than creating your own RestController
by hand, you can also use Spring Data REST repository
to automatically create and expose
a RESTful service that can perform
cloud operations against the Cloud Spanner database.
It's important to understand the topology of your distributed
system.
You can accomplish this through the use
of distributive tracing.
You can use Spring Cloud GCP Trace
Starter to add the distributive tracing capability
to your service.
It uses Spring Cloud Sleuth underneath,
so it's native to Springboard applications.
And they will automatically capture and propagate
the trace ID, the span ID.
And it will automatically configure Spring Cloud Sleuth
to send traces to Cloud Trace
By default, Spring Cloud Sleuth will only sample and report
10% of the requests.
You can adjust the sampling probability.
For this demo, were adjusted to 100%.
And this is all it takes to add distributed tracing
to send traces to Cloud Trace.
Similarly, to send log messages to Cloud Logging,
simply add the Spring Cloud GCP Logging Starter.
Then configure the standard logback configuration
to use Cloud Logging appendix.
There are two appendix you can use.
If you're running on premise, you
can send log entries to the API.
Or if you're running in GKE, you can
use the JSON appender to produce JSON format log entries that's
understood by GKE
In both cases, you do not need to change any code.
Simply use the existing appenders.
And most importantly, the trace context information
will be automatically added to the log entry,
so that later, you can correlate the trace graph
with the corresponding log messages.
Let's go take a look.
In the Trace console, we can clearly
see the trace associated with a request
but also, its subsequent course.
Check the show logs checkbox.
And the related log messages are also displayed.
With Spring Cloud GCP, you can quickly
create services or migrate existing services
to utilize GCP.
You can use Spring data with Cloud Spanner, Firestore,
and Data Store.
You can add distributed tracing and centralize logging
without adding custom code.
And there's so much more.
[MUSIC PLAYING]