SPEAKER 1: Google Cloud comes with built-in infrastructure
and tools to help you develop apps and manage your services.
In this episode, we'll go beyond login and error reporting
and explore the powers of tracing, profiling,
and debugging in production.
Stick around.
[MUSIC PLAYING]
Google Cloud Log tools are great.
And I hope you didn't miss the previous episodes about Cloud
Logging and error reporting.
But when dealing with logs, it's easy to get
lost looking for needle in a haystack, especially
when you're trying to determine where time is actually
spent when your application is carrying out a particular task.
Cloud Trace is a distributed tracing system
to help you with this exact problem
by collecting latency data across multiple Google Cloud
products and many supported languages.
In most cases, Cloud Trace requires no setup.
The cloud tracing graphical interface in the console
provides recent traces, each with URI,
latency, and timestamp, but also most frequent URIs
and even insights pointing you to common application problems.
For any given request URI, a heat map
of request duration through time is presented, giving you
visual hints about which specific requests may
need further investigation.
Capturing distributed traces from your application
used to be a difficult problem, but we now
make it easy with OpenTelemetry, previously named OpenCensus,
a project that we started here at Google.
For any running code that isn't integrated out
of the box with Cloud Trace, OpenTelemetry
provides libraries that capture traces and application metrics
from your applications either automatically, using
included instrumentation, or manually, via the API.
Once you've identified a particular bottleneck
in your application that is likely to require a code
modification, it's time to use a profiler.
What's special about Cloud Profiler
is the little to no overhead that it introduces
while continuously gathering CPU and memory allocation
data from your production applications.
Cloud Profiler then attributes that information back
to the application source code, helping
you identify what's consuming the most resources
and how to fix your performance issues.
Once collected, profiling data is
displayed using flame graphs, which
pack a large amount of information
into a compact and readable format.
This is not the time to go into a course
on troubleshooting your code, but I would instead
recommend that you interact with the Cloud Profiler user
interface.
Click on the Top Functions list, and find out
which are the most expensive functions,
and then click on one to enable the focused view.
There may well be some low-hanging fruit
waiting for you.
Writing code is great, but potentially,
finding hard to identify bugs is just as important.
Now, be honest-- how often have you had to restart
or redeploy your application just because you added a log
statement for debugging?
I know I have.
Cloud Debugger is a tool you can use
to inspect the state of an application at any code
location without stopping or slowing down the running app.
Since we're talking about live-running applications here,
there are no actual breakpoints, but instead
two unique features-- snapshots and logpoints.
With snapshots, you can capture the call stack and inspect
local variables, all without stopping or slowing down
the app.
With logpoints, you can inject logging statements
without the need to restart the app.
Creating a logpoint a lot like creating a snapshot.
Simply click on a given line in your code,
and each logpoint will operate just as a log statement
that you write into your code manually.
You can add free text, reference variables,
and set the conditions for the log to be saved.
Logpoints are written to your standard output,
which means that you can use them with any logging back end.
This is no conventional debugging tool.
It's one that can help you troubleshoot
hard-to-reproduce problems.
So I can only strongly encourage you to look into it.
With Cloud Trace, Profiler, and Debugger in your tool box,
you now have modern and powerful tools to diagnose and fix
issues that may arise in your cloud apps, even in production.
If you like this video, please like, subscribe, comment,
share, and look forward to more Google Cloud Essentials videos.
[MUSIC PLAYING]