@sentry/profiling-node 8.54.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.
- package/LICENSE +1 -1
- package/README.md +2 -3
- package/lib/cjs/index.js +45 -260
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/index.js +46 -255
- 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 +13 -32
- 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-arm64-93.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-darwin-x64-93.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-glibc-93.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-arm64-musl-93.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-glibc-93.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-linux-x64-musl-93.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/sentry_cpu_profiler-win32-x64-93.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/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2022
|
|
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/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.
|
|
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 (
|
|
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,25 +1,11 @@
|
|
|
1
|
-
|
|
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
|
|
|
3
|
+
const nodeCpuProfiler = require('@sentry-internal/node-cpu-profiler');
|
|
9
4
|
const core = require('@sentry/core');
|
|
10
|
-
const node_module = require('node:module');
|
|
11
|
-
const node_os = require('node:os');
|
|
12
|
-
const node_path = require('node:path');
|
|
13
|
-
const node_process = require('node:process');
|
|
14
|
-
const node_url = require('node:url');
|
|
15
|
-
const node_worker_threads = require('node:worker_threads');
|
|
16
|
-
const detectLibc = require('detect-libc');
|
|
17
|
-
const nodeAbi = require('node-abi');
|
|
18
5
|
const os = require('os');
|
|
19
6
|
const process$1 = require('process');
|
|
20
7
|
const worker_threads = require('worker_threads');
|
|
21
8
|
|
|
22
|
-
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
23
9
|
/**
|
|
24
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.
|
|
25
11
|
*
|
|
@@ -27,208 +13,9 @@ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentS
|
|
|
27
13
|
*/
|
|
28
14
|
const DEBUG_BUILD = (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__);
|
|
29
15
|
|
|
30
|
-
const stdlib = detectLibc.familySync();
|
|
31
|
-
const platform = process.env['BUILD_PLATFORM'] || node_os.platform();
|
|
32
|
-
const arch = process.env['BUILD_ARCH'] || node_os.arch();
|
|
33
|
-
const abi = nodeAbi.getAbi(node_process.versions.node, 'node');
|
|
34
|
-
const identifier = [platform, arch, stdlib, abi].filter(c => c !== undefined && c !== null).join('-');
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Imports cpp bindings based on the current platform and architecture.
|
|
38
|
-
*/
|
|
39
|
-
// eslint-disable-next-line complexity
|
|
40
|
-
function importCppBindingsModule() {
|
|
41
|
-
// We need to work around using import.meta.url directly with import.meta.url because jest complains about it.
|
|
42
|
-
const importMetaUrl =
|
|
43
|
-
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'
|
|
44
|
-
? // This case is always hit when the SDK is built
|
|
45
|
-
(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href))
|
|
46
|
-
: // This case is hit when the tests are run
|
|
47
|
-
node_url.pathToFileURL(__filename).href;
|
|
48
|
-
|
|
49
|
-
const createdRequire = node_module.createRequire(importMetaUrl);
|
|
50
|
-
const esmCompatibleDirname = node_path.dirname(node_url.fileURLToPath(importMetaUrl));
|
|
51
|
-
|
|
52
|
-
// If a binary path is specified, use that.
|
|
53
|
-
if (node_process.env['SENTRY_PROFILER_BINARY_PATH']) {
|
|
54
|
-
const envPath = node_process.env['SENTRY_PROFILER_BINARY_PATH'];
|
|
55
|
-
return createdRequire(envPath);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// If a user specifies a different binary dir, they are in control of the binaries being moved there
|
|
59
|
-
if (node_process.env['SENTRY_PROFILER_BINARY_DIR']) {
|
|
60
|
-
const binaryPath = node_path.join(node_path.resolve(node_process.env['SENTRY_PROFILER_BINARY_DIR']), `sentry_cpu_profiler-${identifier}`);
|
|
61
|
-
return createdRequire(`${binaryPath}.node`);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// We need the fallthrough so that in the end, we can fallback to the dynamic require.
|
|
65
|
-
// This is for cases where precompiled binaries were not provided, but may have been compiled from source.
|
|
66
|
-
if (platform === 'darwin') {
|
|
67
|
-
if (arch === 'x64') {
|
|
68
|
-
if (abi === '93') {
|
|
69
|
-
return createdRequire('../sentry_cpu_profiler-darwin-x64-93.node');
|
|
70
|
-
}
|
|
71
|
-
if (abi === '108') {
|
|
72
|
-
return createdRequire('../sentry_cpu_profiler-darwin-x64-108.node');
|
|
73
|
-
}
|
|
74
|
-
if (abi === '115') {
|
|
75
|
-
return createdRequire('../sentry_cpu_profiler-darwin-x64-115.node');
|
|
76
|
-
}
|
|
77
|
-
if (abi === '127') {
|
|
78
|
-
return createdRequire('../sentry_cpu_profiler-darwin-x64-127.node');
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (arch === 'arm64') {
|
|
83
|
-
if (abi === '93') {
|
|
84
|
-
return createdRequire('../sentry_cpu_profiler-darwin-arm64-93.node');
|
|
85
|
-
}
|
|
86
|
-
if (abi === '108') {
|
|
87
|
-
return createdRequire('../sentry_cpu_profiler-darwin-arm64-108.node');
|
|
88
|
-
}
|
|
89
|
-
if (abi === '115') {
|
|
90
|
-
return createdRequire('../sentry_cpu_profiler-darwin-arm64-115.node');
|
|
91
|
-
}
|
|
92
|
-
if (abi === '127') {
|
|
93
|
-
return createdRequire('../sentry_cpu_profiler-darwin-arm64-127.node');
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (platform === 'win32') {
|
|
99
|
-
if (arch === 'x64') {
|
|
100
|
-
if (abi === '93') {
|
|
101
|
-
return createdRequire('../sentry_cpu_profiler-win32-x64-93.node');
|
|
102
|
-
}
|
|
103
|
-
if (abi === '108') {
|
|
104
|
-
return createdRequire('../sentry_cpu_profiler-win32-x64-108.node');
|
|
105
|
-
}
|
|
106
|
-
if (abi === '115') {
|
|
107
|
-
return createdRequire('../sentry_cpu_profiler-win32-x64-115.node');
|
|
108
|
-
}
|
|
109
|
-
if (abi === '127') {
|
|
110
|
-
return createdRequire('../sentry_cpu_profiler-win32-x64-127.node');
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (platform === 'linux') {
|
|
116
|
-
if (arch === 'x64') {
|
|
117
|
-
if (stdlib === 'musl') {
|
|
118
|
-
if (abi === '93') {
|
|
119
|
-
return createdRequire('../sentry_cpu_profiler-linux-x64-musl-93.node');
|
|
120
|
-
}
|
|
121
|
-
if (abi === '108') {
|
|
122
|
-
return createdRequire('../sentry_cpu_profiler-linux-x64-musl-108.node');
|
|
123
|
-
}
|
|
124
|
-
if (abi === '115') {
|
|
125
|
-
return createdRequire('../sentry_cpu_profiler-linux-x64-musl-115.node');
|
|
126
|
-
}
|
|
127
|
-
if (abi === '127') {
|
|
128
|
-
return createdRequire('../sentry_cpu_profiler-linux-x64-musl-127.node');
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (stdlib === 'glibc') {
|
|
132
|
-
if (abi === '93') {
|
|
133
|
-
return createdRequire('../sentry_cpu_profiler-linux-x64-glibc-93.node');
|
|
134
|
-
}
|
|
135
|
-
if (abi === '108') {
|
|
136
|
-
return createdRequire('../sentry_cpu_profiler-linux-x64-glibc-108.node');
|
|
137
|
-
}
|
|
138
|
-
if (abi === '115') {
|
|
139
|
-
return createdRequire('../sentry_cpu_profiler-linux-x64-glibc-115.node');
|
|
140
|
-
}
|
|
141
|
-
if (abi === '127') {
|
|
142
|
-
return createdRequire('../sentry_cpu_profiler-linux-x64-glibc-127.node');
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (arch === 'arm64') {
|
|
147
|
-
if (stdlib === 'musl') {
|
|
148
|
-
if (abi === '93') {
|
|
149
|
-
return createdRequire('../sentry_cpu_profiler-linux-arm64-musl-93.node');
|
|
150
|
-
}
|
|
151
|
-
if (abi === '108') {
|
|
152
|
-
return createdRequire('../sentry_cpu_profiler-linux-arm64-musl-108.node');
|
|
153
|
-
}
|
|
154
|
-
if (abi === '115') {
|
|
155
|
-
return createdRequire('../sentry_cpu_profiler-linux-arm64-musl-115.node');
|
|
156
|
-
}
|
|
157
|
-
if (abi === '127') {
|
|
158
|
-
return createdRequire('../sentry_cpu_profiler-linux-arm64-musl-127.node');
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (stdlib === 'glibc') {
|
|
163
|
-
if (abi === '93') {
|
|
164
|
-
return createdRequire('../sentry_cpu_profiler-linux-arm64-glibc-93.node');
|
|
165
|
-
}
|
|
166
|
-
if (abi === '108') {
|
|
167
|
-
return createdRequire('../sentry_cpu_profiler-linux-arm64-glibc-108.node');
|
|
168
|
-
}
|
|
169
|
-
if (abi === '115') {
|
|
170
|
-
return createdRequire('../sentry_cpu_profiler-linux-arm64-glibc-115.node');
|
|
171
|
-
}
|
|
172
|
-
if (abi === '127') {
|
|
173
|
-
return createdRequire('../sentry_cpu_profiler-linux-arm64-glibc-127.node');
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const built_from_source_path = node_path.resolve(esmCompatibleDirname, '..', `sentry_cpu_profiler-${identifier}`);
|
|
180
|
-
return createdRequire(`${built_from_source_path}.node`);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const PrivateCpuProfilerBindings = importCppBindingsModule();
|
|
184
|
-
|
|
185
|
-
class Bindings {
|
|
186
|
-
startProfiling(name) {
|
|
187
|
-
if (!PrivateCpuProfilerBindings) {
|
|
188
|
-
DEBUG_BUILD && core.logger.log('[Profiling] Bindings not loaded, ignoring call to startProfiling.');
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (typeof PrivateCpuProfilerBindings.startProfiling !== 'function') {
|
|
193
|
-
DEBUG_BUILD &&
|
|
194
|
-
core.logger.log('[Profiling] Native startProfiling function is not available, ignoring call to startProfiling.');
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return PrivateCpuProfilerBindings.startProfiling(name);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
stopProfiling(
|
|
202
|
-
name,
|
|
203
|
-
format,
|
|
204
|
-
) {
|
|
205
|
-
if (!PrivateCpuProfilerBindings) {
|
|
206
|
-
DEBUG_BUILD &&
|
|
207
|
-
core.logger.log('[Profiling] Bindings not loaded or profile was never started, ignoring call to stopProfiling.');
|
|
208
|
-
return null;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (typeof PrivateCpuProfilerBindings.stopProfiling !== 'function') {
|
|
212
|
-
DEBUG_BUILD &&
|
|
213
|
-
core.logger.log('[Profiling] Native stopProfiling function is not available, ignoring call to stopProfiling.');
|
|
214
|
-
return null;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return PrivateCpuProfilerBindings.stopProfiling(
|
|
218
|
-
name,
|
|
219
|
-
format ,
|
|
220
|
-
node_worker_threads.threadId,
|
|
221
|
-
!!core.GLOBAL_OBJ._sentryDebugIds,
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const CpuProfilerBindings = new Bindings();
|
|
227
|
-
|
|
228
16
|
const NODE_VERSION = core.parseSemver(process.versions.node) ;
|
|
229
17
|
const NODE_MAJOR = NODE_VERSION.major;
|
|
230
18
|
|
|
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
19
|
// We require the file because if we import it, it will be included in the bundle.
|
|
233
20
|
// I guess tsc does not check file contents when it's imported.
|
|
234
21
|
const PROFILER_THREAD_ID_STRING = String(worker_threads.threadId);
|
|
@@ -236,16 +23,12 @@ const PROFILER_THREAD_NAME = worker_threads.isMainThread ? 'main' : 'worker';
|
|
|
236
23
|
const FORMAT_VERSION = '1';
|
|
237
24
|
const CONTINUOUS_FORMAT_VERSION = '2';
|
|
238
25
|
|
|
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
26
|
// Machine properties (eval only once)
|
|
244
27
|
const PLATFORM = os.platform();
|
|
245
28
|
const RELEASE = os.release();
|
|
246
29
|
const VERSION = os.version();
|
|
247
30
|
const TYPE = os.type();
|
|
248
|
-
const MODEL = machine;
|
|
31
|
+
const MODEL = os.machine();
|
|
249
32
|
const ARCH = os.arch();
|
|
250
33
|
|
|
251
34
|
/**
|
|
@@ -297,12 +80,12 @@ function createProfilingEvent(client, profile, event) {
|
|
|
297
80
|
}
|
|
298
81
|
|
|
299
82
|
return createProfilePayload(client, profile, {
|
|
300
|
-
release:
|
|
301
|
-
environment:
|
|
302
|
-
event_id:
|
|
303
|
-
transaction:
|
|
83
|
+
release: event.release ?? '',
|
|
84
|
+
environment: event.environment ?? '',
|
|
85
|
+
event_id: event.event_id ?? '',
|
|
86
|
+
transaction: event.transaction ?? '',
|
|
304
87
|
start_timestamp: event.start_timestamp ? event.start_timestamp * 1000 : Date.now(),
|
|
305
|
-
trace_id:
|
|
88
|
+
trace_id: event.contexts?.trace?.trace_id ?? '',
|
|
306
89
|
profile_id: profile.profile_id,
|
|
307
90
|
});
|
|
308
91
|
}
|
|
@@ -331,7 +114,7 @@ function createProfilePayload(
|
|
|
331
114
|
// Log a warning if the profile has an invalid traceId (should be uuidv4).
|
|
332
115
|
// All profiles and transactions are rejected if this is the case and we want to
|
|
333
116
|
// warn users that this is happening if they enable debug flag
|
|
334
|
-
if (trace_id
|
|
117
|
+
if (trace_id?.length !== 32) {
|
|
335
118
|
DEBUG_BUILD && core.logger.log(`[Profiling] Invalid traceId: ${trace_id} on profiled event`);
|
|
336
119
|
}
|
|
337
120
|
|
|
@@ -399,7 +182,7 @@ function createProfileChunkPayload(
|
|
|
399
182
|
// Log a warning if the profile has an invalid traceId (should be uuidv4).
|
|
400
183
|
// All profiles and transactions are rejected if this is the case and we want to
|
|
401
184
|
// warn users that this is happening if they enable debug flag
|
|
402
|
-
if (trace_id
|
|
185
|
+
if (trace_id?.length !== 32) {
|
|
403
186
|
DEBUG_BUILD && core.logger.log(`[Profiling] Invalid traceId: ${trace_id} on profiled event`);
|
|
404
187
|
}
|
|
405
188
|
|
|
@@ -408,8 +191,8 @@ function createProfileChunkPayload(
|
|
|
408
191
|
const profile = {
|
|
409
192
|
chunk_id: chunk_id,
|
|
410
193
|
client_sdk: {
|
|
411
|
-
name:
|
|
412
|
-
version:
|
|
194
|
+
name: sdk?.name ?? 'sentry.javascript.node',
|
|
195
|
+
version: sdk?.version ?? '0.0.0',
|
|
413
196
|
},
|
|
414
197
|
profiler_id: profiler_id,
|
|
415
198
|
platform: 'node',
|
|
@@ -441,9 +224,9 @@ function createProfilingChunkEvent(
|
|
|
441
224
|
}
|
|
442
225
|
|
|
443
226
|
return createProfileChunkPayload(client, profile, {
|
|
444
|
-
release:
|
|
445
|
-
environment:
|
|
446
|
-
trace_id:
|
|
227
|
+
release: options.release ?? '',
|
|
228
|
+
environment: options.environment ?? '',
|
|
229
|
+
trace_id: identifiers.trace_id ?? '',
|
|
447
230
|
chunk_id: identifiers.chunk_id,
|
|
448
231
|
profiler_id: identifiers.profiler_id,
|
|
449
232
|
sdk,
|
|
@@ -553,18 +336,17 @@ function findProfiledTransactionsFromEnvelope(envelope) {
|
|
|
553
336
|
|
|
554
337
|
// First item is the type, so we can skip it, everything else is an event
|
|
555
338
|
for (let j = 1; j < item.length; j++) {
|
|
556
|
-
const event = item[j];
|
|
339
|
+
const event = item[j] ;
|
|
557
340
|
|
|
558
341
|
if (!event) {
|
|
559
342
|
// Shouldn't happen, but lets be safe
|
|
560
343
|
continue;
|
|
561
344
|
}
|
|
562
345
|
|
|
563
|
-
|
|
564
|
-
const profile_id = _optionalChain$1([(event.contexts ), 'optionalAccess', _6 => _6['profile'], 'optionalAccess', _7 => _7['profile_id']]);
|
|
346
|
+
const profile_id = event.contexts?.profile?.profile_id;
|
|
565
347
|
|
|
566
348
|
if (event && profile_id) {
|
|
567
|
-
events.push(
|
|
349
|
+
events.push(event);
|
|
568
350
|
}
|
|
569
351
|
}
|
|
570
352
|
});
|
|
@@ -615,7 +397,7 @@ function makeProfileChunkEnvelope(
|
|
|
615
397
|
function applyDebugMetadata(client, resource_paths) {
|
|
616
398
|
const options = client.getOptions();
|
|
617
399
|
|
|
618
|
-
if (!options
|
|
400
|
+
if (!options?.stackParser) {
|
|
619
401
|
return [];
|
|
620
402
|
}
|
|
621
403
|
|
|
@@ -664,10 +446,6 @@ function maybeProfileSpan(
|
|
|
664
446
|
profilesSampleRate = profilesSampler({
|
|
665
447
|
name: spanName,
|
|
666
448
|
attributes: data,
|
|
667
|
-
transactionContext: {
|
|
668
|
-
name: spanName,
|
|
669
|
-
parentSampled,
|
|
670
|
-
},
|
|
671
449
|
parentSampled,
|
|
672
450
|
...customSamplingContext,
|
|
673
451
|
});
|
|
@@ -708,7 +486,7 @@ function maybeProfileSpan(
|
|
|
708
486
|
}
|
|
709
487
|
|
|
710
488
|
const profile_id = core.uuid4();
|
|
711
|
-
CpuProfilerBindings.startProfiling(profile_id);
|
|
489
|
+
nodeCpuProfiler.CpuProfilerBindings.startProfiling(profile_id);
|
|
712
490
|
DEBUG_BUILD && core.logger.log(`[Profiling] started profiling transaction: ${core.spanToJSON(span).description}`);
|
|
713
491
|
|
|
714
492
|
// set transaction context - do this regardless if profiling fails down the line
|
|
@@ -728,7 +506,7 @@ function stopSpanProfile(span, profile_id) {
|
|
|
728
506
|
return null;
|
|
729
507
|
}
|
|
730
508
|
|
|
731
|
-
const profile = CpuProfilerBindings.stopProfiling(profile_id, 0);
|
|
509
|
+
const profile = nodeCpuProfiler.CpuProfilerBindings.stopProfiling(profile_id, 0);
|
|
732
510
|
DEBUG_BUILD && core.logger.log(`[Profiling] stopped profiling of transaction: ${core.spanToJSON(span).description}`);
|
|
733
511
|
|
|
734
512
|
// In case of an overlapping span, stopProfiling may return null and silently ignore the overlapping profile.
|
|
@@ -746,11 +524,14 @@ function stopSpanProfile(span, profile_id) {
|
|
|
746
524
|
return profile;
|
|
747
525
|
}
|
|
748
526
|
|
|
749
|
-
var ProfileFormat;(function (ProfileFormat) {
|
|
527
|
+
var ProfileFormat; (function (ProfileFormat) {
|
|
750
528
|
const THREAD = 0; ProfileFormat[ProfileFormat["THREAD"] = THREAD] = "THREAD";
|
|
751
529
|
const CHUNK = 1; ProfileFormat[ProfileFormat["CHUNK"] = CHUNK] = "CHUNK";
|
|
752
530
|
})(ProfileFormat || (ProfileFormat = {}));
|
|
753
531
|
|
|
532
|
+
/* eslint-disable max-lines */
|
|
533
|
+
|
|
534
|
+
|
|
754
535
|
const CHUNK_INTERVAL_MS = 5000;
|
|
755
536
|
const PROFILE_MAP = new core.LRUMap(50);
|
|
756
537
|
const PROFILE_TIMEOUTS = {};
|
|
@@ -783,8 +564,7 @@ function setupAutomatedSpanProfiling(client) {
|
|
|
783
564
|
const options = client.getOptions();
|
|
784
565
|
// Not intended for external use, hence missing types, but we want to profile a couple of things at Sentry that
|
|
785
566
|
// currently exceed the default timeout set by the SDKs.
|
|
786
|
-
const maxProfileDurationMs =
|
|
787
|
-
(options._experiments && options._experiments['maxProfileDurationMs']) || MAX_PROFILE_DURATION_MS;
|
|
567
|
+
const maxProfileDurationMs = options._experiments?.maxProfileDurationMs || MAX_PROFILE_DURATION_MS;
|
|
788
568
|
|
|
789
569
|
if (PROFILE_TIMEOUTS[profile_id]) {
|
|
790
570
|
global.clearTimeout(PROFILE_TIMEOUTS[profile_id]);
|
|
@@ -842,8 +622,8 @@ function setupAutomatedSpanProfiling(client) {
|
|
|
842
622
|
const profilesToAddToEnvelope = [];
|
|
843
623
|
|
|
844
624
|
for (const profiledTransaction of profiledTransactionEvents) {
|
|
845
|
-
const profileContext =
|
|
846
|
-
const profile_id =
|
|
625
|
+
const profileContext = profiledTransaction.contexts?.profile;
|
|
626
|
+
const profile_id = profileContext?.profile_id;
|
|
847
627
|
|
|
848
628
|
if (!profile_id) {
|
|
849
629
|
throw new TypeError('[Profiling] cannot find profile for a transaction without a profile context');
|
|
@@ -851,7 +631,7 @@ function setupAutomatedSpanProfiling(client) {
|
|
|
851
631
|
|
|
852
632
|
// Remove the profile from the transaction context before sending, relay will take care of the rest.
|
|
853
633
|
if (profileContext) {
|
|
854
|
-
|
|
634
|
+
delete profiledTransaction.contexts?.profile;
|
|
855
635
|
}
|
|
856
636
|
|
|
857
637
|
const cpuProfile = takeFromProfileQueue(profile_id);
|
|
@@ -869,6 +649,11 @@ function setupAutomatedSpanProfiling(client) {
|
|
|
869
649
|
client.emit('preprocessEvent', profile, {
|
|
870
650
|
event_id: profiledTransaction.event_id,
|
|
871
651
|
});
|
|
652
|
+
|
|
653
|
+
// @ts-expect-error profile does not inherit from Event
|
|
654
|
+
client.emit('postprocessEvent', profile, {
|
|
655
|
+
event_id: profiledTransaction.event_id,
|
|
656
|
+
});
|
|
872
657
|
}
|
|
873
658
|
|
|
874
659
|
addProfilesToEnvelope(envelope, profilesToAddToEnvelope);
|
|
@@ -951,7 +736,7 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
951
736
|
* Stops profiling of the current chunks and flushes the profile to Sentry
|
|
952
737
|
*/
|
|
953
738
|
_chunkStop() {
|
|
954
|
-
if (
|
|
739
|
+
if (this._chunkData?.timer) {
|
|
955
740
|
global.clearTimeout(this._chunkData.timer);
|
|
956
741
|
this._chunkData.timer = undefined;
|
|
957
742
|
DEBUG_BUILD && core.logger.log(`[Profiling] Stopping profiling chunk: ${this._chunkData.id}`);
|
|
@@ -961,13 +746,13 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
961
746
|
core.logger.log('[Profiling] Failed to collect profile, sentry client was never attached to the profiler.');
|
|
962
747
|
return;
|
|
963
748
|
}
|
|
964
|
-
if (!
|
|
749
|
+
if (!this._chunkData?.id) {
|
|
965
750
|
DEBUG_BUILD &&
|
|
966
|
-
core.logger.log(`[Profiling] Failed to collect profile for: ${
|
|
751
|
+
core.logger.log(`[Profiling] Failed to collect profile for: ${this._chunkData?.id}, the chunk_id is missing.`);
|
|
967
752
|
return;
|
|
968
753
|
}
|
|
969
754
|
|
|
970
|
-
const profile = CpuProfilerBindings.stopProfiling(this._chunkData.id, ProfileFormat.CHUNK);
|
|
755
|
+
const profile = nodeCpuProfiler.CpuProfilerBindings.stopProfiling(this._chunkData.id, ProfileFormat.CHUNK);
|
|
971
756
|
|
|
972
757
|
if (!profile) {
|
|
973
758
|
DEBUG_BUILD && core.logger.log(`[Profiling] _chunkiledStartTraceID to collect profile for: ${this._chunkData.id}`);
|
|
@@ -987,7 +772,7 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
987
772
|
this._client,
|
|
988
773
|
this._client.getOptions(),
|
|
989
774
|
profile,
|
|
990
|
-
|
|
775
|
+
this._client.getSdkMetadata()?.sdk,
|
|
991
776
|
{
|
|
992
777
|
chunk_id: this._chunkData.id,
|
|
993
778
|
trace_id: this._chunkData.startTraceID,
|
|
@@ -1030,7 +815,7 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
1030
815
|
const metadata = this._client.getSdkMetadata();
|
|
1031
816
|
const tunnel = this._client.getOptions().tunnel;
|
|
1032
817
|
|
|
1033
|
-
const envelope = makeProfileChunkEnvelope(chunk,
|
|
818
|
+
const envelope = makeProfileChunkEnvelope(chunk, metadata?.sdk, tunnel, dsn);
|
|
1034
819
|
transport.send(envelope).then(null, reason => {
|
|
1035
820
|
DEBUG_BUILD && core.logger.error('Error while sending profile chunk envelope:', reason);
|
|
1036
821
|
});
|
|
@@ -1045,7 +830,7 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
1045
830
|
core.getCurrentScope().getPropagationContext().traceId || core.getIsolationScope().getPropagationContext().traceId;
|
|
1046
831
|
const chunk = this._initializeChunk(traceId);
|
|
1047
832
|
|
|
1048
|
-
CpuProfilerBindings.startProfiling(chunk.id);
|
|
833
|
+
nodeCpuProfiler.CpuProfilerBindings.startProfiling(chunk.id);
|
|
1049
834
|
DEBUG_BUILD && core.logger.log(`[Profiling] starting profiling chunk: ${chunk.id}`);
|
|
1050
835
|
|
|
1051
836
|
chunk.timer = global.setTimeout(() => {
|
|
@@ -1111,7 +896,7 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
1111
896
|
* Assigns thread_id and thread name context to a profiled event.
|
|
1112
897
|
*/
|
|
1113
898
|
_assignThreadIdContext(event) {
|
|
1114
|
-
if (!
|
|
899
|
+
if (!event?.contexts?.profile) {
|
|
1115
900
|
return;
|
|
1116
901
|
}
|
|
1117
902
|
|
|
@@ -1121,10 +906,10 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
1121
906
|
|
|
1122
907
|
// @ts-expect-error the trace fallback value is wrong, though it should never happen
|
|
1123
908
|
// and in case it does, we dont want to override whatever was passed initially.
|
|
1124
|
-
event.contexts
|
|
1125
|
-
...(
|
|
909
|
+
event.contexts.trace = {
|
|
910
|
+
...(event.contexts?.trace ?? {}),
|
|
1126
911
|
data: {
|
|
1127
|
-
...(
|
|
912
|
+
...(event.contexts?.trace?.data ?? {}),
|
|
1128
913
|
['thread.id']: PROFILER_THREAD_ID_STRING,
|
|
1129
914
|
['thread.name']: PROFILER_THREAD_NAME,
|
|
1130
915
|
},
|