DevOps & SRE

Production debugging comes to Cloud Source Repositories

DevOps

Google Cloud has some great tools for software developers. Cloud Source Repositories and Stackdriver Debugger are used daily by thousands of developers who value Cloud Source Repositories’ excellent code search and Debugger’s ability to quickly and safely find errors in production services.

But Debugger isn’t a full-fledged code browser, and isn’t tightly integrated with all the most common developer environments. The good news is that these tools are coming together! Starting today, you can debug your production services directly in Cloud Source Repositories, for every service where Stackdriver Debugger is enabled.

Debugger CSR 1.gif

What’s new in Cloud Source Repositories

This integration brings two pieces of functionality to Cloud Source Repositories: support for snapshots, and logpoints.

Snapshots
Snapshots are point-in-time images of your application’s local variables and stack that are triggered when a code condition is met. Think of snapshots as breakpoints that don’t halt execution. To create one, simply click on a line number as you would with a traditional debugger, and the snapshot will activate the next time that one of your instances executes the selected line. When this happens, you’ll see the local variables captured during the snapshot and the complete call stack—without halting the application or impacting its state and ongoing operations!

You can navigate and view local variables in this snapshot from each frame in the stack, just as with any other debugger. You also have full access to conditions and expressions, and there are safeguards in place to protect against accidental changes to your application’s state.

Logpoints
Logpoints allow you to dynamically insert log statements into your running services without redeploying them. Each logpoint operates just like a log statement that you write into your code normally: you can add free text, reference variables, and set the conditions for the log to be saved. Logpoints are written to your standard output path, meaning that you can use them with any logging backend, not just Stackdriver Logging.

Creating a logpoint is a lot like creating a snapshot: simply click on the line number of the line where you wish to set it, and you’re done.

Upon adding a logpoint to your application, it’s pushed out to all instances of the selected service. Logpoints last for 24 hours or until the service is redeployed, whichever comes first. Logpoints have the same performance impact as any other log statement that exists normally in your source code.

Getting started

To use Cloud Source Repositories’ production debugging capabilities, you must first enable your Google Cloud Platform projects for Stackdriver Debugger. You can learn more about these setup steps in the Stackdriver Debugger documentation.

Once this is complete, navigate to the source code you wish to debug in Cloud Source Repositories, then select ‘Debug application’. Today this works best with code stored in Cloud Source Repositories or that is mirrored from supported third-party sources including GitHub, Bitbucket, and GitLab. Once you’ve selected your application you can start placing snapshots and logpoints in your code by clicking on the line numbers in the left gutter.

Debugger CSR 2.gif

Production debugging done right

Being able to debug code that’s running in production is a critical capability—and being able to do so from a full-featured code browser is even better! Now, through bringing production debugging to Cloud Source Repositories, you can track down hard-to-find problems deep in your code, while being able to do things like  continually sync code from a variety of different sources, cross-reference classes, look at blame layers, view change history, and search by class name, method name, etc. To learn more, check out this getting started guide

Russell Wolf, Product Manager, also contributed to this blog post.