Skip to content

Commit

Permalink
feat(tracer.js): add logging, fix issue with capturing 503 on fetch (#6)
Browse files Browse the repository at this point in the history
Co-authored-by: chris harding <chris@epsagon.com>
  • Loading branch information
HardingRU and chris harding authored Aug 3, 2021
1 parent 38f6660 commit 1b76608
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,21 @@ class Span {
this.addData({ response: json });
});
}
if (contentType && contentType.indexOf('text/html; charset=UTF-8') !== -1) {
this.addData({ response: json });
}
}
}

/**
* Add log data to tracer
* @param {string} message to be added as log.
*/
log(message) {
this.data.logs = this.data.logs || [];
this.data.logs.push(`${new Date().toISOString()}: ${message}`);
}

/**
* Calculate tracer start time.
*/
Expand Down Expand Up @@ -265,6 +277,7 @@ export class Tracer extends Span {
'cloudflare.return_value': events[0].response ? events[0].response.body : null,
'cloudflare.requestContext': events[0].request,
'cloudflare.debug_events': this.config.debug ? JSON.stringify(events) : null,
'cloudflare.logs': events[0].logs || [],
},
},
};
Expand Down

0 comments on commit 1b76608

Please sign in to comment.