Skip to content

Commit

Permalink
fix: treat instanceId metadata as a number (#713)
Browse files Browse the repository at this point in the history
PR-URL: #713
  • Loading branch information
kjin authored Apr 2, 2018
1 parent 0236217 commit 1434d5d
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/trace-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,31 +140,35 @@ 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 Expand Up @@ -192,7 +196,7 @@ export class TraceWriter extends common.Service {
});
}

getInstanceId(cb: (instanceId?: string) => void) {
getInstanceId(cb: (instanceId?: number) => void) {
gcpMetadata.instance({property: 'id', headers})
.then((res) => {
cb(res.data); // instance ID
Expand Down

0 comments on commit 1434d5d

Please sign in to comment.