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

Commit e410c36

Browse files
authored
API changes bring us closer to google-cloud (#180)
This change adapts the primary interface of this module to align it with the API exposed by all the other Google Cloud API Client Libraries available via the `google-cloud` modules [1]. The primary change is that we return a Debug construtor as the return value from the module. This, in the future, will provide a Client Library interface to the Debug APIs. This can be used for programatic access to list or modify breakpoints, logpoints etc. The constructor, like other API clients, accepts authentication and other general configuration. An instantiated debug object exposes a function `startAgent` that can be used to activate the process-wide agent that enables the debugging of an application using the Stackdriver Debug UI in the Google Cloud console. [1]: https://github.com/GoogleCloudPlatform/google-cloud-node
1 parent d6cb2fb commit e410c36

36 files changed

+256
-294
lines changed

.clang-format

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BasedOnStyle: Google
2+
Language: JavaScript

bin/run-e2e.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ echo "npm install in test/e2e"
1616
npm install
1717
echo -en "travis_fold:end:npm_install_test_e2e\\r" | tr / _
1818

19-
node test.js || exit 1
19+
for t in test-breakpoints.js test-log-throttling.js ; do
20+
echo "==== Running ${t} ===="
21+
node $t || exit
22+
done
2023

2124
cd -

package.json

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,20 @@
11
{
2-
"name": "@google/cloud-debug",
3-
"version": "0.9.1",
4-
"description": "Node.js support for Google Cloud Debug",
5-
"main": "index.js",
6-
"repository": "GoogleCloudPlatform/cloud-debug-nodejs",
7-
"scripts": {
8-
"test": "./bin/run-test.sh",
9-
"changelog": "./bin/run-changelog.sh",
10-
"coverage": "./bin/run-test.sh -c",
11-
"bump": "./bin/run-bump.sh",
12-
"closure": "./node_modules/.bin/closure-npc"
13-
},
2+
"name": "@google-cloud/debug",
3+
"version": "0.10.0",
4+
"author": "Google Inc.",
5+
"description": "Stackdriver Debug Agent for Node.js",
6+
"main": "./src/index.js",
7+
"repository": "googlecloudplatform/google-cloud-node",
148
"keywords": [
159
"google",
1610
"debugger",
1711
"debug",
18-
"cloud"
19-
],
20-
"author": "Google Inc.",
21-
"contributors": [
22-
{
23-
"name": "Ali Ijaz Sheikh",
24-
"email": "[email protected]"
25-
},
26-
{
27-
"name": "Matt Loring",
28-
"email": "[email protected]"
29-
},
30-
{
31-
"name": "Steven Kollars",
32-
"email": "[email protected]"
33-
},
34-
{
35-
"name": "Boris Bokowski",
36-
"email": "[email protected]"
37-
},
38-
{
39-
"name": "Chuck Jazdzewski",
40-
"email": "[email protected]"
41-
},
42-
{
43-
"name": "Scott McMaster",
44-
"email": "[email protected]"
45-
}
12+
"cloud",
13+
"cloud debug",
14+
"cloud debugger",
15+
"stackdriver debug",
16+
"stackdriver debugger",
17+
"stackdriver"
4618
],
4719
"license": "Apache-2.0",
4820
"engines": {
@@ -52,6 +24,7 @@
5224
"changelog-maker": "^2.2.2",
5325
"closure-npc": "*",
5426
"coveralls": "^2.11.2",
27+
"extend": "^3.0.0",
5528
"istanbul": "^0.4.1",
5629
"jshint": "^2.7.0",
5730
"mocha": "^3.0.0",
@@ -70,5 +43,12 @@
7043
"semver": "^5.1.0",
7144
"source-map": "^0.5.1",
7245
"split": "^1.0.0"
46+
},
47+
"scripts": {
48+
"test": "./bin/run-test.sh",
49+
"changelog": "./bin/run-changelog.sh",
50+
"coverage": "./bin/run-test.sh -c",
51+
"bump": "./bin/run-bump.sh",
52+
"closure": "./node_modules/.bin/closure-npc"
7353
}
7454
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

index.js renamed to src/index.js

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,42 @@
1616

1717
'use strict';
1818

19-
// NOTE: this file is on the critical path for the startup of the user's
20-
// application. The path-length here needs to be minimal.
21-
2219
var logger = require('@google/cloud-diagnostics-common').logger;
23-
var Debuglet = require('./lib/debuglet.js');
20+
var Debuglet = require('./debuglet.js');
2421
var path = require('path');
2522
var _ = require('lodash');
2623

24+
/**
25+
* <p class="notice">
26+
* **This is an experimental release of Stackdriver Debug.** This API is not
27+
* covered by any SLA of deprecation policy and may be subject to backwards
28+
* incompatible changes.
29+
* </p>
30+
*
31+
* This module provides Stackdriver Debugger support for Node.js applications.
32+
* [Stackdriver Debugger](https://cloud.google.com/debug/) is a feature of
33+
* [Google Cloud Platform](https://cloud.google.com/) that lets you debug your
34+
* applications in production without stopping or pausing your application.
35+
*
36+
* This module provides an agent that lets you automatically enable debugging
37+
* without changes to your application.
38+
*
39+
* @constructor
40+
* @alias module:debug
41+
*
42+
* @resource [What is Stackdriver Debug]{@link https://cloud.google.com/debug/}
43+
*
44+
* @param {object} options - [Configuration object](#/docs). NOTE: at the moment
45+
* this parameter is ignored.
46+
*/
47+
function Debug(options) {
48+
if (!(this instanceof Debug)) {
49+
//TODO(ofrobots)
50+
//options = common.util.normalizeArguments(this, options);
51+
return new Debug(options);
52+
}
53+
}
54+
2755
var initConfig = function(config_) {
2856
var config = config_ || {};
2957

@@ -56,32 +84,32 @@ var initConfig = function(config_) {
5684
return config;
5785
};
5886

59-
module.exports = {
60-
start: start
61-
};
87+
var debuglet;
6288

63-
var log_;
64-
function start(config_) {
65-
if (start.wasSuccessful_) {
66-
return log_.error('The cloud-debug agent has already been started.');
89+
/**
90+
* Start the Debug agent that will make your application available for debugging
91+
* with Stackdriver Debug.
92+
*
93+
* @param {object=} config - Debug configuration. TODO(ofrobots): get rid of
94+
* config.js and include jsdoc here
95+
* TODO: add an optional callback function.
96+
*
97+
* @resource [Introductory video]{@link https://www.youtube.com/watch?v=tyHcK_kAOpw}
98+
*
99+
* @example
100+
* debug.startAgent();
101+
*/
102+
Debug.prototype.startAgent = function(config_) {
103+
if (debuglet) {
104+
throw new Error('Debug Agent has already been started');
67105
}
68-
69106
var config = initConfig(config_);
70-
log_ = logger.create(config.logLevel, '@google/cloud-debug');
71107
if (config.enabled) {
72-
var debuglet = new Debuglet(config, log_);
108+
debuglet = new Debuglet(config, logger.create(config.logLevel, '@google-cloud/debug'));
73109
debuglet.start();
74-
module.exports.private_ = debuglet;
75-
start.wasSuccessful_ = true;
110+
this.private_ = debuglet;
76111
}
77-
}
112+
};
113+
114+
module.exports = Debug;
78115

79-
setTimeout(function() {
80-
if (!start.wasSuccessful_){
81-
start();
82-
log_.error('The @google/cloud-debug agent now needs the start() ' +
83-
'function to be called in ordered to start operating. To ease ' +
84-
'migration we start the agent automatically after a 1 second delay, '+
85-
'but this behaviour will be dropped in a future semver major release.');
86-
}
87-
}, 1000);
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)