Skip to content

Commit

Permalink
fix: treat instanceId metadata as a number
Browse files Browse the repository at this point in the history
  • Loading branch information
kjin committed Apr 2, 2018
1 parent 0236217 commit 7833e8f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/trace-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ export class TraceWriter extends common.Service {

this.getHostname((hostname) => {
this.getInstanceId((instanceId) => {
const labels: LabelObject = {};
this.defaultLabels = {};
// tslint:disable-next-line:no-any
const labels: {[key: string]: any} = {};
labels[TraceLabels.AGENT_DATA] =
'node ' + pjson.name + ' v' + pjson.version;
labels[TraceLabels.GCE_HOSTNAME] = hostname;
Expand All @@ -163,8 +165,11 @@ export class TraceWriter extends common.Service {
labels[TraceLabels.GAE_VERSION] = versionLabel;
}
}
Object.freeze(labels);
this.defaultLabels = labels;
// Coerce values to strings.
for (const key of Object.keys(labels)) {
this.defaultLabels[key] = `${labels[key]}`;
}
Object.freeze(this.defaultLabels);
if (--pendingOperations === 0) {
cb();
}
Expand Down Expand Up @@ -192,7 +197,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 7833e8f

Please sign in to comment.