Skip to content

Commit

Permalink
address comments 2
Browse files Browse the repository at this point in the history
  • Loading branch information
kjin committed Apr 2, 2018
1 parent cb9af00 commit f22db89
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/trace-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,31 +140,36 @@ export class TraceWriter extends common.Service {

this.getHostname((hostname) => {
this.getInstanceId((instanceId) => {
const labels: LabelObject = {};
labels[TraceLabels.AGENT_DATA] =
'node ' + pjson.name + ' v' + pjson.version;
labels[TraceLabels.GCE_HOSTNAME] = hostname;
// tslint:disable-next-line:no-any
const addDefaultLabel = (key: string, value: any) => {
this.defaultLabels[key] = `${value}`;
};

this.defaultLabels = {};
addDefaultLabel(
TraceLabels.AGENT_DATA,
'node ' + pjson.name + ' v' + pjson.version);
addDefaultLabel(TraceLabels.GCE_HOSTNAME, hostname);
if (instanceId) {
labels[TraceLabels.GCE_INSTANCE_ID] = `${instanceId}`;
addDefaultLabel(TraceLabels.GCE_INSTANCE_ID, instanceId);
}
const moduleName = this.config.serviceContext.service || hostname;
labels[TraceLabels.GAE_MODULE_NAME] = moduleName;
addDefaultLabel(TraceLabels.GAE_MODULE_NAME, moduleName);

const moduleVersion = this.config.serviceContext.version;
if (moduleVersion) {
labels[TraceLabels.GAE_MODULE_VERSION] = `${moduleVersion}`;
addDefaultLabel(TraceLabels.GAE_MODULE_VERSION, moduleVersion);
const minorVersion = this.config.serviceContext.minorVersion;
if (minorVersion) {
let versionLabel = '';
if (moduleName !== 'default') {
versionLabel = moduleName + ':';
}
versionLabel += moduleVersion + '.' + minorVersion;
labels[TraceLabels.GAE_VERSION] = versionLabel;
addDefaultLabel(TraceLabels.GAE_VERSION, versionLabel);
}
}
Object.freeze(labels);
this.defaultLabels = labels;
Object.freeze(this.defaultLabels);
if (--pendingOperations === 0) {
cb();
}
Expand Down

0 comments on commit f22db89

Please sign in to comment.