@platformatic/wattpm-pprof-capture 3.55.0 → 3.56.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.
package/index.js CHANGED
@@ -1,11 +1,10 @@
1
- import { time, heap, SourceMapper } from '@datadog/pprof'
1
+ import { heap, SourceMapper, time } from '@datadog/pprof'
2
+ import { getITC, getLogger } from '@platformatic/globals'
2
3
  import { performance } from 'node:perf_hooks'
3
4
  import { workerData } from 'node:worker_threads'
4
5
  import { NoProfileAvailableError, NotEnoughELUError, ProfilingAlreadyStartedError, ProfilingNotStartedError } from './lib/errors.js'
5
6
  import { SourceMapperWrapper } from './lib/source-mapper-wrapper.js'
6
7
 
7
- const kITC = Symbol.for('plt.runtime.itc')
8
-
9
8
  // @datadog/pprof >= 5.14.2 introduced a regression in the legacy time profiler
10
9
  // `stop()`: it now clears the internal source mapper (via handleStopNoRestart)
11
10
  // *before* serializing the profile, so transpiled frames (e.g. TypeScript) are
@@ -70,14 +69,15 @@ const profilingState = {
70
69
  }
71
70
 
72
71
  // Keep trying until ITC is available. This is needed because preloads run
73
- // before the app thread initialization, so globalThis.platformatic.messaging
74
- // and ITC don't exist yet.
72
+ // before the app thread initialization, so messaging and ITC don't exist yet.
75
73
  const registerInterval = setInterval(() => {
76
- if (globalThis[kITC]) {
77
- globalThis[kITC].handle('getLastProfile', getLastProfile)
78
- globalThis[kITC].handle('startProfiling', startProfiling)
79
- globalThis[kITC].handle('stopProfiling', stopProfiling)
80
- globalThis[kITC].handle('getProfilingState', getProfilingState)
74
+ const itc = getITC({ throwOnMissing: false })
75
+
76
+ if (itc) {
77
+ itc.handle('getLastProfile', getLastProfile)
78
+ itc.handle('startProfiling', startProfiling)
79
+ itc.handle('stopProfiling', stopProfiling)
80
+ itc.handle('getProfilingState', getProfilingState)
81
81
  clearInterval(registerInterval)
82
82
  }
83
83
  }, 10)
@@ -228,18 +228,19 @@ function startIfOverThreshold (type, state, wasRunning = state.profilerStarted)
228
228
  // Was not running: only start if ELU rises above start threshold
229
229
  : isAboveThreshold(state)
230
230
 
231
+ const logger = getLogger({ throwOnMissing: false })
231
232
  if (shouldRun) {
232
233
  // ELU is high enough, start/restart profiling
233
- if (!wasRunning && !state.profilerStarted && globalThis.platformatic?.logger) {
234
- globalThis.platformatic.logger.debug(
234
+ if (!wasRunning && !state.profilerStarted && logger) {
235
+ logger.debug(
235
236
  { type, eluThreshold: state.eluThreshold, currentELU },
236
237
  'Starting profiler due to ELU threshold exceeded'
237
238
  )
238
239
  }
239
240
  startProfiler(type, state, state.options)
240
- } else if (!shouldRun && wasRunning && globalThis.platformatic?.logger && state.eluThreshold != null) {
241
+ } else if (!shouldRun && wasRunning && state.eluThreshold != null && logger) {
241
242
  // Log when deciding not to restart after stopping (only in rotation context)
242
- globalThis.platformatic.logger.debug(
243
+ logger.debug(
243
244
  { type, eluThreshold: state.eluThreshold, currentELU },
244
245
  'Pausing profiler due to ELU below threshold'
245
246
  )
@@ -257,8 +258,9 @@ async function initializeSourceMapper (options = {}) {
257
258
  // Get the application directory from workerData
258
259
  const appPath = workerData?.applicationConfig?.path
259
260
  if (!appPath) {
260
- if (globalThis.platformatic?.logger) {
261
- globalThis.platformatic.logger.debug('No application path available for sourcemap resolution')
261
+ const logger = getLogger({ throwOnMissing: false })
262
+ if (logger) {
263
+ logger.debug('No application path available for sourcemap resolution')
262
264
  }
263
265
  return
264
266
  }
@@ -284,16 +286,18 @@ async function initializeSourceMapper (options = {}) {
284
286
  // Wrap the SourceMapper to fix Windows path normalization
285
287
  sourceMapper = new SourceMapperWrapper(innerMapper)
286
288
 
287
- if (globalThis.platformatic?.logger) {
289
+ const logger = getLogger({ throwOnMissing: false })
290
+ if (logger) {
288
291
  const hasMappings = sourceMapper && typeof sourceMapper.hasMappingInfo === 'function'
289
- globalThis.platformatic.logger.info(
292
+ logger.info(
290
293
  { appPath, hasSourceMapper: !!sourceMapper, hasMappingInfo: hasMappings },
291
294
  'SourceMapper initialized for profiling'
292
295
  )
293
296
  }
294
297
  } catch (err) {
295
- if (globalThis.platformatic?.logger) {
296
- globalThis.platformatic.logger.warn(
298
+ const logger = getLogger({ throwOnMissing: false })
299
+ if (logger) {
300
+ logger.warn(
297
301
  { err: err.message, stack: err.stack },
298
302
  'Failed to initialize SourceMapper'
299
303
  )
@@ -1,3 +1,4 @@
1
+ import { getLogger } from '@platformatic/globals'
1
2
  import { promises as fs } from 'node:fs'
2
3
  import path from 'node:path'
3
4
  import { createRequire } from 'node:module'
@@ -184,7 +185,7 @@ function resolveModulePath (appPath, moduleName) {
184
185
  */
185
186
  export async function loadNodeModulesSourceMaps (appPath, moduleNames, debug = false) {
186
187
  const entries = new Map()
187
- const logger = globalThis.platformatic?.logger
188
+ const logger = getLogger({ throwOnMissing: false })
188
189
 
189
190
  if (debug && logger) {
190
191
  logger.debug({ appPath, moduleNames }, 'Loading source maps from node_modules')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/wattpm-pprof-capture",
3
- "version": "3.55.0",
3
+ "version": "3.56.0",
4
4
  "description": "pprof profiling capture for wattpm",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -17,7 +17,8 @@
17
17
  "dependencies": {
18
18
  "@datadog/pprof": "^5.3.0",
19
19
  "@fastify/error": "^4.0.0",
20
- "undici": "^7.0.0"
20
+ "undici": "^7.27.2",
21
+ "@platformatic/globals": "3.56.0"
21
22
  },
22
23
  "devDependencies": {
23
24
  "@types/node": "^22.0.0",
@@ -26,8 +27,8 @@
26
27
  "neostandard": "^0.12.0",
27
28
  "pprof-format": "^2.1.0",
28
29
  "typescript": "^5.0.0",
29
- "@platformatic/foundation": "3.55.0",
30
- "@platformatic/service": "3.55.0"
30
+ "@platformatic/service": "3.56.0",
31
+ "@platformatic/foundation": "3.56.0"
31
32
  },
32
33
  "engines": {
33
34
  "node": ">=22.19.0"