diff --git a/package-lock.json b/package-lock.json index 0c66f5c4..3b9fa4d8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1748,8 +1748,20 @@ "integrity": "sha1-yCYERJEt2M7szYOHYdVvRik3vQI=", "requires": { "async": "2.5.0", + "gcp-metadata": "0.2.0", "google-auth-library": "0.10.0", "request": "2.81.0" + }, + "dependencies": { + "gcp-metadata": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-0.2.0.tgz", + "integrity": "sha1-Ytr8pl86YxvIzi7Dt3Zh9fk4ego=", + "requires": { + "extend": "3.0.1", + "retry-request": "2.0.5" + } + } } }, "google-p12-pem": { diff --git a/src/agent/debuglet.ts b/src/agent/debuglet.ts index be18c8ac..6f9d84f2 100644 --- a/src/agent/debuglet.ts +++ b/src/agent/debuglet.ts @@ -30,6 +30,7 @@ import * as _ from 'lodash'; import * as path from 'path'; import * as semver from 'semver'; import * as util from 'util'; +import * as utils from './util/utils'; import * as http from 'http'; import {Controller} from './controller'; @@ -206,6 +207,13 @@ export class Debuglet extends EventEmitter { */ async start(): Promise { const that = this; + process.on('warning', (warning) => { + if ((warning as any).code === + 'INSPECTOR_ASYNC_STACK_TRACES_NOT_AVAILABLE') { + that.logger_.info(utils.messages.ASYNC_TRACES_WARNING); + } + }); + const stat = promisify(fs.stat); try { diff --git a/src/agent/util/utils.ts b/src/agent/util/utils.ts index b07cbcfe..3f0593c2 100644 --- a/src/agent/util/utils.ts +++ b/src/agent/util/utils.ts @@ -24,7 +24,11 @@ export const messages = { CAPTURE_BREAKPOINT_DATA: 'Error trying to capture snapshot data: ', INVALID_LINE_NUMBER: 'Invalid snapshot position: ', COULD_NOT_FIND_OUTPUT_FILE: - 'Could not determine the output file associated with the transpiled input file' + 'Could not determine the output file associated with the transpiled input file', + ASYNC_TRACES_WARNING: + 'The Stackdriver Debugger for Node.js does not require V8 Inspector ' + + 'async stack traces. The INSPECTOR_ASYNC_STACK_TRACES_NOT_AVAILABLE ' + + 'can be ignored.' }; export interface Listener { diff --git a/test/test-debuglet.ts b/test/test-debuglet.ts index e53275b3..f37defcc 100644 --- a/test/test-debuglet.ts +++ b/test/test-debuglet.ts @@ -17,6 +17,7 @@ import * as stackdriver from '../src/types/stackdriver'; import {DebugAgentConfig} from '../src/agent/config'; import {Debuggee} from '../src/debuggee'; +import * as semver from 'semver'; import * as _ from 'lodash'; import * as path from 'path'; @@ -29,6 +30,7 @@ import * as dns from 'dns'; import * as extend from 'extend'; const metadata: {project: any, instance: any} = require('gcp-metadata'); import {Debug} from '../src/client/stackdriver/debug'; +import * as utils from '../src/agent/util/utils' const DEBUGGEE_ID = 'bar'; const API = 'https://clouddebugger.googleapis.com'; @@ -289,16 +291,19 @@ describe('Debuglet', function() { }); describe('setup', function() { - before(function() { oldGP = process.env.GCLOUD_PROJECT; }); + before(function() { + oldGP = process.env.GCLOUD_PROJECT; + }); after(function() { process.env.GCLOUD_PROJECT = oldGP; }); - beforeEach(function() { delete process.env.GCLOUD_PROJECT; nocks.oauth2(); }); - afterEach(function() { nock.cleanAll(); }); + afterEach(function() { + nock.cleanAll(); + }); it('should merge config correctly', function() { const testValue = 2 * defaultConfig.capture.maxExpandFrames; @@ -315,6 +320,40 @@ describe('Debuglet', function() { assert.deepEqual(mergedConfig, compareConfig); }); + it('should elaborate on inspector warning on 32 bit but not on 64 bit', + function(done) { + const projectId = '11020304f2934-a'; + const debug = new Debug( + {projectId: projectId, credentials: fakeCredentials}); + const debuglet = new Debuglet(debug, defaultConfig); + let logText = ''; + debuglet.logger_.info = function(s: string) { + logText += s; + }; + nocks.projectId('project-via-metadata'); + const scope = nock(API) + .post(REGISTER_PATH) + .reply(200, {debuggee: {id: DEBUGGEE_ID}}); + + debuglet.once('registered', function(id: string) { + assert.equal(id, DEBUGGEE_ID); + // TODO: Handle the case where debuglet.debuggee is undefined + assert.equal((debuglet.debuggee_ as Debuggee).project, projectId); + const arch = process.arch; + if (semver.satisfies(process.version, '>=8.5') && + (arch === 'ia32' || arch === 'x86')) { + assert(logText.includes(utils.messages.ASYNC_TRACES_WARNING)); + } else { + assert(!logText.includes(utils.messages.ASYNC_TRACES_WARNING)); + } + debuglet.stop(); + scope.done(); + done(); + }); + + debuglet.start(); + }); + it('should not start when projectId is not available', function(done) { const savedGetProjectId = Debuglet.getProjectId; Debuglet.getProjectId = () => {