@@ -2,6 +2,22 @@ const os = require('os')
22const perf = require ( 'perf_hooks' ) . performance
33const version = require ( '../../../../../package.json' ) . version
44
5+ const libuvThreadPoolSize = ( ( ) => {
6+ const ss = process . env . UV_THREADPOOL_SIZE
7+ if ( ss === undefined ) {
8+ // Backend will apply the default size based on Node version.
9+ return undefined
10+ }
11+ // libuv uses atoi to parse the value, which is almost the same as parseInt, except that parseInt
12+ // will return NaN on invalid input, while atoi will return 0. This is handled at return.
13+ const s = parseInt ( ss )
14+ // We dont' interpret the value further here in the library. Backend will interpret the number
15+ // based on Node version. In all currently known Node versions, 0 results in 1 worker thread,
16+ // negative values (because they're assigned to an unsigned int) become very high positive values,
17+ // and the value is finally capped at 1024.
18+ return isNaN ( s ) ? 0 : s
19+ } ) ( )
20+
521class EventSerializer {
622 constructor ( { env, host, service, version, libraryInjected, activation } = { } ) {
723 this . _env = env
@@ -56,11 +72,16 @@ class EventSerializer {
5672 version
5773 } ,
5874 runtime : {
75+ // os.availableParallelism only available in node 18.14.0/19.4.0 and above
76+ available_processors : typeof os . availableParallelism === 'function'
77+ ? os . availableParallelism ( )
78+ : os . cpus ( ) . length ,
5979 // Using `nodejs` for consistency with the existing `runtime` tag.
6080 // Note that the event `family` property uses `node`, as that's what's
6181 // proscribed by the Intake API, but that's an internal enum and is
6282 // not customer visible.
6383 engine : 'nodejs' ,
84+ libuv_threadpool_size : libuvThreadPoolSize ,
6485 // strip off leading 'v'. This makes the format consistent with other
6586 // runtimes (e.g. Ruby) but not with the existing `runtime_version` tag.
6687 // We'll keep it like this as we want cross-engine consistency. We
0 commit comments