@sentry/profiling-node 8.53.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 +2 -3
- package/lib/cjs/index.js +34 -45
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/index.js +33 -39
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/package.json +1 -1
- 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-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/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 +6 -6
- package/lib/sentry_cpu_profiler-darwin-arm64-93.node +0 -0
- package/lib/sentry_cpu_profiler-darwin-x64-93.node +0 -0
- package/lib/sentry_cpu_profiler-linux-arm64-glibc-93.node +0 -0
- package/lib/sentry_cpu_profiler-linux-arm64-musl-93.node +0 -0
- package/lib/sentry_cpu_profiler-linux-x64-glibc-93.node +0 -0
- package/lib/sentry_cpu_profiler-linux-x64-musl-93.node +0 -0
- package/lib/sentry_cpu_profiler-win32-x64-93.node +0 -0
package/lib/esm/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { _nullishCoalesce, _optionalChain, _optionalChainDelete } from '@sentry/core';
|
|
2
1
|
import { logger, GLOBAL_OBJ, parseSemver, forEachEnvelopeItem, createEnvelope, getDebugImagesForResources, uuid4, dsnToString, spanIsSampled, spanToJSON, LRUMap, defineIntegration, consoleSandbox, getRootSpan, getIsolationScope, getCurrentScope, getGlobalScope } from '@sentry/core';
|
|
3
2
|
import { createRequire } from 'node:module';
|
|
4
3
|
import { platform as platform$1, arch as arch$1 } from 'node:os';
|
|
@@ -220,7 +219,6 @@ const CpuProfilerBindings = new Bindings();
|
|
|
220
219
|
const NODE_VERSION = parseSemver(process.versions.node) ;
|
|
221
220
|
const NODE_MAJOR = NODE_VERSION.major;
|
|
222
221
|
|
|
223
|
-
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; }
|
|
224
222
|
// We require the file because if we import it, it will be included in the bundle.
|
|
225
223
|
// I guess tsc does not check file contents when it's imported.
|
|
226
224
|
const PROFILER_THREAD_ID_STRING = String(threadId$1);
|
|
@@ -228,16 +226,12 @@ const PROFILER_THREAD_NAME = isMainThread ? 'main' : 'worker';
|
|
|
228
226
|
const FORMAT_VERSION = '1';
|
|
229
227
|
const CONTINUOUS_FORMAT_VERSION = '2';
|
|
230
228
|
|
|
231
|
-
// Os machine was backported to 16.18, but this was not reflected in the types
|
|
232
|
-
// @ts-expect-error ignore missing
|
|
233
|
-
const machine = typeof os.machine === 'function' ? os.machine() : os.arch();
|
|
234
|
-
|
|
235
229
|
// Machine properties (eval only once)
|
|
236
230
|
const PLATFORM = os.platform();
|
|
237
231
|
const RELEASE = os.release();
|
|
238
232
|
const VERSION = os.version();
|
|
239
233
|
const TYPE = os.type();
|
|
240
|
-
const MODEL = machine;
|
|
234
|
+
const MODEL = os.machine();
|
|
241
235
|
const ARCH = os.arch();
|
|
242
236
|
|
|
243
237
|
/**
|
|
@@ -289,12 +283,12 @@ function createProfilingEvent(client, profile, event) {
|
|
|
289
283
|
}
|
|
290
284
|
|
|
291
285
|
return createProfilePayload(client, profile, {
|
|
292
|
-
release:
|
|
293
|
-
environment:
|
|
294
|
-
event_id:
|
|
295
|
-
transaction:
|
|
286
|
+
release: event.release ?? '',
|
|
287
|
+
environment: event.environment ?? '',
|
|
288
|
+
event_id: event.event_id ?? '',
|
|
289
|
+
transaction: event.transaction ?? '',
|
|
296
290
|
start_timestamp: event.start_timestamp ? event.start_timestamp * 1000 : Date.now(),
|
|
297
|
-
trace_id:
|
|
291
|
+
trace_id: event.contexts?.['trace']?.['trace_id'] ?? '',
|
|
298
292
|
profile_id: profile.profile_id,
|
|
299
293
|
});
|
|
300
294
|
}
|
|
@@ -323,7 +317,7 @@ function createProfilePayload(
|
|
|
323
317
|
// Log a warning if the profile has an invalid traceId (should be uuidv4).
|
|
324
318
|
// All profiles and transactions are rejected if this is the case and we want to
|
|
325
319
|
// warn users that this is happening if they enable debug flag
|
|
326
|
-
if (trace_id
|
|
320
|
+
if (trace_id?.length !== 32) {
|
|
327
321
|
DEBUG_BUILD && logger.log(`[Profiling] Invalid traceId: ${trace_id} on profiled event`);
|
|
328
322
|
}
|
|
329
323
|
|
|
@@ -391,7 +385,7 @@ function createProfileChunkPayload(
|
|
|
391
385
|
// Log a warning if the profile has an invalid traceId (should be uuidv4).
|
|
392
386
|
// All profiles and transactions are rejected if this is the case and we want to
|
|
393
387
|
// warn users that this is happening if they enable debug flag
|
|
394
|
-
if (trace_id
|
|
388
|
+
if (trace_id?.length !== 32) {
|
|
395
389
|
DEBUG_BUILD && logger.log(`[Profiling] Invalid traceId: ${trace_id} on profiled event`);
|
|
396
390
|
}
|
|
397
391
|
|
|
@@ -400,8 +394,8 @@ function createProfileChunkPayload(
|
|
|
400
394
|
const profile = {
|
|
401
395
|
chunk_id: chunk_id,
|
|
402
396
|
client_sdk: {
|
|
403
|
-
name:
|
|
404
|
-
version:
|
|
397
|
+
name: sdk?.name ?? 'sentry.javascript.node',
|
|
398
|
+
version: sdk?.version ?? '0.0.0',
|
|
405
399
|
},
|
|
406
400
|
profiler_id: profiler_id,
|
|
407
401
|
platform: 'node',
|
|
@@ -433,9 +427,9 @@ function createProfilingChunkEvent(
|
|
|
433
427
|
}
|
|
434
428
|
|
|
435
429
|
return createProfileChunkPayload(client, profile, {
|
|
436
|
-
release:
|
|
437
|
-
environment:
|
|
438
|
-
trace_id:
|
|
430
|
+
release: options.release ?? '',
|
|
431
|
+
environment: options.environment ?? '',
|
|
432
|
+
trace_id: identifiers.trace_id ?? '',
|
|
439
433
|
chunk_id: identifiers.chunk_id,
|
|
440
434
|
profiler_id: identifiers.profiler_id,
|
|
441
435
|
sdk,
|
|
@@ -553,7 +547,7 @@ function findProfiledTransactionsFromEnvelope(envelope) {
|
|
|
553
547
|
}
|
|
554
548
|
|
|
555
549
|
// @ts-expect-error profile_id is not part of the metadata type
|
|
556
|
-
const profile_id =
|
|
550
|
+
const profile_id = (event.contexts )?.['profile']?.['profile_id'];
|
|
557
551
|
|
|
558
552
|
if (event && profile_id) {
|
|
559
553
|
events.push(item[j] );
|
|
@@ -607,7 +601,7 @@ function makeProfileChunkEnvelope(
|
|
|
607
601
|
function applyDebugMetadata(client, resource_paths) {
|
|
608
602
|
const options = client.getOptions();
|
|
609
603
|
|
|
610
|
-
if (!options
|
|
604
|
+
if (!options?.stackParser) {
|
|
611
605
|
return [];
|
|
612
606
|
}
|
|
613
607
|
|
|
@@ -656,10 +650,6 @@ function maybeProfileSpan(
|
|
|
656
650
|
profilesSampleRate = profilesSampler({
|
|
657
651
|
name: spanName,
|
|
658
652
|
attributes: data,
|
|
659
|
-
transactionContext: {
|
|
660
|
-
name: spanName,
|
|
661
|
-
parentSampled,
|
|
662
|
-
},
|
|
663
653
|
parentSampled,
|
|
664
654
|
...customSamplingContext,
|
|
665
655
|
});
|
|
@@ -738,7 +728,7 @@ function stopSpanProfile(span, profile_id) {
|
|
|
738
728
|
return profile;
|
|
739
729
|
}
|
|
740
730
|
|
|
741
|
-
var ProfileFormat;(function (ProfileFormat) {
|
|
731
|
+
var ProfileFormat; (function (ProfileFormat) {
|
|
742
732
|
const THREAD = 0; ProfileFormat[ProfileFormat["THREAD"] = THREAD] = "THREAD";
|
|
743
733
|
const CHUNK = 1; ProfileFormat[ProfileFormat["CHUNK"] = CHUNK] = "CHUNK";
|
|
744
734
|
})(ProfileFormat || (ProfileFormat = {}));
|
|
@@ -775,8 +765,7 @@ function setupAutomatedSpanProfiling(client) {
|
|
|
775
765
|
const options = client.getOptions();
|
|
776
766
|
// Not intended for external use, hence missing types, but we want to profile a couple of things at Sentry that
|
|
777
767
|
// currently exceed the default timeout set by the SDKs.
|
|
778
|
-
const maxProfileDurationMs =
|
|
779
|
-
(options._experiments && options._experiments['maxProfileDurationMs']) || MAX_PROFILE_DURATION_MS;
|
|
768
|
+
const maxProfileDurationMs = options._experiments?.maxProfileDurationMs || MAX_PROFILE_DURATION_MS;
|
|
780
769
|
|
|
781
770
|
if (PROFILE_TIMEOUTS[profile_id]) {
|
|
782
771
|
global.clearTimeout(PROFILE_TIMEOUTS[profile_id]);
|
|
@@ -834,8 +823,8 @@ function setupAutomatedSpanProfiling(client) {
|
|
|
834
823
|
const profilesToAddToEnvelope = [];
|
|
835
824
|
|
|
836
825
|
for (const profiledTransaction of profiledTransactionEvents) {
|
|
837
|
-
const profileContext =
|
|
838
|
-
const profile_id =
|
|
826
|
+
const profileContext = profiledTransaction.contexts?.['profile'];
|
|
827
|
+
const profile_id = profileContext?.['profile_id'];
|
|
839
828
|
|
|
840
829
|
if (!profile_id) {
|
|
841
830
|
throw new TypeError('[Profiling] cannot find profile for a transaction without a profile context');
|
|
@@ -843,7 +832,7 @@ function setupAutomatedSpanProfiling(client) {
|
|
|
843
832
|
|
|
844
833
|
// Remove the profile from the transaction context before sending, relay will take care of the rest.
|
|
845
834
|
if (profileContext) {
|
|
846
|
-
|
|
835
|
+
delete profiledTransaction.contexts?.['profile'];
|
|
847
836
|
}
|
|
848
837
|
|
|
849
838
|
const cpuProfile = takeFromProfileQueue(profile_id);
|
|
@@ -861,6 +850,11 @@ function setupAutomatedSpanProfiling(client) {
|
|
|
861
850
|
client.emit('preprocessEvent', profile, {
|
|
862
851
|
event_id: profiledTransaction.event_id,
|
|
863
852
|
});
|
|
853
|
+
|
|
854
|
+
// @ts-expect-error profile does not inherit from Event
|
|
855
|
+
client.emit('postprocessEvent', profile, {
|
|
856
|
+
event_id: profiledTransaction.event_id,
|
|
857
|
+
});
|
|
864
858
|
}
|
|
865
859
|
|
|
866
860
|
addProfilesToEnvelope(envelope, profilesToAddToEnvelope);
|
|
@@ -943,7 +937,7 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
943
937
|
* Stops profiling of the current chunks and flushes the profile to Sentry
|
|
944
938
|
*/
|
|
945
939
|
_chunkStop() {
|
|
946
|
-
if (
|
|
940
|
+
if (this._chunkData?.timer) {
|
|
947
941
|
global.clearTimeout(this._chunkData.timer);
|
|
948
942
|
this._chunkData.timer = undefined;
|
|
949
943
|
DEBUG_BUILD && logger.log(`[Profiling] Stopping profiling chunk: ${this._chunkData.id}`);
|
|
@@ -953,9 +947,9 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
953
947
|
logger.log('[Profiling] Failed to collect profile, sentry client was never attached to the profiler.');
|
|
954
948
|
return;
|
|
955
949
|
}
|
|
956
|
-
if (!
|
|
950
|
+
if (!this._chunkData?.id) {
|
|
957
951
|
DEBUG_BUILD &&
|
|
958
|
-
logger.log(`[Profiling] Failed to collect profile for: ${
|
|
952
|
+
logger.log(`[Profiling] Failed to collect profile for: ${this._chunkData?.id}, the chunk_id is missing.`);
|
|
959
953
|
return;
|
|
960
954
|
}
|
|
961
955
|
|
|
@@ -979,7 +973,7 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
979
973
|
this._client,
|
|
980
974
|
this._client.getOptions(),
|
|
981
975
|
profile,
|
|
982
|
-
|
|
976
|
+
this._client.getSdkMetadata()?.sdk,
|
|
983
977
|
{
|
|
984
978
|
chunk_id: this._chunkData.id,
|
|
985
979
|
trace_id: this._chunkData.startTraceID,
|
|
@@ -1022,7 +1016,7 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
1022
1016
|
const metadata = this._client.getSdkMetadata();
|
|
1023
1017
|
const tunnel = this._client.getOptions().tunnel;
|
|
1024
1018
|
|
|
1025
|
-
const envelope = makeProfileChunkEnvelope(chunk,
|
|
1019
|
+
const envelope = makeProfileChunkEnvelope(chunk, metadata?.sdk, tunnel, dsn);
|
|
1026
1020
|
transport.send(envelope).then(null, reason => {
|
|
1027
1021
|
DEBUG_BUILD && logger.error('Error while sending profile chunk envelope:', reason);
|
|
1028
1022
|
});
|
|
@@ -1103,7 +1097,7 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
1103
1097
|
* Assigns thread_id and thread name context to a profiled event.
|
|
1104
1098
|
*/
|
|
1105
1099
|
_assignThreadIdContext(event) {
|
|
1106
|
-
if (!
|
|
1100
|
+
if (!event?.['contexts']?.['profile']) {
|
|
1107
1101
|
return;
|
|
1108
1102
|
}
|
|
1109
1103
|
|
|
@@ -1114,9 +1108,9 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
1114
1108
|
// @ts-expect-error the trace fallback value is wrong, though it should never happen
|
|
1115
1109
|
// and in case it does, we dont want to override whatever was passed initially.
|
|
1116
1110
|
event.contexts['trace'] = {
|
|
1117
|
-
...(
|
|
1111
|
+
...(event.contexts?.['trace'] ?? {}),
|
|
1118
1112
|
data: {
|
|
1119
|
-
...(
|
|
1113
|
+
...(event.contexts?.['trace']?.['data'] ?? {}),
|
|
1120
1114
|
['thread.id']: PROFILER_THREAD_ID_STRING,
|
|
1121
1115
|
['thread.name']: PROFILER_THREAD_NAME,
|
|
1122
1116
|
},
|