Giter VIP home page Giter VIP logo

cloud-debug-nodejs's Introduction

Node.js agent for Google Cloud Debug

NPM Version Build Status Test Coverage Dependency Status devDependency Status

This module is experimental, and should be used by early adopters. This module uses APIs there may be undocumented and may be subject to change without notice.

This module provides Cloud Debug support for Node.js applications. Google Cloud Debug is a feature of Google Cloud Platform that lets you debug your applications in production without stopping or pausing your application. Here's an introductory video:

Cloud Debugger Intro

Prerequisites

  • Your application will need to be using Node.js version 0.12 or greater. Node.js v5+ is recommended.
  • The source of your application is uploaded to a cloud source repository. The Debugger UI needs the source to be available in order to set snapshots.

Quick Start (Node.js v4.x+)

# Install with `npm` or add to your `package.json`.
npm install --save @google/cloud-debug

# Require the agent at the top of your main script.
require('@google/cloud-debug');

Deploy your application, and navigate to the Debug tab within the Google Developers Console to set snapshots and start debugging.

Running on Google Cloud Platform

There are three different services that can host Node.js application to Google Cloud Platform.

Google App Engine Managed VMs

If you are using Google App Engine Managed VMs, you do not have to do any additional configuration.

Google Compute Engine

Your VM instances need to be created with cloud-platform scope if created via gcloud or the 'Allow API access' checkbox selected if created via the console (see screenshot).

GCE API

If you already have VMs that were created without API access and do not wish to recreate it, you can follow the instructions for using a service account under running elsewhere.

Google Container Engine

Container Engine nodes need to also be created with the cloud-platform scope, which is configurable during cluster creation. Alternatively, you can follow the instructions for using a service account under running elsewhere. It's recommended that you store the service account credentials as Kubernetes Secret.

Running elsewhere

If your application is running outside of Google Cloud Platform, such as locally, on-premise, or on another cloud provider, you can still use Cloud Debug.

  1. You will need to specify your project name. Your project name is visible in the Google Cloud Console, it may be something like particular-future-12345. If your application is running on Google Cloud Platform, you don't need to specify the project name.

     export GCLOUD_PROJECT=<project name>
    
  2. You need to provide service account credentials to your application. The recommended way is via Application Default Credentials.

  3. Create a new JSON service account key.

  4. Copy the key somewhere your application can access it. Be sure not to expose the key publicly.

  5. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the full path to the key. The debug agent will automatically look for this environment variable.

  6. Alternatively, if you are running your application on a machine where your are using the gcloud command line tools, and are logged using gcloud auth login, you already have sufficient credentials, and a service account key is not required.

  7. Generate a source-context.json file which contains information about the version of the source code used to build the application. This file should be located in the root directory of your application. When you open the Stackdriver Debugger in the Cloud Platform Console, it uses the information in this file to display the correct version of the source.

     gcloud preview app gen-repo-info-file
    

Using the Debugger

Once your application is running (deployed, or elsewhere), you should be able to use the Debug UI in your Cloud developer console. You can find the Debug UI in the 'STACKDRIVER -> Debug' section in the navigation panel, or by simply searching for 'Debug' in the developer console.

Debug UI

You can browse the code, and set a snapshot by clicking in the gutter (line number area). Once you set a snapshot, the debug agent will insert a momentary breakpoint at the code location in the running instances of the application.

Breakpoint Set

As soon as that line of code is reached in any of the running instances of your application, the stack traces, local variables, and watch expressions are captured, and your application continues.

Breakpoint Hit

Limitations and Requirements

  • The root directory of your application needs to contain a package.json file.
  • You can set snapshot conditions and watch expressions to be evaluated in the context of your application. This leads to some issues you should be aware of
    • You may be able to view sensitive data of your own users by looking at the values of the variables.
    • The debug agent tries to ensure that all conditions and watchpoints you add are read-only and have no side effects. It catches, and disallows, all expressions that may have static side effects to prevent accidental state change. However, it presently does not catch expressions that have dynamic side-effects. For example, o.f looks like a property access, but dynamically, it may end up calling a getter function. We presently do NOT detect such dynamic-side effects.
  • With Node.js 4.x and older, your application may experience a performance impact when there are snapshots active. There should be no impact to performance when no snapshots are active. Node.js v5.x does not have this issue.
  • Node.js v0.10.x or older are not supported as they lack some necessary APIs to avoid a permanent (life of the application) performance hit.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.