Skip to content

Commit

Permalink
Merge pull request #140 from PostHog/track-in-flight-requests
Browse files Browse the repository at this point in the history
Track in-flight requests from posthog-js
  • Loading branch information
macobo authored Dec 1, 2020
2 parents 5c0a9c9 + 6def0ff commit b54e0d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/capture-metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ export class CaptureMetrics {
}

incr(key, by = 1) {
key = `phjs-${key}`
if (this.capture) {
key = `phjs-${key}`
this.metrics[key] = (this.metrics[key] || 0) + by
}
}

decr(key) {
if (this.capture) {
key = `phjs-${key}`
this.metrics[key] = (this.metrics[key] || 0) - 1
}
}
}
2 changes: 2 additions & 0 deletions src/posthog-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ PostHogLib.prototype._send_request = function (url, data, options, callback) {
this._captureMetrics.incr('_send_request')
this._captureMetrics.incr(`_send_request_${options.transport}`)
this._captureMetrics.incr(`_send_request_${classifier}`)
this._captureMetrics.incr('_send_request_inflight')

// needed to correctly format responses
var verbose_mode = this.get_config('verbose')
Expand Down Expand Up @@ -451,6 +452,7 @@ PostHogLib.prototype._send_request = function (url, data, options, callback) {
this._captureMetrics.incr(`xhr-response`)
this._captureMetrics.incr(`xhr-response-${req.status}`)
this._captureMetrics.incr(`xhr-done-${classifier}-${req.status}`)
this._captureMetrics.decr('_send_request_inflight')
// XMLHttpRequest.DONE == 4, except in safari 4
if (req.status === 200) {
if (callback) {
Expand Down

0 comments on commit b54e0d4

Please sign in to comment.