@sentry/profiling-node 8.54.0 → 9.0.0-alpha.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/README.md CHANGED
@@ -12,8 +12,7 @@
12
12
 
13
13
  ## Installation
14
14
 
15
- Profiling works as an extension of tracing so you will need both @sentry/node and @sentry/profiling-node installed. The
16
- minimum required major version of @sentry/node that supports profiling is 7.x.
15
+ Profiling works as an extension of tracing so you will need both @sentry/node and @sentry/profiling-node installed.
17
16
 
18
17
  ```bash
19
18
  # Using yarn
@@ -84,7 +83,7 @@ After the binaries are built, you should see them inside the profiling-node/lib
84
83
 
85
84
  ### Prebuilt binaries
86
85
 
87
- We currently ship prebuilt binaries for a few of the most common platforms and node versions (v16-22).
86
+ We currently ship prebuilt binaries for a few of the most common platforms and node versions (v18-22).
88
87
 
89
88
  - macOS x64
90
89
  - Linux ARM64 (musl)
package/lib/cjs/index.js CHANGED
@@ -1,10 +1,4 @@
1
- var {
2
- _nullishCoalesce,
3
- _optionalChain,
4
- _optionalChainDelete
5
- } = require('@sentry/core');
6
-
7
- Object.defineProperty(exports, '__esModule', { value: true });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
8
2
 
9
3
  const core = require('@sentry/core');
10
4
  const node_module = require('node:module');
@@ -228,7 +222,6 @@ const CpuProfilerBindings = new Bindings();
228
222
  const NODE_VERSION = core.parseSemver(process.versions.node) ;
229
223
  const NODE_MAJOR = NODE_VERSION.major;
230
224
 
231
- function _nullishCoalesce$1(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
232
225
  // We require the file because if we import it, it will be included in the bundle.
233
226
  // I guess tsc does not check file contents when it's imported.
234
227
  const PROFILER_THREAD_ID_STRING = String(worker_threads.threadId);
@@ -236,16 +229,12 @@ const PROFILER_THREAD_NAME = worker_threads.isMainThread ? 'main' : 'worker';
236
229
  const FORMAT_VERSION = '1';
237
230
  const CONTINUOUS_FORMAT_VERSION = '2';
238
231
 
239
- // Os machine was backported to 16.18, but this was not reflected in the types
240
- // @ts-expect-error ignore missing
241
- const machine = typeof os.machine === 'function' ? os.machine() : os.arch();
242
-
243
232
  // Machine properties (eval only once)
244
233
  const PLATFORM = os.platform();
245
234
  const RELEASE = os.release();
246
235
  const VERSION = os.version();
247
236
  const TYPE = os.type();
248
- const MODEL = machine;
237
+ const MODEL = os.machine();
249
238
  const ARCH = os.arch();
250
239
 
251
240
  /**
@@ -297,12 +286,12 @@ function createProfilingEvent(client, profile, event) {
297
286
  }
298
287
 
299
288
  return createProfilePayload(client, profile, {
300
- release: _nullishCoalesce$1(event.release, () => ( '')),
301
- environment: _nullishCoalesce$1(event.environment, () => ( '')),
302
- event_id: _nullishCoalesce$1(event.event_id, () => ( '')),
303
- transaction: _nullishCoalesce$1(event.transaction, () => ( '')),
289
+ release: event.release ?? '',
290
+ environment: event.environment ?? '',
291
+ event_id: event.event_id ?? '',
292
+ transaction: event.transaction ?? '',
304
293
  start_timestamp: event.start_timestamp ? event.start_timestamp * 1000 : Date.now(),
305
- trace_id: _nullishCoalesce$1(_optionalChain$1([event, 'access', _ => _.contexts, 'optionalAccess', _2 => _2['trace'], 'optionalAccess', _3 => _3['trace_id']]), () => ( '')),
294
+ trace_id: event.contexts?.['trace']?.['trace_id'] ?? '',
306
295
  profile_id: profile.profile_id,
307
296
  });
308
297
  }
@@ -331,7 +320,7 @@ function createProfilePayload(
331
320
  // Log a warning if the profile has an invalid traceId (should be uuidv4).
332
321
  // All profiles and transactions are rejected if this is the case and we want to
333
322
  // warn users that this is happening if they enable debug flag
334
- if (trace_id && trace_id.length !== 32) {
323
+ if (trace_id?.length !== 32) {
335
324
  DEBUG_BUILD && core.logger.log(`[Profiling] Invalid traceId: ${trace_id} on profiled event`);
336
325
  }
337
326
 
@@ -399,7 +388,7 @@ function createProfileChunkPayload(
399
388
  // Log a warning if the profile has an invalid traceId (should be uuidv4).
400
389
  // All profiles and transactions are rejected if this is the case and we want to
401
390
  // warn users that this is happening if they enable debug flag
402
- if (trace_id && trace_id.length !== 32) {
391
+ if (trace_id?.length !== 32) {
403
392
  DEBUG_BUILD && core.logger.log(`[Profiling] Invalid traceId: ${trace_id} on profiled event`);
404
393
  }
405
394
 
@@ -408,8 +397,8 @@ function createProfileChunkPayload(
408
397
  const profile = {
409
398
  chunk_id: chunk_id,
410
399
  client_sdk: {
411
- name: _nullishCoalesce$1(_optionalChain$1([sdk, 'optionalAccess', _4 => _4.name]), () => ( 'sentry.javascript.node')),
412
- version: _nullishCoalesce$1(_optionalChain$1([sdk, 'optionalAccess', _5 => _5.version]), () => ( '0.0.0')),
400
+ name: sdk?.name ?? 'sentry.javascript.node',
401
+ version: sdk?.version ?? '0.0.0',
413
402
  },
414
403
  profiler_id: profiler_id,
415
404
  platform: 'node',
@@ -441,9 +430,9 @@ function createProfilingChunkEvent(
441
430
  }
442
431
 
443
432
  return createProfileChunkPayload(client, profile, {
444
- release: _nullishCoalesce$1(options.release, () => ( '')),
445
- environment: _nullishCoalesce$1(options.environment, () => ( '')),
446
- trace_id: _nullishCoalesce$1(identifiers.trace_id, () => ( '')),
433
+ release: options.release ?? '',
434
+ environment: options.environment ?? '',
435
+ trace_id: identifiers.trace_id ?? '',
447
436
  chunk_id: identifiers.chunk_id,
448
437
  profiler_id: identifiers.profiler_id,
449
438
  sdk,
@@ -561,7 +550,7 @@ function findProfiledTransactionsFromEnvelope(envelope) {
561
550
  }
562
551
 
563
552
  // @ts-expect-error profile_id is not part of the metadata type
564
- const profile_id = _optionalChain$1([(event.contexts ), 'optionalAccess', _6 => _6['profile'], 'optionalAccess', _7 => _7['profile_id']]);
553
+ const profile_id = (event.contexts )?.['profile']?.['profile_id'];
565
554
 
566
555
  if (event && profile_id) {
567
556
  events.push(item[j] );
@@ -615,7 +604,7 @@ function makeProfileChunkEnvelope(
615
604
  function applyDebugMetadata(client, resource_paths) {
616
605
  const options = client.getOptions();
617
606
 
618
- if (!options || !options.stackParser) {
607
+ if (!options?.stackParser) {
619
608
  return [];
620
609
  }
621
610
 
@@ -664,10 +653,6 @@ function maybeProfileSpan(
664
653
  profilesSampleRate = profilesSampler({
665
654
  name: spanName,
666
655
  attributes: data,
667
- transactionContext: {
668
- name: spanName,
669
- parentSampled,
670
- },
671
656
  parentSampled,
672
657
  ...customSamplingContext,
673
658
  });
@@ -746,7 +731,7 @@ function stopSpanProfile(span, profile_id) {
746
731
  return profile;
747
732
  }
748
733
 
749
- var ProfileFormat;(function (ProfileFormat) {
734
+ var ProfileFormat; (function (ProfileFormat) {
750
735
  const THREAD = 0; ProfileFormat[ProfileFormat["THREAD"] = THREAD] = "THREAD";
751
736
  const CHUNK = 1; ProfileFormat[ProfileFormat["CHUNK"] = CHUNK] = "CHUNK";
752
737
  })(ProfileFormat || (ProfileFormat = {}));
@@ -783,8 +768,7 @@ function setupAutomatedSpanProfiling(client) {
783
768
  const options = client.getOptions();
784
769
  // Not intended for external use, hence missing types, but we want to profile a couple of things at Sentry that
785
770
  // currently exceed the default timeout set by the SDKs.
786
- const maxProfileDurationMs =
787
- (options._experiments && options._experiments['maxProfileDurationMs']) || MAX_PROFILE_DURATION_MS;
771
+ const maxProfileDurationMs = options._experiments?.maxProfileDurationMs || MAX_PROFILE_DURATION_MS;
788
772
 
789
773
  if (PROFILE_TIMEOUTS[profile_id]) {
790
774
  global.clearTimeout(PROFILE_TIMEOUTS[profile_id]);
@@ -842,8 +826,8 @@ function setupAutomatedSpanProfiling(client) {
842
826
  const profilesToAddToEnvelope = [];
843
827
 
844
828
  for (const profiledTransaction of profiledTransactionEvents) {
845
- const profileContext = _optionalChain([profiledTransaction, 'access', _ => _.contexts, 'optionalAccess', _2 => _2['profile']]);
846
- const profile_id = _optionalChain([profileContext, 'optionalAccess', _3 => _3['profile_id']]);
829
+ const profileContext = profiledTransaction.contexts?.['profile'];
830
+ const profile_id = profileContext?.['profile_id'];
847
831
 
848
832
  if (!profile_id) {
849
833
  throw new TypeError('[Profiling] cannot find profile for a transaction without a profile context');
@@ -851,7 +835,7 @@ function setupAutomatedSpanProfiling(client) {
851
835
 
852
836
  // Remove the profile from the transaction context before sending, relay will take care of the rest.
853
837
  if (profileContext) {
854
- _optionalChainDelete([profiledTransaction, 'access', _4 => _4.contexts, 'optionalAccess', _5 => delete _5['profile']]);
838
+ delete profiledTransaction.contexts?.['profile'];
855
839
  }
856
840
 
857
841
  const cpuProfile = takeFromProfileQueue(profile_id);
@@ -869,6 +853,11 @@ function setupAutomatedSpanProfiling(client) {
869
853
  client.emit('preprocessEvent', profile, {
870
854
  event_id: profiledTransaction.event_id,
871
855
  });
856
+
857
+ // @ts-expect-error profile does not inherit from Event
858
+ client.emit('postprocessEvent', profile, {
859
+ event_id: profiledTransaction.event_id,
860
+ });
872
861
  }
873
862
 
874
863
  addProfilesToEnvelope(envelope, profilesToAddToEnvelope);
@@ -951,7 +940,7 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
951
940
  * Stops profiling of the current chunks and flushes the profile to Sentry
952
941
  */
953
942
  _chunkStop() {
954
- if (_optionalChain([this, 'access', _6 => _6._chunkData, 'optionalAccess', _7 => _7.timer])) {
943
+ if (this._chunkData?.timer) {
955
944
  global.clearTimeout(this._chunkData.timer);
956
945
  this._chunkData.timer = undefined;
957
946
  DEBUG_BUILD && core.logger.log(`[Profiling] Stopping profiling chunk: ${this._chunkData.id}`);
@@ -961,9 +950,9 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
961
950
  core.logger.log('[Profiling] Failed to collect profile, sentry client was never attached to the profiler.');
962
951
  return;
963
952
  }
964
- if (!_optionalChain([this, 'access', _8 => _8._chunkData, 'optionalAccess', _9 => _9.id])) {
953
+ if (!this._chunkData?.id) {
965
954
  DEBUG_BUILD &&
966
- core.logger.log(`[Profiling] Failed to collect profile for: ${_optionalChain([this, 'access', _10 => _10._chunkData, 'optionalAccess', _11 => _11.id])}, the chunk_id is missing.`);
955
+ core.logger.log(`[Profiling] Failed to collect profile for: ${this._chunkData?.id}, the chunk_id is missing.`);
967
956
  return;
968
957
  }
969
958
 
@@ -987,7 +976,7 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
987
976
  this._client,
988
977
  this._client.getOptions(),
989
978
  profile,
990
- _optionalChain([this, 'access', _12 => _12._client, 'access', _13 => _13.getSdkMetadata, 'call', _14 => _14(), 'optionalAccess', _15 => _15.sdk]),
979
+ this._client.getSdkMetadata()?.sdk,
991
980
  {
992
981
  chunk_id: this._chunkData.id,
993
982
  trace_id: this._chunkData.startTraceID,
@@ -1030,7 +1019,7 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
1030
1019
  const metadata = this._client.getSdkMetadata();
1031
1020
  const tunnel = this._client.getOptions().tunnel;
1032
1021
 
1033
- const envelope = makeProfileChunkEnvelope(chunk, _optionalChain([metadata, 'optionalAccess', _16 => _16.sdk]), tunnel, dsn);
1022
+ const envelope = makeProfileChunkEnvelope(chunk, metadata?.sdk, tunnel, dsn);
1034
1023
  transport.send(envelope).then(null, reason => {
1035
1024
  DEBUG_BUILD && core.logger.error('Error while sending profile chunk envelope:', reason);
1036
1025
  });
@@ -1111,7 +1100,7 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
1111
1100
  * Assigns thread_id and thread name context to a profiled event.
1112
1101
  */
1113
1102
  _assignThreadIdContext(event) {
1114
- if (!_optionalChain([event, 'optionalAccess', _17 => _17['contexts'], 'optionalAccess', _18 => _18['profile']])) {
1103
+ if (!event?.['contexts']?.['profile']) {
1115
1104
  return;
1116
1105
  }
1117
1106
 
@@ -1122,9 +1111,9 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
1122
1111
  // @ts-expect-error the trace fallback value is wrong, though it should never happen
1123
1112
  // and in case it does, we dont want to override whatever was passed initially.
1124
1113
  event.contexts['trace'] = {
1125
- ...(_nullishCoalesce(_optionalChain([event, 'access', _19 => _19.contexts, 'optionalAccess', _20 => _20['trace']]), () => ( {}))),
1114
+ ...(event.contexts?.['trace'] ?? {}),
1126
1115
  data: {
1127
- ...(_nullishCoalesce(_optionalChain([event, 'access', _21 => _21.contexts, 'optionalAccess', _22 => _22['trace'], 'optionalAccess', _23 => _23['data']]), () => ( {}))),
1116
+ ...(event.contexts?.['trace']?.['data'] ?? {}),
1128
1117
  ['thread.id']: PROFILER_THREAD_ID_STRING,
1129
1118
  ['thread.name']: PROFILER_THREAD_NAME,
1130
1119
  },