Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Reorganize code#337

Merged
DominicKramer merged 22 commits intogoogleapis:masterfrom
DominicKramer:reorganize-code
Oct 10, 2017
Merged

Reorganize code#337
DominicKramer merged 22 commits intogoogleapis:masterfrom
DominicKramer:reorganize-code

Conversation

@DominicKramer
Copy link
Copy Markdown
Contributor

No description provided.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 8, 2017
tsconfig.json Outdated
"lib": ["es2015"]
},
"include": [
"src/*.ts",

This comment was marked as spam.

package.json Outdated
"email": "[email protected]"
}
],
"readme": "# Stackdriver Debugger agent for Node.js\n\n[![NPM Version][npm-image]][npm-url]\n[![Build Status][travis-image]][travis-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n[![Dependency Status][david-image]][david-url]\n[![devDependency Status][david-dev-image]][david-dev-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n\n> **Beta**. *This is a Beta release of the Stackdriver Debugger agent for Node.js. These libraries might be changed in backward-incompatible ways and are not subject to any SLA or deprecation policy.*\n\nThis module provides Stackdriver Debugger support for Node.js applications. [Stackdriver Debugger](https://cloud.google.com/tools/cloud-debugger/) is a feature of [Google Cloud Platform](https://cloud.google.com/) that lets you debug your applications in production without stopping or pausing your application. Here's an introductory video:\n\n[![Cloud Debugger Intro](http://img.youtube.com/vi/tyHcK_kAOpw/0.jpg)](https://www.youtube.com/watch?v=tyHcK_kAOpw)\n\nSee also, [Setting up Stackdriver Debugger for Node.js][setting-up-nodejs].\n\n## Prerequisites\n* Stackdriver Debugger is comptible with Node.js version 4 or greater. Node.js v5+ is recommended.\n\n## Quick Start\n```shell\n# Install with `npm` or add to your `package.json`.\nnpm install --save @google-cloud/debug-agent\n```\n\n```js\n// Require and start in the startup of your application:\nrequire('@google-cloud/debug-agent').start({ allowExpressions: true });\n// No auth necessary if your code is running on Google Cloud Platform.\n\n// ... or, if you are running elsewhere, you can manually provide credentials:\nrequire('@google-cloud/debug-agent').start({\n allowExpressions: true,\n projectId: 'particular-future-12345',\n keyFilename: '/path/to/keyfile.json'\n});\n```\n\nThis starts the automatic Debugger Agent that enables your app to be debuggable using the Stackdriver [Stackdriver Debug view][debug-tab] within\nthe [Google Cloud Console][dev-console]. You can start adding snapshots and log-points to your application.\n\n## Running on Google Cloud Platform\n\nThe Stackdriver Debugger agent should work without the need to manually provide authentication credentials for instances running on Google Cloud Platform, as long as the [Stackdriver Debugger API][debugger-api] access scope is enabled on that instance.\n\n### App Engine\n\nOn **Google App Engine**, the Stackdriver Debugger API access scope is enabled by default, and the Stackdriver Debugger agent can be used without needing to provide credentials or a project ID.\n\n### Container Engine\n\nOn **Google Container Engine**, you need to explicitly add the `cloud_debugger` OAuth scope when creating the cluster:\n\n```\n$ gcloud container clusters create example-cluster-name --scopes https://www.googleapis.com/auth/cloud_debugger\n```\n\n### Compute Engine\n\nFor **Google Compute Engine instances**, you need to explicitly enable the `cloud_debugger` Stackdriver Debugger API access scope for each instance. When creating a new instance through the Google Cloud Platform Console, you can do this under **Identity and API access**: Use the Compute Engine default service account and select \"Allow full access to all Cloud APIs\" under Access scopes.\n\nTo use something other than the Compute Engine default service account see the docs for [Creating and Enabling Service Accounts for Instances][service-account-docs] and the [Running elsewhere](#running-locally-and-elsewhere) section below. The important thing is that the service account you use has the [**Cloud Debugger Agent**][debugger-roles] role.\n\n## Running locally and elsewhere\n\nIf your application is running outside of Google Cloud Platform, such as locally, on-premise, or on another cloud provider, you can still use Stackdriver Debugger, provided that you supply a project ID and credentials to the Stackdriver Debugger agent.\n\n### Project ID\n\nProvide a project ID to the Stackdriver Debugger agent by setting the projectId value in the options object passed to the agent's `start` method, or set the `GCLOUD_PROJECT` environment variable:\n\nOn Linux or Mac OS X:\n\n```bash\nexport GCLOUD_PROJECT=your-project-id\n```\n\nOn Windows:\n\n```\nset GCLOUD_PROJECT=your-project-id\n```\n\nAnd on Windows Powershell:\n\n```\n$env:GCLOUD_PROJECT=\"your-project-id\"\n```\n\n### Credentials\n\nGoogle Cloud Platform client libraries use a strategy called [Application Default Credentials (ADC)][app-default-credentials] to find your application's credentials. You can provide credentials to the Stackdriver Debugger agent by setting the `keyFilename` value in the `options` object passed to the agent's `start` method, or you can set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable. For more information, see [Providing credentials to your application][providing-credentials].\n\n### Example\n\n```js\nrequire('@google-cloud/debug-agent').start({\n projectId: 'your-project-id',\n keyFilename: '/path/to/key.json'\n});\n```\n\n### Source version\n\nGenerate 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.\n\n```\ngcloud beta debug source gen-repo-info-file\n```\n\nFor more information see [Selecting Source Code Manually][selecting-source].\n\n## Debugger Agent Settings\n\nYou can customize the behaviour of the automatic debugger agent. See [the agent configuration][config-js] for a list of possible configuration options. These options can be passed in the `options` object passed to the `start` function.\n\n```js\nrequire('@google-cloud/debug-agent').start({\n // .. auth settings ..\n\n // debug agent settings:\n allowExpressions: true,\n serviceContext: {\n service: 'my-service',\n version: 'version-1'\n },\n capture: { maxFrames: 20, maxProperties: 100 }\n});\n```\n\n## Using the Debugger\n\nOnce your application is running (deployed, or elsewhere), you should be able to use the [Debug UI][debug-tab] in your Cloud [developer console][dev-console]. You can find the Debug UI in the 'STACKDRIVER -> Debug' section in the navigation panel, or by simply searching for 'Debug' in the cloud console.\n\n![Debug UI](doc/images/debug-ui.png?raw=true)\n\nIf your source is hosted in a [cloud source repository](https://cloud.google.com/tools/cloud-repositories/docs/), Stackdriver Debugger will display the source code of your application automatically. Alternatively, you can also point the debugger to local files, a GitHub or Bitbucket repository, through a Source Capture, or you can simply type in a filename and line number. More details are on source options are [available here](https://cloud.google.com/debugger/docs/source-options).\n\nIf you have the source available, you can 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.\n\n![Breakpoint Set](doc/images/breakpoint-set.png?raw=true)\n\nAs 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.\n\n![Breakpoint Hit](doc/images/breakpoint-hit.png?raw=true)\n\n**Note:** The directory layout of the code that is being debugged does not have to exactly match the source code specified in the Debug UI. This is because the debug agent resolves a snapshot filename by searching for a file with the longest matching path suffix. If a unique match is found, that file will be used to set the snapshot.\n\nAn example will help illustrate this. That is, suppose that the code on the running instance is structured as follows:\n```\n/running/instance/package.json\n/running/instance/main.js\n/running/instance/a/index.js\n/running/instance/b/a/index.js\n```\nFurther, suppose the source code repository or local directory you have provided to the Debug UI is structured as follows.\n```\npackage.json\nmain.js\na/index.js\nb/a/index.js\n```\n\nIn this case, if you specify a snapshot in file `b/a/index.js` in the Debug UI, the debugger will identify that that file corresponds to the file `/running/instance/b/a/index.js` of the code on the running instance, and the breakpoint will hit when the specified line of `/running/instance/b/a/index.js` is reached.\n\nNote, however, if a snapshot is specified for the file `a/index.js` in the Debug UI, then the debugger would not know whether this file corresponds to the file `/running/instance/a/index.js` or `/running/instance/b/a/index.js`. If such an ambiguity occurs, the snapshot cannot be set and a message will be displayed in the Debug UI with additional information.\n\n## Support for Transpiled Code\n\nThe debugger supports the use of transpiled code, whether it be Javascript to Javascript transpilation or transpilation from another language (such as Typescript) to Javascript. In order to use transpiled code with the debugger, sourcemaps need to be generated with the transpiled code. The sourcemaps need to be provided in `.js.map` files.\n\nFurther, you do not need to deploy the original source files to the deployment environment as long as the sourcemap files are available at runtime.\n\nIn the Debug UI, you only need to provide the original source code -- you don't need the transpiled output files or the sourcemaps. When you set a snapshot in an original source file in the Debug UI, the corresponding file and line in the transpiled code is automatically determined based on the sourcemap files provided with the transpiled code at runtime. See the [Using the Debugger](#using-the-debugger) section for more information about using the Debug UI. In addition, the exact directory layout of the original source is somewhat flexible, just as it is with the use of non-transpiled code as described in the [Using the Debugger](#using-the-debugger) section.\n\n## Limitations and Requirements\n* The root directory of your application needs to contain a `package.json` file.\n* 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\n * You may be able to view sensitive data of your own users by looking at the values of the variables.\n * 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.\n* 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.\n* 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.\n\n\n[cloud-debugger]: https://cloud.google.com/tools/cloud-debugger/\n[setting-up-nodejs]: https://cloud.google.com/debugger/docs/setup/nodejs\n[dev-console]: https://console.cloud.google.com/\n[debug-tab]: https://console.cloud.google.com/debug\n[gcloud-sdk]: https://cloud.google.com/sdk/gcloud/\n[cloud-console-projects]: https://console.cloud.google.com/iam-admin/projects\n[app-default-credentials]: https://developers.google.com/identity/protocols/application-default-credentials\n[providing-credentials]: https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application\n[selecting-source]: https://cloud.google.com/debugger/docs/source-options\n[service-account-docs]: https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances\n[debugger-roles]: https://cloud.google.com/debugger/docs/iam#roles\n[npm-image]: https://img.shields.io/npm/v/@google-cloud/debug-agent.svg\n[npm-url]: https://npmjs.org/package/@google-cloud/debug-agent\n[travis-image]: https://travis-ci.org/GoogleCloudPlatform/cloud-debug-nodejs.svg?branch=master\n[travis-url]: https://travis-ci.org/GoogleCloudPlatform/cloud-debug-nodejs\n[coveralls-image]: https://img.shields.io/coveralls/GoogleCloudPlatform/cloud-debug-nodejs/master.svg\n[coveralls-url]: https://coveralls.io/r/GoogleCloudPlatform/cloud-debug-nodejs?branch=master\n[david-image]: https://david-dm.org/GoogleCloudPlatform/cloud-debug-nodejs.svg\n[david-url]: https://david-dm.org/GoogleCloudPlatform/cloud-debug-nodejs\n[david-dev-image]: https://david-dm.org/GoogleCloudPlatform/cloud-debug-nodejs/dev-status.svg\n[david-dev-url]: https://david-dm.org/GoogleCloudPlatform/cloud-debug-nodejs?type=dev\n[debugger-api]: https://console.cloud.google.com/apis/api/clouddebugger.googleapis.com/overview\n[snyk-image]: https://snyk.io/test/github/GoogleCloudPlatform/cloud-debug-nodejs/badge.svg\n[snyk-url]: https://snyk.io/test/github/GoogleCloudPlatform/cloud-debug-nodejs\n[config-js]: https://github.com/GoogleCloudPlatform/cloud-debug-nodejs/blob/master/src/agent/config.js\n[configuration-object]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/google-cloud/0.45.0/google-cloud\n",

This comment was marked as spam.

Copy link
Copy Markdown
Contributor

@kjin kjin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (CI failure is being fixed in #339)

@DominicKramer DominicKramer merged commit 82fb478 into googleapis:master Oct 10, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants