Skip to content

Commit d8ba083

Browse files
committed
Added the ability to add the request info
1 parent 14f9acf commit d8ba083

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

example/express/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ app.get('/boom', function (req, res) {
2121

2222

2323
app.use(function(err, req, res, next) {
24-
client.submitUnhandledException(err, 'express');
24+
client.createUnhandledException(err, 'express').addRequestInfo(req).submit();
2525
res.status(500).send('Something broke!');
2626
});
2727

2828
app.use(function(req, res, next) {
29-
client.submitNotFound(req.originalUrl);
29+
client.createNotFound(req.originalUrl).addRequestInfo(req).submit();
3030
res.status(404).send('Sorry cant find that!');
3131
});
3232

src/EventBuilder.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ export class EventBuilder {
114114
return this;
115115
}
116116

117+
public addRequestInfo(request:any) {
118+
return this.setProperty('@request', request);
119+
}
120+
117121
public submit(): Promise<any> {
118122
return this.client.submitEvent(this.target, this.pluginContextData);
119123
}

src/services/NodeRequestInfoCollector.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@ import { EventPluginContext } from '../plugins/EventPluginContext';
44

55
export class NodeRequestInfoCollector implements IRequestInfoCollector {
66
getRequestInfo(context:EventPluginContext):IRequestInfo {
7-
return undefined;
7+
if (!context.contextData['@request']) {
8+
return null;
9+
}
10+
11+
var request = context.contextData['@request'];
12+
var ri:IRequestInfo = {
13+
client_ip_address: request.ip,
14+
//user_agent: TODO,
15+
is_secure: request.secure,
16+
//http_method: TODO,
17+
host: request.hostname,
18+
//port: TODO,
19+
path: request.path,
20+
post_data: request.body,
21+
//referrer: TODO,
22+
cookies: request.cookies,
23+
query_string: request.params
24+
};
25+
26+
return ri;
827
}
928
}

0 commit comments

Comments
 (0)