Add the start() Method and the Ability to Specify the Service Name/Version in the Debug Config#167
Conversation
Now the cloud debugger is started by explicitly calling the newly exposed `start()` method that accepts an optional config object. Currently if the `start()` method is not called within 5 seconds it is automatically called and the user is issued a message detailing that the `start()` method will need to be explicitly called in future releases.
In particular, the `GAE_MODULE_NAME` environment variable takes priority over the `serviceName` config item and the `GAE_MODULE_VERSION` environment variable takes priority over the `serviceVersion` config item.
In particular, if the config object supplied to the `start()` method has a `debug` attribute then the value of that attribute will be used as the config. Otherwise, as long as the config object is defined, it is assumed to directly contain the config options.
The values of `serviceName` and `serviceVersion` were previously determined in `lib/debugletapi.js` by determining if certain environment variables are set. Now that check is done in `index.js`.
The unit tests have been updated so that the `start()` method is called when requiring `index.js`.
If the GCLOUD_DEBUG_LOGLEVEL environment variable is set then its value will be used as the log level instead of the value specified in the supplied configuration file. However, the unit test had the value of GCLOUD_DEBUG_LOGLEVEL and the value in the config file both set to the same value. Thus, the test wouldn't verify if the environment variable was actually taking precedence.
The tests verify that the value of the `GAE_MODULE_NAME` environment variable (if defined) takes precendence over the config value of `serviceName`. Similar checks are also done for the environment variable `GAE_MODULE_VERSION` and the config option `serviceVersion`.
|
@GoogleCloudPlatform/node-team PTAL This PR replaces PR #166, which I closed to avoid confusion. |
The checking of whether the service version was 'default' was incorrectly only checking the environment variable GAE_MODULE_VERSION.
|
@GoogleCloudPlatform/node-team Everybody on |
index.js
Outdated
| } | ||
| } | ||
|
|
||
| // exports is populated by the agent |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
index.js
Outdated
| log.error('The cloud-debug agent has been automatically started. ' + | ||
| 'This action will be deprecated in the future.'); | ||
| } | ||
| }, 5*1000); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
The test in `test-module.js` that tests that two calls to `require()` return the same object was updated to call the `start()` method on both requires.
index.js
Outdated
| setTimeout(function() { | ||
| if (!started_){ | ||
| start(); | ||
| log_.error('The cloud-debug agent has been automatically started. ' + |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Now the service name and version is specified as
```
serviceContext: {
service: 'service-name',
version: '1'
}
```
index.js
Outdated
| var config = initConfig(); | ||
| module.exports = { | ||
| start: start, | ||
| hasStarted: hasStarted |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
That is, the config is not expected to contain a `debug` attribute that contains the actual configuration options. This change makes the debug agent consistent with the trace agent.
In particular, tests were added to verify that the order of priority from highest to lowest is ``` env var -> config given to start() -> config file ```
|
Could you update the title to reflect that this introduces the |
This PR adds a configuration section to the README file that should have been added in PR #167.
This PR contains an update where the new start() method can be called on the object returned from require('@google/cloud-debug) to start the debugger while specifying a configuration.
Additionally, the configuration can now specify custom values for the app's service name and service version.
This PR replaces PR #166