1616
1717'use strict' ;
1818
19- var common = require ( '@google-cloud/common ' ) ;
19+ var Debug = require ( './debug.js ' ) ;
2020var Debuglet = require ( './agent/debuglet.js' ) ;
21- var util = require ( 'util' ) ;
22-
23- /**
24- * <p class="notice">
25- * **This is an experimental release of Stackdriver Debug.** This API is not
26- * covered by any SLA of deprecation policy and may be subject to backwards
27- * incompatible changes.
28- * </p>
29- *
30- * This module provides Stackdriver Debugger support for Node.js applications.
31- * [Stackdriver Debugger](https://cloud.google.com/debug/) is a feature of
32- * [Google Cloud Platform](https://cloud.google.com/) that lets you debug your
33- * applications in production without stopping or pausing your application.
34- *
35- * This module provides an agent that lets you automatically enable debugging
36- * without changes to your application.
37- *
38- * @constructor
39- * @alias module:debug
40- *
41- * @resource [What is Stackdriver Debug]{@link https://cloud.google.com/debug/}
42- *
43- * @param {object } options - [Configuration object](#/docs)
44- */
45- function Debug ( options ) {
46- if ( ! ( this instanceof Debug ) ) {
47- options = common . util . normalizeArguments ( this , options ) ;
48- return new Debug ( options ) ;
49- }
50-
51- var config = {
52- projectIdRequired : false ,
53- baseUrl : 'https://clouddebugger.googleapis.com/v2' ,
54- scopes : [ 'https://www.googleapis.com/auth/cloud_debugger' ] ,
55- packageJson : require ( '../package.json' )
56- } ;
57-
58- common . Service . call ( this , config , options ) ;
59-
60- // FIXME(ofrobots): We need our own copy of options because Service may
61- // default to '{{projectId}}' when options doesn't contain the `projectId`.
62- // property. This breaks the SSOT principle. Remove this when
63- // https://github.com/GoogleCloudPlatform/google-cloud-node/issues/1891
64- // is resolved.
65- this . options = options ;
66- }
67- util . inherits ( Debug , common . Service ) ;
6821
22+ // Singleton.
6923var debuglet ;
7024
7125/**
7226 * Start the Debug agent that will make your application available for debugging
7327 * with Stackdriver Debug.
7428 *
75- * @param {object= } config - Debug configuration. TODO(ofrobots): get rid of
76- * config.js and include jsdoc here?
29+ * @param {object= } options - Options
30+ * @param { object= } options.debugAgent - Debug agent configuration
7731 * TODO: add an optional callback function.
7832 *
7933 * @resource [Introductory video]{@link
@@ -82,15 +36,23 @@ var debuglet;
8236 * @example
8337 * debug.startAgent();
8438 */
85- Debug . prototype . startAgent = function ( config ) {
86- // config.forceNewAgent_ is for testing purposes only.
87- if ( debuglet && ! config . forceNewAgent_ ) {
88- throw new Error ( 'Debug Agent has already been started' ) ;
39+ function start ( options ) {
40+ options = options || { } ;
41+ var agentConfig = options . debug || { } ;
42+
43+ // forceNewAgent_ is for testing purposes only.
44+ if ( debuglet && ! agentConfig . forceNewAgent_ ) {
45+ throw new Error ( 'Debug Agent has already been starterd' ) ;
8946 }
9047
91- debuglet = new Debuglet ( this , config ) ;
48+ var debug = new Debug ( options ) ;
49+ debuglet = new Debuglet ( debug , agentConfig ) ;
9250 debuglet . start ( ) ;
93- this . private_ = debuglet ;
94- } ;
9551
96- module . exports = Debug ;
52+ // We return the debuglet to facilitate testing.
53+ return agentConfig . testMode_ ? debuglet : undefined ;
54+ }
55+
56+ module . exports = {
57+ start : start
58+ } ;
0 commit comments