Skip to content

Commit

Permalink
Handle remaining todos in code
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Loring committed Jan 14, 2016
1 parent 67f6c67 commit 7a61849
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
4 changes: 1 addition & 3 deletions lib/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ function findModulePath(request, parent) {
var paths = resolvedModule[1];
for (var i = 0, PL = paths.length; i < PL; i++) {
if (mainScriptDir.indexOf(paths[i]) === 0) {
// This is unsafe on windows if request contains a namespace
// TODO: convert path separators in request
return path.join(paths[i], request);
return path.join(paths[i], request.replace('/', path.sep));
}
}
return null;
Expand Down
9 changes: 8 additions & 1 deletion lib/trace-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var TraceWriter = require('./trace-writer.js');
var uuid = require('uuid');
var constants = require('./constants.js');
var tracingPolicy = require('./tracing-policy.js');
var isEqual = require('lodash.isequal');

/** @type {TraceAgent} */
var traceAgent;
Expand Down Expand Up @@ -51,6 +52,7 @@ function TraceAgent(config, logger) {
TraceAgent.prototype.stop = function() {
hooks.deactivate();
cls.destroyNamespace();
this.traceWriter.stop();
this.namespace = null;
traceAgent = null;
this.logger.info('trace agent deactivated');
Expand Down Expand Up @@ -234,7 +236,12 @@ TraceAgent.prototype.addContextToHeaders = function(spanData, headers) {
module.exports = {
get: function(config, logger) {
if (traceAgent) {
// TODO: log error if config object is different from traceAgent.config
if (!isEqual(config, traceAgent.config_)) {
traceAgent.logger.warn('New configuration does not match configuration' +
'of existing agent. The old configuration will be used.\nNew: ' +
JSON.stringify(config) + '\nExisting: ' +
JSON.stringify(traceAgent.config_));
}
return traceAgent;
}
traceAgent = new TraceAgent(config, logger);
Expand Down
15 changes: 11 additions & 4 deletions lib/trace-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ function TraceWriter(logger, config) {
/** @private {Object} default labels to be attached to written spans */
this.defaultLabels_ = {};

/** @private {Boolean} whether the trace writer is active */
this.isActive = true;

// Schedule periodic flushing of the buffer, but only if we are able to get
// the project number (potentially from the network.)
// TODO(ofrobots): if the agent gets stopped, we need to stop flush interval
// too.
var that = this;
that.getProjectNumber(function(err, project) {
if (err) { return; } // ignore as index.js takes care of this.
Expand Down Expand Up @@ -88,6 +89,10 @@ function TraceWriter(logger, config) {
});
}

TraceWriter.prototype.stop = function() {
this.isActive = false;
};

TraceWriter.prototype.getHostname = function(cb) {
var that = this;
utils.getHostname(headers, function(err, hostname) {
Expand Down Expand Up @@ -169,8 +174,10 @@ TraceWriter.prototype.scheduleFlush_ = function(project) {
this.flushBuffer_(project);

// Do it again after delay
setTimeout(this.scheduleFlush_.bind(this, project),
this.config_.flushDelaySeconds * 1000).unref();
if (this.isActive) {
setTimeout(this.scheduleFlush_.bind(this, project),
this.config_.flushDelaySeconds * 1000).unref();
}
};

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"dependencies": {
"@google/cloud-diagnostics-common": "^0.2.1",
"continuation-local-storage": "^3.1.4",
"lodash.isequal": "^4.0.0",
"methods": "^1.1.1",
"semver": "^5.0.1",
"shimmer": "^1.0.0",
Expand Down

0 comments on commit 7a61849

Please sign in to comment.