@sentry/profiling-node 9.0.0-alpha.0 → 9.0.0-alpha.2
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/LICENSE +1 -1
- package/lib/cjs/index.js +19 -223
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/index.js +21 -224
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/package.json +1 -1
- package/lib/types/integration.d.ts.map +1 -1
- package/lib/types/spanProfileUtils.d.ts.map +1 -1
- package/lib/types/utils.d.ts.map +1 -1
- package/package.json +11 -30
- package/binding.gyp +0 -20
- package/bindings/cpu_profiler.cc +0 -1226
- package/lib/sentry_cpu_profiler-darwin-arm64-108.node +0 -0
- package/lib/sentry_cpu_profiler-darwin-arm64-115.node +0 -0
- package/lib/sentry_cpu_profiler-darwin-arm64-127.node +0 -0
- package/lib/sentry_cpu_profiler-darwin-x64-108.node +0 -0
- package/lib/sentry_cpu_profiler-darwin-x64-115.node +0 -0
- package/lib/sentry_cpu_profiler-darwin-x64-127.node +0 -0
- package/lib/sentry_cpu_profiler-linux-arm64-glibc-108.node +0 -0
- package/lib/sentry_cpu_profiler-linux-arm64-glibc-115.node +0 -0
- package/lib/sentry_cpu_profiler-linux-arm64-glibc-127.node +0 -0
- package/lib/sentry_cpu_profiler-linux-arm64-musl-108.node +0 -0
- package/lib/sentry_cpu_profiler-linux-arm64-musl-115.node +0 -0
- package/lib/sentry_cpu_profiler-linux-arm64-musl-127.node +0 -0
- package/lib/sentry_cpu_profiler-linux-x64-glibc-108.node +0 -0
- package/lib/sentry_cpu_profiler-linux-x64-glibc-115.node +0 -0
- package/lib/sentry_cpu_profiler-linux-x64-glibc-127.node +0 -0
- package/lib/sentry_cpu_profiler-linux-x64-musl-108.node +0 -0
- package/lib/sentry_cpu_profiler-linux-x64-musl-115.node +0 -0
- package/lib/sentry_cpu_profiler-linux-x64-musl-127.node +0 -0
- package/lib/sentry_cpu_profiler-win32-x64-108.node +0 -0
- package/lib/sentry_cpu_profiler-win32-x64-115.node +0 -0
- package/lib/sentry_cpu_profiler-win32-x64-127.node +0 -0
- package/lib/types/cpu_profiler.d.ts +0 -16
- package/lib/types/cpu_profiler.d.ts.map +0 -1
- package/lib/types-ts3.8/cpu_profiler.d.ts +0 -16
- package/scripts/binaries.js +0 -27
- package/scripts/check-build.js +0 -56
- package/scripts/copy-target.js +0 -27
package/lib/esm/index.js
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { platform as platform$1, arch as arch$1 } from 'node:os';
|
|
4
|
-
import { dirname, join, resolve } from 'node:path';
|
|
5
|
-
import { versions, env } from 'node:process';
|
|
6
|
-
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
7
|
-
import { threadId } from 'node:worker_threads';
|
|
8
|
-
import { familySync } from 'detect-libc';
|
|
9
|
-
import { getAbi } from 'node-abi';
|
|
1
|
+
import { CpuProfilerBindings } from '@sentry-internal/node-cpu-profiler';
|
|
2
|
+
import { parseSemver, logger, forEachEnvelopeItem, createEnvelope, getDebugImagesForResources, uuid4, dsnToString, spanIsSampled, spanToJSON, LRUMap, defineIntegration, consoleSandbox, getRootSpan, getIsolationScope, getCurrentScope, getGlobalScope } from '@sentry/core';
|
|
10
3
|
import * as os from 'os';
|
|
11
|
-
import { versions
|
|
12
|
-
import { threadId
|
|
4
|
+
import { versions, env } from 'process';
|
|
5
|
+
import { threadId, isMainThread } from 'worker_threads';
|
|
13
6
|
|
|
14
7
|
/**
|
|
15
8
|
* 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.
|
|
@@ -18,210 +11,12 @@ import { threadId as threadId$1, isMainThread } from 'worker_threads';
|
|
|
18
11
|
*/
|
|
19
12
|
const DEBUG_BUILD = (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__);
|
|
20
13
|
|
|
21
|
-
const stdlib = familySync();
|
|
22
|
-
const platform = process.env['BUILD_PLATFORM'] || platform$1();
|
|
23
|
-
const arch = process.env['BUILD_ARCH'] || arch$1();
|
|
24
|
-
const abi = getAbi(versions.node, 'node');
|
|
25
|
-
const identifier = [platform, arch, stdlib, abi].filter(c => c !== undefined && c !== null).join('-');
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Imports cpp bindings based on the current platform and architecture.
|
|
29
|
-
*/
|
|
30
|
-
// eslint-disable-next-line complexity
|
|
31
|
-
function importCppBindingsModule() {
|
|
32
|
-
// We need to work around using import.meta.url directly with import.meta.url because jest complains about it.
|
|
33
|
-
const importMetaUrl =
|
|
34
|
-
typeof import.meta.url !== 'undefined'
|
|
35
|
-
? // This case is always hit when the SDK is built
|
|
36
|
-
import.meta.url
|
|
37
|
-
: // This case is hit when the tests are run
|
|
38
|
-
pathToFileURL(__filename).href;
|
|
39
|
-
|
|
40
|
-
const createdRequire = createRequire(importMetaUrl);
|
|
41
|
-
const esmCompatibleDirname = dirname(fileURLToPath(importMetaUrl));
|
|
42
|
-
|
|
43
|
-
// If a binary path is specified, use that.
|
|
44
|
-
if (env['SENTRY_PROFILER_BINARY_PATH']) {
|
|
45
|
-
const envPath = env['SENTRY_PROFILER_BINARY_PATH'];
|
|
46
|
-
return createdRequire(envPath);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// If a user specifies a different binary dir, they are in control of the binaries being moved there
|
|
50
|
-
if (env['SENTRY_PROFILER_BINARY_DIR']) {
|
|
51
|
-
const binaryPath = join(resolve(env['SENTRY_PROFILER_BINARY_DIR']), `sentry_cpu_profiler-${identifier}`);
|
|
52
|
-
return createdRequire(`${binaryPath}.node`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// We need the fallthrough so that in the end, we can fallback to the dynamic require.
|
|
56
|
-
// This is for cases where precompiled binaries were not provided, but may have been compiled from source.
|
|
57
|
-
if (platform === 'darwin') {
|
|
58
|
-
if (arch === 'x64') {
|
|
59
|
-
if (abi === '93') {
|
|
60
|
-
return createdRequire('../sentry_cpu_profiler-darwin-x64-93.node');
|
|
61
|
-
}
|
|
62
|
-
if (abi === '108') {
|
|
63
|
-
return createdRequire('../sentry_cpu_profiler-darwin-x64-108.node');
|
|
64
|
-
}
|
|
65
|
-
if (abi === '115') {
|
|
66
|
-
return createdRequire('../sentry_cpu_profiler-darwin-x64-115.node');
|
|
67
|
-
}
|
|
68
|
-
if (abi === '127') {
|
|
69
|
-
return createdRequire('../sentry_cpu_profiler-darwin-x64-127.node');
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (arch === 'arm64') {
|
|
74
|
-
if (abi === '93') {
|
|
75
|
-
return createdRequire('../sentry_cpu_profiler-darwin-arm64-93.node');
|
|
76
|
-
}
|
|
77
|
-
if (abi === '108') {
|
|
78
|
-
return createdRequire('../sentry_cpu_profiler-darwin-arm64-108.node');
|
|
79
|
-
}
|
|
80
|
-
if (abi === '115') {
|
|
81
|
-
return createdRequire('../sentry_cpu_profiler-darwin-arm64-115.node');
|
|
82
|
-
}
|
|
83
|
-
if (abi === '127') {
|
|
84
|
-
return createdRequire('../sentry_cpu_profiler-darwin-arm64-127.node');
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (platform === 'win32') {
|
|
90
|
-
if (arch === 'x64') {
|
|
91
|
-
if (abi === '93') {
|
|
92
|
-
return createdRequire('../sentry_cpu_profiler-win32-x64-93.node');
|
|
93
|
-
}
|
|
94
|
-
if (abi === '108') {
|
|
95
|
-
return createdRequire('../sentry_cpu_profiler-win32-x64-108.node');
|
|
96
|
-
}
|
|
97
|
-
if (abi === '115') {
|
|
98
|
-
return createdRequire('../sentry_cpu_profiler-win32-x64-115.node');
|
|
99
|
-
}
|
|
100
|
-
if (abi === '127') {
|
|
101
|
-
return createdRequire('../sentry_cpu_profiler-win32-x64-127.node');
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (platform === 'linux') {
|
|
107
|
-
if (arch === 'x64') {
|
|
108
|
-
if (stdlib === 'musl') {
|
|
109
|
-
if (abi === '93') {
|
|
110
|
-
return createdRequire('../sentry_cpu_profiler-linux-x64-musl-93.node');
|
|
111
|
-
}
|
|
112
|
-
if (abi === '108') {
|
|
113
|
-
return createdRequire('../sentry_cpu_profiler-linux-x64-musl-108.node');
|
|
114
|
-
}
|
|
115
|
-
if (abi === '115') {
|
|
116
|
-
return createdRequire('../sentry_cpu_profiler-linux-x64-musl-115.node');
|
|
117
|
-
}
|
|
118
|
-
if (abi === '127') {
|
|
119
|
-
return createdRequire('../sentry_cpu_profiler-linux-x64-musl-127.node');
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (stdlib === 'glibc') {
|
|
123
|
-
if (abi === '93') {
|
|
124
|
-
return createdRequire('../sentry_cpu_profiler-linux-x64-glibc-93.node');
|
|
125
|
-
}
|
|
126
|
-
if (abi === '108') {
|
|
127
|
-
return createdRequire('../sentry_cpu_profiler-linux-x64-glibc-108.node');
|
|
128
|
-
}
|
|
129
|
-
if (abi === '115') {
|
|
130
|
-
return createdRequire('../sentry_cpu_profiler-linux-x64-glibc-115.node');
|
|
131
|
-
}
|
|
132
|
-
if (abi === '127') {
|
|
133
|
-
return createdRequire('../sentry_cpu_profiler-linux-x64-glibc-127.node');
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (arch === 'arm64') {
|
|
138
|
-
if (stdlib === 'musl') {
|
|
139
|
-
if (abi === '93') {
|
|
140
|
-
return createdRequire('../sentry_cpu_profiler-linux-arm64-musl-93.node');
|
|
141
|
-
}
|
|
142
|
-
if (abi === '108') {
|
|
143
|
-
return createdRequire('../sentry_cpu_profiler-linux-arm64-musl-108.node');
|
|
144
|
-
}
|
|
145
|
-
if (abi === '115') {
|
|
146
|
-
return createdRequire('../sentry_cpu_profiler-linux-arm64-musl-115.node');
|
|
147
|
-
}
|
|
148
|
-
if (abi === '127') {
|
|
149
|
-
return createdRequire('../sentry_cpu_profiler-linux-arm64-musl-127.node');
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (stdlib === 'glibc') {
|
|
154
|
-
if (abi === '93') {
|
|
155
|
-
return createdRequire('../sentry_cpu_profiler-linux-arm64-glibc-93.node');
|
|
156
|
-
}
|
|
157
|
-
if (abi === '108') {
|
|
158
|
-
return createdRequire('../sentry_cpu_profiler-linux-arm64-glibc-108.node');
|
|
159
|
-
}
|
|
160
|
-
if (abi === '115') {
|
|
161
|
-
return createdRequire('../sentry_cpu_profiler-linux-arm64-glibc-115.node');
|
|
162
|
-
}
|
|
163
|
-
if (abi === '127') {
|
|
164
|
-
return createdRequire('../sentry_cpu_profiler-linux-arm64-glibc-127.node');
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const built_from_source_path = resolve(esmCompatibleDirname, '..', `sentry_cpu_profiler-${identifier}`);
|
|
171
|
-
return createdRequire(`${built_from_source_path}.node`);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const PrivateCpuProfilerBindings = importCppBindingsModule();
|
|
175
|
-
|
|
176
|
-
class Bindings {
|
|
177
|
-
startProfiling(name) {
|
|
178
|
-
if (!PrivateCpuProfilerBindings) {
|
|
179
|
-
DEBUG_BUILD && logger.log('[Profiling] Bindings not loaded, ignoring call to startProfiling.');
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (typeof PrivateCpuProfilerBindings.startProfiling !== 'function') {
|
|
184
|
-
DEBUG_BUILD &&
|
|
185
|
-
logger.log('[Profiling] Native startProfiling function is not available, ignoring call to startProfiling.');
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return PrivateCpuProfilerBindings.startProfiling(name);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
stopProfiling(
|
|
193
|
-
name,
|
|
194
|
-
format,
|
|
195
|
-
) {
|
|
196
|
-
if (!PrivateCpuProfilerBindings) {
|
|
197
|
-
DEBUG_BUILD &&
|
|
198
|
-
logger.log('[Profiling] Bindings not loaded or profile was never started, ignoring call to stopProfiling.');
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (typeof PrivateCpuProfilerBindings.stopProfiling !== 'function') {
|
|
203
|
-
DEBUG_BUILD &&
|
|
204
|
-
logger.log('[Profiling] Native stopProfiling function is not available, ignoring call to stopProfiling.');
|
|
205
|
-
return null;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return PrivateCpuProfilerBindings.stopProfiling(
|
|
209
|
-
name,
|
|
210
|
-
format ,
|
|
211
|
-
threadId,
|
|
212
|
-
!!GLOBAL_OBJ._sentryDebugIds,
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const CpuProfilerBindings = new Bindings();
|
|
218
|
-
|
|
219
14
|
const NODE_VERSION = parseSemver(process.versions.node) ;
|
|
220
15
|
const NODE_MAJOR = NODE_VERSION.major;
|
|
221
16
|
|
|
222
17
|
// We require the file because if we import it, it will be included in the bundle.
|
|
223
18
|
// I guess tsc does not check file contents when it's imported.
|
|
224
|
-
const PROFILER_THREAD_ID_STRING = String(threadId
|
|
19
|
+
const PROFILER_THREAD_ID_STRING = String(threadId);
|
|
225
20
|
const PROFILER_THREAD_NAME = isMainThread ? 'main' : 'worker';
|
|
226
21
|
const FORMAT_VERSION = '1';
|
|
227
22
|
const CONTINUOUS_FORMAT_VERSION = '2';
|
|
@@ -288,7 +83,7 @@ function createProfilingEvent(client, profile, event) {
|
|
|
288
83
|
event_id: event.event_id ?? '',
|
|
289
84
|
transaction: event.transaction ?? '',
|
|
290
85
|
start_timestamp: event.start_timestamp ? event.start_timestamp * 1000 : Date.now(),
|
|
291
|
-
trace_id: event.contexts?.
|
|
86
|
+
trace_id: event.contexts?.trace?.trace_id ?? '',
|
|
292
87
|
profile_id: profile.profile_id,
|
|
293
88
|
});
|
|
294
89
|
}
|
|
@@ -333,7 +128,7 @@ function createProfilePayload(
|
|
|
333
128
|
measurements: cpuProfile.measurements,
|
|
334
129
|
runtime: {
|
|
335
130
|
name: 'node',
|
|
336
|
-
version: versions
|
|
131
|
+
version: versions.node || '',
|
|
337
132
|
},
|
|
338
133
|
os: {
|
|
339
134
|
name: PLATFORM,
|
|
@@ -341,7 +136,7 @@ function createProfilePayload(
|
|
|
341
136
|
build_number: VERSION,
|
|
342
137
|
},
|
|
343
138
|
device: {
|
|
344
|
-
locale: env
|
|
139
|
+
locale: env['LC_ALL'] || env['LC_MESSAGES'] || env['LANG'] || env['LANGUAGE'] || '',
|
|
345
140
|
model: MODEL,
|
|
346
141
|
manufacturer: TYPE,
|
|
347
142
|
architecture: ARCH,
|
|
@@ -539,18 +334,17 @@ function findProfiledTransactionsFromEnvelope(envelope) {
|
|
|
539
334
|
|
|
540
335
|
// First item is the type, so we can skip it, everything else is an event
|
|
541
336
|
for (let j = 1; j < item.length; j++) {
|
|
542
|
-
const event = item[j];
|
|
337
|
+
const event = item[j] ;
|
|
543
338
|
|
|
544
339
|
if (!event) {
|
|
545
340
|
// Shouldn't happen, but lets be safe
|
|
546
341
|
continue;
|
|
547
342
|
}
|
|
548
343
|
|
|
549
|
-
|
|
550
|
-
const profile_id = (event.contexts )?.['profile']?.['profile_id'];
|
|
344
|
+
const profile_id = event.contexts?.profile?.profile_id;
|
|
551
345
|
|
|
552
346
|
if (event && profile_id) {
|
|
553
|
-
events.push(
|
|
347
|
+
events.push(event);
|
|
554
348
|
}
|
|
555
349
|
}
|
|
556
350
|
});
|
|
@@ -733,6 +527,9 @@ var ProfileFormat; (function (ProfileFormat) {
|
|
|
733
527
|
const CHUNK = 1; ProfileFormat[ProfileFormat["CHUNK"] = CHUNK] = "CHUNK";
|
|
734
528
|
})(ProfileFormat || (ProfileFormat = {}));
|
|
735
529
|
|
|
530
|
+
/* eslint-disable max-lines */
|
|
531
|
+
|
|
532
|
+
|
|
736
533
|
const CHUNK_INTERVAL_MS = 5000;
|
|
737
534
|
const PROFILE_MAP = new LRUMap(50);
|
|
738
535
|
const PROFILE_TIMEOUTS = {};
|
|
@@ -823,8 +620,8 @@ function setupAutomatedSpanProfiling(client) {
|
|
|
823
620
|
const profilesToAddToEnvelope = [];
|
|
824
621
|
|
|
825
622
|
for (const profiledTransaction of profiledTransactionEvents) {
|
|
826
|
-
const profileContext = profiledTransaction.contexts?.
|
|
827
|
-
const profile_id = profileContext?.
|
|
623
|
+
const profileContext = profiledTransaction.contexts?.profile;
|
|
624
|
+
const profile_id = profileContext?.profile_id;
|
|
828
625
|
|
|
829
626
|
if (!profile_id) {
|
|
830
627
|
throw new TypeError('[Profiling] cannot find profile for a transaction without a profile context');
|
|
@@ -832,7 +629,7 @@ function setupAutomatedSpanProfiling(client) {
|
|
|
832
629
|
|
|
833
630
|
// Remove the profile from the transaction context before sending, relay will take care of the rest.
|
|
834
631
|
if (profileContext) {
|
|
835
|
-
delete profiledTransaction.contexts?.
|
|
632
|
+
delete profiledTransaction.contexts?.profile;
|
|
836
633
|
}
|
|
837
634
|
|
|
838
635
|
const cpuProfile = takeFromProfileQueue(profile_id);
|
|
@@ -1097,7 +894,7 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
1097
894
|
* Assigns thread_id and thread name context to a profiled event.
|
|
1098
895
|
*/
|
|
1099
896
|
_assignThreadIdContext(event) {
|
|
1100
|
-
if (!event?.
|
|
897
|
+
if (!event?.contexts?.profile) {
|
|
1101
898
|
return;
|
|
1102
899
|
}
|
|
1103
900
|
|
|
@@ -1107,10 +904,10 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
1107
904
|
|
|
1108
905
|
// @ts-expect-error the trace fallback value is wrong, though it should never happen
|
|
1109
906
|
// and in case it does, we dont want to override whatever was passed initially.
|
|
1110
|
-
event.contexts
|
|
1111
|
-
...(event.contexts?.
|
|
907
|
+
event.contexts.trace = {
|
|
908
|
+
...(event.contexts?.trace ?? {}),
|
|
1112
909
|
data: {
|
|
1113
|
-
...(event.contexts?.
|
|
910
|
+
...(event.contexts?.trace?.data ?? {}),
|
|
1114
911
|
['thread.id']: PROFILER_THREAD_ID_STRING,
|
|
1115
912
|
['thread.name']: PROFILER_THREAD_NAME,
|
|
1116
913
|
},
|