@platformatic/node 2.4.0 → 3.4.1

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 (3) hide show
  1. package/index.js +31 -10
  2. package/package.json +7 -7
  3. package/schema.json +1 -1
package/index.js CHANGED
@@ -53,6 +53,9 @@ export class NodeStackable extends BaseStackable {
53
53
  #isFastify
54
54
  #isKoa
55
55
 
56
+ #startHttpTimer
57
+ #endHttpTimer
58
+
56
59
  constructor (options, root, configManager) {
57
60
  super('nodejs', packageJson.version, options, root, configManager)
58
61
  }
@@ -163,11 +166,11 @@ export class NodeStackable extends BaseStackable {
163
166
  })
164
167
  }
165
168
 
166
- async collectMetrics () {
167
- return {
168
- defaultMetrics: true,
169
- httpMetrics: true
170
- }
169
+ async collectMetrics ({ startHttpTimer, endHttpTimer }) {
170
+ this.#startHttpTimer = startHttpTimer
171
+ this.#endHttpTimer = endHttpTimer
172
+
173
+ return { defaultMetrics: true, httpMetrics: true }
171
174
  }
172
175
 
173
176
  async build () {
@@ -196,12 +199,30 @@ export class NodeStackable extends BaseStackable {
196
199
  if (this.url) {
197
200
  this.logger.trace({ injectParams, url: this.url }, 'injecting via request')
198
201
  res = await injectViaRequest(this.url, injectParams, onInject)
199
- } else if (this.#isFastify) {
200
- this.logger.trace({ injectParams }, 'injecting via fastify')
201
- res = await this.#app.inject(injectParams, onInject)
202
202
  } else {
203
- this.logger.trace({ injectParams }, 'injecting via light-my-request')
204
- res = await inject(this.#dispatcher ?? this.#app, injectParams, onInject)
203
+ if (this.#startHttpTimer && this.#endHttpTimer) {
204
+ this.#startHttpTimer({ request: injectParams })
205
+
206
+ if (onInject) {
207
+ const originalOnInject = onInject
208
+ onInject = (err, response) => {
209
+ this.#endHttpTimer({ request: injectParams, response })
210
+ originalOnInject(err, response)
211
+ }
212
+ }
213
+ }
214
+
215
+ if (this.#isFastify) {
216
+ this.logger.trace({ injectParams }, 'injecting via fastify')
217
+ res = await this.#app.inject(injectParams, onInject)
218
+ } else {
219
+ this.logger.trace({ injectParams }, 'injecting via light-my-request')
220
+ res = await inject(this.#dispatcher ?? this.#app, injectParams, onInject)
221
+ }
222
+
223
+ if (this.#endHttpTimer && !onInject) {
224
+ this.#endHttpTimer({ request: injectParams, response: res })
225
+ }
205
226
  }
206
227
 
207
228
  /* c8 ignore next 3 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/node",
3
- "version": "2.4.0",
3
+ "version": "3.4.1",
4
4
  "description": "Platformatic Node.js Stackable",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -16,10 +16,10 @@
16
16
  "homepage": "https://github.com/platformatic/platformatic#readme",
17
17
  "dependencies": {
18
18
  "light-my-request": "^6.0.0",
19
- "@platformatic/basic": "2.4.0",
20
- "@platformatic/telemetry": "2.4.0",
21
- "@platformatic/utils": "2.4.0",
22
- "@platformatic/config": "2.4.0"
19
+ "@platformatic/basic": "3.4.1",
20
+ "@platformatic/config": "3.4.1",
21
+ "@platformatic/telemetry": "3.4.1",
22
+ "@platformatic/utils": "3.4.1"
23
23
  },
24
24
  "devDependencies": {
25
25
  "borp": "^0.17.0",
@@ -31,8 +31,8 @@
31
31
  "neostandard": "^0.11.1",
32
32
  "tsx": "^4.19.0",
33
33
  "typescript": "^5.5.4",
34
- "@platformatic/composer": "2.4.0",
35
- "@platformatic/service": "2.4.0"
34
+ "@platformatic/composer": "3.4.1",
35
+ "@platformatic/service": "3.4.1"
36
36
  },
37
37
  "scripts": {
38
38
  "test": "npm run lint && borp --concurrency=1 --no-timeout",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/node/2.4.0.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/node/3.4.1.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Node.js Stackable",
5
5
  "type": "object",