@sentry/profiling-node 9.0.0-alpha.0 → 9.0.0-alpha.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 (39) hide show
  1. package/LICENSE +1 -1
  2. package/lib/cjs/index.js +19 -223
  3. package/lib/cjs/index.js.map +1 -1
  4. package/lib/esm/index.js +21 -224
  5. package/lib/esm/index.js.map +1 -1
  6. package/lib/esm/package.json +1 -1
  7. package/lib/types/integration.d.ts.map +1 -1
  8. package/lib/types/spanProfileUtils.d.ts.map +1 -1
  9. package/lib/types/utils.d.ts.map +1 -1
  10. package/package.json +11 -30
  11. package/binding.gyp +0 -20
  12. package/bindings/cpu_profiler.cc +0 -1226
  13. package/lib/sentry_cpu_profiler-darwin-arm64-108.node +0 -0
  14. package/lib/sentry_cpu_profiler-darwin-arm64-115.node +0 -0
  15. package/lib/sentry_cpu_profiler-darwin-arm64-127.node +0 -0
  16. package/lib/sentry_cpu_profiler-darwin-x64-108.node +0 -0
  17. package/lib/sentry_cpu_profiler-darwin-x64-115.node +0 -0
  18. package/lib/sentry_cpu_profiler-darwin-x64-127.node +0 -0
  19. package/lib/sentry_cpu_profiler-linux-arm64-glibc-108.node +0 -0
  20. package/lib/sentry_cpu_profiler-linux-arm64-glibc-115.node +0 -0
  21. package/lib/sentry_cpu_profiler-linux-arm64-glibc-127.node +0 -0
  22. package/lib/sentry_cpu_profiler-linux-arm64-musl-108.node +0 -0
  23. package/lib/sentry_cpu_profiler-linux-arm64-musl-115.node +0 -0
  24. package/lib/sentry_cpu_profiler-linux-arm64-musl-127.node +0 -0
  25. package/lib/sentry_cpu_profiler-linux-x64-glibc-108.node +0 -0
  26. package/lib/sentry_cpu_profiler-linux-x64-glibc-115.node +0 -0
  27. package/lib/sentry_cpu_profiler-linux-x64-glibc-127.node +0 -0
  28. package/lib/sentry_cpu_profiler-linux-x64-musl-108.node +0 -0
  29. package/lib/sentry_cpu_profiler-linux-x64-musl-115.node +0 -0
  30. package/lib/sentry_cpu_profiler-linux-x64-musl-127.node +0 -0
  31. package/lib/sentry_cpu_profiler-win32-x64-108.node +0 -0
  32. package/lib/sentry_cpu_profiler-win32-x64-115.node +0 -0
  33. package/lib/sentry_cpu_profiler-win32-x64-127.node +0 -0
  34. package/lib/types/cpu_profiler.d.ts +0 -16
  35. package/lib/types/cpu_profiler.d.ts.map +0 -1
  36. package/lib/types-ts3.8/cpu_profiler.d.ts +0 -16
  37. package/scripts/binaries.js +0 -27
  38. package/scripts/check-build.js +0 -56
  39. package/scripts/copy-target.js +0 -27
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022-2024 Functional Software, Inc. dba Sentry
3
+ Copyright (c) 2022 Functional Software, Inc. dba Sentry
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
package/lib/cjs/index.js CHANGED
@@ -1,19 +1,11 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
+ const nodeCpuProfiler = require('@sentry-internal/node-cpu-profiler');
3
4
  const core = require('@sentry/core');
4
- const node_module = require('node:module');
5
- const node_os = require('node:os');
6
- const node_path = require('node:path');
7
- const node_process = require('node:process');
8
- const node_url = require('node:url');
9
- const node_worker_threads = require('node:worker_threads');
10
- const detectLibc = require('detect-libc');
11
- const nodeAbi = require('node-abi');
12
5
  const os = require('os');
13
6
  const process$1 = require('process');
14
7
  const worker_threads = require('worker_threads');
15
8
 
16
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
17
9
  /**
18
10
  * This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.
19
11
  *
@@ -21,204 +13,6 @@ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentS
21
13
  */
22
14
  const DEBUG_BUILD = (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__);
23
15
 
24
- const stdlib = detectLibc.familySync();
25
- const platform = process.env['BUILD_PLATFORM'] || node_os.platform();
26
- const arch = process.env['BUILD_ARCH'] || node_os.arch();
27
- const abi = nodeAbi.getAbi(node_process.versions.node, 'node');
28
- const identifier = [platform, arch, stdlib, abi].filter(c => c !== undefined && c !== null).join('-');
29
-
30
- /**
31
- * Imports cpp bindings based on the current platform and architecture.
32
- */
33
- // eslint-disable-next-line complexity
34
- function importCppBindingsModule() {
35
- // We need to work around using import.meta.url directly with import.meta.url because jest complains about it.
36
- const importMetaUrl =
37
- typeof (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)) !== 'undefined'
38
- ? // This case is always hit when the SDK is built
39
- (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href))
40
- : // This case is hit when the tests are run
41
- node_url.pathToFileURL(__filename).href;
42
-
43
- const createdRequire = node_module.createRequire(importMetaUrl);
44
- const esmCompatibleDirname = node_path.dirname(node_url.fileURLToPath(importMetaUrl));
45
-
46
- // If a binary path is specified, use that.
47
- if (node_process.env['SENTRY_PROFILER_BINARY_PATH']) {
48
- const envPath = node_process.env['SENTRY_PROFILER_BINARY_PATH'];
49
- return createdRequire(envPath);
50
- }
51
-
52
- // If a user specifies a different binary dir, they are in control of the binaries being moved there
53
- if (node_process.env['SENTRY_PROFILER_BINARY_DIR']) {
54
- const binaryPath = node_path.join(node_path.resolve(node_process.env['SENTRY_PROFILER_BINARY_DIR']), `sentry_cpu_profiler-${identifier}`);
55
- return createdRequire(`${binaryPath}.node`);
56
- }
57
-
58
- // We need the fallthrough so that in the end, we can fallback to the dynamic require.
59
- // This is for cases where precompiled binaries were not provided, but may have been compiled from source.
60
- if (platform === 'darwin') {
61
- if (arch === 'x64') {
62
- if (abi === '93') {
63
- return createdRequire('../sentry_cpu_profiler-darwin-x64-93.node');
64
- }
65
- if (abi === '108') {
66
- return createdRequire('../sentry_cpu_profiler-darwin-x64-108.node');
67
- }
68
- if (abi === '115') {
69
- return createdRequire('../sentry_cpu_profiler-darwin-x64-115.node');
70
- }
71
- if (abi === '127') {
72
- return createdRequire('../sentry_cpu_profiler-darwin-x64-127.node');
73
- }
74
- }
75
-
76
- if (arch === 'arm64') {
77
- if (abi === '93') {
78
- return createdRequire('../sentry_cpu_profiler-darwin-arm64-93.node');
79
- }
80
- if (abi === '108') {
81
- return createdRequire('../sentry_cpu_profiler-darwin-arm64-108.node');
82
- }
83
- if (abi === '115') {
84
- return createdRequire('../sentry_cpu_profiler-darwin-arm64-115.node');
85
- }
86
- if (abi === '127') {
87
- return createdRequire('../sentry_cpu_profiler-darwin-arm64-127.node');
88
- }
89
- }
90
- }
91
-
92
- if (platform === 'win32') {
93
- if (arch === 'x64') {
94
- if (abi === '93') {
95
- return createdRequire('../sentry_cpu_profiler-win32-x64-93.node');
96
- }
97
- if (abi === '108') {
98
- return createdRequire('../sentry_cpu_profiler-win32-x64-108.node');
99
- }
100
- if (abi === '115') {
101
- return createdRequire('../sentry_cpu_profiler-win32-x64-115.node');
102
- }
103
- if (abi === '127') {
104
- return createdRequire('../sentry_cpu_profiler-win32-x64-127.node');
105
- }
106
- }
107
- }
108
-
109
- if (platform === 'linux') {
110
- if (arch === 'x64') {
111
- if (stdlib === 'musl') {
112
- if (abi === '93') {
113
- return createdRequire('../sentry_cpu_profiler-linux-x64-musl-93.node');
114
- }
115
- if (abi === '108') {
116
- return createdRequire('../sentry_cpu_profiler-linux-x64-musl-108.node');
117
- }
118
- if (abi === '115') {
119
- return createdRequire('../sentry_cpu_profiler-linux-x64-musl-115.node');
120
- }
121
- if (abi === '127') {
122
- return createdRequire('../sentry_cpu_profiler-linux-x64-musl-127.node');
123
- }
124
- }
125
- if (stdlib === 'glibc') {
126
- if (abi === '93') {
127
- return createdRequire('../sentry_cpu_profiler-linux-x64-glibc-93.node');
128
- }
129
- if (abi === '108') {
130
- return createdRequire('../sentry_cpu_profiler-linux-x64-glibc-108.node');
131
- }
132
- if (abi === '115') {
133
- return createdRequire('../sentry_cpu_profiler-linux-x64-glibc-115.node');
134
- }
135
- if (abi === '127') {
136
- return createdRequire('../sentry_cpu_profiler-linux-x64-glibc-127.node');
137
- }
138
- }
139
- }
140
- if (arch === 'arm64') {
141
- if (stdlib === 'musl') {
142
- if (abi === '93') {
143
- return createdRequire('../sentry_cpu_profiler-linux-arm64-musl-93.node');
144
- }
145
- if (abi === '108') {
146
- return createdRequire('../sentry_cpu_profiler-linux-arm64-musl-108.node');
147
- }
148
- if (abi === '115') {
149
- return createdRequire('../sentry_cpu_profiler-linux-arm64-musl-115.node');
150
- }
151
- if (abi === '127') {
152
- return createdRequire('../sentry_cpu_profiler-linux-arm64-musl-127.node');
153
- }
154
- }
155
-
156
- if (stdlib === 'glibc') {
157
- if (abi === '93') {
158
- return createdRequire('../sentry_cpu_profiler-linux-arm64-glibc-93.node');
159
- }
160
- if (abi === '108') {
161
- return createdRequire('../sentry_cpu_profiler-linux-arm64-glibc-108.node');
162
- }
163
- if (abi === '115') {
164
- return createdRequire('../sentry_cpu_profiler-linux-arm64-glibc-115.node');
165
- }
166
- if (abi === '127') {
167
- return createdRequire('../sentry_cpu_profiler-linux-arm64-glibc-127.node');
168
- }
169
- }
170
- }
171
- }
172
-
173
- const built_from_source_path = node_path.resolve(esmCompatibleDirname, '..', `sentry_cpu_profiler-${identifier}`);
174
- return createdRequire(`${built_from_source_path}.node`);
175
- }
176
-
177
- const PrivateCpuProfilerBindings = importCppBindingsModule();
178
-
179
- class Bindings {
180
- startProfiling(name) {
181
- if (!PrivateCpuProfilerBindings) {
182
- DEBUG_BUILD && core.logger.log('[Profiling] Bindings not loaded, ignoring call to startProfiling.');
183
- return;
184
- }
185
-
186
- if (typeof PrivateCpuProfilerBindings.startProfiling !== 'function') {
187
- DEBUG_BUILD &&
188
- core.logger.log('[Profiling] Native startProfiling function is not available, ignoring call to startProfiling.');
189
- return;
190
- }
191
-
192
- return PrivateCpuProfilerBindings.startProfiling(name);
193
- }
194
-
195
- stopProfiling(
196
- name,
197
- format,
198
- ) {
199
- if (!PrivateCpuProfilerBindings) {
200
- DEBUG_BUILD &&
201
- core.logger.log('[Profiling] Bindings not loaded or profile was never started, ignoring call to stopProfiling.');
202
- return null;
203
- }
204
-
205
- if (typeof PrivateCpuProfilerBindings.stopProfiling !== 'function') {
206
- DEBUG_BUILD &&
207
- core.logger.log('[Profiling] Native stopProfiling function is not available, ignoring call to stopProfiling.');
208
- return null;
209
- }
210
-
211
- return PrivateCpuProfilerBindings.stopProfiling(
212
- name,
213
- format ,
214
- node_worker_threads.threadId,
215
- !!core.GLOBAL_OBJ._sentryDebugIds,
216
- );
217
- }
218
- }
219
-
220
- const CpuProfilerBindings = new Bindings();
221
-
222
16
  const NODE_VERSION = core.parseSemver(process.versions.node) ;
223
17
  const NODE_MAJOR = NODE_VERSION.major;
224
18
 
@@ -291,7 +85,7 @@ function createProfilingEvent(client, profile, event) {
291
85
  event_id: event.event_id ?? '',
292
86
  transaction: event.transaction ?? '',
293
87
  start_timestamp: event.start_timestamp ? event.start_timestamp * 1000 : Date.now(),
294
- trace_id: event.contexts?.['trace']?.['trace_id'] ?? '',
88
+ trace_id: event.contexts?.trace?.trace_id ?? '',
295
89
  profile_id: profile.profile_id,
296
90
  });
297
91
  }
@@ -542,18 +336,17 @@ function findProfiledTransactionsFromEnvelope(envelope) {
542
336
 
543
337
  // First item is the type, so we can skip it, everything else is an event
544
338
  for (let j = 1; j < item.length; j++) {
545
- const event = item[j];
339
+ const event = item[j] ;
546
340
 
547
341
  if (!event) {
548
342
  // Shouldn't happen, but lets be safe
549
343
  continue;
550
344
  }
551
345
 
552
- // @ts-expect-error profile_id is not part of the metadata type
553
- const profile_id = (event.contexts )?.['profile']?.['profile_id'];
346
+ const profile_id = event.contexts?.profile?.profile_id;
554
347
 
555
348
  if (event && profile_id) {
556
- events.push(item[j] );
349
+ events.push(event);
557
350
  }
558
351
  }
559
352
  });
@@ -693,7 +486,7 @@ function maybeProfileSpan(
693
486
  }
694
487
 
695
488
  const profile_id = core.uuid4();
696
- CpuProfilerBindings.startProfiling(profile_id);
489
+ nodeCpuProfiler.CpuProfilerBindings.startProfiling(profile_id);
697
490
  DEBUG_BUILD && core.logger.log(`[Profiling] started profiling transaction: ${core.spanToJSON(span).description}`);
698
491
 
699
492
  // set transaction context - do this regardless if profiling fails down the line
@@ -713,7 +506,7 @@ function stopSpanProfile(span, profile_id) {
713
506
  return null;
714
507
  }
715
508
 
716
- const profile = CpuProfilerBindings.stopProfiling(profile_id, 0);
509
+ const profile = nodeCpuProfiler.CpuProfilerBindings.stopProfiling(profile_id, 0);
717
510
  DEBUG_BUILD && core.logger.log(`[Profiling] stopped profiling of transaction: ${core.spanToJSON(span).description}`);
718
511
 
719
512
  // In case of an overlapping span, stopProfiling may return null and silently ignore the overlapping profile.
@@ -736,6 +529,9 @@ var ProfileFormat; (function (ProfileFormat) {
736
529
  const CHUNK = 1; ProfileFormat[ProfileFormat["CHUNK"] = CHUNK] = "CHUNK";
737
530
  })(ProfileFormat || (ProfileFormat = {}));
738
531
 
532
+ /* eslint-disable max-lines */
533
+
534
+
739
535
  const CHUNK_INTERVAL_MS = 5000;
740
536
  const PROFILE_MAP = new core.LRUMap(50);
741
537
  const PROFILE_TIMEOUTS = {};
@@ -826,8 +622,8 @@ function setupAutomatedSpanProfiling(client) {
826
622
  const profilesToAddToEnvelope = [];
827
623
 
828
624
  for (const profiledTransaction of profiledTransactionEvents) {
829
- const profileContext = profiledTransaction.contexts?.['profile'];
830
- const profile_id = profileContext?.['profile_id'];
625
+ const profileContext = profiledTransaction.contexts?.profile;
626
+ const profile_id = profileContext?.profile_id;
831
627
 
832
628
  if (!profile_id) {
833
629
  throw new TypeError('[Profiling] cannot find profile for a transaction without a profile context');
@@ -835,7 +631,7 @@ function setupAutomatedSpanProfiling(client) {
835
631
 
836
632
  // Remove the profile from the transaction context before sending, relay will take care of the rest.
837
633
  if (profileContext) {
838
- delete profiledTransaction.contexts?.['profile'];
634
+ delete profiledTransaction.contexts?.profile;
839
635
  }
840
636
 
841
637
  const cpuProfile = takeFromProfileQueue(profile_id);
@@ -956,7 +752,7 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
956
752
  return;
957
753
  }
958
754
 
959
- const profile = CpuProfilerBindings.stopProfiling(this._chunkData.id, ProfileFormat.CHUNK);
755
+ const profile = nodeCpuProfiler.CpuProfilerBindings.stopProfiling(this._chunkData.id, ProfileFormat.CHUNK);
960
756
 
961
757
  if (!profile) {
962
758
  DEBUG_BUILD && core.logger.log(`[Profiling] _chunkiledStartTraceID to collect profile for: ${this._chunkData.id}`);
@@ -1034,7 +830,7 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
1034
830
  core.getCurrentScope().getPropagationContext().traceId || core.getIsolationScope().getPropagationContext().traceId;
1035
831
  const chunk = this._initializeChunk(traceId);
1036
832
 
1037
- CpuProfilerBindings.startProfiling(chunk.id);
833
+ nodeCpuProfiler.CpuProfilerBindings.startProfiling(chunk.id);
1038
834
  DEBUG_BUILD && core.logger.log(`[Profiling] starting profiling chunk: ${chunk.id}`);
1039
835
 
1040
836
  chunk.timer = global.setTimeout(() => {
@@ -1100,7 +896,7 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
1100
896
  * Assigns thread_id and thread name context to a profiled event.
1101
897
  */
1102
898
  _assignThreadIdContext(event) {
1103
- if (!event?.['contexts']?.['profile']) {
899
+ if (!event?.contexts?.profile) {
1104
900
  return;
1105
901
  }
1106
902
 
@@ -1110,10 +906,10 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
1110
906
 
1111
907
  // @ts-expect-error the trace fallback value is wrong, though it should never happen
1112
908
  // and in case it does, we dont want to override whatever was passed initially.
1113
- event.contexts['trace'] = {
1114
- ...(event.contexts?.['trace'] ?? {}),
909
+ event.contexts.trace = {
910
+ ...(event.contexts?.trace ?? {}),
1115
911
  data: {
1116
- ...(event.contexts?.['trace']?.['data'] ?? {}),
912
+ ...(event.contexts?.trace?.data ?? {}),
1117
913
  ['thread.id']: PROFILER_THREAD_ID_STRING,
1118
914
  ['thread.name']: PROFILER_THREAD_NAME,
1119
915
  },