@contrast/agentify 1.5.1 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/sources.js +20 -3
  2. package/package.json +4 -1
package/lib/sources.js CHANGED
@@ -14,19 +14,36 @@
14
14
  */
15
15
 
16
16
  'use strict';
17
- const patchType = 'http-sources';
17
+
18
+ const { Event } = require('@contrast/common');
19
+ const patchType = 'sources';
18
20
 
19
21
  module.exports = function(core) {
20
22
  const {
23
+ events: { lifecycle },
21
24
  instrumentation: { instrument },
22
25
  scopes: { sources: sourcesStorage }
23
26
  } = core;
24
27
 
25
28
  function aroundHook(serverType) {
26
29
  return function around(next, data) {
27
- const { args: [event] } = data;
30
+ const { args: [event, req, res] } = data;
31
+
28
32
  if (event !== 'request') return next();
29
- const store = { serverType };
33
+
34
+ const store = {
35
+ sourceInfo: {
36
+ port: req.socket.address?.()?.port || 0,
37
+ protocol: serverType === 'http' ? 'http' : 'https',
38
+ serverType,
39
+ time: Date.now(),
40
+ }
41
+ };
42
+
43
+ res.on('finish', () => {
44
+ lifecycle.emit(Event.RESPONSE_FINISH, store);
45
+ });
46
+
30
47
  return sourcesStorage.run(store, next);
31
48
  };
32
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/agentify",
3
- "version": "1.5.1",
3
+ "version": "1.7.0",
4
4
  "description": "Configures Contrast agent services and instrumentation within an application",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -15,5 +15,8 @@
15
15
  },
16
16
  "scripts": {
17
17
  "test": "../scripts/test.sh"
18
+ },
19
+ "dependencies": {
20
+ "@contrast/common": "1.9.0"
18
21
  }
19
22
  }