-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic performance trace reporting
- Loading branch information
1 parent
f1f065a
commit 9f0cbc5
Showing
3 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//since we need to test crashing the app | ||
/*global app*/ | ||
var Countly = require("../lib/countly.js"); | ||
|
||
Countly.init({ | ||
app_key: "YOUR_APP_KEY", | ||
url: "https://try.count.ly", //your server goes here | ||
debug: true | ||
}); | ||
|
||
//report app start trace | ||
Countly.report_app_start(); | ||
|
||
//example express middleware | ||
function expressMiddleware(req, res, next) { | ||
var trace = { | ||
type: "network", | ||
name: req.baseUrl + req.path, | ||
stz: Date.now(), | ||
}; | ||
|
||
var processed = false; | ||
|
||
function processRequest() { | ||
if (!processed) { | ||
processed = true; | ||
trace.etz = Date.now(); | ||
trace.apm_metrics = { | ||
response_time: trace.etz - trace.stz, | ||
response_code: res.statusCode | ||
}; | ||
Countly.report_trace(trace); | ||
} | ||
} | ||
|
||
res.on('finish', processRequest); | ||
|
||
res.on('close', processRequest); | ||
|
||
next(); | ||
} | ||
|
||
app.use(expressMiddleware); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters