Skip to content

Commit

Permalink
fix: improve logs from the trace writer (#800)
Browse files Browse the repository at this point in the history
Adds hostnames to error messages coming from the Trace Writer. It also changes one error message to not print "status code unknown" (this is misleading because unknown actually means an error was thrown when making an outgoing request).
  • Loading branch information
kjin authored Jul 18, 2018
1 parent 63b13ca commit 4ac6ded
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/trace-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ export class TraceWriter extends common.Service {
this.logger.error(
'TraceWriter#initialize: Unable to acquire the project number',
'automatically from the GCP metadata service. Please provide a',
'valid project ID as environmental variable GCLOUD_PROJECT, or as',
`config.projectId passed to start. Original error: ${err}`);
'valid project ID as environmental variable GCLOUD_PROJECT, or',
`as config.projectId passed to start. Original error: ${err}`);
cb(err);
});

Expand Down Expand Up @@ -190,8 +190,9 @@ export class TraceWriter extends common.Service {
if (err.code !== 'ENOTFOUND') {
// We are running on GCP.
this.logger.warn(
'TraceWriter#getHostname: Unable to retrieve GCE hostname',
`from the GCP metadata service. Original error: ${err}`);
'TraceWriter#getHostname: Encountered an error while',
'retrieving GCE hostname from the GCP metadata service',
`(metadata.google.internal): ${err}`);
}
cb(os.hostname());
});
Expand All @@ -206,8 +207,9 @@ export class TraceWriter extends common.Service {
if (err.code !== 'ENOTFOUND') {
// We are running on GCP.
this.logger.warn(
'TraceWriter#getInstanceId: Unable to retrieve GCE instance ID',
`from the GCP metadata service. Original error: ${err}`);
'TraceWriter#getInstanceId: Encountered an error while',
'retrieving GCE instance ID from the GCP metadata service',
`(metadata.google.internal): ${err}`);
}
cb();
});
Expand Down Expand Up @@ -328,15 +330,16 @@ export class TraceWriter extends common.Service {
* @param json The stringified json representation of the queued traces.
*/
publish(json: string) {
const uri = `https://cloudtrace.googleapis.com/v1/projects/${
this.projectId}/traces`;
const hostname = 'cloudtrace.googleapis.com';
const uri = `https://${hostname}/v1/projects/${this.projectId}/traces`;
const options = {method: 'PATCH', uri, body: json, headers};
this.logger.info('TraceWriter#publish: Publishing to ' + uri);
this.request(options, (err, body?, response?) => {
const statusCode = (response && response.statusCode) || 'unknown';
const statusCode = response && response.statusCode;
if (err) {
this.logger.error(`TraceWriter#publish: Received error status code ${
statusCode}. Original error: ${err}`);
this.logger.error(`TraceWriter#publish: Received error ${
statusCode ? `with status code ${statusCode}` :
''} while publishing traces to ${hostname}: ${err}`);
} else {
this.logger.info(
`TraceWriter#publish: Published w/ status code: ${statusCode}`);
Expand Down

0 comments on commit 4ac6ded

Please sign in to comment.