@sentry/profiling-node 8.9.2 → 8.10.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/bindings/cpu_profiler.cc +2 -2
- package/lib/cjs/index.js +743 -33
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/index.js +744 -34
- package/lib/esm/index.js.map +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-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/core/src/asyncContext/index.d.ts +14 -0
- package/lib/types/core/src/asyncContext/index.d.ts.map +1 -0
- package/lib/types/core/src/asyncContext/stackStrategy.d.ts +52 -0
- package/lib/types/core/src/asyncContext/stackStrategy.d.ts.map +1 -0
- package/lib/types/core/src/asyncContext/types.d.ts +47 -0
- package/lib/types/core/src/asyncContext/types.d.ts.map +1 -0
- package/lib/types/core/src/carrier.d.ts +37 -0
- package/lib/types/core/src/carrier.d.ts.map +1 -0
- package/lib/types/core/src/constants.d.ts +2 -0
- package/lib/types/core/src/constants.d.ts.map +1 -0
- package/lib/types/core/src/currentScopes.d.ts +55 -0
- package/lib/types/core/src/currentScopes.d.ts.map +1 -0
- package/lib/types/core/src/debug-build.d.ts.map +1 -0
- package/lib/types/core/src/defaultScopes.d.ts +6 -0
- package/lib/types/core/src/defaultScopes.d.ts.map +1 -0
- package/lib/types/core/src/envelope.d.ts +15 -0
- package/lib/types/core/src/envelope.d.ts.map +1 -0
- package/lib/types/core/src/metrics/constants.d.ts +19 -0
- package/lib/types/core/src/metrics/constants.d.ts.map +1 -0
- package/lib/types/core/src/metrics/metric-summary.d.ts +13 -0
- package/lib/types/core/src/metrics/metric-summary.d.ts.map +1 -0
- package/lib/types/core/src/metrics/types.d.ts +5 -0
- package/lib/types/core/src/metrics/types.d.ts.map +1 -0
- package/lib/types/core/src/scope.d.ts +211 -0
- package/lib/types/core/src/scope.d.ts.map +1 -0
- package/lib/types/core/src/semanticAttributes.d.ts +33 -0
- package/lib/types/core/src/semanticAttributes.d.ts.map +1 -0
- package/lib/types/core/src/session.d.ts +35 -0
- package/lib/types/core/src/session.d.ts.map +1 -0
- package/lib/types/core/src/tracing/dynamicSamplingContext.d.ts +24 -0
- package/lib/types/core/src/tracing/dynamicSamplingContext.d.ts.map +1 -0
- package/lib/types/core/src/tracing/logSpans.d.ts +10 -0
- package/lib/types/core/src/tracing/logSpans.d.ts.map +1 -0
- package/lib/types/core/src/tracing/measurement.d.ts +10 -0
- package/lib/types/core/src/tracing/measurement.d.ts.map +1 -0
- package/lib/types/core/src/tracing/sampling.d.ts +9 -0
- package/lib/types/core/src/tracing/sampling.d.ts.map +1 -0
- package/lib/types/core/src/tracing/sentryNonRecordingSpan.d.ts +26 -0
- package/lib/types/core/src/tracing/sentryNonRecordingSpan.d.ts.map +1 -0
- package/lib/types/core/src/tracing/sentrySpan.d.ts +86 -0
- package/lib/types/core/src/tracing/sentrySpan.d.ts.map +1 -0
- package/lib/types/core/src/tracing/spanstatus.d.ts +17 -0
- package/lib/types/core/src/tracing/spanstatus.d.ts.map +1 -0
- package/lib/types/core/src/tracing/trace.d.ts +76 -0
- package/lib/types/core/src/tracing/trace.d.ts.map +1 -0
- package/lib/types/core/src/tracing/utils.d.ts +13 -0
- package/lib/types/core/src/tracing/utils.d.ts.map +1 -0
- package/lib/types/core/src/utils/handleCallbackErrors.d.ts +13 -0
- package/lib/types/core/src/utils/handleCallbackErrors.d.ts.map +1 -0
- package/lib/types/core/src/utils/hasTracingEnabled.d.ts +8 -0
- package/lib/types/core/src/utils/hasTracingEnabled.d.ts.map +1 -0
- package/lib/types/core/src/utils/parseSampleRate.d.ts +9 -0
- package/lib/types/core/src/utils/parseSampleRate.d.ts.map +1 -0
- package/lib/types/core/src/utils/spanOnScope.d.ts +17 -0
- package/lib/types/core/src/utils/spanOnScope.d.ts.map +1 -0
- package/lib/types/core/src/utils/spanUtils.d.ts +74 -0
- package/lib/types/core/src/utils/spanUtils.d.ts.map +1 -0
- package/lib/types/profiling-node/src/cpu_profiler.d.ts.map +1 -0
- package/lib/types/profiling-node/src/debug-build.d.ts +7 -0
- package/lib/types/profiling-node/src/debug-build.d.ts.map +1 -0
- package/lib/types/profiling-node/src/index.d.ts.map +1 -0
- package/lib/types/{integration.d.ts → profiling-node/src/integration.d.ts} +18 -0
- package/lib/types/profiling-node/src/integration.d.ts.map +1 -0
- package/lib/types/profiling-node/src/nodeVersion.d.ts.map +1 -0
- package/lib/types/profiling-node/src/spanProfileUtils.d.ts.map +1 -0
- package/lib/types/profiling-node/src/types.d.ts.map +1 -0
- package/lib/types/{utils.d.ts → profiling-node/src/utils.d.ts} +3 -1
- package/lib/types/profiling-node/src/utils.d.ts.map +1 -0
- package/lib/types-ts3.8/core/src/asyncContext/index.d.ts +14 -0
- package/lib/types-ts3.8/core/src/asyncContext/stackStrategy.d.ts +52 -0
- package/lib/types-ts3.8/core/src/asyncContext/types.d.ts +47 -0
- package/lib/types-ts3.8/core/src/carrier.d.ts +37 -0
- package/lib/types-ts3.8/core/src/constants.d.ts +2 -0
- package/lib/types-ts3.8/core/src/currentScopes.d.ts +55 -0
- package/lib/types-ts3.8/core/src/defaultScopes.d.ts +6 -0
- package/lib/types-ts3.8/core/src/envelope.d.ts +18 -0
- package/lib/types-ts3.8/core/src/metrics/constants.d.ts +19 -0
- package/lib/types-ts3.8/core/src/metrics/metric-summary.d.ts +13 -0
- package/lib/types-ts3.8/core/src/metrics/types.d.ts +5 -0
- package/lib/types-ts3.8/core/src/scope.d.ts +211 -0
- package/lib/types-ts3.8/core/src/semanticAttributes.d.ts +33 -0
- package/lib/types-ts3.8/core/src/session.d.ts +35 -0
- package/lib/types-ts3.8/core/src/tracing/dynamicSamplingContext.d.ts +24 -0
- package/lib/types-ts3.8/core/src/tracing/logSpans.d.ts +10 -0
- package/lib/types-ts3.8/core/src/tracing/measurement.d.ts +10 -0
- package/lib/types-ts3.8/core/src/tracing/sampling.d.ts +12 -0
- package/lib/types-ts3.8/core/src/tracing/sentryNonRecordingSpan.d.ts +26 -0
- package/lib/types-ts3.8/core/src/tracing/sentrySpan.d.ts +86 -0
- package/lib/types-ts3.8/core/src/tracing/spanstatus.d.ts +17 -0
- package/lib/types-ts3.8/core/src/tracing/trace.d.ts +76 -0
- package/lib/types-ts3.8/core/src/tracing/utils.d.ts +13 -0
- package/lib/types-ts3.8/core/src/utils/handleCallbackErrors.d.ts +13 -0
- package/lib/types-ts3.8/core/src/utils/hasTracingEnabled.d.ts +8 -0
- package/lib/types-ts3.8/core/src/utils/parseSampleRate.d.ts +9 -0
- package/lib/types-ts3.8/core/src/utils/spanOnScope.d.ts +17 -0
- package/lib/types-ts3.8/core/src/utils/spanUtils.d.ts +74 -0
- package/lib/types-ts3.8/profiling-node/src/debug-build.d.ts +7 -0
- package/lib/types-ts3.8/{integration.d.ts → profiling-node/src/integration.d.ts} +18 -0
- package/lib/types-ts3.8/{utils.d.ts → profiling-node/src/utils.d.ts} +3 -1
- package/package.json +5 -5
- package/lib/types/cpu_profiler.d.ts.map +0 -1
- package/lib/types/debug-build.d.ts.map +0 -1
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/integration.d.ts.map +0 -1
- package/lib/types/nodeVersion.d.ts.map +0 -1
- package/lib/types/spanProfileUtils.d.ts.map +0 -1
- package/lib/types/types.d.ts.map +0 -1
- package/lib/types/utils.d.ts.map +0 -1
- /package/lib/types/{debug-build.d.ts → core/src/debug-build.d.ts} +0 -0
- /package/lib/types/{cpu_profiler.d.ts → profiling-node/src/cpu_profiler.d.ts} +0 -0
- /package/lib/types/{index.d.ts → profiling-node/src/index.d.ts} +0 -0
- /package/lib/types/{nodeVersion.d.ts → profiling-node/src/nodeVersion.d.ts} +0 -0
- /package/lib/types/{spanProfileUtils.d.ts → profiling-node/src/spanProfileUtils.d.ts} +0 -0
- /package/lib/types/{types.d.ts → profiling-node/src/types.d.ts} +0 -0
- /package/lib/types-ts3.8/{debug-build.d.ts → core/src/debug-build.d.ts} +0 -0
- /package/lib/types-ts3.8/{cpu_profiler.d.ts → profiling-node/src/cpu_profiler.d.ts} +0 -0
- /package/lib/types-ts3.8/{index.d.ts → profiling-node/src/index.d.ts} +0 -0
- /package/lib/types-ts3.8/{nodeVersion.d.ts → profiling-node/src/nodeVersion.d.ts} +0 -0
- /package/lib/types-ts3.8/{spanProfileUtils.d.ts → profiling-node/src/spanProfileUtils.d.ts} +0 -0
- /package/lib/types-ts3.8/{types.d.ts → profiling-node/src/types.d.ts} +0 -0
package/lib/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _nullishCoalesce, _optionalChain, _optionalChainDelete } from '@sentry/utils';
|
|
2
2
|
import { spanIsSampled, spanToJSON, defineIntegration, getRootSpan, getCurrentScope, getIsolationScope } from '@sentry/core';
|
|
3
|
-
import { logger, GLOBAL_OBJ, parseSemver, forEachEnvelopeItem, createEnvelope,
|
|
3
|
+
import { timestampInSeconds, uuid4, addNonEnumerableProperty, generatePropagationContext, isPlainObject, dateTimestampInSeconds, logger, getGlobalSingleton, GLOBAL_OBJ, parseSemver, forEachEnvelopeItem, createEnvelope, dsnToString, LRUMap } from '@sentry/utils';
|
|
4
4
|
import { platform as platform$1, arch as arch$1 } from 'node:os';
|
|
5
5
|
import { resolve, join } from 'node:path';
|
|
6
6
|
import { versions, env } from 'node:process';
|
|
@@ -19,6 +19,666 @@ import cjsModule from 'node:module';
|
|
|
19
19
|
const __filename = cjsUrl.fileURLToPath(import.meta.url);
|
|
20
20
|
const __dirname = cjsPath.dirname(__filename);
|
|
21
21
|
const require = cjsModule.createRequire(import.meta.url);
|
|
22
|
+
/**
|
|
23
|
+
* Updates a session object with the properties passed in the context.
|
|
24
|
+
*
|
|
25
|
+
* Note that this function mutates the passed object and returns void.
|
|
26
|
+
* (Had to do this instead of returning a new and updated session because closing and sending a session
|
|
27
|
+
* makes an update to the session after it was passed to the sending logic.
|
|
28
|
+
* @see BaseClient.captureSession )
|
|
29
|
+
*
|
|
30
|
+
* @param session the `Session` to update
|
|
31
|
+
* @param context the `SessionContext` holding the properties that should be updated in @param session
|
|
32
|
+
*/
|
|
33
|
+
// eslint-disable-next-line complexity
|
|
34
|
+
function updateSession(session, context = {}) {
|
|
35
|
+
if (context.user) {
|
|
36
|
+
if (!session.ipAddress && context.user.ip_address) {
|
|
37
|
+
session.ipAddress = context.user.ip_address;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!session.did && !context.did) {
|
|
41
|
+
session.did = context.user.id || context.user.email || context.user.username;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
session.timestamp = context.timestamp || timestampInSeconds();
|
|
46
|
+
|
|
47
|
+
if (context.abnormal_mechanism) {
|
|
48
|
+
session.abnormal_mechanism = context.abnormal_mechanism;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (context.ignoreDuration) {
|
|
52
|
+
session.ignoreDuration = context.ignoreDuration;
|
|
53
|
+
}
|
|
54
|
+
if (context.sid) {
|
|
55
|
+
// Good enough uuid validation. — Kamil
|
|
56
|
+
session.sid = context.sid.length === 32 ? context.sid : uuid4();
|
|
57
|
+
}
|
|
58
|
+
if (context.init !== undefined) {
|
|
59
|
+
session.init = context.init;
|
|
60
|
+
}
|
|
61
|
+
if (!session.did && context.did) {
|
|
62
|
+
session.did = `${context.did}`;
|
|
63
|
+
}
|
|
64
|
+
if (typeof context.started === 'number') {
|
|
65
|
+
session.started = context.started;
|
|
66
|
+
}
|
|
67
|
+
if (session.ignoreDuration) {
|
|
68
|
+
session.duration = undefined;
|
|
69
|
+
} else if (typeof context.duration === 'number') {
|
|
70
|
+
session.duration = context.duration;
|
|
71
|
+
} else {
|
|
72
|
+
const duration = session.timestamp - session.started;
|
|
73
|
+
session.duration = duration >= 0 ? duration : 0;
|
|
74
|
+
}
|
|
75
|
+
if (context.release) {
|
|
76
|
+
session.release = context.release;
|
|
77
|
+
}
|
|
78
|
+
if (context.environment) {
|
|
79
|
+
session.environment = context.environment;
|
|
80
|
+
}
|
|
81
|
+
if (!session.ipAddress && context.ipAddress) {
|
|
82
|
+
session.ipAddress = context.ipAddress;
|
|
83
|
+
}
|
|
84
|
+
if (!session.userAgent && context.userAgent) {
|
|
85
|
+
session.userAgent = context.userAgent;
|
|
86
|
+
}
|
|
87
|
+
if (typeof context.errors === 'number') {
|
|
88
|
+
session.errors = context.errors;
|
|
89
|
+
}
|
|
90
|
+
if (context.status) {
|
|
91
|
+
session.status = context.status;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const SCOPE_SPAN_FIELD = '_sentrySpan';
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Set the active span for a given scope.
|
|
99
|
+
* NOTE: This should NOT be used directly, but is only used internally by the trace methods.
|
|
100
|
+
*/
|
|
101
|
+
function _setSpanForScope(scope, span) {
|
|
102
|
+
if (span) {
|
|
103
|
+
addNonEnumerableProperty(scope , SCOPE_SPAN_FIELD, span);
|
|
104
|
+
} else {
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
106
|
+
delete (scope )[SCOPE_SPAN_FIELD];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Get the active span for a given scope.
|
|
112
|
+
* NOTE: This should NOT be used directly, but is only used internally by the trace methods.
|
|
113
|
+
*/
|
|
114
|
+
function _getSpanForScope(scope) {
|
|
115
|
+
return scope[SCOPE_SPAN_FIELD];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Default value for maximum number of breadcrumbs added to an event.
|
|
120
|
+
*/
|
|
121
|
+
const DEFAULT_MAX_BREADCRUMBS = 100;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Holds additional event information.
|
|
125
|
+
*/
|
|
126
|
+
class ScopeClass {
|
|
127
|
+
/** Flag if notifying is happening. */
|
|
128
|
+
|
|
129
|
+
/** Callback for client to receive scope changes. */
|
|
130
|
+
|
|
131
|
+
/** Callback list that will be called during event processing. */
|
|
132
|
+
|
|
133
|
+
/** Array of breadcrumbs. */
|
|
134
|
+
|
|
135
|
+
/** User */
|
|
136
|
+
|
|
137
|
+
/** Tags */
|
|
138
|
+
|
|
139
|
+
/** Extra */
|
|
140
|
+
|
|
141
|
+
/** Contexts */
|
|
142
|
+
|
|
143
|
+
/** Attachments */
|
|
144
|
+
|
|
145
|
+
/** Propagation Context for distributed tracing */
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* A place to stash data which is needed at some point in the SDK's event processing pipeline but which shouldn't get
|
|
149
|
+
* sent to Sentry
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
/** Fingerprint */
|
|
153
|
+
|
|
154
|
+
/** Severity */
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Transaction Name
|
|
158
|
+
*
|
|
159
|
+
* IMPORTANT: The transaction name on the scope has nothing to do with root spans/transaction objects.
|
|
160
|
+
* It's purpose is to assign a transaction to the scope that's added to non-transaction events.
|
|
161
|
+
*/
|
|
162
|
+
|
|
163
|
+
/** Session */
|
|
164
|
+
|
|
165
|
+
/** Request Mode Session Status */
|
|
166
|
+
|
|
167
|
+
/** The client on this scope */
|
|
168
|
+
|
|
169
|
+
/** Contains the last event id of a captured event. */
|
|
170
|
+
|
|
171
|
+
// NOTE: Any field which gets added here should get added not only to the constructor but also to the `clone` method.
|
|
172
|
+
|
|
173
|
+
constructor() {
|
|
174
|
+
this._notifyingListeners = false;
|
|
175
|
+
this._scopeListeners = [];
|
|
176
|
+
this._eventProcessors = [];
|
|
177
|
+
this._breadcrumbs = [];
|
|
178
|
+
this._attachments = [];
|
|
179
|
+
this._user = {};
|
|
180
|
+
this._tags = {};
|
|
181
|
+
this._extra = {};
|
|
182
|
+
this._contexts = {};
|
|
183
|
+
this._sdkProcessingMetadata = {};
|
|
184
|
+
this._propagationContext = generatePropagationContext();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @inheritDoc
|
|
189
|
+
*/
|
|
190
|
+
clone() {
|
|
191
|
+
const newScope = new ScopeClass();
|
|
192
|
+
newScope._breadcrumbs = [...this._breadcrumbs];
|
|
193
|
+
newScope._tags = { ...this._tags };
|
|
194
|
+
newScope._extra = { ...this._extra };
|
|
195
|
+
newScope._contexts = { ...this._contexts };
|
|
196
|
+
newScope._user = this._user;
|
|
197
|
+
newScope._level = this._level;
|
|
198
|
+
newScope._session = this._session;
|
|
199
|
+
newScope._transactionName = this._transactionName;
|
|
200
|
+
newScope._fingerprint = this._fingerprint;
|
|
201
|
+
newScope._eventProcessors = [...this._eventProcessors];
|
|
202
|
+
newScope._requestSession = this._requestSession;
|
|
203
|
+
newScope._attachments = [...this._attachments];
|
|
204
|
+
newScope._sdkProcessingMetadata = { ...this._sdkProcessingMetadata };
|
|
205
|
+
newScope._propagationContext = { ...this._propagationContext };
|
|
206
|
+
newScope._client = this._client;
|
|
207
|
+
newScope._lastEventId = this._lastEventId;
|
|
208
|
+
|
|
209
|
+
_setSpanForScope(newScope, _getSpanForScope(this));
|
|
210
|
+
|
|
211
|
+
return newScope;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* @inheritDoc
|
|
216
|
+
*/
|
|
217
|
+
setClient(client) {
|
|
218
|
+
this._client = client;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* @inheritDoc
|
|
223
|
+
*/
|
|
224
|
+
setLastEventId(lastEventId) {
|
|
225
|
+
this._lastEventId = lastEventId;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* @inheritDoc
|
|
230
|
+
*/
|
|
231
|
+
getClient() {
|
|
232
|
+
return this._client ;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* @inheritDoc
|
|
237
|
+
*/
|
|
238
|
+
lastEventId() {
|
|
239
|
+
return this._lastEventId;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* @inheritDoc
|
|
244
|
+
*/
|
|
245
|
+
addScopeListener(callback) {
|
|
246
|
+
this._scopeListeners.push(callback);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* @inheritDoc
|
|
251
|
+
*/
|
|
252
|
+
addEventProcessor(callback) {
|
|
253
|
+
this._eventProcessors.push(callback);
|
|
254
|
+
return this;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* @inheritDoc
|
|
259
|
+
*/
|
|
260
|
+
setUser(user) {
|
|
261
|
+
// If null is passed we want to unset everything, but still define keys,
|
|
262
|
+
// so that later down in the pipeline any existing values are cleared.
|
|
263
|
+
this._user = user || {
|
|
264
|
+
email: undefined,
|
|
265
|
+
id: undefined,
|
|
266
|
+
ip_address: undefined,
|
|
267
|
+
username: undefined,
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
if (this._session) {
|
|
271
|
+
updateSession(this._session, { user });
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
this._notifyScopeListeners();
|
|
275
|
+
return this;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* @inheritDoc
|
|
280
|
+
*/
|
|
281
|
+
getUser() {
|
|
282
|
+
return this._user;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* @inheritDoc
|
|
287
|
+
*/
|
|
288
|
+
getRequestSession() {
|
|
289
|
+
return this._requestSession;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* @inheritDoc
|
|
294
|
+
*/
|
|
295
|
+
setRequestSession(requestSession) {
|
|
296
|
+
this._requestSession = requestSession;
|
|
297
|
+
return this;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* @inheritDoc
|
|
302
|
+
*/
|
|
303
|
+
setTags(tags) {
|
|
304
|
+
this._tags = {
|
|
305
|
+
...this._tags,
|
|
306
|
+
...tags,
|
|
307
|
+
};
|
|
308
|
+
this._notifyScopeListeners();
|
|
309
|
+
return this;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* @inheritDoc
|
|
314
|
+
*/
|
|
315
|
+
setTag(key, value) {
|
|
316
|
+
this._tags = { ...this._tags, [key]: value };
|
|
317
|
+
this._notifyScopeListeners();
|
|
318
|
+
return this;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* @inheritDoc
|
|
323
|
+
*/
|
|
324
|
+
setExtras(extras) {
|
|
325
|
+
this._extra = {
|
|
326
|
+
...this._extra,
|
|
327
|
+
...extras,
|
|
328
|
+
};
|
|
329
|
+
this._notifyScopeListeners();
|
|
330
|
+
return this;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* @inheritDoc
|
|
335
|
+
*/
|
|
336
|
+
setExtra(key, extra) {
|
|
337
|
+
this._extra = { ...this._extra, [key]: extra };
|
|
338
|
+
this._notifyScopeListeners();
|
|
339
|
+
return this;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* @inheritDoc
|
|
344
|
+
*/
|
|
345
|
+
setFingerprint(fingerprint) {
|
|
346
|
+
this._fingerprint = fingerprint;
|
|
347
|
+
this._notifyScopeListeners();
|
|
348
|
+
return this;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* @inheritDoc
|
|
353
|
+
*/
|
|
354
|
+
setLevel(level) {
|
|
355
|
+
this._level = level;
|
|
356
|
+
this._notifyScopeListeners();
|
|
357
|
+
return this;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* @inheritDoc
|
|
362
|
+
*/
|
|
363
|
+
setTransactionName(name) {
|
|
364
|
+
this._transactionName = name;
|
|
365
|
+
this._notifyScopeListeners();
|
|
366
|
+
return this;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* @inheritDoc
|
|
371
|
+
*/
|
|
372
|
+
setContext(key, context) {
|
|
373
|
+
if (context === null) {
|
|
374
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
375
|
+
delete this._contexts[key];
|
|
376
|
+
} else {
|
|
377
|
+
this._contexts[key] = context;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
this._notifyScopeListeners();
|
|
381
|
+
return this;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* @inheritDoc
|
|
386
|
+
*/
|
|
387
|
+
setSession(session) {
|
|
388
|
+
if (!session) {
|
|
389
|
+
delete this._session;
|
|
390
|
+
} else {
|
|
391
|
+
this._session = session;
|
|
392
|
+
}
|
|
393
|
+
this._notifyScopeListeners();
|
|
394
|
+
return this;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* @inheritDoc
|
|
399
|
+
*/
|
|
400
|
+
getSession() {
|
|
401
|
+
return this._session;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* @inheritDoc
|
|
406
|
+
*/
|
|
407
|
+
update(captureContext) {
|
|
408
|
+
if (!captureContext) {
|
|
409
|
+
return this;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const scopeToMerge = typeof captureContext === 'function' ? captureContext(this) : captureContext;
|
|
413
|
+
|
|
414
|
+
const [scopeInstance, requestSession] =
|
|
415
|
+
scopeToMerge instanceof Scope
|
|
416
|
+
? [scopeToMerge.getScopeData(), scopeToMerge.getRequestSession()]
|
|
417
|
+
: isPlainObject(scopeToMerge)
|
|
418
|
+
? [captureContext , (captureContext ).requestSession]
|
|
419
|
+
: [];
|
|
420
|
+
|
|
421
|
+
const { tags, extra, user, contexts, level, fingerprint = [], propagationContext } = scopeInstance || {};
|
|
422
|
+
|
|
423
|
+
this._tags = { ...this._tags, ...tags };
|
|
424
|
+
this._extra = { ...this._extra, ...extra };
|
|
425
|
+
this._contexts = { ...this._contexts, ...contexts };
|
|
426
|
+
|
|
427
|
+
if (user && Object.keys(user).length) {
|
|
428
|
+
this._user = user;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (level) {
|
|
432
|
+
this._level = level;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (fingerprint.length) {
|
|
436
|
+
this._fingerprint = fingerprint;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if (propagationContext) {
|
|
440
|
+
this._propagationContext = propagationContext;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (requestSession) {
|
|
444
|
+
this._requestSession = requestSession;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
return this;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* @inheritDoc
|
|
452
|
+
*/
|
|
453
|
+
clear() {
|
|
454
|
+
// client is not cleared here on purpose!
|
|
455
|
+
this._breadcrumbs = [];
|
|
456
|
+
this._tags = {};
|
|
457
|
+
this._extra = {};
|
|
458
|
+
this._user = {};
|
|
459
|
+
this._contexts = {};
|
|
460
|
+
this._level = undefined;
|
|
461
|
+
this._transactionName = undefined;
|
|
462
|
+
this._fingerprint = undefined;
|
|
463
|
+
this._requestSession = undefined;
|
|
464
|
+
this._session = undefined;
|
|
465
|
+
_setSpanForScope(this, undefined);
|
|
466
|
+
this._attachments = [];
|
|
467
|
+
this._propagationContext = generatePropagationContext();
|
|
468
|
+
|
|
469
|
+
this._notifyScopeListeners();
|
|
470
|
+
return this;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* @inheritDoc
|
|
475
|
+
*/
|
|
476
|
+
addBreadcrumb(breadcrumb, maxBreadcrumbs) {
|
|
477
|
+
const maxCrumbs = typeof maxBreadcrumbs === 'number' ? maxBreadcrumbs : DEFAULT_MAX_BREADCRUMBS;
|
|
478
|
+
|
|
479
|
+
// No data has been changed, so don't notify scope listeners
|
|
480
|
+
if (maxCrumbs <= 0) {
|
|
481
|
+
return this;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
const mergedBreadcrumb = {
|
|
485
|
+
timestamp: dateTimestampInSeconds(),
|
|
486
|
+
...breadcrumb,
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
const breadcrumbs = this._breadcrumbs;
|
|
490
|
+
breadcrumbs.push(mergedBreadcrumb);
|
|
491
|
+
this._breadcrumbs = breadcrumbs.length > maxCrumbs ? breadcrumbs.slice(-maxCrumbs) : breadcrumbs;
|
|
492
|
+
|
|
493
|
+
this._notifyScopeListeners();
|
|
494
|
+
|
|
495
|
+
return this;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* @inheritDoc
|
|
500
|
+
*/
|
|
501
|
+
getLastBreadcrumb() {
|
|
502
|
+
return this._breadcrumbs[this._breadcrumbs.length - 1];
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* @inheritDoc
|
|
507
|
+
*/
|
|
508
|
+
clearBreadcrumbs() {
|
|
509
|
+
this._breadcrumbs = [];
|
|
510
|
+
this._notifyScopeListeners();
|
|
511
|
+
return this;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* @inheritDoc
|
|
516
|
+
*/
|
|
517
|
+
addAttachment(attachment) {
|
|
518
|
+
this._attachments.push(attachment);
|
|
519
|
+
return this;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* @inheritDoc
|
|
524
|
+
*/
|
|
525
|
+
clearAttachments() {
|
|
526
|
+
this._attachments = [];
|
|
527
|
+
return this;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/** @inheritDoc */
|
|
531
|
+
getScopeData() {
|
|
532
|
+
return {
|
|
533
|
+
breadcrumbs: this._breadcrumbs,
|
|
534
|
+
attachments: this._attachments,
|
|
535
|
+
contexts: this._contexts,
|
|
536
|
+
tags: this._tags,
|
|
537
|
+
extra: this._extra,
|
|
538
|
+
user: this._user,
|
|
539
|
+
level: this._level,
|
|
540
|
+
fingerprint: this._fingerprint || [],
|
|
541
|
+
eventProcessors: this._eventProcessors,
|
|
542
|
+
propagationContext: this._propagationContext,
|
|
543
|
+
sdkProcessingMetadata: this._sdkProcessingMetadata,
|
|
544
|
+
transactionName: this._transactionName,
|
|
545
|
+
span: _getSpanForScope(this),
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* @inheritDoc
|
|
551
|
+
*/
|
|
552
|
+
setSDKProcessingMetadata(newData) {
|
|
553
|
+
this._sdkProcessingMetadata = { ...this._sdkProcessingMetadata, ...newData };
|
|
554
|
+
|
|
555
|
+
return this;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* @inheritDoc
|
|
560
|
+
*/
|
|
561
|
+
setPropagationContext(context) {
|
|
562
|
+
this._propagationContext = context;
|
|
563
|
+
return this;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* @inheritDoc
|
|
568
|
+
*/
|
|
569
|
+
getPropagationContext() {
|
|
570
|
+
return this._propagationContext;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* @inheritDoc
|
|
575
|
+
*/
|
|
576
|
+
captureException(exception, hint) {
|
|
577
|
+
const eventId = hint && hint.event_id ? hint.event_id : uuid4();
|
|
578
|
+
|
|
579
|
+
if (!this._client) {
|
|
580
|
+
logger.warn('No client configured on scope - will not capture exception!');
|
|
581
|
+
return eventId;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
const syntheticException = new Error('Sentry syntheticException');
|
|
585
|
+
|
|
586
|
+
this._client.captureException(
|
|
587
|
+
exception,
|
|
588
|
+
{
|
|
589
|
+
originalException: exception,
|
|
590
|
+
syntheticException,
|
|
591
|
+
...hint,
|
|
592
|
+
event_id: eventId,
|
|
593
|
+
},
|
|
594
|
+
this,
|
|
595
|
+
);
|
|
596
|
+
|
|
597
|
+
return eventId;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* @inheritDoc
|
|
602
|
+
*/
|
|
603
|
+
captureMessage(message, level, hint) {
|
|
604
|
+
const eventId = hint && hint.event_id ? hint.event_id : uuid4();
|
|
605
|
+
|
|
606
|
+
if (!this._client) {
|
|
607
|
+
logger.warn('No client configured on scope - will not capture message!');
|
|
608
|
+
return eventId;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
const syntheticException = new Error(message);
|
|
612
|
+
|
|
613
|
+
this._client.captureMessage(
|
|
614
|
+
message,
|
|
615
|
+
level,
|
|
616
|
+
{
|
|
617
|
+
originalException: message,
|
|
618
|
+
syntheticException,
|
|
619
|
+
...hint,
|
|
620
|
+
event_id: eventId,
|
|
621
|
+
},
|
|
622
|
+
this,
|
|
623
|
+
);
|
|
624
|
+
|
|
625
|
+
return eventId;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* @inheritDoc
|
|
630
|
+
*/
|
|
631
|
+
captureEvent(event, hint) {
|
|
632
|
+
const eventId = hint && hint.event_id ? hint.event_id : uuid4();
|
|
633
|
+
|
|
634
|
+
if (!this._client) {
|
|
635
|
+
logger.warn('No client configured on scope - will not capture event!');
|
|
636
|
+
return eventId;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
this._client.captureEvent(event, { ...hint, event_id: eventId }, this);
|
|
640
|
+
|
|
641
|
+
return eventId;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* This will be called on every set call.
|
|
646
|
+
*/
|
|
647
|
+
_notifyScopeListeners() {
|
|
648
|
+
// We need this check for this._notifyingListeners to be able to work on scope during updates
|
|
649
|
+
// If this check is not here we'll produce endless recursion when something is done with the scope
|
|
650
|
+
// during the callback.
|
|
651
|
+
if (!this._notifyingListeners) {
|
|
652
|
+
this._notifyingListeners = true;
|
|
653
|
+
this._scopeListeners.forEach(callback => {
|
|
654
|
+
callback(this);
|
|
655
|
+
});
|
|
656
|
+
this._notifyingListeners = false;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// NOTE: By exporting this here as const & type, instead of doing `export class`,
|
|
662
|
+
// We can get the correct class when importing from `@sentry/core`, but the original type (from `@sentry/types`)
|
|
663
|
+
// This is helpful for interop, e.g. when doing `import type { Scope } from '@sentry/node';` (which re-exports this)
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* Holds additional event information.
|
|
667
|
+
*/
|
|
668
|
+
const Scope = ScopeClass;
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* Holds additional event information.
|
|
672
|
+
*/
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Get the global scope.
|
|
676
|
+
* This scope is applied to _all_ events.
|
|
677
|
+
*/
|
|
678
|
+
function getGlobalScope() {
|
|
679
|
+
return getGlobalSingleton('globalScope', () => new Scope());
|
|
680
|
+
}
|
|
681
|
+
|
|
22
682
|
/**
|
|
23
683
|
* 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.
|
|
24
684
|
*
|
|
@@ -203,12 +863,12 @@ const CpuProfilerBindings = new Bindings();
|
|
|
203
863
|
const NODE_VERSION = parseSemver(process.versions.node) ;
|
|
204
864
|
const NODE_MAJOR = NODE_VERSION.major;
|
|
205
865
|
|
|
206
|
-
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; }/* eslint-disable max-lines */
|
|
866
|
+
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; }/* eslint-disable max-lines */
|
|
207
867
|
|
|
208
868
|
// We require the file because if we import it, it will be included in the bundle.
|
|
209
869
|
// I guess tsc does not check file contents when it's imported.
|
|
210
|
-
const
|
|
211
|
-
const
|
|
870
|
+
const PROFILER_THREAD_ID_STRING = String(threadId$1);
|
|
871
|
+
const PROFILER_THREAD_NAME = isMainThread ? 'main' : 'worker';
|
|
212
872
|
const FORMAT_VERSION = '1';
|
|
213
873
|
const CONTINUOUS_FORMAT_VERSION = '2';
|
|
214
874
|
|
|
@@ -254,8 +914,8 @@ function enrichWithThreadInformation(
|
|
|
254
914
|
frames: profile.frames,
|
|
255
915
|
stacks: profile.stacks,
|
|
256
916
|
thread_metadata: {
|
|
257
|
-
[
|
|
258
|
-
name:
|
|
917
|
+
[PROFILER_THREAD_ID_STRING]: {
|
|
918
|
+
name: PROFILER_THREAD_NAME,
|
|
259
919
|
},
|
|
260
920
|
},
|
|
261
921
|
} ;
|
|
@@ -273,12 +933,12 @@ function createProfilingEvent(client, profile, event) {
|
|
|
273
933
|
}
|
|
274
934
|
|
|
275
935
|
return createProfilePayload(client, profile, {
|
|
276
|
-
release: _nullishCoalesce(event.release, () => ( '')),
|
|
277
|
-
environment: _nullishCoalesce(event.environment, () => ( '')),
|
|
278
|
-
event_id: _nullishCoalesce(event.event_id, () => ( '')),
|
|
279
|
-
transaction: _nullishCoalesce(event.transaction, () => ( '')),
|
|
936
|
+
release: _nullishCoalesce$1(event.release, () => ( '')),
|
|
937
|
+
environment: _nullishCoalesce$1(event.environment, () => ( '')),
|
|
938
|
+
event_id: _nullishCoalesce$1(event.event_id, () => ( '')),
|
|
939
|
+
transaction: _nullishCoalesce$1(event.transaction, () => ( '')),
|
|
280
940
|
start_timestamp: event.start_timestamp ? event.start_timestamp * 1000 : Date.now(),
|
|
281
|
-
trace_id: _nullishCoalesce(_optionalChain$1([event, 'access', _ => _.contexts, 'optionalAccess', _2 => _2['trace'], 'optionalAccess', _3 => _3['trace_id']]), () => ( '')),
|
|
941
|
+
trace_id: _nullishCoalesce$1(_optionalChain$1([event, 'access', _ => _.contexts, 'optionalAccess', _2 => _2['trace'], 'optionalAccess', _3 => _3['trace_id']]), () => ( '')),
|
|
282
942
|
profile_id: profile.profile_id,
|
|
283
943
|
});
|
|
284
944
|
}
|
|
@@ -345,7 +1005,7 @@ function createProfilePayload(
|
|
|
345
1005
|
name: transaction,
|
|
346
1006
|
id: event_id,
|
|
347
1007
|
trace_id: trace_id || '',
|
|
348
|
-
active_thread_id:
|
|
1008
|
+
active_thread_id: PROFILER_THREAD_ID_STRING,
|
|
349
1009
|
},
|
|
350
1010
|
};
|
|
351
1011
|
|
|
@@ -364,7 +1024,6 @@ function createProfileChunkPayload(
|
|
|
364
1024
|
{
|
|
365
1025
|
release,
|
|
366
1026
|
environment,
|
|
367
|
-
start_timestamp,
|
|
368
1027
|
trace_id,
|
|
369
1028
|
profiler_id,
|
|
370
1029
|
chunk_id,
|
|
@@ -384,7 +1043,6 @@ function createProfileChunkPayload(
|
|
|
384
1043
|
const profile = {
|
|
385
1044
|
chunk_id: chunk_id,
|
|
386
1045
|
profiler_id: profiler_id,
|
|
387
|
-
timestamp: new Date(start_timestamp).toISOString(),
|
|
388
1046
|
platform: 'node',
|
|
389
1047
|
version: CONTINUOUS_FORMAT_VERSION,
|
|
390
1048
|
release: release,
|
|
@@ -403,7 +1061,6 @@ function createProfileChunkPayload(
|
|
|
403
1061
|
* Creates a profiling chunk envelope item, if the profile does not pass validation, returns null.
|
|
404
1062
|
*/
|
|
405
1063
|
function createProfilingChunkEvent(
|
|
406
|
-
start_timestamp,
|
|
407
1064
|
client,
|
|
408
1065
|
options,
|
|
409
1066
|
profile,
|
|
@@ -414,10 +1071,9 @@ function createProfilingChunkEvent(
|
|
|
414
1071
|
}
|
|
415
1072
|
|
|
416
1073
|
return createProfileChunkPayload(client, profile, {
|
|
417
|
-
release: _nullishCoalesce(options.release, () => ( '')),
|
|
418
|
-
environment: _nullishCoalesce(options.environment, () => ( '')),
|
|
419
|
-
|
|
420
|
-
trace_id: _nullishCoalesce(identifiers.trace_id, () => ( '')),
|
|
1074
|
+
release: _nullishCoalesce$1(options.release, () => ( '')),
|
|
1075
|
+
environment: _nullishCoalesce$1(options.environment, () => ( '')),
|
|
1076
|
+
trace_id: _nullishCoalesce$1(identifiers.trace_id, () => ( '')),
|
|
421
1077
|
chunk_id: identifiers.chunk_id,
|
|
422
1078
|
profiler_id: identifiers.profiler_id,
|
|
423
1079
|
});
|
|
@@ -754,7 +1410,6 @@ function stopSpanProfile(span, profile_id) {
|
|
|
754
1410
|
}
|
|
755
1411
|
|
|
756
1412
|
const profile = CpuProfilerBindings.stopProfiling(profile_id, 0);
|
|
757
|
-
|
|
758
1413
|
DEBUG_BUILD && logger.log(`[Profiling] stopped profiling of transaction: ${spanToJSON(span).description}`);
|
|
759
1414
|
|
|
760
1415
|
// In case of an overlapping span, stopProfiling may return null and silently ignore the overlapping profile.
|
|
@@ -963,8 +1618,10 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
963
1618
|
logger.log(`[Profiling] Failed to collect profile for: ${_optionalChain([this, 'access', _10 => _10._chunkData, 'optionalAccess', _11 => _11.id])}, the chunk_id is missing.`);
|
|
964
1619
|
return;
|
|
965
1620
|
}
|
|
966
|
-
|
|
967
|
-
|
|
1621
|
+
|
|
1622
|
+
const profile = this._stopChunkProfiling(this._chunkData);
|
|
1623
|
+
|
|
1624
|
+
if (!profile) {
|
|
968
1625
|
DEBUG_BUILD && logger.log(`[Profiling] _chunkiledStartTraceID to collect profile for: ${this._chunkData.id}`);
|
|
969
1626
|
return;
|
|
970
1627
|
}
|
|
@@ -973,17 +1630,11 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
973
1630
|
}
|
|
974
1631
|
|
|
975
1632
|
DEBUG_BUILD && logger.log(`[Profiling] Profile chunk ${this._chunkData.id} sent to Sentry.`);
|
|
976
|
-
const chunk = createProfilingChunkEvent(
|
|
977
|
-
this._chunkData.
|
|
978
|
-
this.
|
|
979
|
-
this.
|
|
980
|
-
|
|
981
|
-
{
|
|
982
|
-
chunk_id: this._chunkData.id,
|
|
983
|
-
trace_id: this._chunkData.startTraceID,
|
|
984
|
-
profiler_id: this._profilerId,
|
|
985
|
-
},
|
|
986
|
-
);
|
|
1633
|
+
const chunk = createProfilingChunkEvent(this._client, this._client.getOptions(), profile, {
|
|
1634
|
+
chunk_id: this._chunkData.id,
|
|
1635
|
+
trace_id: this._chunkData.startTraceID,
|
|
1636
|
+
profiler_id: this._profilerId,
|
|
1637
|
+
});
|
|
987
1638
|
|
|
988
1639
|
if (!chunk) {
|
|
989
1640
|
DEBUG_BUILD && logger.log(`[Profiling] Failed to create profile chunk for: ${this._chunkData.id}`);
|
|
@@ -1026,11 +1677,21 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
1026
1677
|
});
|
|
1027
1678
|
}
|
|
1028
1679
|
|
|
1680
|
+
/**
|
|
1681
|
+
* Stops the profile and clears chunk instrumentation from global scope
|
|
1682
|
+
* @returns void
|
|
1683
|
+
*/
|
|
1684
|
+
_stopChunkProfiling(chunk) {
|
|
1685
|
+
this._teardownSpanChunkInstrumentation();
|
|
1686
|
+
return CpuProfilerBindings.stopProfiling(chunk.id, ProfileFormat.CHUNK);
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1029
1689
|
/**
|
|
1030
1690
|
* Starts the profiler and registers the flush timer for a given chunk.
|
|
1031
1691
|
* @param chunk
|
|
1032
1692
|
*/
|
|
1033
1693
|
_startChunkProfiling(chunk) {
|
|
1694
|
+
this._setupSpanChunkInstrumentation();
|
|
1034
1695
|
CpuProfilerBindings.startProfiling(chunk.id);
|
|
1035
1696
|
DEBUG_BUILD && logger.log(`[Profiling] starting profiling chunk: ${chunk.id}`);
|
|
1036
1697
|
|
|
@@ -1045,6 +1706,32 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
1045
1706
|
chunk.timer.unref();
|
|
1046
1707
|
}
|
|
1047
1708
|
|
|
1709
|
+
/**
|
|
1710
|
+
* Attaches profiling information to spans that were started
|
|
1711
|
+
* during a profiling session.
|
|
1712
|
+
*/
|
|
1713
|
+
_setupSpanChunkInstrumentation() {
|
|
1714
|
+
if (!this._client) {
|
|
1715
|
+
DEBUG_BUILD &&
|
|
1716
|
+
logger.log('[Profiling] Failed to collect profile, sentry client was never attached to the profiler.');
|
|
1717
|
+
return;
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
getGlobalScope().setContext('profile', {
|
|
1721
|
+
profiler_id: this._profilerId,
|
|
1722
|
+
});
|
|
1723
|
+
|
|
1724
|
+
this._client.on('beforeSendEvent', e => this._assignThreadIdContext(e));
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
/**
|
|
1728
|
+
* Clear profiling information from global context when a profile is not running.
|
|
1729
|
+
*/
|
|
1730
|
+
_teardownSpanChunkInstrumentation() {
|
|
1731
|
+
const globalScope = getGlobalScope();
|
|
1732
|
+
globalScope.setContext('profile', {});
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1048
1735
|
/**
|
|
1049
1736
|
* Initializes new profile chunk metadata
|
|
1050
1737
|
*/
|
|
@@ -1052,11 +1739,34 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
1052
1739
|
this._chunkData = {
|
|
1053
1740
|
id: uuid4(),
|
|
1054
1741
|
startTraceID: traceId,
|
|
1055
|
-
startTimestampMS: timestampInSeconds(),
|
|
1056
1742
|
timer: undefined,
|
|
1057
1743
|
};
|
|
1058
1744
|
}
|
|
1059
1745
|
|
|
1746
|
+
/**
|
|
1747
|
+
* Assigns thread_id and thread name context to a profiled event.
|
|
1748
|
+
*/
|
|
1749
|
+
_assignThreadIdContext(event) {
|
|
1750
|
+
if (!_optionalChain([event, 'optionalAccess', _13 => _13['contexts'], 'optionalAccess', _14 => _14['profile']])) {
|
|
1751
|
+
return;
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
if (!event.contexts) {
|
|
1755
|
+
return;
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
// @ts-expect-error the trace fallback value is wrong, though it should never happen
|
|
1759
|
+
// and in case it does, we dont want to override whatever was passed initially.
|
|
1760
|
+
event.contexts['trace'] = {
|
|
1761
|
+
...(_nullishCoalesce(_optionalChain([event, 'access', _15 => _15.contexts, 'optionalAccess', _16 => _16['trace']]), () => ( {}))),
|
|
1762
|
+
data: {
|
|
1763
|
+
...(_nullishCoalesce(_optionalChain([event, 'access', _17 => _17.contexts, 'optionalAccess', _18 => _18['trace'], 'optionalAccess', _19 => _19['data']]), () => ( {}))),
|
|
1764
|
+
['thread.id']: PROFILER_THREAD_ID_STRING,
|
|
1765
|
+
['thread.name']: PROFILER_THREAD_NAME,
|
|
1766
|
+
},
|
|
1767
|
+
};
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1060
1770
|
/**
|
|
1061
1771
|
* Resets the current chunk state.
|
|
1062
1772
|
*/
|